Hey, so we need to make a pinball machine kinda thing for an assignement, and i need the to do something when 2 pinballs collide, now both circles have a diiferant class to modify there speed etc. how could I call Object1 in Object2. what should i use to do this
|
Java
Two Circles Coliding in sperate class ? |
|
Mar 23, 2017 10:48 PM
(This post was last modified: Mar 23, 2017 10:51 PM by ☕⚛Austin⚛☕.)
You should have an ArrayList(Object based array with no fixed size) of all your game objects. So this is a polymorphism problem. You should probably have an interface GameObject which has tick(); and render(); and then a class called BaseGameEntity immplements GameObject. In Game Object initialize a public static final ArrayList<Game Object> gameobjects and in the constructor simply add this Object to your list.
GameObject.java PHP Code PHP Code Main.java PHP Code This code isn't ideal for a real game I left out threading and a physics loop but it should resemble something like that. Typed this out in edit comment so the syntax might be off.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
(Mar 23, 2017 10:48 PM)☕⚛Austin⚛☕ Wrote: You should have an ArrayList(Object based array with no fixed size) of all your game objects. So this is a polymorphism problem. You should probably have an interface GameObject which has tick(); and render(); and then a class called BaseGameEntity immplements GameObject. In Game Object initialize a public static final ArrayList<Game Object> gameobjects and in the constructor simply add this Object to your list. Its not exactly a game, I have 5 classes, demo which had the objects, game time any anything to do with the actual game, pinballobject1 which has everything to do with the first pinball, pinballobject2 same thing as 1 but for the 2nd pinball, machine which has the size of canvas and most of the values and canvas, is there a way me can can talk on skype ? |
|
|

