Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualwarnexus

Posted 01 June 2013 - 07:45 PM

The big picture idea of a class is re-usability.

 

You will a Sprite class to establish that this class will be updated and drawn on screen and have some idea of position and velocity 

 

A Vector2D class(this is just a class that contains values of type double x and y to describe the object's position and velocity followed by methods for basic arithmetic (+,-,*)

 

A Collidable interface that establishes collision methods.

 

A GameComponent interface that establishes the idea of updating and drawing the objects

 

A Game class that loads your game.

 

Example code in Java:

 

The Game can also extends JPanel or Canvas instead. The choice is yours.

 

public class Game extends Canvas
{
 
}
public class Alien extends Sprite implements Collidable
{
 
}

 

 

public class Sprite implements GameComponent
{ 
 
private Vector2D position;
private Vector2D velocity;
 
public void update(long milliseconds)
{
 
}
 
public void draw(Graphics g)
{
 
}
 
}

public interface GameComponent
{
 
public void update(long milliseconds);
 
public void draw(Graphics g);
}

Example how to create one row of 5 different aliens using a for loop:

 

int offSet = 135;
// create a row of Aliens
 
for(int row = 0;row < getWidth() ;row += offSet  )
{
 
Alien alien = new Alien(row,0);
add(alien);
 
}

#6warnexus

Posted 01 June 2013 - 07:36 PM

The big picture idea of a class is re-usability.

 

You will a Sprite class to establish that this class will be updated and drawn on screen and have some idea of position and velocity 

 

A Vector2D class(this is just a class that contains values of type double x and y to describe the object's position and velocity followed by methods for basic arithmetic (+,-,*)

 

A Collidable interface that establishes collision methods.

 

A GameComponent interface that establishes the idea of updating and drawing the objects

 

A Game class that loads your game.

 

Example code in Java:

 

The Game can also extends JPanel or Canvas instead. The choice is yours.

 

public class Game extends Canvas
{
 
}
public class Alien extends Sprite implements Collidable
{
 
}

 

 

public class Sprite implements GameComponent
{ 
 
private Vector2D position;
private Vector2D velocity;
 
public void update(long milliseconds)
{
 
}
 
public void draw(Graphics g)
{
 
}
 
}

public interface GameComponent
{
 
public void update(long milliseconds);
 
public void draw(Graphics g);
}

#5warnexus

Posted 01 June 2013 - 07:35 PM

The big picture idea of a class is re-usability.

 

You will a Sprite class to establish that this class will be updated and drawn on screen and have some idea of position and velocity 

 

A Vector2D class(this is just a class that contains values of type double x and y to describe the object's position and velocity followed by methods for basic arithmetic (+,-,*)

 

A Collidable interface that establishes collision methods.

 

A GameComponent interface that establishes the idea of updating and drawing the objects

 

A Game class that loads your game.

 

Example code in Java:

 

The Game can also extends JPanel or Canvas instead. The choice is yours.

public class Game extends Canvas
{
 
}
public class Alien extends Sprite implements Collidable
{
 
}

 

 

public class Sprite implements GameComponent
{ 
 
private Vector2D position;
private Vector2D velocity;
 
public void update(long milliseconds)
{
 
}
 
public void draw(Graphics g)
{
 
}
 
}

public interface GameComponent
{
 
public void update(long milliseconds);
 
public void draw(Graphics g);
}

#4warnexus

Posted 01 June 2013 - 07:32 PM

The big picture idea of a class is re-usability.

 

You will a Sprite class to establish that this class will be updated and drawn on screen and have some idea of position and velocity 

 

A Vector2D class(this is just a class that contains values of type double x and y to describe the object's position and velocity followed by methods for basic arithmetic (+,-,*)

 

A Collidable interface that establishes collision methods.

 

A GameComponent interface that establishes the idea of updating and drawing the objects

 

Example code in Java:

 

 

public class Alien extends Sprite implements Collidable
{
 
}

 

 

public class Sprite implements GameComponent
{ 
 
private Vector2D position;
private Vector2D velocity;
 
public void update(long milliseconds)
{
 
}
 
public void draw(Graphics g)
{
 
}
 
}

public interface GameComponent
{
 
public void update(long milliseconds);
 
public void draw(Graphics g);
}

#3warnexus

Posted 01 June 2013 - 07:32 PM

The big picture idea of a class is re-usability.

 

You will a Sprite class to establish that this class will be updated and drawn on screen and have some idea of position and velocity 

 

A Vector2D class(this is just a class that contains values of type double x and y to describe the object's position and velocity followed by methods for basic arithmetic (+,-,*)

 

A Collidable interface that establishes collision methods.

 

A GameComponent interface that establishes the idea of updating and drawing the objects

 

Example code in Java:

 

 

public class Alien extends Sprite implements Collidable
{
 
}

 

 

public class Sprite implements GameComponent
{ 
 
private Vector2D position;
private Vector2D velocity;
 
public void update(long milliseconds)
{
 
}
 
public void draw(Graphics g)
{
 
}
 
}
[code]
 
[code]
public interface GameComponent
{
 
public void update(long milliseconds);
 
public void draw(Graphics g);
}

#2warnexus

Posted 01 June 2013 - 07:28 PM

The big picture idea of a class is re-usability.

 

You will a Sprite class to establish that this class will be updated and drawn on screen and have some idea of position and velocity 

 

A Vector2D class(this is just a class that contains values of type double x and y to describe the object's position and velocity followed by methods for basic arithmetic (+,-,*)

 

A Collidable interface that establishes collision methods.

 

A GameComponent interface that establishes the idea of updating and drawing the objects

 

Example code in Java:

 

public class Alien extends Sprite implements Collidable
{
 
}

 

public class Sprite implements GameObjects
{ 
 
private Vector2D position;
private Vector2D velocity;
 
public void update(long milliseconds)
{
 
}
 
public void draw(Graphics g)
{
 
}
 
}
[code]
 
[code]
public interface GameComponent
{
 
public void update(long milliseconds);
 
public void draw(Graphics g);
}

PARTNERS