awt - How do I delete objects in a Java game -
i have object in java game going coin, rect made
g.setcolor(color.yellow); g.fillrect(x, y, 16, 16); i have collisions set give player points when touch it, , works fine, how make delete after touched? points keep going up.
the thing think of recolor make wasn't there, thats far same thing.
you should have rectangle class, or rather coin class, e.g.
public class coin { int xpos; int ypos; int width; int height; // giving player points int points; // constructors, etc // e.g. public int getxpos(), public int getypos().. } at start, have arraylist of coin, e.g.
arraylist<coin> coins = new arraylist<coin>(); in drawing method,
for (coin c : coins) { g.filloval(c.getxpos(), c.getypos(), c.getwidth(), c.getheight()); } when player collides coin, you'll need remove arraylist.
to make more extensible, can define interface collectible, , make collectible in-game objects such coin in case implement collectible interface.
Comments
Post a Comment