4 Replies - 560 Views - Last Post: 21 June 2009 - 08:33 AM Rate Topic: -----

#1 xiva  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 21-June 09

Classes help

Post icon  Posted 21 June 2009 - 06:20 AM

Hi im new to c++ and im making a clone of space invaders, using c++ and DarkGDK. Im not sure how i would go about coding the shooting of the bullet, so that i could shoot from wherever my ship is, and also how i could fire multiple bullets after each other with having to move the bullet back down again. By this i mean that it would never "run out of ammo".

Sorry if you can't understand, ask me (ill try to rephrase it) or add me on msn at [email protected]

Heres my code so far.

This is the class im using for the shooting. It really isn't much because im not sure what to do. Help is appreciated.
class tbullet {
	int Damage;
	int Speed;
public:
	void Move();
	void Fire (int spd, int dmg);



};


xiva

Is This A Good Question/Topic? 0
  • +

Replies To: Classes help

#2 bodom658  Icon User is offline

  • Villiage Idiom
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,123
  • Joined: 22-February 08

Re: Classes help

Posted 21 June 2009 - 06:50 AM

So what is basically happening when you fire some object is that it is fired from an initial position, travels in 2D and collides with an alien, or with a wall.

So, basically you need a class like yours, but with a few more variables.

Something along the lines of
class Bullet
{
	 public:
		  int damage; // in case some bullets are stronger than others?
		  int speed;	// speed of the bullet (usually in pixels)
		  int position[2] // position vector.
		  bool alive;	  // Useful for determining when to draw the bullet
		  // have another variable for the sprite
		  Bullet(/* load sprite here when you call this */);	// Constructor
		  void UpdatePosn();  // Updates the position
		  void Fire();		   // Fires the bullet
};



Hope this helps!
Was This Post Helpful? 1
  • +
  • -

#3 xiva  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 21-June 09

Re: Classes help

Posted 21 June 2009 - 07:17 AM

Never mind

This post has been edited by xiva: 21 June 2009 - 07:50 AM

Was This Post Helpful? 0
  • +
  • -

#4 xiva  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 21-June 09

Re: Classes help

Posted 21 June 2009 - 07:50 AM

class Bullet
{
	 public:
		  int damage; // in case some bullets are stronger than others?
damage = 100 //????
		  int speed;	// speed of the bullet (usually in pixels)
speed = 3.0f // ?????
		  int position[2] // position vector. Whats this for ?????
		  bool alive = true;	  // Useful for determining when to draw the bullet
		  // have another variable for the sprite
		  Bullet(/* load sprite here when you call this */);	// Constructor how do i load a sprite ???
		  void UpdatePosn();  // Updates the position
		  void Fire();		   // Fires the bullet
//How do i "initiate this" ??
};


I hope thats right. Or am i getting the wrong end of the stick ??
Was This Post Helpful? 0
  • +
  • -

#5 xiva  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 21-June 09

Re: Classes help

Posted 21 June 2009 - 08:33 AM

could anybody help ??

This post has been edited by xiva: 21 June 2009 - 08:34 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1