-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'yaamboo/master'
Conflicts: src/fi/ringofsnake/gamestates/PlayGameState.java
- Loading branch information
Showing
4 changed files
with
73 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |