-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.java
94 lines (80 loc) · 1.83 KB
/
Player.java
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
/**
* Player class, used in Minigame for hit detection, movement, etc
* Code completed by Nia Decaire
* <h2>Course Info:</h2>
* ICS4U0 with Krasteva, V.
*
* @version 08-06-2023
* @author BLD Studios
*/
public class Player{
//coordinate position
private int x,y;
//number of good objects caught
private int caught;
//player health
private int health;
/**
* constructor, intializes starting values
*/
public Player(){
x = 490;
y = 420;
caught = 0;
health = 10;
}
/**
* Updates position of player
* @param right Whether right is held
* @param left Whether left is held
*/
public void move(boolean right, boolean left){ //movement method, updates x coordinate
//updates horizontal position based on value fed
if(left){
x-=18;
}
else if(right){
x+=18;
}
//keeps player within bounds
if(x<50){
x = 50;
}
else if(x>900){
x = 900;
}
}
/**
* checks if player hitbox is intersecting with object
*/
public void hitDetect(FallingObject f){
//coordinates intersect
if(f.getX() >= x-80 && f.getX() <= x+90 && f.getY() >= y-75 && f.getY() <= y){
//bad object, decrement health
if(f.getBad()){
health --;
//System.out.println("Health: "+health);
}
//good object, increments progress
else{
caught++;
//System.out.println("caught: " +caught);
}
//marks for deletion
f.setDelete();
}
}
//get methods
public int getX(){
return x;
}
public int getY(){
return y;
}
public int getHealth(){
return health;
}
public int getCaught(){
return caught;
}
}