-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacter.java
More file actions
186 lines (150 loc) · 3.95 KB
/
Copy pathCharacter.java
File metadata and controls
186 lines (150 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package AoJGame;
import javafx.geometry.Rectangle2D;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.scene.paint.ImagePattern;
import javafx.scene.shape.Rectangle;
import javafx.stage.Screen;
import java.util.ArrayList;
public class Character extends Rectangle
{
protected GameEngine game;
private Character enemy;
private int healthPoints;
protected Rectangle2D primaryScreenBounds = Screen.getPrimary().getBounds();
protected final float GRAVITAIONALFORCE = (float)(primaryScreenBounds.getHeight()*.0004);
protected float gravity;
protected boolean jumping = false;
protected final int MOVEMENTSPEED = 5;
protected String direction;
protected double prevXPos;
protected int maxPosition;
protected boolean shooting = false;
protected int sleepTime = 0;
protected Rectangle healthBar = new Rectangle(.25 * primaryScreenBounds.getWidth(), 35);
public Character()
{
super.setY(primaryScreenBounds.getHeight()*(.84));
gravity = 0;
}
public void reduceHealth(int dmg)
{
this.healthPoints -= dmg;
}
public void setPrevXPos(double prevXPos)
{
this.prevXPos = prevXPos;
}
public void setHealth(int healthPoints)
{
this.healthPoints = healthPoints;
}
public void setDirection(String direction)
{
this.direction = direction;
}
public double getPrevXPos()
{
return this.prevXPos;
}
public int getHealth()
{
return this.healthPoints;
}
public String getDirection()
{
return this.direction;
}
public int getMovementSpeed()
{
return this.MOVEMENTSPEED;
}
public void defenseAbility(){}
public boolean isAlive()
{
if (this.healthPoints > 0)
return true;
else if (this.healthPoints <= 0)
return false;
else
return true;
}
public void handleMovement(ArrayList input)
{
//Identifying which way the character is facing
if (this.getX() > this.getPrevXPos())
{
this.setDirection("right");
//this.setFill(archerRightP);
}
if (this.getX() < this.getPrevXPos())
{
this.setDirection("left");
//this.setFill(archerLeftP);
}
if(input.contains("A"))
{
this.setX(this.getX() - MOVEMENTSPEED);
}
if(input.contains(("D")))
{
this.setX(this.getX() + MOVEMENTSPEED);
}
if(jumping)
{
this.setY(this.getY() - 10 + gravity);
gravity += GRAVITAIONALFORCE;
if(this.getY() + this.getHeight() > game.getGround().getY())
{
gravity = 0;
jumping = false;
}
}
if (((this.getY()) + (this.getHeight())) > (game.getGround().getY() - game.getGround().getHeight()))
this.setY(game.getGround().getY() - (this.getHeight()));
if (this.getY() < 0){
this.setY(0);
}
if ((this.getX() < 0)){
this.setX(0);
}
if (this.getX() > maxPosition)
this.setX(maxPosition);
}
public void setGame(GameEngine game)
{
this.game = game;
}
public void jump()
{
this.jumping = true;
}
public void setEnemy(Character enemy)
{
this.enemy = enemy;
}
public Character getEnemy()
{
return this.enemy;
}
public int getSleepTime()
{
return this.sleepTime;
}
public void setSleepTime(int sleepTime)
{
this.sleepTime = sleepTime;
}
protected javafx.geometry.Rectangle2D getBoundary(double posX, double posY, double width, double height)
{
return new javafx.geometry.Rectangle2D(posX, posY, width, height);
}
public void setHealthBar(Rectangle healthBar)
{
this.healthBar = healthBar;
}
public Rectangle getHealthBar()
{
return this.healthBar;
}
}