diff --git a/bin/Object/Projectile.class b/bin/Object/Projectile.class new file mode 100644 index 0000000..7898201 Binary files /dev/null and b/bin/Object/Projectile.class differ diff --git a/bin/ShadowPot/ball.png b/bin/ShadowPot/ball.png new file mode 100644 index 0000000..c0561fb Binary files /dev/null and b/bin/ShadowPot/ball.png differ diff --git a/bin/logic/entity/Chicknight.class b/bin/logic/entity/Chicknight.class index 64cfadd..c91eef2 100644 Binary files a/bin/logic/entity/Chicknight.class and b/bin/logic/entity/Chicknight.class differ diff --git a/bin/logic/entity/Enemy.class b/bin/logic/entity/Enemy.class index f477b40..a3afc4c 100644 Binary files a/bin/logic/entity/Enemy.class and b/bin/logic/entity/Enemy.class differ diff --git a/bin/logic/entity/Entity.class b/bin/logic/entity/Entity.class index 7007064..4b97f14 100644 Binary files a/bin/logic/entity/Entity.class and b/bin/logic/entity/Entity.class differ diff --git a/bin/logic/entity/EyeOfQwifot.class b/bin/logic/entity/EyeOfQwifot.class index 9beba65..57b75ca 100644 Binary files a/bin/logic/entity/EyeOfQwifot.class and b/bin/logic/entity/EyeOfQwifot.class differ diff --git a/bin/logic/entity/GriszlyEye.class b/bin/logic/entity/GriszlyEye.class index 9b3ca58..0145211 100644 Binary files a/bin/logic/entity/GriszlyEye.class and b/bin/logic/entity/GriszlyEye.class differ diff --git a/bin/logic/entity/MagicalTortoise.class b/bin/logic/entity/MagicalTortoise.class index d478831..d8b2dce 100644 Binary files a/bin/logic/entity/MagicalTortoise.class and b/bin/logic/entity/MagicalTortoise.class differ diff --git a/bin/logic/entity/Player.class b/bin/logic/entity/Player.class index e417bf7..5183ef7 100644 Binary files a/bin/logic/entity/Player.class and b/bin/logic/entity/Player.class differ diff --git a/bin/logic/entity/ShadowPot.class b/bin/logic/entity/ShadowPot.class index 8a4249b..6f258d5 100644 Binary files a/bin/logic/entity/ShadowPot.class and b/bin/logic/entity/ShadowPot.class differ diff --git a/bin/logic/game/GameLogic.class b/bin/logic/game/GameLogic.class index 75164ad..de79225 100644 Binary files a/bin/logic/game/GameLogic.class and b/bin/logic/game/GameLogic.class differ diff --git a/bin/sharedObject/RenderableHolder.class b/bin/sharedObject/RenderableHolder.class index 5240fb2..33f071f 100644 Binary files a/bin/sharedObject/RenderableHolder.class and b/bin/sharedObject/RenderableHolder.class differ diff --git a/res/ShadowPot/ball.png b/res/ShadowPot/ball.png new file mode 100644 index 0000000..c0561fb Binary files /dev/null and b/res/ShadowPot/ball.png differ diff --git a/src/Object/Projectile.java b/src/Object/Projectile.java new file mode 100644 index 0000000..1c8a80d --- /dev/null +++ b/src/Object/Projectile.java @@ -0,0 +1,108 @@ +package Object; + +import javafx.scene.canvas.GraphicsContext; +import javafx.scene.paint.Color; +import javafx.scene.shape.Rectangle; +import logic.entity.Player; +import logic.game.GameLogic; +import sharedObject.IRenderable; +import sharedObject.RenderableHolder; + +public class Projectile implements IRenderable { + + protected double worldX, worldY; + public double screenX, screenY; + private Rectangle solidArea,solidScreen; + private double angle; + private int dmg, speed; + protected int z, radius; + protected boolean visible, destroyed; + public GameLogic gameLogic; + private double xspeed, yspeed; + + public Projectile(double worldX, double worldY, double angle, GameLogic gameLogic) { + this.worldX = worldX; + this.worldY = worldY; + this.gameLogic = gameLogic; + this.angle = angle; + this.speed = 3; + this.z = 10; + this.visible = true; + this.destroyed = false; + this.xspeed = Math.cos(angle) * speed; + this.yspeed = Math.sin(angle) * speed; + this.dmg = 5; + solidArea = new Rectangle(0, 0, 8, 8); + solidScreen = new Rectangle(screenX,screenY,8,8); + } + + public void update() { + worldX += xspeed; + worldY += yspeed; + screenX = worldX - gameLogic.getPlayer().getWorldX() + gameLogic.getPlayer().screenX; + screenY = worldY - gameLogic.getPlayer().getWorldY() + gameLogic.getPlayer().screenY; + solidArea.setX(screenX); + solidArea.setY(screenY); +// System.out.println("X =" + xspeed + " Y = " + yspeed); + boolean isOut = screenX < 0 || screenX > 1280 || screenY < 0 || screenY > 720; + if (isOut) { + destroyed = true; + } + checkEnemyHit(); + } + + public void checkEnemyHit() { + Player p =gameLogic.getPlayer(); + int x = (int) p.getScreenX(); + int y = (int) p.getScreenY(); + int width = (int) p.getSolidArea().getWidth(); + int height = (int) p.getSolidArea().getHeight(); + boolean overlap = solidArea.intersects(x,y,width,height); + System.out.println("Overlap = " + overlap); + System.out.println("X = " + x + " Y = " + y); + if (overlap) { + p.changeHealthTo(p.getCurrentHealth() - dmg); + destroyed = true; + } + solidArea.setX(screenX); + solidArea.setY(screenY); + } + + public Rectangle getSolidArea() { + return solidArea; + } + + @Override + public int getZ() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void draw(GraphicsContext gc) { + // TODO Auto-generated method stub + gc.drawImage(RenderableHolder.ball, screenX, screenY); + drawHitbox(gc); + } + + @Override + public boolean isDestroyed() { + // TODO Auto-generated method stub + + return destroyed; + } + + @Override + public boolean isVisible() { + // TODO Auto-generated method stub + return visible; + } + + // Debugger + public void drawHitbox(GraphicsContext gc) { + gc.setLineWidth(2); + gc.setFill(Color.RED); + gc.strokeRect(solidArea.getX(), solidArea.getY(), solidArea.getWidth(), + solidArea.getHeight()); + } +} diff --git a/src/logic/entity/Chicknight.java b/src/logic/entity/Chicknight.java index b52c5fd..41876f6 100644 --- a/src/logic/entity/Chicknight.java +++ b/src/logic/entity/Chicknight.java @@ -7,21 +7,17 @@ import logic.game.GameLogic; import sharedObject.RenderableHolder; -public class Chicknight extends Entity { - private double angle = 0; +public class Chicknight extends Enemy { + private Image image = RenderableHolder.CKRight; private String currentState = "default"; - // AttackBlock - private Rectangle attackBlock; - private int attackOffset; - public Chicknight(int x, int y, GameLogic gameLogic) { super(x,y,gameLogic); this.maxHp = 10; this.currentHealth = maxHp; this.dmg = 5; + this.z = -100; this.speed = 1; - image = RenderableHolder.CKRight; initSolidArea(); initAttackBlock(); } @@ -70,20 +66,14 @@ public void draw(GraphicsContext gc) { drawAttackBlock(gc); } - @Override - public void attack(Entity p) { - // TODO Auto-generated method stub - System.out.println(currentState); - ((Player) p).changeHealthTo(gameLogic.getPlayer().getCurrentHealth()-dmg); - System.out.println("SKDASDKLASMDKANDKLDKLMLWQD"); - - } + @Override public void update() { // TODO Auto-generated method stub - screenX = worldX - gameLogic.getPlayer().worldX + gameLogic.getPlayer().screenX; - screenY = worldY - gameLogic.getPlayer().worldY + gameLogic.getPlayer().screenY; + super.update(); + + Player player = gameLogic.getPlayer(); if (!canAttack(player.worldX, player.worldY, worldX, worldY, (int)(attackBlock.getWidth()+solidArea.getWidth()))) { angle = Math.atan2(player.worldY - worldY, player.worldX - worldX); @@ -117,7 +107,6 @@ public void update() { currentState = "attack"; attack(gameLogic.getPlayer()); } - updateAttackBlock(); } @@ -126,54 +115,15 @@ public void initSolidArea() { } public void initAttackBlock() { -// screenX = worldX-gameLogic.getPlayer().worldX+gameLogic.getPlayer().screenX; -// screenY = worldY-gameLogic.getPlayer().worldY+gameLogic.getPlayer().screenY; - attackBlock = new Rectangle(screenX, screenY, 10 * 2, 7 * 2); -// attackOffset = (int)(*2); - } - - public void checkEnemyHit(Rectangle attackBlock) { - int x = (int) getSolidArea().getX(); - int y = (int) getSolidArea().getY(); - int width = (int) getSolidArea().getWidth(); - int height = (int) getSolidArea().getHeight(); - boolean overlap = attackBlock.intersects(x,y,width,height); - if (overlap) this.attack(gameLogic.getPlayer()); - } - - public void updateAttackBlock() { - attackBlock.setX(screenX + solidArea.getX()); - attackBlock.setY(screenY + solidArea.getY()); - } - - public void changeHealthTo(int health) { - if (health>=maxHp) { - currentHealth = maxHp; - } - else if (health<=0) { - currentHealth = 0; - setDestroyed(true); - } - else { - currentHealth = health; -// System.out.println("Plathong" + currentHealth); - } + attackBlock = new Rectangle(screenX+solidArea.getWidth(), screenY, 10 * 2, 7 * 2); } - public int getCurrentHealth() { - return currentHealth; - } - - // for Debugging - public void drawHitbox(GraphicsContext gc) { - gc.setLineWidth(2); - gc.setFill(Color.PINK); - gc.strokeRect(screenX, screenY, 32, 64); - } - +// Debug Chick public void drawAttackBlock(GraphicsContext gc) { gc.setFill(Color.BLACK); - gc.strokeRect(attackBlock.getX()+solidArea.getWidth(), attackBlock.getY(), attackBlock.getWidth(), attackBlock.getHeight()); + gc.strokeRect(attackBlock.getX()+solidArea.getWidth(), attackBlock.getY(), attackBlock.getWidth(), + attackBlock.getHeight()); } + } diff --git a/src/logic/entity/Enemy.java b/src/logic/entity/Enemy.java index f09941c..758ab90 100644 --- a/src/logic/entity/Enemy.java +++ b/src/logic/entity/Enemy.java @@ -1,12 +1,78 @@ package logic.entity; +import javafx.scene.canvas.GraphicsContext; +import javafx.scene.paint.Color; +import javafx.scene.shape.Rectangle; import logic.game.GameLogic; public abstract class Enemy extends Entity{ + + protected double angle = 0; + protected String currentState; + public Enemy(int x, int y, GameLogic gameLogic) { super(x, y, gameLogic); // TODO Auto-generated constructor stub } + + public void changeHealthTo(int health) { + if (health>=maxHp) { + currentHealth = maxHp; + } + else if (health<=0) { + currentHealth = 0; + setDestroyed(true); + } + else { + currentHealth = health; +// System.out.println("Plathong" + currentHealth); + } + } + public boolean checkEnemyHit() { + Player p =gameLogic.getPlayer(); + int x = (int) p.getScreenX(); + int y = (int) p.getScreenY(); + int width = (int) p.getSolidArea().getWidth(); + int height = (int) p.getSolidArea().getHeight(); + boolean overlap = solidScreen.intersects(x,y,width,height); +// System.out.println("Overlap = " + overlap); +// System.out.println("X = " + x + " Y = " + y); + return overlap; + + } + + public int getCurrentHealth() { + return currentHealth; + } + + public void attack(Entity p) { + // TODO Auto-generated method stub + System.out.println(this.getClass().getSimpleName()+"Attack"); + if (checkEnemyHit()) ((Player) p).changeHealthTo(gameLogic.getPlayer().getCurrentHealth()-dmg); + } + + //Debugger + public void drawHitbox(GraphicsContext gc) { + gc.setLineWidth(2); + gc.setFill(Color.PINK); + gc.strokeRect(solidScreen.getX(), solidScreen.getY(), solidScreen.getWidth(), solidScreen.getHeight()); + } - protected String currentState = "alive"; + public void drawAttackBlock(GraphicsContext gc) { + gc.setFill(Color.BLACK); + gc.strokeRect(solidArea.getX(), attackBlock.getY(), attackBlock.getWidth(), + attackBlock.getHeight()); + } + + public void updateAttackBlock() { + attackBlock.setX(screenX); + attackBlock.setY(screenY); + } + + public void update() { + super.update(); + solidScreen = new Rectangle(screenX+solidArea.getX(),screenY+solidArea.getY(),solidArea.getWidth(),solidArea.getHeight()); + } + public abstract void initSolidArea(); + public abstract void initAttackBlock(); } diff --git a/src/logic/entity/Entity.java b/src/logic/entity/Entity.java index d1a8621..cbadf88 100644 --- a/src/logic/entity/Entity.java +++ b/src/logic/entity/Entity.java @@ -5,22 +5,27 @@ import logic.game.GameLogic; import sharedObject.IRenderable; -public abstract class Entity implements IRenderable{ - protected double worldX,worldY; - public double screenX,screenY; - protected int z,radius; - protected boolean visible,destroyed; +public abstract class Entity implements IRenderable { + protected double worldX, worldY; + public double screenX, screenY; + protected int z, radius; + protected boolean visible, destroyed; protected int speed; protected String direction; - public Rectangle solidArea; + protected Image image; + public Rectangle solidArea,solidScreen; public boolean collisionOn = false; public GameLogic gameLogic; + + // Status protected int maxHp; protected int currentHealth; protected int dmg; - protected Image image; - - public Entity(int x, int y,GameLogic gameLogic){ + + // AttackBlock + protected Rectangle attackBlock; + + public Entity(int x, int y, GameLogic gameLogic) { visible = true; destroyed = false; worldX = x; @@ -28,14 +33,18 @@ public Entity(int x, int y,GameLogic gameLogic){ this.gameLogic = gameLogic; this.direction = "right"; } - + public abstract void attack(Entity t); - public abstract void update(); - - public boolean canAttack(double x1,double y1,double x2,double y2,int attackRange) { - return (Math.abs(x1-x2) < attackRange && Math.abs(y1-y2) < attackRange); + + public void update() { + screenX = worldX - gameLogic.getPlayer().worldX + gameLogic.getPlayer().screenX; + screenY = worldY - gameLogic.getPlayer().worldY + gameLogic.getPlayer().screenY; } - + + public boolean canAttack(double x1, double y1, double x2, double y2, int attackRange) { + return (Math.abs(x1 - x2) < attackRange && Math.abs(y1 - y2) < attackRange); + } + @Override public int getZ() { // TODO Auto-generated method stub @@ -60,8 +69,8 @@ public double getWorldX() { public double getWorldY() { return worldY; - } - + } + public String getDirection() { return direction; } @@ -89,7 +98,7 @@ public Rectangle getSolidArea() { public boolean isCollisionOn() { return collisionOn; } - + public void setCollisionOn(boolean collisionOn) { this.collisionOn = collisionOn; } @@ -97,5 +106,5 @@ public void setCollisionOn(boolean collisionOn) { public void setDestroyed(boolean destroyed) { this.destroyed = destroyed; } - + } diff --git a/src/logic/entity/EyeOfQwifot.java b/src/logic/entity/EyeOfQwifot.java index 21a9844..d01cd84 100644 --- a/src/logic/entity/EyeOfQwifot.java +++ b/src/logic/entity/EyeOfQwifot.java @@ -1,54 +1,86 @@ package logic.entity; import javafx.scene.canvas.GraphicsContext; +import javafx.scene.shape.Rectangle; import logic.game.GameLogic; import sharedObject.RenderableHolder; public class EyeOfQwifot extends Miniboss{ - public EyeOfQwifot(int x, int y, GameLogic gameLogic) { - super(x, y, gameLogic); - maxHp = 100; - z = -100; - image = RenderableHolder.EQ1; - // TODO Auto-generated constructor stub - } + public EyeOfQwifot(int x, int y, GameLogic gameLogic) { + super(x, y, gameLogic); + maxHp = 100; + currentHealth = maxHp; + z = -100; + image = RenderableHolder.EQ1; + currentState = "alive"; +// initAttackBlock(); + initSolidArea(); + // TODO Auto-generated constructor stub + } - @Override - public void draw(GraphicsContext gc) { - // TODO Auto-generated method stub - switch(currentState) { - case "alive": - if (gameLogic.getCounter()/10%2==1) - image = RenderableHolder.EQ1; - - else - image = RenderableHolder.EQ2; - break; - case "dead": - if (gameLogic.getCounter()/10%2==1) - image = RenderableHolder.EQDead1; - - else - image = RenderableHolder.EQDead2; - break; - } - gc.drawImage(image,screenX,screenY); - // TODO Auto-generated method stub - - } + @Override + public void draw(GraphicsContext gc) { + // TODO Auto-generated method stub + switch(currentState) { + case "alive": + if (gameLogic.getCounter()/10%2==1) + image = RenderableHolder.EQ1; + + else + image = RenderableHolder.EQ2; + break; + case "dead": + if (gameLogic.getCounter()/10%2==1) + image = RenderableHolder.EQDead1; + + else + image = RenderableHolder.EQDead2; + break; + } + gc.drawImage(image,screenX,screenY); + // TODO Auto-generated method stub + drawHitbox(gc); + + } + + @Override + public void attack(Entity t) { + // TODO Auto-generated method stub + + } + + @Override + public void update() { + // TODO Auto-generated method stub + super.update(); + } @Override - public void attack(Entity t) { + public void initSolidArea() { // TODO Auto-generated method stub - + solidArea = new Rectangle(0,0,256,256); + } @Override - public void update() { + public void initAttackBlock() { // TODO Auto-generated method stub - screenX = worldX - gameLogic.getPlayer().worldX + gameLogic.getPlayer().screenX; - screenY = worldY - gameLogic.getPlayer().worldY + gameLogic.getPlayer().screenY; +// solidArea = new Rectangle(0,0,256,256); + } + + public void changeHealthTo(int health) { + if (health>=maxHp) { + currentHealth = maxHp; + } + else if (health<=0) { + currentHealth = 0; + currentState = "dead"; + } + else { + currentHealth = health; +// System.out.println("Plathong" + currentHealth); + } } -} +} \ No newline at end of file diff --git a/src/logic/entity/GriszlyEye.java b/src/logic/entity/GriszlyEye.java index 8e5b5f4..d5d8b84 100644 --- a/src/logic/entity/GriszlyEye.java +++ b/src/logic/entity/GriszlyEye.java @@ -2,71 +2,81 @@ import javafx.scene.canvas.GraphicsContext; import javafx.scene.image.Image; +import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import logic.game.GameLogic; import sharedObject.RenderableHolder; -public class GriszlyEye extends Entity{ +public class GriszlyEye extends Enemy { private double angle = 0; public String currentState = "default"; - public GriszlyEye(int x,int y,GameLogic gameLogic) { - super(x,y,gameLogic); - this.speed =3; - solidArea = new Rectangle(20,0,24,32); - image = RenderableHolder.GERight; + + public GriszlyEye(int x, int y, GameLogic gameLogic) { + super(x, y, gameLogic); + this.maxHp = 10; + this.currentHealth = maxHp; + this.dmg = 3; + this.z = -100; + this.speed = 3; + this.dmg = 3; + this.image = RenderableHolder.GERight; + initSolidArea(); + initAttackBlock(); } + + @Override public void draw(GraphicsContext gc) { // TODO Auto-generated method stub - switch(direction) { + switch (direction) { case "right": - if(currentState=="default") - image = RenderableHolder.GERight; + if (currentState == "default") + image = RenderableHolder.GERight; else { - if (gameLogic.getCounter()/10%2==1) { + if (gameLogic.getCounter() / 10 % 2 == 1) { image = RenderableHolder.GERightWalk; - } - else + } else image = RenderableHolder.GERightWalk2; } break; case "left": - if(currentState=="default") - image = RenderableHolder.GELeft; + if (currentState == "default") + image = RenderableHolder.GELeft; else { - if (gameLogic.getCounter()/10%2==1) { + if (gameLogic.getCounter() / 10 % 2 == 1) { image = RenderableHolder.GELeftWalk; - } - else + } else image = RenderableHolder.GELeftWalk2; } break; } gc.drawImage(image, screenX, screenY); + drawHitbox(gc); +// drawAttackBlock(gc); } - - @Override - public void attack(Entity p) { - // TODO Auto-generated method stub - - } +// @Override +// public void attack(Entity p) { +// // TODO Auto-generated method stub +// System.out.println("GrsizlyEye Attack"); +// +// ((Player) p).changeHealthTo(gameLogic.getPlayer().getCurrentHealth()-dmg); +// } @Override public void update() { // TODO Auto-generated method stub - screenX = worldX-gameLogic.getPlayer().worldX+gameLogic.getPlayer().screenX; - screenY = worldY-gameLogic.getPlayer().worldY+gameLogic.getPlayer().screenY; + super.update(); Player player = gameLogic.getPlayer(); if (!canAttack(player.worldX, player.worldY, worldX, worldY, 24)) { - angle = Math.atan2(player.worldY-worldY,player.worldX-worldX); + angle = Math.atan2(player.worldY - worldY, player.worldX - worldX); double xspeed = Math.cos(angle) * speed; double yspeed = Math.sin(angle) * speed; currentState = "walking"; - if(yspeed<0) + if (yspeed < 0) direction = "up"; else direction = "down"; @@ -75,24 +85,39 @@ public void update() { if (collisionOn == false) { worldY += yspeed; - } - - if (xspeed<0) + } + + if (xspeed < 0) direction = "left"; - else direction = "right"; - + else + direction = "right"; + setCollisionOn(false); gameLogic.checkTile(this); if (collisionOn == false) { - worldX += xspeed; + worldX += xspeed; } - + } - + else { currentState = "default"; attack(gameLogic.getPlayer()); } + updateAttackBlock(); } + + public void initSolidArea() { + solidArea = new Rectangle(20, 0, 24, 32); + solidScreen = new Rectangle(screenX,screenY,8,8); + + } + + public void initAttackBlock() { + attackBlock = new Rectangle(20, 0, 24, 32); + + } + + } diff --git a/src/logic/entity/MagicalTortoise.java b/src/logic/entity/MagicalTortoise.java index 755cc74..c784edb 100644 --- a/src/logic/entity/MagicalTortoise.java +++ b/src/logic/entity/MagicalTortoise.java @@ -6,9 +6,9 @@ import sharedObject.RenderableHolder; public class MagicalTortoise extends Entity{ + private Image image = RenderableHolder.MTRight1; public MagicalTortoise(int x, int y, GameLogic gameLogic) { super(x, y, gameLogic); - image = RenderableHolder.MTRight1; // TODO Auto-generated constructor stub } diff --git a/src/logic/entity/Player.java b/src/logic/entity/Player.java index 0d3869d..776b767 100644 --- a/src/logic/entity/Player.java +++ b/src/logic/entity/Player.java @@ -28,8 +28,10 @@ public class Player extends Entity{ private int healthBarY = (int) (11*1.5); //Status + protected int maxHp = 100; + protected int currentHealth = maxHp; protected float healthWidth = healthBarWidth; - + protected int dmg = 5; protected int iframe = 0; //AttackBlock @@ -40,13 +42,7 @@ public Player(int x, int y,GameLogic gameLogic) { super(x,y,gameLogic); this.speed = 3; this.radius = 32; - - maxHp = 100; - currentHealth = maxHp; - dmg = 5; - - image = RenderableHolder.playerRight; - + screenX = gameLogic.getGameScreen().getWidth()/2-radius; screenY = gameLogic.getGameScreen().getHeight()/2-radius; initSolidArea(); @@ -55,17 +51,18 @@ public Player(int x, int y,GameLogic gameLogic) { @Override public void draw(GraphicsContext gc) { int count = 0; + Image playerImage = RenderableHolder.playerRight; // TODO Auto-generated method stub switch(direction) { case "left": - image = (RenderableHolder.playerLeft); + playerImage = (RenderableHolder.playerLeft); break; case "right": - image = RenderableHolder.playerRight; + playerImage = RenderableHolder.playerRight; break; } - gc.drawImage(image , screenX, screenY); + gc.drawImage(playerImage , screenX, screenY); drawUI(gc); //Debugging @@ -90,13 +87,14 @@ public void drawAttackBlock(GraphicsContext gc){ gc.strokeRect(attackBlock.getX(), attackBlock.getY(), attackBlock.getWidth(),attackBlock.getHeight()); } - public void attack(Entity enemy) { + public void attack(Entity e) { attackState = "yes"; - ((Chicknight)enemy).changeHealthTo(((Chicknight)enemy).getCurrentHealth()-dmg); + System.out.println("Player Attack "+e.getClass().getSimpleName()); + ((Enemy)e).changeHealthTo(((Enemy)e).getCurrentHealth()-dmg); } - + @Override public void update() { // TODO Auto-generated method stub direction = ""; @@ -144,12 +142,15 @@ public void update() { } if (InputUtility.isLeftClickTriggered()) { for (Entity entity: gameLogic.getGameObjectContainer()) { - if ((entity instanceof Chicknight)) { - Chicknight enemy = ((Chicknight)entity); + if ((entity instanceof Enemy)) { + Enemy enemy = ((Enemy)entity); boolean canAtk = canAttack(worldX,worldY,enemy.getWorldX(),enemy.getWorldY(),(int) (solidArea.getWidth()+attackBlock.getWidth())); if (canAtk) { attack(entity); } + if(enemy instanceof EyeOfQwifot) { + System.out.println(enemy.solidScreen.getWidth()+" "+enemy.solidScreen.getHeight()); + } } } diff --git a/src/logic/entity/ShadowPot.java b/src/logic/entity/ShadowPot.java index 052f369..bfe56bd 100644 --- a/src/logic/entity/ShadowPot.java +++ b/src/logic/entity/ShadowPot.java @@ -1,58 +1,86 @@ package logic.entity; +import Object.Projectile; import javafx.scene.canvas.GraphicsContext; +import javafx.scene.shape.Rectangle; import logic.game.GameLogic; import sharedObject.RenderableHolder; public class ShadowPot extends Enemy{ + + private int cooldown; + public ShadowPot(int x, int y, GameLogic gameLogic) { + super(x, y, gameLogic); + image = RenderableHolder.SPRight1; + maxHp = 10; + currentHealth = maxHp; + cooldown = 1*60; + initSolidArea(); + initAttackBlock(); + } - public ShadowPot(int x, int y, GameLogic gameLogic) { - super(x, y, gameLogic); - image = RenderableHolder.SPRight1; - // TODO Auto-generated constructor stub - } + @Override + public void draw(GraphicsContext gc) { + // TODO Auto-generated method stub + switch(direction) { + case "right": + if (gameLogic.getCounter()/10%2==1) + image = RenderableHolder.SPRight1; - @Override - public void draw(GraphicsContext gc) { - // TODO Auto-generated method stub - switch(direction) { - case "right": - if (gameLogic.getCounter()/10%2==1) - image = RenderableHolder.SPRight1; - - else - image = RenderableHolder.SPRight2; - break; - case "left": - if (gameLogic.getCounter()/10%2==1) - image = RenderableHolder.SPLeft1; - - else - image = RenderableHolder.SPLeft2; - - break; - } - gc.drawImage(image, screenX, screenY); - // TODO Auto-generated method stub - } + else + image = RenderableHolder.SPRight2; + break; + case "left": + if (gameLogic.getCounter()/10%2==1) + image = RenderableHolder.SPLeft1; + + else + image = RenderableHolder.SPLeft2; + + break; + } + gc.drawImage(image, screenX, screenY); + // TODO Auto-generated method stub + drawHitbox(gc); + } + + @Override + public void attack(Entity t) { + // TODO Auto-generated method stub + Projectile projectile = new Projectile(worldX+solidArea.getX(), worldY+solidArea.getY(), angle,gameLogic); + gameLogic.addNewProjectile(projectile); + } + + @Override + public void update() { + // TODO Auto-generated method stub + super.update(); + Player player = gameLogic.getPlayer(); + angle = Math.atan2(player.worldY - worldY, player.worldX - worldX); + double xDirection = Math.cos(Math.atan2(player.worldY-worldY,player.worldX-worldX)); + if(xDirection<0) + direction = "left"; + else + direction = "right"; + + if(cooldown==0) { + attack(gameLogic.getPlayer()); + cooldown = 1*60; + } + cooldown--; + } @Override - public void attack(Entity t) { + public void initSolidArea() { // TODO Auto-generated method stub - + solidArea = new Rectangle(16,24,32,40); + solidScreen = new Rectangle(screenX,screenY,8,8); } @Override - public void update() { + public void initAttackBlock() { // TODO Auto-generated method stub - screenX = worldX - gameLogic.getPlayer().worldX + gameLogic.getPlayer().screenX; - screenY = worldY - gameLogic.getPlayer().worldY + gameLogic.getPlayer().screenY; - Player player = gameLogic.getPlayer(); - double xDirection = Math.cos(Math.atan2(player.worldY-worldY,player.worldX-worldX)); - if(xDirection<0) - direction = "left"; - else - direction = "right"; + attackBlock = new Rectangle(16,24,32,40); } -} +} \ No newline at end of file diff --git a/src/logic/game/GameLogic.java b/src/logic/game/GameLogic.java index 305a90c..0cfd6dd 100644 --- a/src/logic/game/GameLogic.java +++ b/src/logic/game/GameLogic.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.List; +import Object.Projectile; import drawing.GameScreen; import input.InputUtility; import javafx.scene.canvas.GraphicsContext; @@ -20,13 +21,16 @@ public class GameLogic { private ArrayList gameObjectContainer; + private ArrayList projectilesContainer; private static int counter = 0; private GameScreen gameScreen; private Player player; private Chicknight ck1; - private GriszlyEye ge1; - private MagicalTortoise mg; + private GriszlyEye GE1; + private MagicalTortoise MG; + private EyeOfQwifot EQ; + private ShadowPot SP; private Map1 map; //GameState @@ -36,6 +40,7 @@ public class GameLogic { public GameLogic(GameScreen gameScreen){ this.gameObjectContainer = new ArrayList(); + this.projectilesContainer = new ArrayList(); this.gameScreen = gameScreen; player = new Player(384,288,this); @@ -43,16 +48,16 @@ public GameLogic(GameScreen gameScreen){ RenderableHolder.getInstance().add(map); ck1 = new Chicknight(200,0,this); - mg = new MagicalTortoise(200,200,this); - ge1 = new GriszlyEye(200,200,this); - EyeOfQwifot eq = new EyeOfQwifot(500, 500, this); - ShadowPot sp = new ShadowPot(300, 200, this); + MG = new MagicalTortoise(200,200,this); + GE1 = new GriszlyEye(200,200,this); + EQ = new EyeOfQwifot(780, 780 , this); + SP = new ShadowPot(300, 500, this); addNewObject(player); addNewObject(ck1); - addNewObject(mg); - addNewObject(ge1); - addNewObject(eq); - addNewObject(sp); + addNewObject(MG); + addNewObject(GE1); + addNewObject(EQ); + addNewObject(SP); } public GameScreen getGameScreen() { @@ -63,6 +68,12 @@ protected void addNewObject(Entity entity){ gameObjectContainer.add(entity); RenderableHolder.getInstance().add(entity); } + + public void addNewProjectile(Projectile p){ + projectilesContainer.add(p); + RenderableHolder.getInstance().add(p); + } + public void checkTile(Entity entity) { int entityLeftWorldX = (int) (entity.getWorldX() + entity.solidArea.getX()); int entityRightWorldX = (int) (entity.getWorldX() + entity.solidArea.getX() + entity.solidArea.getWidth()); @@ -144,6 +155,11 @@ public void logicUpdate(){ if (objectContainer.get(i).isDestroyed()) getGameObjectContainer().remove(objectContainer.get(i)); } + ArrayList projectileContainer = getProjectileContainer(); + for (int i = 0 ;i getGameObjectContainer(){ return gameObjectContainer; } + public ArrayList getProjectileContainer(){ + return projectilesContainer; + } + } diff --git a/src/sharedObject/RenderableHolder.java b/src/sharedObject/RenderableHolder.java index d908f80..008ebe0 100644 --- a/src/sharedObject/RenderableHolder.java +++ b/src/sharedObject/RenderableHolder.java @@ -28,7 +28,7 @@ public class RenderableHolder { public static Image pauseOverlay,pauseMenu, soundButton, urm, volumeButton; public static Image GELeft, GELeftWalk, GELeftWalk2, GERight, GERightWalk, GERightWalk2; public static Image MTLeft1, MTLeft2, MTRight1, MTRight2; - public static Image SPLeft1,SPLeft2,SPRight2,SPRight1,SPLeftAtk,SPRightAtk; + public static Image SPLeft1,SPLeft2,SPRight2,SPRight1,SPLeftAtk,SPRightAtk,ball; public static Image EQ1,EQ2,EQDead1,EQDead2; public static Image moonSprite; public static Image healthBar; @@ -95,6 +95,7 @@ public static void loadResource() { SPRight1 = new Image(ClassLoader.getSystemResource("ShadowPot/ShadowPotRight1.png").toString()); SPRight2 = new Image(ClassLoader.getSystemResource("ShadowPot/ShadowPotRight2.png").toString()); SPRightAtk = new Image(ClassLoader.getSystemResource("ShadowPot/ShadowPotRightAtk.png").toString()); + ball = new Image(ClassLoader.getSystemResource("ShadowPot/ball.png").toString()); //Eye of Qwifot EQ1 = new Image(ClassLoader.getSystemResource("EyeOfQwifot/EyeOfQwifot1.png").toString()); EQ2 = new Image(ClassLoader.getSystemResource("EyeOfQwifot/EyeOfQwifot2.png").toString());