Methods Summary |
---|
public int | getX()Get the X coordinate of the cell that contains the food item.
return cellX;
|
public int | getY()Get the Y coordinate of the cell that contains the food item.
return cellY;
|
public boolean | isAt(int cx, int cy)Returns true if the food item is at the given cell.
return ((this.cellX == cx) && (this.cellY == cy));
|
public void | paint(javax.microedition.lcdui.Graphics g)Paint the piece of food.
g.setColor(WormPit.FOOD_COLOUR);
g.fillRect(x+1, y+1, WormPit.CELL_SIZE-2, WormPit.CELL_SIZE-2);
g.setColor(WormPit.DRAW_COLOUR);
g.drawRect(x, y, WormPit.CELL_SIZE-1, WormPit.CELL_SIZE-1);
|
public void | regenerate()Regenerate the food item. Whenever the worm eats a piece of
food, this method is called.
int loc = (int)(System.currentTimeMillis() % arenaSize);
cellY = (int)(loc / WormPit.CellWidth);
cellX = (int)(loc % WormPit.CellHeight);
y = cellY * WormPit.CELL_SIZE; // Cache to save time during paint
x = cellX * WormPit.CELL_SIZE; // Cache to save time during paint
|