Commits

Valerio Riva  committed 96938dc Merge

merge

  • Participants
  • Parent commits 1ba878e, fedf379

Comments (0)

Files changed (8)

File levels/level.txt

File contents unchanged.

File src/ggj/bloodrace/Game.java

 	public void render(GameContainer gc, Graphics g) throws SlickException {
 		g.setBackground(new Color(104, 17, 1));
 		for (Entity entity : entities)
-			if (entity.draw() != null)
+			if (entity.draw() != null && entity.isVisible())
 				g.drawAnimation(entity.draw(), entity.getShape().getX(), entity.getShape().getY(), Color.white);
 	}
 

File src/ggj/bloodrace/RaceGame.java

 import ggj.bloodrace.entities.HorizontalBottom;
 import ggj.bloodrace.entities.HorizontalTop;
 import ggj.bloodrace.entities.Player;
+import ggj.bloodrace.entities.obstacles.Obstacle;
 import ggj.bloodrace.game.levels.ElementsType;
 import ggj.bloodrace.game.levels.Level;
 import ggj.bloodrace.utils.Constants;
 		super(level);
 	}
 
+	Player player1;
+	Player player2;
+	Player player3;
+	Player player4;
 	protected static String title = "Race";
 
 	public void init(GameContainer gc) throws SlickException {
 		HorizontalBottom bottom = new HorizontalBottom();
 		HorizontalTop top = new HorizontalTop();
-		
-		Player player1 = new Player(collisionHandler,gc,entities);
-		Player player2 = new Player(collisionHandler,gc,entities);
-		Player player3 = new Player(collisionHandler,gc,entities);
-		Player player4 = new Player(collisionHandler,gc,entities);
+
+		player1 = new Player(collisionHandler, gc, entities);
+		player2 = new Player(collisionHandler, gc, entities);
+		player3 = new Player(collisionHandler, gc, entities);
+		player4 = new Player(collisionHandler, gc, entities);
 
 		//GENERAZIONE DEL LIVELLO
 		
 			
 				Entity block = ElementsType.getBlock(ElementsType.getById(element));
 				block.setPosition(posx, posy);
-				
 				entities.add(block);
-				System.out.println("x: "+posx+" posy: "+posy+" element: "+element);
 			}
 		}
 		
 		Sound fx = new Sound("resources/music/bloodway.ogg");
 		fx.play();
 	}
+
+	@Override
+	public void render(GameContainer gc, Graphics g) throws SlickException {
+		super.render(gc, g);
+		Integer player1_score = player1.getScore();
+		Integer player2_score = player2.getScore();
+		Integer player3_score = player3.getScore();
+		Integer player4_score = player4.getScore();
+		g.drawString("SCORES - PLAYER 1: " + player1_score + " PLAYER 2: "
+				+ player2_score + " PLAYER 3: " + player3_score + " PLAYER 4: "
+				+ player4_score, 0, 0);
+
+	}
 }

File src/ggj/bloodrace/RaceMain.java

 		AppGameContainer app = new AppGameContainer(new RaceGame( new Level("levels/level.txt")));
 		app.setTargetFrameRate(60);
 		app.setDisplayMode(800, 600, false);
+		app.setShowFPS(false);
 		app.start();
 	}
 }

File src/ggj/bloodrace/entities/Entity.java

 	private int XActionPoint;
 	private int YActionPoint;
 	
+	private boolean visible = true;
+	
 	private HashMap<String,Animation> animations = new HashMap<String,Animation>();
 	
 	private Animation currentAnimation;
 	public void setCollisionHandler(CollisionHandler collisionHandler) {
 		this.collisionHandler = collisionHandler;
 	}
+
+	public boolean isVisible() {
+		return visible;
+	}
+
+	public void setVisible(boolean visible) {
+		this.visible = visible;
+	}
 }

File src/ggj/bloodrace/entities/Ossigeno.java

 		}
 	this.shape = new Rectangle(this.getXPosition(),this.getYPosition(),this.getCurrentAnimation().getCurrentFrame().getWidth(),this.getCurrentAnimation().getCurrentFrame().getHeight());
 	this.setPosition(Constants.OBSTACLE_X_OFFSET, Constants.OBSTACLE_Y_OFFSET);
+	
 	}
 }

File src/ggj/bloodrace/entities/Player.java

 import org.newdawn.slick.command.KeyControl;
 import org.newdawn.slick.geom.Circle;
 
-public class Player extends Entity implements InputProviderListener {	
-	List<ActionCommand> actions = new ArrayList<ActionCommand>();	
+public class Player extends Entity implements InputProviderListener {
+	List<ActionCommand> actions = new ArrayList<ActionCommand>();
 	protected InputProvider provider;
-	protected GameContainer gameContainer;	
+	protected GameContainer gameContainer;
 	protected static int instances = 0;
 	protected int player = instances;
 	protected int life = 5;
-	protected int points = 0; 
+	protected int points = 0;
 	protected int jumping = 0;
 	protected boolean collidesBackground = false;
 	private int jumpAcc = 0;
 				collidesBackground = true;
 				jumping = 0;
 				velocity = 0;
-				setYPosition((int) (target.getYPosition()-shape.getHeight()));
+				setYPosition((int) (target.getYPosition() - shape.getHeight() - 1));
 			}
 		};
 
-		rightCollision = new ActionCollision() {
+		ActionCollision rightCollision = new ActionCollision() {
 			public void execute(Entity me, Entity target) {
-				int rightSide = (int) (getXPosition()+shape.getWidth());
-				int bottomSide = (int) (getYPosition()+shape.getHeight());
-				if (rightSide >= target.getXPosition() && bottomSide >= target.getYPosition()) {
-					setXPosition((int) (target.getXPosition()-shape.getWidth()));
-				}
+
+				setXPosition((int) (target.getXPosition() - shape.getWidth()));
+
 			}
 		};
-		
-		leftCollision = new ActionCollision() {
+
+		ActionCollision leftCollision = new ActionCollision() {
 			public void execute(Entity me, Entity target) {
-				int leftSide = getXPosition();
-				int bottomSide = (int) (getYPosition()+shape.getHeight());
-				if (leftSide <= target.getXPosition() && bottomSide >= target.getYPosition()) {
-					setXPosition((int) (target.getXPosition()+shape.getWidth()));
-				}
+				setXPosition((int) (target.getXPosition() + target.getShape()
+						.getWidth()));
 			}
 		};
 	}
 				e.printStackTrace();
 			}
 		}
-		
+
 		entities.add(top);
 		entities.add(bottom);
 		entities.add(left);
         provider.bindCommand(new KeyControl(Input.KEY_LEFT), moveBackwards);
 	}
 
-	public void update(BasicGame game,int delta) {
+	public void update(BasicGame game, int delta) {
+		moveX();
 		collidesBackground = false;
 		for (ActionCommand action:actions)
 			action.exec();
 		gravity();
-		moveX();
 		updateCollider();
 	}
-	
+
 	protected void gravity() {
-		if (this.jumpAcc>0) this.jumpAcc--;
-		this.velocity = this.velocity+((!collidesBackground)?Constants.GRAVITY:0)-jumpAcc;
-		this.setYPosition(this.getYPosition()+this.velocity);
+		if (this.jumpAcc > 0)
+			this.jumpAcc--;
+		this.velocity = this.velocity
+				+ ((!collidesBackground) ? Constants.GRAVITY : 0) - jumpAcc;
+		this.setYPosition(this.getYPosition() + this.velocity);
 	}
-	
+
 	protected void jump(int acc) {
 		if (jumping == 0 || (jumping == 1 && velocity > -10)) {
 			jumping++;
 			if (jumping == Constants.PLAYER_MAX_JUMPS) {
 				velocity = 0;
 			}
-			jumpAcc+= acc;
+			jumpAcc += acc;
 		}
 	}
-	
+
 	protected void moveX() {
 		if (Xacc != 0) {
-			int mod = speed*unitMovement;
+			int mod = speed * unitMovement;
 			if (Xacc < 0) {
-				mod*= -1;
+				mod *= -1;
 			}
-			setXPosition(getXPosition()+mod);
-			Xacc -= 2;
+			setXPosition(getXPosition() + mod);
+			if (collidesBackground) {
+				if (Xacc > 0)
+					Xacc -= 2;
+				if (Xacc < 0)
+					Xacc += 2;
+			}
 		}
 	}
-	
+
 	protected ActionCommand moveBackwards = new ActionCommand() {
-    	public void exec() {
-    		Xacc = Constants.ACC_X*-1;
-    	}
-	};	
-	
-	protected ActionCommand moveForward = new ActionCommand() {
-    	public void exec() {
-    		Xacc = Constants.ACC_X;
-    	}
+		public void exec() {
+			Xacc = Constants.ACC_X * -1;
+		}
 	};
 
-	protected ActionCommand jumpLow = new ActionCommand() { 
-    	public void exec() {
-    		jump(Constants.ACC_JUMP_LOW);
-    	}
-    };
+	protected ActionCommand moveForward = new ActionCommand() {
+		public void exec() {
+			Xacc = Constants.ACC_X;
+		}
+	};
 
-	protected ActionCommand jumpMedium = new ActionCommand() { 
-    	public void exec() {
-    		jump(Constants.ACC_JUMP_MEDIUM);
-    	}
-    };
+	protected ActionCommand jumpLow = new ActionCommand() {
+		public void exec() {
+			jump(Constants.ACC_JUMP_LOW);
+		}
+	};
 
-	protected ActionCommand jumpHigh = new ActionCommand() { 
-    	public void exec() {
-    		jump(Constants.ACC_JUMP_HIGH);
-    	}
-    };	
+	protected ActionCommand jumpMedium = new ActionCommand() {
+		public void exec() {
+			jump(Constants.ACC_JUMP_MEDIUM);
+		}
+	};
 
-    public void loadAnimation() {
+	protected ActionCommand jumpHigh = new ActionCommand() {
+		public void exec() {
+			jump(Constants.ACC_JUMP_HIGH);
+		}
+	};
+
+	public void loadAnimation() {
 		try {
 			Animation animation = new Animation(new Image[] { new Image(
 					"resources/images/globuloide.png") }, 250);
 		} catch (SlickException e) {
 			e.printStackTrace();
 		}
-    }
-    
+	}
+
 	public void controlPressed(Command action) {
 		((ActionCommand) action).exec();
 	}
 
 	public void controlReleased(Command action) {
 	}
+
+	public int getScore() {
+		return score;
+	}
+
+	public void setScore(int score) {
+		this.score = score;
+	}
 }

File src/ggj/bloodrace/utils/Constants.java

 	public static final int DEFAULT_UNIT_MOVEMENT = 1;
 	public static final int DEFAULT_SPEED = 3;
 	
-	public static final int GRAVITY = 1;
+	public static final int GRAVITY = 1; 
 	
 	public static final int OBSTACLE_SPEED = 0; //4
 	public static final int OBSTACLE_RATIO = 1000;
 	public static final int PLAYER_START_SPACE_X = 25;
 	public static final int PLAYER_MAX_JUMPS = 2;
 	
-	public static final int ACC_X = 60;
+	public static final int ACC_X = 30;
 	public static final int ACC_JUMP_LOW = 6;
 	public static final int ACC_JUMP_MEDIUM = 7;
 	public static final int ACC_JUMP_HIGH = 8;