wizard is drinnen

master
Jonathan Hager 6 years ago
parent a6a768ee54
commit f4908aa4bb

@ -298,6 +298,10 @@ public class DungeonGenerator {
temp = new Swordsman(xPos, yPos, lvl);
break;
case 2:
temp = new Wizard(xPos, yPos, lvl);
break;
default:
temp = null;
}

@ -11,7 +11,7 @@ public class Archer extends Entity{
this.maxhp = 5*lvl;
this.hp = this.maxhp;
this.direction = 2;
this.direction = 1;
this.dmg = 3*lvl;
this.id = 0;
this.type = 1;

@ -9,7 +9,7 @@ public class Swordsman extends Entity {
this.maxhp = 5*lvl;
this.hp = this.maxhp;
this.direction = 2;
this.direction = 1;
this.dmg = 3*lvl;
this.id = 1;
this.type = 0;

@ -0,0 +1,143 @@
/*
* 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 com.dungeoncrawler.model.entities;
import com.dungeoncrawler.model.Entity;
/**
*
* @author jonathan
*/
public class Wizard extends Entity{
int counter;
public Wizard(float xPos, float yPos, int lvl) {
super(xPos, yPos, lvl);
this.maxhp = 5*lvl;
this.hp = this.maxhp;
this.direction = 1;
this.dmg = 3*lvl;
this.id = 3;
this.type = 1;
counter = 0;
// TODO: Sinnvolle Werte finden
direction = 1;
}
@Override
public boolean move(int xPosPlayer, int yPosPlayer) {
if(!isToDelete()){
float deltaX = xPosPlayer - (int) xPos;
float deltaY = yPosPlayer - (int) yPos;
double alpha;
if(deltaX == 0 && deltaY >= 0){
alpha = Math.PI / 2;
}
else if(deltaX == 0 && deltaY < 0){
alpha = Math.PI / -2;
}
else{
alpha = Math.abs(Math.atan(deltaY / deltaX));
if(deltaX < 0 && deltaY < 0){
alpha = Math.PI + alpha;
}
else if(deltaX < 0 && deltaY > 0){
alpha = Math.PI - alpha;
}
else if(deltaX > 0 && deltaY < 0){
alpha = 2*Math.PI - alpha;
}
}
int distance = (int) Math.abs((deltaY / Math.sin(alpha)));
if(distance >= 104 && distance <= 184 && counter % 40 == 0){
return true;
}
else{
movementX = (int) (3 * Math.cos(alpha));
movementY = (int) (3 * Math.sin(alpha));
System.out.println(distance);
if(distance < 124){
movementX *= -1;
movementY *= -1;
}
else if(distance >= 124 && distance <= 164){
movementX = 0;
movementY = 0;
}
xPos += movementX;
yPos += movementY;
}
if(alpha >= Math.PI / -2 && alpha <= Math.PI / 2){
setDirection(1);
}
else{
setDirection(0);
}
counter++;
}
return false;
}
@Override
public Entity shoot(int xPosPlayer, int yPosPlayer){
Arrow a = null;
if(!isToDelete()){
float deltaX = xPosPlayer - (int) xPos;
float deltaY = yPosPlayer - (int) yPos;
double alpha;
if(deltaX == 0 && deltaY >= 0){
alpha = Math.PI / 2;
}
else if(deltaX == 0 && deltaY < 0){
alpha = Math.PI / -2;
}
else{
alpha = Math.abs(Math.atan(deltaY / deltaX));
if(deltaX < 0 && deltaY < 0){
alpha = Math.PI + alpha;
}
else if(deltaX < 0 && deltaY > 0){
alpha = Math.PI - alpha;
}
else if(deltaX > 0 && deltaY < 0){
alpha = 2*Math.PI - alpha;
}
}
a = new Arrow(this.xPos + 32, this.yPos + 32, this.lvl, 0);
movementX = (int) (6 * Math.cos(alpha));
movementY = (int) (6 * Math.sin(alpha));
a.setMovementX(movementX);
a.setMovementY(movementY);
a.setAngle(alpha);
if((alpha >= 0 && alpha <= Math.PI / 2) || (alpha <= 2 * Math.PI && alpha >= 2 * Math.PI - Math.PI / 2)){
setDirection(1);
}
else{
setDirection(0);
}
}
return a;
}
}

@ -249,17 +249,28 @@ public class GameScreen {
public void generateNewEntitySprite(Entity e, int i){
if(e != null){
Texture[] tx = new Texture[1];
if(e.getId() == 0){ //nimmt entity ID -> 0 = Archer || 1 = Swordsman || 2 = Arrow
//nimmt entity ID -> 0 = Archer || 1 = Swordsman || 2 = Arrow || 3 = Wizard
switch(e.getId()){
case 0:
tx[0] = new Texture("sprites/archer.png");
entitySprites[i] = new EntitySprite(tx, 64, 64);
}
if(e.getId() == 1){
break;
case 1:
tx[0] = new Texture("sprites/swordsman.png");
entitySprites[i] = new EntitySprite(tx, 64, 64);
}
if(e.getId() == 2){
break;
case 2:
tx[0] = new Texture("sprites/arrow.png");
entitySprites[i] = new EntitySprite(tx, 36, 15);
break;
case 3:
tx[0] = new Texture("sprites/wizard.png");
entitySprites[i] = new EntitySprite(tx, 64, 64);
break;
}
entitySprites[i].update((int) e.getxPos() + 32, (int) e.getyPos() + 32);

Loading…
Cancel
Save