package ru.vagrant_ai.questionmarkgame.obj;
import java.util.Random;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import ru.vagrant_ai.questionmarkgame.main.Game;
import ru.vagrant_ai.questionmarkgame.main.GameplayState;
import ru.vagrant_ai.questionmarkgame.obj.add.Sniper;
import ru.vagrant_ai.questionmarkgame.util.Particle;
import ru.vagrant_ai.questionmarkgame.util.Util;
import ru.vagrant_ai.questionmarkgame.util.list.WS;
public class Background {
Image room;
Image grass;
Image grass_small;
Image cover;
Image ramp;
Image sky;
Image tree[] = new Image[3];
private static Image shop;
byte distance[] = {23,12,29,5,18,21,10,3};
private Color grass_color = new Color(145,186,20);
private Color earth_color = new Color(185,121,87);
private byte ramp_offset = 0;
public Background()
{
room = Util.loadImage("background/locker.png");
cover = Util.loadImage("background/cover.png");
ramp = Util.loadImage("background/ramp.png");
grass = Util.loadImage("background/grass.png");
grass_small = Util.loadImage("background/grass_small.png");
sky = Util.loadImage("background/sky.png");
tree[2] = Util.loadImage("background/tree.png");
tree[1] = Util.loadImage("background/tree_2.png");
tree[0] = Util.loadImage("background/tree_3.png");
shop = Util.loadImage("background/shop_dispenser");
}
public void render_1st_layer(Graphics g)
{
/* background */
g.setColor(new Color(0, 0, 95));
g.fillRect(0, 0, Game.getAppX(), Game.getAppY()); //sky
sky.draw((int)(0-(float)30/Game.getAppX()*GameplayState.player.getX()),0); //stars
/* land */
g.setColor(new Color(70,92,10));
g.fillRect(0, GameplayState.ground_level+27, Game.getAppX(), 18); //layer top
g.setColor(new Color(100,125,14));
g.fillRect(0, GameplayState.ground_level+9, Game.getAppX(), 18); //layer mid
g.setColor(new Color(115,160,15));
g.fillRect(0, GameplayState.ground_level-9, Game.getAppX(), 18); //layer low
int loop[] = {0,0}; //[0] for layer, [1] for tree offset
while (loop[0] < 3)
{
if (loop[0] == 1)
Particle.update_and_render_2nd_layer(g); //projector particle update
int reverse = 1;
loop[1] = 0;
for (int i = (int) (-50+loop[0]*35-((float)25/Game.getAppX()*GameplayState.player.getX())*loop[0]+1); i < 850; i += 80)
{
tree[loop[0]].getFlippedCopy((reverse>0?true:false), false).draw(i+loop[1]*(loop[0]+1), GameplayState.ground_level+18-18*(2-loop[0])-200);
reverse *= -1;
i += loop[0]*45;
}
if (loop[0] == 2) //sniper bushes render
{
for (int i = 0; i < Elements.sniper_array.size(); ++i)
{
Sniper element = Elements.sniper_array.get(i);
element.render();
}
if (GameplayState.monster_controller.getState() == WS.BREAK) //shop render
shop.draw(600, GameplayState.ground_level-60);
}
for (int i = (int) (-10-((float)25/Game.getAppX()*GameplayState.player.getX())*loop[0]+1); i < 801; i += 80)
{
grass.draw(i, GameplayState.ground_level-3-18*(2-loop[0]));
}
loop[1]++;
if (loop[1] > 8) loop[1] = 0;
loop[0]++;
}
if (GameplayState.player.bunker_opened)
room.draw(118, GameplayState.ground_level+94); //room
g.setColor(grass_color);
g.fillRect(0, GameplayState.ground_level+27, Game.getAppX(), 27); //land player_layer
if (GameplayState.player.bunker_opened)
cover.draw(175,GameplayState.ground_level+27); //hatch
if (GameplayState.player.ramp_opened)
ramp.draw(235+ramp_offset, GameplayState.ground_level-44); //ramp
GameplayState.gui.render_1st_layer(g); //render frames of gui
}
public void render_2nd_layer(Graphics g)
{
g.setColor(earth_color);
if (GameplayState.player.bunker_opened)
{
g.fillRect(0, GameplayState.ground_level+53, 118, 287);
g.fillRect(118, GameplayState.ground_level+53, Game.getAppX()-118, 40);
g.fillRect(290, GameplayState.ground_level+93, Game.getAppX()-118, Game.getAppY()-(GameplayState.ground_level+93));
g.fillRect(118, GameplayState.ground_level+218, 172, Game.getAppY()-(GameplayState.ground_level+215));
}
else
g.fillRect(0, GameplayState.ground_level+53, Game.getAppX(), Game.getAppY()-GameplayState.ground_level-53);
for (int i = -30; i < 801; i += 30)
{
grass_small.draw(i, GameplayState.ground_level+39);
}
}
public void update()
{
}
public void shakeRamp()
{
if (new Random().nextInt(7) == 4)
{
ramp_offset = (byte) (new Random().nextBoolean()?2:-2);
}
else
ramp_offset = 0;
}
}