-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7e018d
commit 79eaf1b
Showing
24 changed files
with
461 additions
and
221 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.