Thanks
i will not release the source code because I want to make a really good game with it (atleast not until after its done), but you should look at this code here:
http://www.java-gaming.org/index.php?topic=22773.0
This gives a basic applet and motion blur example working (beware that there will be dirt trails in this one: just set colour with float values instead of integer values, and set it depending on the last frame time (as i said above).
A good tutorial on asteroids is here: although the collision detection is not good (distance not pixel perfect), so use mine (see below)
http://www.giosoft.net/Development/Java-Asteroids-Tutorial.html
For the ship: it is a java polygon: http://download.oracle.com/javase/1.4.2/docs/api/java/awt/Polygon.html
it has 4 points (in counter clockwise order). Draw the polygon with graphics.fillPolygon() method.
start with a list of points, (java arraylist or something similar), and each frame reset your Polygon and add the rotated vertices.
(this needs javax.vecmath library for vectors by the way)
Sorry for my c++ style naming conventions:
//m_ = class member variable
//m_i... = int variable
//m_f... = float variable
//m_list... = Java util ArrayList
//m_vec2... javax.vecmath Vector2f
//CLOCK.GetDeltaTick() //get the time (milliseconds) of the last frame
for (Vector2f point: m_listPoints)
{
Vector2f rotated = RotatePoint(point);
int x = (int)(rotated.x*m_fSize + m_vec2Position.x);
int y = (int)(rotated.y*m_fSize + m_vec2Position.y);
m_polygon.addPoint(x, y);
iPoint++;
}
private Vector2f RotatePoint(Vector2f point)
{
Vector2f result = new Vector2f();
result.x = (float) (point.x*Math.cos(m_fRotation) - point.y*Math.sin(m_fRotation));
result.y = (float) (point.x*Math.sin(m_fRotation) + point.y*Math.cos(m_fRotation));
return result;
}
for moving the ship:
public void Forward()
{
m_vec2Velocity.x += m_fSpeed * Math.cos(m_fRotation-Math.PI/2) * CLOCK.GetDeltaTick();
m_vec2Velocity.y += m_fSpeed * Math.sin(m_fRotation-Math.PI/2) * CLOCK.GetDeltaTick();
}
Asteroids and particles are also made out of polygons.
The points in the polygon seem random,
each point is made like this:
where i is a for loop variable (for (int i = 0; i < iNumPoints; i++)
float angle = (float) ((Math.PI*2) / iNumPoints)*i;
vec2Pos.x += fRandomSize * Math.cos(angle);
vec2Pos.y += fRandomSize * Math.sin(angle);
for collisions:
you have 2 Java Polygons.
Loop through one of the polygon’s points.
for each point, see if the other polygon contains that point http://download.oracle.com/javase/1.4.2/docs/api/java/awt/Polygon.html#contains(int,%20int)
if it does, you have a collision.
hope that helps