@SuppressWarnings("unchecked")
@Override
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
try {
bg_sprite = new Image("data/8bitBGgood.gif");
} catch (SlickException e) {
e.printStackTrace();
}
gc.setTargetFrameRate(Constants.FRAME_RATE);
gc.setVSync(true);
worldCenterX = gc.getWidth() / 2;
worldCenterY = gc.getHeight() / 2;
world = new World();
world.setIterations(Constants.ITERATIONS);
world.setGravity(-10);
p1 = new Player(p1Name);
p2 = new Player(p2Name);
terrainy = new ImageBuffer(Constants.MAX_WIDTH, Constants.MAX_HEIGHT*2);
terrainBitmap = Noise.GenerateWhiteNoise(Constants.MAX_WIDTH,Constants.MAX_HEIGHT*2);
terrainBitmap = Noise.GenerateSmoothNoise(terrainBitmap,7);
terrainBitmap = Noise.GeneratePerlinNoise(terrainBitmap,7);
SlickDisplay();
terrainyImage = terrainy.getImage();
createTerrainBody2(-terrainyImage.getWidth()/2, -terrainyImage.getHeight()/2);
for (int i = 0; i < Constants.BEAVERS_PER_TEAM; i++) {
int[] coord = randomFreeCoordinate(20);
if (coord[0] < 0) p1.getTeam()[i].setBody(new DynamicBody(new Circle(10.0f), -100*i, 1300));
else p1.getTeam()[i].setBody(new DynamicBody(new Circle(10.0f), (coord[0]-terrainyImage.getWidth()/2), (coord[1]-terrainyImage.getHeight()/2)));
p1.getTeam()[i].getBody().setDensity(1);
p1.getTeam()[i].getBody().setFriction(1000);
p1.getTeam()[i].getBody().setRestitution(0f);
p1.getTeam()[i].getBody().setAngularDamping(1f);
p1.getTeam()[i].getBody().setFixedRotation(true);
world.add(p1.getTeam()[i].getBody());
}
for (int i = 0; i < Constants.BEAVERS_PER_TEAM; i++) {
int[] coord = randomFreeCoordinate(20);
if (coord[0] < 0) p2.getTeam()[i].setBody(new DynamicBody(new Circle(10.0f), -100*i, 1300));
else p2.getTeam()[i].setBody(new DynamicBody(new Circle(10.0f), (coord[0]-terrainyImage.getWidth()/2), (coord[1]-terrainyImage.getHeight()/2)));
p2.getTeam()[i].getBody().setDensity(1);
p2.getTeam()[i].getBody().setFriction(1000);
p2.getTeam()[i].getBody().setRestitution(0f);
p2.getTeam()[i].getBody().setAngularDamping(1f);
p2.getTeam()[i].getBody().setFixedRotation(true);
world.add(p2.getTeam()[i].getBody());
}
currentPlayer = p1;
//Add the invisible boundary
boundary = addBoundary(Constants.MAX_WIDTH*2,Constants.MAX_HEIGHT*3);
boundary.setRestitution(0f);
world.add(boundary);
world.addBodyListener(boundary, this);
// load beaver images to use in our animation
Image beaver = new Image("data/bazooka4.png");
Image beaver2 = new Image("data/bazooka5.png");
Image[] frames = {beaver.getFlippedCopy(false, true).getScaledCopy(0.5f), beaver2.getFlippedCopy(false, true).getScaledCopy(0.5f)};
Image[] frames2 = {beaver.getFlippedCopy(true, true).getScaledCopy(0.5f), beaver2.getFlippedCopy(true, true).getScaledCopy(0.5f)};
team1Moving = new Animation(frames, 1000, false); // duration in ms
team1MovingR = new Animation(frames2, 1000, false); // duration in ms
Image beaver3 = new Image("data/darkBazooka4.png");
Image beaver4 = new Image("data/darkBazooka5.png");
Image[] frames3 = {beaver3.getFlippedCopy(false, true).getScaledCopy(0.5f), beaver4.getFlippedCopy(false, true).getScaledCopy(0.5f)};
Image[] frames4 = {beaver3.getFlippedCopy(true, true).getScaledCopy(0.5f), beaver4.getFlippedCopy(true, true).getScaledCopy(0.5f)};
team2Moving = new Animation(frames3, 1000, false); // duration in ms
team2MovingR = new Animation(frames4, 1000, false); // duration in ms
// add the mouse listener
gc.getInput().addMouseListener(this);
//add two items to the world
item = new Item[]{new Item(), new Item()};
item[0].setTypeAmmo();
item[1].setTypeHP();
item[0].getBody().setFriction(1000);
item[1].getBody().setFriction(1000);
item[0].getBody().setRestitution(0);
item[1].getBody().setRestitution(0);
item[0].getBody().setFixedRotation(true);
item[1].getBody().setFixedRotation(true);
world.add(item[0].getBody());
world.add(item[1].getBody());
world.addBodyListener(item[0].getBody(), this);
world.addBodyListener(item[1].getBody(), this);
Body currentBeaverBody = currentPlayer.getCurrentBeaver().getBody();
crosshairAngle = 45;
crosshair = new StaticBody(new Rectangle(50f,5f),currentBeaverBody.getX(),currentBeaverBody.getY());
world.add(crosshair);
crosshair.setRotation(crosshairAngle);
crosshairImage = new Image("data/crosshair.png").getScaledCopy(0.5f);
bulletImage = new Image("data/wood.png").getScaledCopy(0.5f);
healthImage = new Image("data/health.png").getScaledCopy(0.5f);
ammoImage = new Image("data/ammo.png").getFlippedCopy(false, true).getScaledCopy(0.5f);
timer(Constants.SECONDS_PER_TURN);
}