From ce7f15d9654c5ecf38bfa5f566d4aa9dcb6c8b67 Mon Sep 17 00:00:00 2001 From: Jonathan Hager Date: Fri, 25 Sep 2020 22:09:39 +0200 Subject: [PATCH] Projectile movement working --- core/src/com/trs/game/Controller.java | 8 ++++--- core/src/com/trs/game/model/Model.java | 1 + core/src/com/trs/game/model/Projectile.java | 26 ++++++++++++++------- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/core/src/com/trs/game/Controller.java b/core/src/com/trs/game/Controller.java index 72e4224..4e801c9 100644 --- a/core/src/com/trs/game/Controller.java +++ b/core/src/com/trs/game/Controller.java @@ -47,9 +47,11 @@ public class Controller extends ApplicationAdapter implements InputProcessor { wallTimer.scheduleTask(new Timer.Task() { @Override public void run() { - model.timerStep(); + if(screen.getId() == 1) { + model.timerStep(); + } } - }, 0, 1f); + }, 0, 0.05f); font = new BitmapFont(); // BITMAP FONT @@ -81,7 +83,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor { renderer.rect(wall.getRect().getX(), wall.getRect().getY(),0,0, wall.getRect().getWidth(), wall.getRect().getHeight(),1,1, (float)wall.getRotation()); } for(Projectile projectile : model.getProjectiles()){ - renderer.circle(projectile.getxPos(),projectile.getyPos(),5); + renderer.circle(projectile.getxPos(), projectile.getyPos(), projectile.getRadius()); } renderer.end(); model.getMonster().drawMonster(renderer); diff --git a/core/src/com/trs/game/model/Model.java b/core/src/com/trs/game/model/Model.java index 618ae53..ea62bee 100644 --- a/core/src/com/trs/game/model/Model.java +++ b/core/src/com/trs/game/model/Model.java @@ -16,6 +16,7 @@ public class Model { walls.add(new PermWall(20,new Rectangle(250,250,50,25))); projectiles = new ArrayList<>(); + projectiles.add(new Projectile(200, 200, 1000, 600)); } public void timerStep(){ diff --git a/core/src/com/trs/game/model/Projectile.java b/core/src/com/trs/game/model/Projectile.java index 3be523a..f888a85 100644 --- a/core/src/com/trs/game/model/Projectile.java +++ b/core/src/com/trs/game/model/Projectile.java @@ -1,22 +1,22 @@ package com.trs.game.model; +import com.badlogic.gdx.math.Circle; import com.trs.game.StaticMath; public class Projectile { private final int SPEED = 3; - private int xPos; - private int yPos; private double movementX; private double movementY; + private Circle circle; + public Projectile(int xPos, int yPos, int xPosMonster, int yPosMonster){ - this.xPos = xPos; - this.yPos = yPos; + this.circle = new Circle(xPos, yPos, 5); // calculating values for movementX and movementY - double angle = StaticMath.calculateAngle(this.xPos, this.yPos, xPosMonster, yPosMonster); + double angle = StaticMath.calculateAngle((int) circle.x, (int) circle.y, xPosMonster, yPosMonster); movementX = Math.cos(angle) * SPEED; movementY = Math.sin(angle) * SPEED; @@ -27,15 +27,23 @@ public class Projectile { } public void move(){ - this.xPos += this.movementX; - this.yPos += this.movementY; + circle.x += this.movementX; + circle.y += this.movementY; } public int getxPos() { - return xPos; + return (int) circle.x; } public int getyPos() { - return yPos; + return (int) circle.y; + } + + public int getRadius(){ + return (int) circle.radius; + } + + public Circle getCircle() { + return circle; } }