Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

i am trying to make a java game. i have a spaceShip(player) on left. you can go up and down, and shoot bullets. from right side enemy keep on coming and shoot bullets. you have to avoid them and kill as many you can.

i want random items coming from right side of window. and x-=dx going left slowly.

u start with normal bullets, one bullet per timer.

item1 - get half life bar
item2 - get full life bar
item3 - bullets change - shoot double bullets at same time.
item4 - bullets change - bullet goes up down up down....

i will be only have two types of item. can some one tell me a good struct in oop for this.

i know the basic of oop and game programming but i am still new at it. so try to explain as much as you can plz.

share|improve this question
    
You haven't actually asked a question. "What's the best way to get started?" is close to what you want I think, but that is explicitly off-topic here according to the FAQ. –  Sean Middleditch Apr 7 '13 at 3:53
add comment

closed as not a real question by Sean Middleditch, bummzack, Josh Petrie, Byte56, Anko Apr 8 '13 at 8:29

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

When designing an item system, or in reality any system requiring collections of whatever, you should begin by considering what type of functionality is shared by all objects in these collections. For instance, all items may need to be rendered to the screen, all items have a quantity, all items require collision detection, etc. So starting with this, begin creating base classes that contain the similar functionality between items, but allow for unique derivations for customized behavior. Here is an example, written in pseudo code.

This first class represents a base class called Item, which would extend the abstract class renderable. Whenever extending from another class, always ensure you consider whether or not your class "Is A" or "Contains A". For instance, an item "Is A" renderable object, or does it "Contain A" renderable object. Depending on your architecture, this could be different.

This item class implements basic functionality and variables that would be common to all types of items, such as a name, quantity, and the callback OnCollision that is triggered whenever something collides with it.

class item implements renderable
{
  string mName;
  int mQuantity;

   Draw();
   Update();
   OnCollision();
}

Next is the item class Banana, which is extended from Item. Notice i specified override for the functions within banana, meaning that it is receiving this base functionality from item, but is choosing to override it to provide customized behavior based on whatever banana needs to do.

class Banana implements item
{
  overrides Update();
  overrides Draw();
  overrides OnCOllision();
}
share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.