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

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -