GammelJan 6 years ago
parent cb6f007f01
commit 0939c3bb7c

@ -70,7 +70,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
viewport.apply();
camera.position.set(GAME_WORLD_WIDTH/2, GAME_WORLD_HEIGHT/2, 0);
level = new Level(new Goal(800,500,200,80), new Projectile(0,0,0),200,200);
level = new Level(new Goal(500,200,150,50, 0.2f), new Projectile(0,0,0),200,200);
stepTimer = new Timer();
stepTimer.scheduleTask(new Timer.Task() {
@ -81,7 +81,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
level.reset();
gs.dispose();
gs = null;
ws = new Winscreen(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT);
ws = new Winscreen(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, false);
}
else{
level.step();
@ -107,7 +107,14 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
batch.setProjectionMatrix(camera.combined);
if(ts != null) ts.render(batch);
else if(ls != null) ls.render(batch);
else if(gs != null) gs.render(batch, level);
else if(gs != null){
gs.render(batch, level);
if(gs.getWin()){
gs.dispose();
gs = null;
ws = new Winscreen(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, true);
}
}
else if(ws != null) ws.render(batch);
batch.end();
}

@ -6,12 +6,14 @@ public class Goal {
private int yPos;
private int sizeX;
private int sizeY;
private float thickness;
public Goal(int xPos, int yPos, int sizeX, int sizeY){
public Goal(int xPos, int yPos, int sizeX, int sizeY, float thickness){
this.xPos = xPos;
this.yPos = yPos;
this.sizeX = sizeX;
this.sizeY = sizeY;
this.thickness = thickness;
}
public int getxPos() {
@ -45,4 +47,11 @@ public class Goal {
public void setSizeY(int sizeY) {
this.sizeY = sizeY;
}
public float getThickness() {
return thickness;
}
public void setThickness(float thickness) {
this.thickness = thickness;
}
}

@ -27,6 +27,12 @@ public class Gamescreen{
Goal g;
Projectile p;
int x;
int y;
float w;
float h;
float th;
//Rectangle goalLeft;
//Rectangle goalRight;
//Rectangle goalBottom;
@ -39,27 +45,34 @@ public class Gamescreen{
float GAME_WORLD_WIDTH;
float GAME_WORLD_HEIGHT;
boolean win;
public Gamescreen(Level level, float width, float height, Matrix4 matrix){
GAME_WORLD_WIDTH = width;
GAME_WORLD_HEIGHT = height;
pivotX = level.getPivotX();
pivotY = level.getPivotY();
g = level.getGoal();
x = g.getxPos();
y = g.getyPos();
w = g.getSizeX();
h = g.getSizeY();
th = g.getThickness();
p = level.getProjectile();
// Goal rectangles
//goalLeft = new Rectangle(g.getxPos(), g.getyPos(), 0.1f * g.getSizeX(), g.getSizeY());
//goalBottom = new Rectangle(g.getxPos() + 0.1f * g.getSizeX(), g.getyPos(), 0.8f * g.getSizeX(),0.2f * g.getSizeY());
//goalRight = new Rectangle(g.getxPos() + 0.1f * g.getSizeX() + 0.8f * g.getSizeX(), g.getyPos(), 0.1f * g.getSizeX(),g.getSizeY());
win = false;
goalRects = new Rectangle[8];
goalRects[0] = new Rectangle(g.getxPos(),g.getyPos(),1,g.getSizeY());
goalRects[1] = new Rectangle(g.getxPos(), g.getyPos() + g.getSizeY() - 1, g.getSizeX() * 0.2f, 1);
goalRects[2] = new Rectangle(g.getxPos() + 0.2f * g.getSizeX()-1f,g.getyPos() + g.getSizeY() * 0.2f, 1, g.getSizeY() * 0.8f );
goalRects[3] = new Rectangle(g.getxPos() + 0.2f * g.getSizeX(), g.getyPos() + g.getSizeY() * 0.2f - 1, g.getSizeX() * 0.6f, 1);
goalRects[4] = new Rectangle(g.getxPos() + 0.8f * g.getSizeX(),g.getyPos() + g.getSizeY() * 0.2f,1, g.getSizeY() * 0.8f);
goalRects[5] = new Rectangle(g.getxPos() + 0.8f * g.getSizeX(), g.getyPos() + g.getSizeY() - 1f, g.getSizeX() * 0.2f, 1);
goalRects[6] = new Rectangle(g.getxPos() + g.getSizeX()-1, g.getyPos(), 1, g.getSizeY());
goalRects[7] = new Rectangle(g.getxPos(), g.getyPos(), g.getSizeX(), 1);
goalRects[0] = new Rectangle(x ,y ,1 ,h );
goalRects[1] = new Rectangle(x ,y + h - 1 ,w * th ,1 );
goalRects[2] = new Rectangle(x + th * w-1f ,y + h * th ,1 ,h * th*4 );
goalRects[3] = new Rectangle(x + th * w ,y + h * th - 1 ,w *th*3 ,1 );
goalRects[4] = new Rectangle(x + th*4 * w ,y + h * th ,1 ,h * th*4 );
goalRects[5] = new Rectangle(x + th*4 * w ,y + h - 1f ,w *th ,1 );
goalRects[6] = new Rectangle(x + w-1 ,y ,1 ,h );
goalRects[7] = new Rectangle(x ,y ,w ,1 );
shapeRenderer = new ShapeRenderer();
shapeRenderer.setProjectionMatrix(matrix);
@ -89,9 +102,9 @@ public class Gamescreen{
}
shapeRenderer.setColor(Color.BLACK);
shapeRenderer.rect(g.getxPos(), g.getyPos(), 0.2f * g.getSizeX(), g.getSizeY());
shapeRenderer.rect(g.getxPos() + 0.2f * g.getSizeX(), g.getyPos(), 0.6f * g.getSizeX(),0.2f * g.getSizeY());
shapeRenderer.rect(g.getxPos() + 0.2f * g.getSizeX() + 0.6f * g.getSizeX(), g.getyPos(), 0.2f * g.getSizeX(),g.getSizeY());
shapeRenderer.rect(x, y,th * w, h);
shapeRenderer.rect(x + th * w,y, th*3 * w,th * h);
shapeRenderer.rect(x + th *w + th*3 * w, y, th * w,h);
shapeRenderer.circle((float) p.getxPos(), (float) p.getyPos(), p.getRadius());
shapeRenderer.setColor(Color.RED);
for(int i = 0; i < goalRects.length; i++){
@ -103,10 +116,17 @@ public class Gamescreen{
shapeRenderer.circle(pivotX, pivotY, 5);
shapeRenderer.end();
if(p.getxPos() > x + w*th && p.getxPos() < x+w*4*th && p.getyPos() > y + h * th && p.getyPos() < y + h ){
win = true;
}
}
public void dispose() {
}
public boolean getWin(){
return win;
}
}

@ -25,22 +25,26 @@ public class Winscreen{
Sprite level;
Sprite next;
Sprite win;
Sprite winSprite;
boolean movement;
float GAME_WORLD_WIDTH;
float GAME_WORLD_HEIGHT;
public Winscreen(float width, float height){
boolean win;
public Winscreen(float width, float height, boolean win){
t = new Timer();
GAME_WORLD_WIDTH = width;
GAME_WORLD_HEIGHT = height;
/*
this.win = win;
if(win){
movement = true;
win = new Sprite(new Texture(Gdx.files.internal("win.png")));
win.setX(GAME_WORLD_WIDTH / 2 - win.getWidth() / 2);
win.setY(GAME_WORLD_HEIGHT * 0.7f - win.getHeight() / 2);
*/
winSprite = new Sprite(new Texture(Gdx.files.internal("win.png")));
winSprite.setX(GAME_WORLD_WIDTH / 2 - winSprite.getWidth() / 2);
winSprite.setY(GAME_WORLD_HEIGHT * 0.7f - winSprite.getHeight() / 2);
}
float w = GAME_WORLD_WIDTH;
float h = GAME_WORLD_HEIGHT;
@ -52,21 +56,23 @@ public class Winscreen{
reset = new Sprite(new Texture("reseticon.png"));
reset.setPosition(w/2 - reset.getWidth()/2, h*0.35f - reset.getHeight()/2);
if(win){
t.scheduleTask(new Timer.Task() {
@Override
public void run() {
/*if(win.getY() < GAME_WORLD_HEIGHT*0.8)
movement = true;
else if(win.getY() > GAME_WORLD_HEIGHT * 0.7)
movement = false;
if(movement)
win.setY(win.getY() + 3);
else
win.setY(win.getY() - 3);*/
if(winSprite.getY() < GAME_WORLD_HEIGHT*0.7){
movement = true;}
if(winSprite.getY() > GAME_WORLD_HEIGHT * 0.8){
movement = false;}
if(movement){
winSprite.setY(winSprite.getY() + 3);
}
else{
winSprite.setY(winSprite.getY() - 3);
}
}
},0 , 0.035f);
}
}
@ -74,7 +80,8 @@ public class Winscreen{
next.draw(batch);
level.draw(batch);
reset.draw(batch);
//win.draw(batch);
if(win)winSprite.draw(batch);
}
public void dispose() {
t.clear();

Loading…
Cancel
Save