-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jelly.java
145 lines (142 loc) · 4.77 KB
/
Jelly.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
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
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
public class Jelly extends Entity {
private Image[] frames;
private Image image;
private double frameRate = 8;
private double tempsTotal = 0;
protected boolean parterre = true;
protected boolean faceDroite;
protected boolean accelere = false;
protected int score = 0;
public Jelly(double x, double y) {
this.x = x;
this.y = y;
this.largeur = 50;
this.hauteur = 50;
this.ay = 0;
this.vx = 0;
updateImage();
}
public void setParterre(boolean vF){
if (vF == true){
this.parterre = true;
}else {
this.parterre = false;
}
}
public void updateImage(){
if (faceDroite) {
frames = new Image[]{
new Image("/jellyfish1.png"),
new Image("/jellyfish2.png"),
new Image("/jellyfish3.png"),
new Image("/jellyfish4.png"),
new Image("/jellyfish5.png"),
new Image("/jellyfish6.png")
};
}else {
frames = new Image[]{
new Image("/jellyfish1g.png"),
new Image("/jellyfish2g.png"),
new Image("/jellyfish3g.png"),
new Image("/jellyfish4g.png"),
new Image("/jellyfish5g.png"),
new Image("/jellyfish6g.png")
};
};
image = frames[0];
}
@Override
public void update(double dt) {
super.update(dt);
score = (int)(-this.y + HighSeaTower.HEIGHT - this.hauteur);
tempsTotal += dt;
int frame = (int) (tempsTotal * frameRate);
image = frames[frame % frames.length];
if (this.vx<0 && this.x<=0){
this.x = 0;
this.vx = -vx;
}
if (this.vx>0 && this.x+this.largeur>= HighSeaTower.WIDTH){
this.x=HighSeaTower.WIDTH-this.largeur;
this.vx = -vx;
}
}
public boolean testGameOver(double fond){
if ((-this.y + HighSeaTower.HEIGHT) < fond){
return true;
}else {
return false;
}
}
public void testCollision(Plateforme other) {
if (intersects(other) && Math.abs(this.y + this.hauteur - other.y) < 10
&& this.vy > 0 ) {
pushOut(other);
if (other instanceof PlateformeSimple || other instanceof PlateformeRouge || other instanceof Fond) {
this.vy = 0;
this.parterre = true;
}else if (other instanceof PlateformeBond){
this.parterre = true;
this.vy *=-1.5;
if(this.vy > -100){
this.vy = -100;
}
}else if (other instanceof PlateformeAccelerante){
this.parterre= true;
this.vy = 0;
this.accelere = true;
}
}
if (intersects(other) && Math.abs(this.y - other.y-10) < 10
&& vy < 0 && other instanceof PlateformeRouge) {
this.vy = -vy;
}
}
public boolean intersects(Plateforme other) {
return !(this.x + largeur < other.x || other.x + other.largeur < this.x
|| this.y + this.hauteur < other.y || other.y + other.hauteur < this.y);
}
/**
* Repousse le personnage vers le haut (sans déplacer la
* plateforme)
*/
public void pushOut(Plateforme other) {
double deltaY = this.y + this.hauteur - other.y;
this.y -= deltaY;
}
/**
* Le personnage peut seulement sauter s'il se trouve sur une
* plateforme
*/
public void jump() {
if(this.parterre) {
this.setParterre(false);
this.vy = -600;
}
}
public void move(String side){
int mult = 1;
if (side == "gauche"){
mult = -1;
faceDroite = false;
}else{
faceDroite = true;
}
this.ax = 1200 * mult;
updateImage();
}
@Override
public void draw(GraphicsContext context, double fenetreY) {
this.yAffiche = this.y - fenetreY;
context.drawImage(this.image, this.x, yAffiche, this.largeur, this.hauteur);
}
public void drawDebug(GraphicsContext context, double fenetreY) {
this.yAffiche = this.y - fenetreY;
context.setFill(Color.PINK);
context.fillRect(this.x, yAffiche, this.largeur, this.hauteur);
context.drawImage(image, x, yAffiche, this.largeur, this.hauteur);
}
}