Making a 'bullet' class

Gluttard

Active member
Joined
Jan 9, 2008
Messages
44
Programming Experience
Beginner
Hello, I've been making a fun little rocketship program, I've been adding things slowly. You can see it, I'll attach the zip file. Press Enter to exit the program.

Anyways, I want to learn about classes, and I can't find anything on it online that works for me.
I want to shoot 'bullets' out the nose of the rocket, with more than one in existance at one time.
Do I make a new class and give it properties and stuff? How would I do that?
 

Attachments

  • Rocketship.zip
    13.5 KB · Views: 32
Last edited by a moderator:
I originally replied with a link to a tutorial to building a space invaders type game I had been looking at recently then i remembered it was a java tutorial. Sorry, if i find anything else I will let you know.

Lesson - Don't post in forums when you are just out your bed.
 
Last edited:
Anyways, I want to learn about classes, and I can't find anything on it online that works for me.
I want to shoot 'bullets' out the nose of the rocket, with more than one in existance at one time.
Do I make a new class and give it properties and stuff? How would I do that?
What you have now in your form class is the combined functionality of two classes; the form that manages keyboard events and paiting the ship, and the "ship" class with its properties location/image/angle, calculating its movement and the paint implementations. What I did was to split these up, instead of calling the class "ship" I called it "GameObject" because it is the same class that is used for each bullet. I also gave the GameObject its own Timer to bring it to life and have its independent movement. Since it's basically your own code just reordered I think you will understand it without further explanation once read through it, take a look at the attached project. And I changed game exit to Escape key :)

Well, one more comment, notice the ResetTransform call in GameObject Paint method, without this all transformations set by any object would affect all objects afterwards and add up, the transformations have "world" scope on the Graphics instance. When each object do ResetTransform when it's finished the Graphics world is fresh for the next.
 

Attachments

  • vbnet35-RocketShip.zip
    18.7 KB · Views: 27
Back
Top