java - Destroy image object present in grid when an object enters the grid -


i learning game programming. trying make game similar pacman. have made grid x[] , y[] (no using tiled). when sprite in specific grid want destroy food item image within grid , add 1 score. tried use image.destroy(); method didn't worked.

i tried, instead of destroying image change location.

image.drawimage(image,x+25,y+25); created new object long inside specific grid.
game loop not let me destroy image or move outside screen.

i tried

if(sprite in grid){score=score+1;}

so once sprite in grid score keeps on incrementing. want increment of "1" once sprite in specific grid.

any highly appreciated. thanks.

normally grid[y][x] contain values indicating what's there? can enum values empty, wall or fruit.

so when player enters cell grid[player.gety()][player.getx()] == fruit, clear cell empty, add 1 score, , invalidate rectangle of grid on screen.

the render() method check grid[], find empty.. , not draw fruit.

you should have single fruit image or imagebuffer -- doesn't have specific position, acts off-screen source render() function draw whereever needed. doesn't represent single fruit, doesn't destroyed -- nor have position.

unlike sprites (for monsters/ player etc), fruit not expected individually animated/ positioned around screen.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -