I am creating my very first game project, but I have no idea how to actually start the code for the boundaries. The game is pretty much an ordinary kid maze game which you are suppose to find your way from point A or point B. Right now I have 2 ideas on how to set the boundaries:
1: (If Java is smart enough), where ever there is black (the boundaries), the person cannot go past it. EASY WAY
2: Figure out the coordinates for all of the black lines and do not allow the person to go past any of it. HARD WAY
OR are none of these valid ways?
Here is my code right now for the play state
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| package gameOne;
import org.newdawn.slick.*; import org.newdawn.slick.state.*;
public class PlayFirstGame extends BasicGameState{
Image maze; Image player; float x = 50; float y = 50; float speed = .25f; public PlayFirstGame(int state){ } public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{ maze = new Image("res1/maze3.jpg"); player = new Image("res1/normalFace.png"); } public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{ g.drawImage(maze, 82, 15); g.drawImage(player, x, y); } public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{ Input input = gc.getInput();
if(input.isKeyDown(Input.KEY_UP)){ y = y - speed * delta; } if(input.isKeyDown(Input.KEY_DOWN)){ y = y + speed * delta; } if(input.isKeyDown(Input.KEY_LEFT)){ x = x - speed * delta; } if(input.isKeyDown(Input.KEY_RIGHT)){ x = x + speed * delta; } } public int getID(){ return 1; } } |
Pretty much this code is just the background, the player, and the ability to move the player around.