|
|
|
|
@ -8,22 +8,24 @@ package controller;
|
|
|
|
|
import com.badlogic.gdx.ApplicationAdapter;
|
|
|
|
|
import com.badlogic.gdx.Gdx;
|
|
|
|
|
import com.badlogic.gdx.InputProcessor;
|
|
|
|
|
import com.badlogic.gdx.Preferences;
|
|
|
|
|
import com.badlogic.gdx.graphics.GL20;
|
|
|
|
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
|
|
|
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
|
|
|
|
|
|
|
|
|
import model.Goal;
|
|
|
|
|
import model.Level;
|
|
|
|
|
import model.Projectile;
|
|
|
|
|
import view.Gamescreen;
|
|
|
|
|
import view.Levelscreen;
|
|
|
|
|
|
|
|
|
|
import com.badlogic.gdx.math.Intersector;
|
|
|
|
|
import com.badlogic.gdx.math.Rectangle;
|
|
|
|
|
import com.badlogic.gdx.utils.Json;
|
|
|
|
|
import com.badlogic.gdx.utils.Timer;
|
|
|
|
|
import com.badlogic.gdx.utils.viewport.ExtendViewport;
|
|
|
|
|
import com.badlogic.gdx.utils.viewport.Viewport;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
|
import model.Level;
|
|
|
|
|
import view.Gamescreen;
|
|
|
|
|
import view.Levelscreen;
|
|
|
|
|
import view.Titlescreen;
|
|
|
|
|
import view.Winscreen;
|
|
|
|
|
|
|
|
|
|
@ -36,6 +38,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
|
|
|
|
|
final float GAME_WORLD_WIDTH = 1600;
|
|
|
|
|
final float GAME_WORLD_HEIGHT = 900;
|
|
|
|
|
|
|
|
|
|
File filesDir;
|
|
|
|
|
|
|
|
|
|
Titlescreen ts;
|
|
|
|
|
Levelscreen ls;
|
|
|
|
|
@ -45,7 +48,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
|
|
|
|
|
SpriteBatch batch;
|
|
|
|
|
Timer stepTimer;
|
|
|
|
|
boolean isColliding;
|
|
|
|
|
Level[] level;
|
|
|
|
|
ArrayList<Level> level;
|
|
|
|
|
int currentLevel;
|
|
|
|
|
int beatenLevel = 9;
|
|
|
|
|
|
|
|
|
|
@ -75,8 +78,9 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
|
|
|
|
|
camera.position.set(GAME_WORLD_WIDTH/2, GAME_WORLD_HEIGHT/2, 0);
|
|
|
|
|
|
|
|
|
|
isColliding = false;
|
|
|
|
|
level = new Level[10];
|
|
|
|
|
level = new ArrayList<>();
|
|
|
|
|
currentLevel = 0;
|
|
|
|
|
/*
|
|
|
|
|
level[0] = new Level(new Goal(500,200,450,100, 0.2f), new Projectile(0,0,0),200,200);
|
|
|
|
|
level[1] = new Level(new Goal(700,200,450,100, 0.2f), new Projectile(0,0,0),200,200);
|
|
|
|
|
level[2] = new Level(new Goal(560,400,450,100, 0.2f), new Projectile(0,0,0),200,200);
|
|
|
|
|
@ -88,23 +92,43 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
|
|
|
|
|
level[8] = new Level(new Goal(760,460,450,100, 0.2f), new Projectile(0,0,0),200,200);
|
|
|
|
|
level[9] = new Level(new Goal(1000,580,350,100, 0.2f), new Projectile(0,0,0),200,200);
|
|
|
|
|
level[9].addRectangle(400, 400, 50,200);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
Json json = new Json();
|
|
|
|
|
File levelJson;
|
|
|
|
|
for(int i = 0; i < 1000; i++){
|
|
|
|
|
try{
|
|
|
|
|
levelJson = new File(filesDir, "level" + i + ".json");
|
|
|
|
|
if(levelJson == null){
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
Level tempLevel = json.fromJson(Level.class, new FileInputStream(levelJson));
|
|
|
|
|
level.add(tempLevel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch(FileNotFoundException e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stepTimer = new Timer();
|
|
|
|
|
stepTimer.scheduleTask(new Timer.Task() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
if(gs != null){
|
|
|
|
|
if(level[currentLevel].getProjectile().getxPos() > GAME_WORLD_WIDTH || level[currentLevel].getProjectile().getxPos() < 0 || level[currentLevel].getProjectile().getyPos() < 0){
|
|
|
|
|
gs.step(level[currentLevel]);
|
|
|
|
|
level[currentLevel].reset();
|
|
|
|
|
if(level.get(currentLevel).getProjectile().getxPos() > GAME_WORLD_WIDTH || level.get(currentLevel).getProjectile().getxPos() < 0 || level.get(currentLevel).getProjectile().getyPos() < 0){
|
|
|
|
|
gs.step(level.get(currentLevel));
|
|
|
|
|
level.get(currentLevel).reset();
|
|
|
|
|
gs.dispose();
|
|
|
|
|
stepTimer.stop();
|
|
|
|
|
gs = null;
|
|
|
|
|
ws = new Winscreen(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, false, currentLevel);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
level[currentLevel].step();
|
|
|
|
|
gs.step(level[currentLevel]);
|
|
|
|
|
level.get(currentLevel).step();
|
|
|
|
|
gs.step(level.get(currentLevel));
|
|
|
|
|
|
|
|
|
|
boolean collision = false;
|
|
|
|
|
for(Rectangle rect : gs.getGoalRects()){
|
|
|
|
|
@ -113,9 +137,9 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
|
|
|
|
|
collision = true;
|
|
|
|
|
if (!isColliding) {
|
|
|
|
|
if (rect.getHeight() == 1) {
|
|
|
|
|
level[currentLevel].horizontalCollision();
|
|
|
|
|
level.get(currentLevel).horizontalCollision();
|
|
|
|
|
} else if (rect.getWidth() == 1) {
|
|
|
|
|
level[currentLevel].verticalCollision();
|
|
|
|
|
level.get(currentLevel).verticalCollision();
|
|
|
|
|
}
|
|
|
|
|
isColliding = true;
|
|
|
|
|
break;
|
|
|
|
|
@ -129,9 +153,9 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
|
|
|
|
|
collision = true;
|
|
|
|
|
if (!isColliding) {
|
|
|
|
|
if (rect.getHeight() == 1) {
|
|
|
|
|
level[currentLevel].horizontalCollision();
|
|
|
|
|
level.get(currentLevel).horizontalCollision();
|
|
|
|
|
} else if (rect.getWidth() == 1) {
|
|
|
|
|
level[currentLevel].verticalCollision();
|
|
|
|
|
level.get(currentLevel).verticalCollision();
|
|
|
|
|
}
|
|
|
|
|
isColliding = true;
|
|
|
|
|
break;
|
|
|
|
|
@ -167,14 +191,14 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
|
|
|
|
|
if(ts != null) ts.render(batch);
|
|
|
|
|
else if(ls != null){
|
|
|
|
|
currentLevel = ls.getSelectedLevel();
|
|
|
|
|
ls.render(batch, level[currentLevel]);
|
|
|
|
|
ls.render(batch, level.get(currentLevel);
|
|
|
|
|
}
|
|
|
|
|
else if(gs != null){
|
|
|
|
|
gs.render(batch, level[currentLevel]);
|
|
|
|
|
gs.render(batch, level.get(currentLevel));
|
|
|
|
|
if(gs.getWin()){
|
|
|
|
|
gs.dispose();
|
|
|
|
|
stepTimer.stop();
|
|
|
|
|
level[currentLevel].reset();
|
|
|
|
|
level.get(currentLevel).reset();
|
|
|
|
|
if(currentLevel == beatenLevel && currentLevel < levelAmount)beatenLevel++;
|
|
|
|
|
gs = null;
|
|
|
|
|
ws = new Winscreen(GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, true, currentLevel);
|
|
|
|
|
@ -189,6 +213,10 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void initContext(File context){
|
|
|
|
|
this.filesDir = context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean keyDown(int keycode) {
|
|
|
|
|
camera.translate(5f, 5f);
|
|
|
|
|
@ -223,13 +251,13 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
|
|
|
|
|
else{
|
|
|
|
|
ls.dispose();
|
|
|
|
|
ls = null;
|
|
|
|
|
gs = new Gamescreen(level[currentLevel], GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined);
|
|
|
|
|
gs = new Gamescreen(level.get(currentLevel), GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined);
|
|
|
|
|
stepTimer.start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(gs != null){
|
|
|
|
|
if(!level[currentLevel].released()){
|
|
|
|
|
level[currentLevel].projectileReleased();
|
|
|
|
|
if(!level.get(currentLevel).released()){
|
|
|
|
|
level.get(currentLevel).projectileReleased();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(ws != null){
|
|
|
|
|
@ -238,13 +266,13 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
|
|
|
|
|
ws = null;
|
|
|
|
|
}
|
|
|
|
|
else if(x < Gdx.graphics.getWidth() * 0.66){
|
|
|
|
|
gs = new Gamescreen(level[currentLevel], GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined);
|
|
|
|
|
gs = new Gamescreen(level.get(currentLevel), GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined);
|
|
|
|
|
stepTimer.start();
|
|
|
|
|
ws = null;
|
|
|
|
|
}
|
|
|
|
|
else if(currentLevel < levelAmount && ws.getWin()){
|
|
|
|
|
currentLevel++;
|
|
|
|
|
gs = new Gamescreen(level[currentLevel], GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined);
|
|
|
|
|
gs = new Gamescreen(level.get(currentLevel), GAME_WORLD_WIDTH, GAME_WORLD_HEIGHT, camera.combined);
|
|
|
|
|
stepTimer.start();
|
|
|
|
|
ws = null;
|
|
|
|
|
}
|
|
|
|
|
|