Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
CSE2102_group_37/src/main/Player.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
87 lines (75 sloc)
1.52 KB
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
package main; | |
import java.awt.Graphics; | |
import java.awt.Rectangle; | |
import entity.EntityTypeA; | |
import entity.EntityTypeD; | |
public class Player extends GameObject implements EntityTypeA{ | |
private double velX = 0; | |
private double velY = 0; | |
private int health = 3; | |
private Skins skin; | |
private Game game; | |
private Controller controller; | |
public Player(double x, double y, Skins skin, Game game, Controller controller){ | |
super(x,y); | |
this.skin = skin; | |
this.game = game; | |
this.controller = controller; | |
} | |
public void tick(){ | |
x += velX; | |
y += velY; | |
if (x <= 0 ){ | |
x = 0; | |
} | |
if (x >= 736){ | |
x = 736; | |
} | |
if (y <= 0){ | |
y = 0; | |
} | |
if (y >= 536){ | |
y = 536; | |
} | |
for(int n = 0; n < game.ed.size(); n++){ | |
EntityTypeD tempa = game.ed.get(n); | |
if(GamePhysics.Collision(this, tempa)){ | |
if(health == 1){ | |
game.State = game.State.END; | |
health = 3; | |
} | |
else{ | |
health--; | |
controller.removeEntity(tempa); | |
} | |
} | |
} | |
} | |
public void render(Graphics g){ | |
g.drawImage(skin.player, (int)x, (int)y, null); | |
} | |
public double getX(){ | |
return x; | |
} | |
public double getY(){ | |
return y; | |
} | |
public void setX(double x){ | |
this.x = x; | |
} | |
public void setY(double y){ | |
this.y = y; | |
} | |
public void setVelX(double velX){ | |
this.velX = velX; | |
} | |
public void setVelY(double velY){ | |
this.velY = velY; | |
} | |
public Rectangle getBounds(){ | |
return new Rectangle((int)x, (int) y, 64, 64); | |
} | |
public int getHealth(){ | |
return health; | |
} | |
} |