Skip to content

Commit

Permalink
Merge remote-tracking branch 'yaamboo/master'
Browse files Browse the repository at this point in the history
Conflicts:
	src/fi/ringofsnake/gamestates/PlayGameState.java
  • Loading branch information
puumuki committed Jan 29, 2012
2 parents 1162311 + 9d53dd6 commit 79e2fa0
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/fi/ringofsnake/entities/Box.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.util.Log;

import fi.ringofsnake.io.ResourceManager;

public class Box extends AEntity {

public float tunnelHorizontalOffset = 0;

private Image boxImg;

public Box(int x, int y, float velX, float velY) {
Expand All @@ -26,19 +29,16 @@ public Box(int x, int y, float velX, float velY) {

@Override
public void render(GameContainer cont, Graphics grap) throws SlickException {

boxImg.draw(position.x, position.y);
grap.draw(shape);

}


@Override
public void update(GameContainer cont, int delta) throws SlickException {
boxImg.rotate(-0.2f*delta);
position.add(velocity);
shape.setLocation(this.position.x, this.position.y);

// TODO: check if off screen and destroy
}

}
2 changes: 1 addition & 1 deletion src/fi/ringofsnake/entities/SnakeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class SnakeMap implements IGameObject {

private Player player;

public float tunnelHorizontalOffset = 0;
public float tunnelHorizontalOffset = 0;
public float tunnelSpeed = 0.5f;

public static enum Tileset {
Expand Down
12 changes: 8 additions & 4 deletions src/fi/ringofsnake/gamestates/PlayGameState.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import fi.ringofsnake.io.ResourceManager;
import fi.ringofsnake.entities.Player;

import fi.ringofsnake.util.BoxDispenser;

public class PlayGameState extends BasicGameState {

private int stateID = -1;
Expand All @@ -43,7 +45,8 @@ public int getID() {
return stateID;
}

private Box box;
//Put dispenser here!
private BoxDispenser boxes;

@Override
public void init(GameContainer container, StateBasedGame game)
Expand All @@ -58,7 +61,7 @@ public void init(GameContainer container, StateBasedGame game)
scrollingBackGround = new ScrollingBackGround(0.5f);
squirrels = new SquirrelMob();

box = new Box(1500,400,-5.0f,0);
boxes = new BoxDispenser();
}


Expand Down Expand Up @@ -104,7 +107,7 @@ public void render(GameContainer container, StateBasedGame game, Graphics g)

drawDebugLines( container, g );

box.render(container, g);
boxes.render(container, g);
}

private void drawDebugLines( GameContainer cont, Graphics g ) {
Expand Down Expand Up @@ -140,8 +143,9 @@ public void update(GameContainer container, StateBasedGame game, int delta) thr

scrollingBackGround.update(container, delta);

box.update(container, delta);
boxes.update(container, delta);

currentMap.tunnelHorizontalOffset += currentMap.tunnelSpeed * delta;

}
}
60 changes: 60 additions & 0 deletions src/fi/ringofsnake/util/BoxDispenser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package fi.ringofsnake.util;

import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;

import fi.ringofsnake.entities.Box;

/**
* Creates boxes for the player to try to bypass
* @author Yaamboo
*
*/
public class BoxDispenser {

private static final int[] BOXLEVELS = {200, 300, 400};

private List<Box> boxes = new LinkedList<Box>();

public BoxDispenser() {
}

private void createBox() {
// randomize and stuff
// let's forget about y-velocity right now
Box box = new Box(1280 + (int)(Math.random() * 1000), BOXLEVELS[(int)(Math.random()* 3)], (float)(Math.random() * -10) - 5, 0);
//Log.debug("Creating new box at " + box.position.x + "," + box.position.y);
boxes.add(box);
}

public void update(GameContainer cont, int delta) throws SlickException {

if (Math.random() > 0.99)
createBox();

for (Box box : boxes)
box.update(cont, delta);
}

public void render(GameContainer cont, Graphics g) throws SlickException {
HashSet<Box> toRemove = new HashSet<Box>();
for (Iterator<Box> i = boxes.iterator(); i.hasNext();) {
Box box = i.next();
if ( box.position.x < -100)
{
//Log.debug("Destroying box at " + box.position.x);
toRemove.add(box);
}
else
box.render(cont, g);
}
boxes.removeAll(toRemove);
}

}

0 comments on commit 79e2fa0

Please sign in to comment.