-1

ゲームプログラミングを学んでいます。パックマンに似たゲームを作ろうとしています。x[] と y[] でグリッドを作成しました (タイルを使用しません)。スプライトが特定のグリッドにある場合、グリッド内の画像である食品アイテムを破壊し、スコアに 1 を追加します。image.destroy(); を使用しようとしました。方法ですが、うまくいきませんでした。

画像を破壊して場所を変更する代わりに、試しました。

image.drawImage(画像、x+25、y+25); 特定のグリッド内にいる間だけ、新しいオブジェクトが作成されました。
ゲーム ループでは、画像を破棄したり、画面の外に移動したりできませんでした。

私も試しました

if(スプライトがグリッドにある){score=score+1;}

したがって、スプライトがグリッドに入ると、スコアは増加し続けます。スプライトが特定のグリッドに入ったら、「1」の増分が必要です。

どんな助けでも大歓迎です。ありがとう。

4

1 に答える 1

0

Normally your grid[y][x] would contain values indicating what's there? This can be an enum with values EMPTY, WALL or FRUIT.

So when the player enters a cell with grid[player.getY()][player.getX()] == FRUIT, clear the cell to EMPTY, add 1 to the score, and invalidate that rectangle of the grid on screen.

The render() method will then check grid[], find it is empty.. and not draw any fruit.

You should have a single fruit image or ImageBuffer -- this doesn't have any specific position, but acts as an off-screen source for the render() function to draw it whereever it is needed. This doesn't represent any single fruit, so it doesn't get destroyed -- nor does it have a position.

Unlike sprites (for monsters/ player etc), fruit are not expected to be individually animated/ positioned around the screen.

于 2013-07-28T02:51:21.207 に答える