simple motion blur

Thanks :slight_smile:
i will not release the source code because I want to make a really good game with it :slight_smile: (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 :wink:

Ah I just wanted to see how you do the physics and explosion :smiley:

ok. :slight_smile: My physics are using polygon collision as I showed above, and the javax.vecmath library (for vectors).
my explosions are just a list of polygons, that have a certain amount of life. Their alpha = currentLife / initialLife.
i decrease their life by the last frame (ms), and their colour is:
red = 1;
green = random.nextfloat();
blue = 0;
if their life <= 0 then remove. When I create them I give them a random x & y velocity

something like this: http://paraschopra.com/tutorials/particle-systems/

And how did you do the physics when two entities collide? Like when the player and a rock hit each other, how would you figure out the resulting velocities?


//When collision between player and asteroid happens, player.Recoil(asteroid.getPosition(), 100) is called.
//_vec2Object = position of asteroid
//speed = how fast the player should be pushed back
public void Recoil(Vector2f _vec2Object, float _fSpeed) 
	{
                //reverse players speed and divide by 2
		m_vec2Velocity.x *= -0.5f;
		m_vec2Velocity.y *= -0.5f;
		
                //get direction between player and asteroid
		Vector2f vec2Direction = new Vector2f();
		vec2Direction.x = _vec2Object.x-m_vec2Position.x;
		vec2Direction.y = _vec2Object.y-m_vec2Position.y;
		vec2Direction.normalize(); 
                //change the players velocity by the recoil speed and the direction between the player and the asteroid
		m_vec2Velocity.x -= _fSpeed * vec2Direction.x;
		m_vec2Velocity.y -= _fSpeed * vec2Direction.y;
	}

as to the asteroid: it splits apart into a random amount of smaller ones which all have random velocities.
after the collision between the player and the asteroid, the player becomes invincible for a second (so it can’t collide with the new asteroids) ;D

Ohhh…I thought it would be more complicated than that. Hahaha thanks that helps :smiley:

no problem :wink: