From 428fbc706574b9b8e20d23a74e47e2a9f3678d2f Mon Sep 17 00:00:00 2001 From: Jonathan Hager Date: Mon, 1 Jun 2020 11:48:06 +0200 Subject: [PATCH] Klassen implementiert --- core/src/com/throwgame/main/ThrowMath.java | 33 +++++++++ core/src/model/Goal.java | 48 +++++++++++++ core/src/model/Level.java | 41 +++++++++++ core/src/model/Model.java | 14 ---- core/src/model/Projectile.java | 79 ++++++++++++++++++++++ 5 files changed, 201 insertions(+), 14 deletions(-) create mode 100644 core/src/com/throwgame/main/ThrowMath.java create mode 100644 core/src/model/Goal.java create mode 100644 core/src/model/Level.java delete mode 100644 core/src/model/Model.java create mode 100644 core/src/model/Projectile.java diff --git a/core/src/com/throwgame/main/ThrowMath.java b/core/src/com/throwgame/main/ThrowMath.java new file mode 100644 index 0000000..4d22cda --- /dev/null +++ b/core/src/com/throwgame/main/ThrowMath.java @@ -0,0 +1,33 @@ +package com.throwgame.main; + +public class ThrowMath { + private double tanA; + private double coefficient; + private double y0; + private boolean initialised; + + public ThrowMath(){ + this.tanA = 0; + this.coefficient = 0; + this.y0 = 0; + this.initialised = false; + } + + public void initThrow(double alpha, double g, double v0, double y0){ + this.tanA = Math.tan(alpha); + this.coefficient = g / (2 * Math.pow(v0, 2) * Math.pow(Math.cos(alpha), 2)); + this.y0 = y0; + this.initialised = true; + } + + public int calculateY(int xPos){ + if(this.initialised){ + double res = this.y0 + this.tanA * xPos - this.coefficient * Math.pow(xPos, 2); + return (int) res; + } + else{ + System.out.println("Der Wurf wurde nicht initialisiert!"); + return -1; + } + } +} diff --git a/core/src/model/Goal.java b/core/src/model/Goal.java new file mode 100644 index 0000000..9735be0 --- /dev/null +++ b/core/src/model/Goal.java @@ -0,0 +1,48 @@ +package model; + +public class Goal { + + private int xPos; + private int yPos; + private int sizeX; + private int sizeY; + + public Goal(int xPos, int yPos, int sizeX, int sizeY){ + this.xPos = xPos; + this.yPos = yPos; + this.sizeX = sizeX; + this.sizeY = sizeY; + } + + 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; + } + + public int getSizeX() { + return sizeX; + } + + public void setSizeX(int sizeX) { + this.sizeX = sizeX; + } + + public int getSizeY() { + return sizeY; + } + + public void setSizeY(int sizeY) { + this.sizeY = sizeY; + } +} diff --git a/core/src/model/Level.java b/core/src/model/Level.java new file mode 100644 index 0000000..47e2fb7 --- /dev/null +++ b/core/src/model/Level.java @@ -0,0 +1,41 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package model; + +import com.throwgame.main.ThrowMath; + +/** + * + * @author Jan + */ +public class Level { + + private Goal goal; + private Projectile projectile; + private ThrowMath math; + + public Level(Goal goal, Projectile projectile){ + this.goal = goal; + this.projectile = projectile; + this.math = new ThrowMath(); + } + + public void projectileReleased(){ + + } + + public void step(){ + + } + + public Goal getGoal() { + return goal; + } + + public Projectile getProjectile() { + return projectile; + } +} diff --git a/core/src/model/Model.java b/core/src/model/Model.java deleted file mode 100644 index c0fc09e..0000000 --- a/core/src/model/Model.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package model; - -/** - * - * @author Jan - */ -public class Model { - -} diff --git a/core/src/model/Projectile.java b/core/src/model/Projectile.java new file mode 100644 index 0000000..93d79bd --- /dev/null +++ b/core/src/model/Projectile.java @@ -0,0 +1,79 @@ +package model; + +public class Projectile { + + private int xPos; + private int yPos; + private int mass; + private int radius; + private double vX; + private double vY; + private final int type; + + Projectile(int xPos, int yPos, int type){ + this.xPos = xPos; + this.yPos = yPos; + this.type = type; + this.vX = 0; + this.vY = 0; + + switch(type){ + case 0: + mass = 5; + radius = 5; + break; + } + } + + 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; + } + + public int getMass() { + return mass; + } + + public void setMass(int mass) { + this.mass = mass; + } + + public int getRadius() { + return radius; + } + + public void setRadius(int radius) { + this.radius = radius; + } + + public double getvX() { + return vX; + } + + public void setvX(double vX) { + this.vX = vX; + } + + public double getvY() { + return vY; + } + + public void setvY(double vY) { + this.vY = vY; + } + + public int getType() { + return type; + } +}