Commits

Valerio Riva committed c3f06db

non lo so

Comments (0)

Files changed (5)

src/ggj/bloodrace/Game.java

 	public Game(Level level) {
 		super(title);
 		this.setLevel(level);
-		
-
 	}
 
 	public abstract void init(GameContainer gc) throws SlickException;
 
 	public void update(GameContainer gc, int delta) throws SlickException {
-		// ogni tanto creo un ostacolo
-//		if (System.currentTimeMillis() - time >= Constants.OBSTACLE_RATIO) {
-//			time = System.currentTimeMillis();
-//			ElementsType next = level.pop();
-//			
-//			if (next != null) {
-//				Obstacle o = ElementsType.getObstacle(next);
-//				this.entities.add(o);
-//			}
-//		}
-
 		for (Entity entity : entities)
 			entity.update(this, delta);
 		this.collisionHandler.checkCollisions();

src/ggj/bloodrace/entities/Entity.java

 	protected CollisionHandler collisionHandler;
 	
 	protected int unitMovement = Constants.DEFAULT_UNIT_MOVEMENT;
-	protected int speed = Constants.DEFAULT_SPEED;	
+	protected int speed = Constants.DEFAULT_SPEED;
 
 	private int XPosition = 0;
 	private int YPosition = 0;

src/ggj/bloodrace/entities/Player.java

 				int rightSide = (int) (getXPosition()+shape.getWidth());
 				int bottomSide = (int) (getYPosition()+shape.getHeight());
 				if (rightSide >= target.getXPosition() && bottomSide >= target.getYPosition()) {
-					setXPosition((int) (target.getXPosition()-shape.getHeight()));
+					setXPosition((int) (target.getXPosition()-shape.getWidth()));
 				}
 			}
 		};
 		
+		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()));
+				}
+			}
+		};		
+
+		collisionHandler.registerAction(left, Dosso.class, leftCollision);
+		collisionHandler.registerAction(left, Blocco.class, leftCollision);
+		collisionHandler.registerAction(left, Montagna.class, leftCollision);
+		
 		collisionHandler.registerAction(right, Dosso.class, rightCollision);
 		collisionHandler.registerAction(right, Blocco.class, rightCollision);
 		collisionHandler.registerAction(right, Montagna.class, rightCollision);
 		bottom = new PlayerCollider(collisionHandler, this);
 		left = new PlayerCollider(collisionHandler, this);
 		right = new PlayerCollider(collisionHandler, this);
+
+		try {
+			Animation animation = new Animation(new Image[] { new Image(
+					"resources/images/collider.png") }, 250);
+			top.setAnimation("basic", animation);
+			top.setCurrentAnimation(top.getAnimation("basic"));
+			animation = new Animation(new Image[] { new Image(
+					"resources/images/collider.png") }, 250);
+			bottom.setAnimation("basic", animation);
+			bottom.setCurrentAnimation(bottom.getAnimation("basic"));
+			animation = new Animation(new Image[] { new Image(
+					"resources/images/collider.png") }, 250);
+			left.setAnimation("basic", animation);
+			left.setCurrentAnimation(left.getAnimation("basic"));
+			animation = new Animation(new Image[] { new Image(
+					"resources/images/collider.png") }, 250);
+			right.setAnimation("basic", animation);
+			right.setCurrentAnimation(right.getAnimation("basic"));
+		} catch (SlickException e) {
+			e.printStackTrace();
+		}		
+		
+		
 		entities.add(top);
 		entities.add(bottom);
 		entities.add(left);
 	
 	protected void moveX() {
 		if (Xacc != 0) {
-			int mod = 1;
+			int mod = speed*unitMovement;
 			if (Xacc < 0) {
-				mod = -1;
+				mod*= -1;
 			}
 			setXPosition(getXPosition()+mod);
 			Xacc -= 2;
 	
 	protected ActionCommand moveBackwards = new ActionCommand() {
     	public void exec() {
-    		Xacc = -60;
+    		Xacc = Constants.ACC_X*-1;
     	}
 	};	
 	
 	protected ActionCommand moveForward = new ActionCommand() {
     	public void exec() {
-    		Xacc = 60;
+    		Xacc = Constants.ACC_X;
     	}
 	};
 
 	protected ActionCommand jumpLow = new ActionCommand() { 
     	public void exec() {
-    		jump(Constants.JUMP_LOW);
+    		jump(Constants.ACC_JUMP_LOW);
     	}
     };
 
 	protected ActionCommand jumpMedium = new ActionCommand() { 
     	public void exec() {
-    		jump(Constants.JUMP_MEDIUM);
+    		jump(Constants.ACC_JUMP_MEDIUM);
     	}
     };
 
 	protected ActionCommand jumpHigh = new ActionCommand() { 
     	public void exec() {
-    		jump(Constants.JUMP_HIGH);
+    		jump(Constants.ACC_JUMP_HIGH);
     	}
     };	
 

src/ggj/bloodrace/utils/Constants.java

 	
 	public static final int GRAVITY = 1;
 	
-	public static final int OBSTACLE_SPEED = 4;
+	public static final int OBSTACLE_SPEED = 0; //4
 	public static final int OBSTACLE_RATIO = 1000;
 	public static final int OBSTACLE_X_OFFSET = 800;
 	public static final int OBSTACLE_Y_OFFSET = 550;
 	public static final int PLAYER_START_SPACE_X = 25;
 	public static final int PLAYER_MAX_JUMPS = 2;
 	
-	public static final int JUMP_LOW = 6;
-	public static final int JUMP_MEDIUM = 7;
-	public static final int JUMP_HIGH = 8;
+	public static final int ACC_X = 60;
+	public static final int ACC_JUMP_LOW = 6;
+	public static final int ACC_JUMP_MEDIUM = 7;
+	public static final int ACC_JUMP_HIGH = 8;
 	
 	public static final int BOTTOM_X = 0;
 	public static final int BOTTOM_Y = 550;

src/resources/images/collider.png

Added
New image