Merge branch 'jonathan'

Projectile movement working, buttons working
master
Jonathan Hager 5 years ago
commit 1a4793d22f

@ -47,9 +47,11 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
wallTimer.scheduleTask(new Timer.Task() { wallTimer.scheduleTask(new Timer.Task() {
@Override @Override
public void run() { public void run() {
model.timerStep(); if(screen.getId() == 1) {
model.timerStep();
}
} }
}, 0, 1f); }, 0, 0.05f);
font = new BitmapFont(); font = new BitmapFont();
// BITMAP FONT // 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()); 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()){ for(Projectile projectile : model.getProjectiles()){
renderer.circle(projectile.getxPos(),projectile.getyPos(),5); renderer.circle(projectile.getxPos(), projectile.getyPos(), projectile.getRadius());
} }
renderer.end(); renderer.end();
model.getMonster().drawMonster(renderer); model.getMonster().drawMonster(renderer);

@ -16,6 +16,7 @@ public class Model {
walls.add(new PermWall(20,new Rectangle(250,250,50,25))); walls.add(new PermWall(20,new Rectangle(250,250,50,25)));
projectiles = new ArrayList<>(); projectiles = new ArrayList<>();
projectiles.add(new Projectile(200, 200, 1000, 600));
} }
public void timerStep(){ public void timerStep(){

@ -1,22 +1,22 @@
package com.trs.game.model; package com.trs.game.model;
import com.badlogic.gdx.math.Circle;
import com.trs.game.StaticMath; import com.trs.game.StaticMath;
public class Projectile { public class Projectile {
private final int SPEED = 3; private final int SPEED = 3;
private int xPos;
private int yPos;
private double movementX; private double movementX;
private double movementY; private double movementY;
private Circle circle;
public Projectile(int xPos, int yPos, int xPosMonster, int yPosMonster){ public Projectile(int xPos, int yPos, int xPosMonster, int yPosMonster){
this.xPos = xPos; this.circle = new Circle(xPos, yPos, 5);
this.yPos = yPos;
// calculating values for movementX and movementY // 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; movementX = Math.cos(angle) * SPEED;
movementY = Math.sin(angle) * SPEED; movementY = Math.sin(angle) * SPEED;
@ -27,15 +27,23 @@ public class Projectile {
} }
public void move(){ public void move(){
this.xPos += this.movementX; circle.x += this.movementX;
this.yPos += this.movementY; circle.y += this.movementY;
} }
public int getxPos() { public int getxPos() {
return xPos; return (int) circle.x;
} }
public int getyPos() { public int getyPos() {
return yPos; return (int) circle.y;
}
public int getRadius(){
return (int) circle.radius;
}
public Circle getCircle() {
return circle;
} }
} }

Loading…
Cancel
Save