From 3a0a43cb66efa17beb2fd3cb3048c10a879df5b5 Mon Sep 17 00:00:00 2001 From: Jonathan Hager Date: Sat, 26 Sep 2020 13:52:36 +0200 Subject: [PATCH] Projectile spawning working --- core/src/com/trs/game/model/Model.java | 46 +++++++++++++++++++++++- core/src/com/trs/game/model/Monster.java | 17 ++++++++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/core/src/com/trs/game/model/Model.java b/core/src/com/trs/game/model/Model.java index 09e4299..f9d3bd9 100644 --- a/core/src/com/trs/game/model/Model.java +++ b/core/src/com/trs/game/model/Model.java @@ -16,9 +16,13 @@ public class Model { private boolean drawing = false; private int currentLength; + private int difficulty; + private int leftWallLength = 2500; public Model(){ + difficulty = 0; + monster = new Monster(250,150); walls = new ArrayList<>(); walls.add(new PermWall(60, StaticMath.createPolygon(250,250, 60,25, 100))); @@ -30,13 +34,24 @@ public class Model { public void timerStep(){ monster.move(walls, projectiles); - for(Projectile projectile : projectiles){ + for(int i = projectiles.size() - 1; i >= 0; i--){ + Projectile projectile = projectiles.get(i); + projectile.move(walls); + if(projectile.getxPos() < -110 || projectile.getxPos() > 1710 || projectile.getyPos() < -110 || projectile.getyPos() > 1010){ + projectiles.remove(i); + } } if(monster.getIsDead()){ // TODO: Tod implementieren } + + // Generation of new projectiles + int value = (int) (Math.random() * 5) + difficulty; + if(value > 0){ + projectiles.add(spawnProjectile()); + } } public void startWall(int x, int y){ @@ -86,6 +101,35 @@ public class Model { currentLength = 0; } + private Projectile spawnProjectile(){ + int xPos; + int yPos; + + int direction = (int) (Math.random() * 4); + + // up + if(direction == 0){ + xPos = (int) (Math.random() * 1600); + yPos = 1000; + } + // right + else if(direction == 1){ + xPos = 1700; + yPos = (int) (Math.random() * 900); + } + // down + else if(direction == 2){ + xPos = (int) (Math.random() * 1600); + yPos = -100; + } + // left + else{ + xPos = -100; + yPos = (int) (Math.random() * 900); + } + + return new Projectile(xPos, yPos, monster.getxPos(), monster.getyPos()); + } public ArrayList getWalls(){ return walls; diff --git a/core/src/com/trs/game/model/Monster.java b/core/src/com/trs/game/model/Monster.java index 6280ff6..ade3663 100644 --- a/core/src/com/trs/game/model/Monster.java +++ b/core/src/com/trs/game/model/Monster.java @@ -78,7 +78,6 @@ public class Monster { this.xPos += this.movementX; this.yPos += this.movementY; - System.out.println(hp); // Collisions float[] verticesMonster = new float[8]; @@ -154,4 +153,20 @@ public class Monster { public boolean getIsDead(){ return this.isDead; } + + public int getxPos() { + return xPos; + } + + public void setxPos(int xPos) { + this.xPos = xPos; + } + + public int getyPos() { + return yPos; + } + + public void setyPos(int yPos) { + this.yPos = yPos; + } }