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
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){
}
// load all fonts, graphics, sounds, etc
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{
maze = new Image("res1/maze3.jpg");
player = new Image("res1/normalFace.png");
}
//draw stuff on the screen
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{
g.drawImage(maze, 82, 15);
g.drawImage(player, x, y);
}
//animation and game logic(AI, user input, etc)
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{
//movement
Input input = gc.getInput();
//up
if(input.isKeyDown(Input.KEY_UP)){
y = y - speed * delta;//delta makes the speed run the same on ANY computer
}
//down
if(input.isKeyDown(Input.KEY_DOWN)){
y = y + speed * delta;
}
//left
if(input.isKeyDown(Input.KEY_LEFT)){
x = x - speed * delta;
}
//right
if(input.isKeyDown(Input.KEY_RIGHT)){
x = x + speed * delta;
}
// add foot prints as they move
//make foot prints disappear after X amount of steps
//if they reach a dead end, failFace
//if they reach the end, winFace
}
public int getID(){
return 1;//play is 1
}
}
Pretty much this code is just the background, the player, and the ability to move the player around.