-
Notifications
You must be signed in to change notification settings - Fork 0
Snake Grid
rp3002 edited this page Aug 26, 2024
·
1 revision
The SnakeGrid
class is a designed specifically for the Snake mini-game. This extends the general Grid
class and provides additional functionality such as checking for collisions and having grid positions for rendering.
package com.csse3200.game.components.minigame.snake;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Vector2;
import com.csse3200.game.components.minigame.Grid;
The SnakeGrid
class represents a grid specifically tailored for the Snake mini-game. It includes default dimensions and methods that assist with snake-specific functionality, such as detecting collisions and having grid positions for rendering.
-
Description:
- New instance of the
SnakeGrid
with default dimensions of 20x20 cells.
- New instance of the
-
Parameters:
-
int x
andint y
: The x-coordinate/ y-coordinate of the cell to check.
-
-
Returns:
-
boolean
:true
if the specified cell is occupied (indicating a potential collision),false
otherwise.
-
-
Description:
- Checks whether a particular cell on the grid is occupied. This is primarily used to detect collisions with the snake's body or other obstacles.
-
Parameters:
-
Vector2 gridPosition
: The position on the grid that needs to be converted to world coordinates. -
int cellSize
: The size of each cell in pixels.
-
-
Returns:
-
Vector2
: The corresponding world position for rendering.
-
-
Description:
- Calculate the offset to centre the grid and calculate the world position