-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoomba.java
More file actions
119 lines (107 loc) · 2.77 KB
/
Goomba.java
File metadata and controls
119 lines (107 loc) · 2.77 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
//----------------------------------------------------------------------
// Author: Micheal Oyenekan
// Date : 10/23/2020 (Completed)
// File : Goomba.java
//----------------------------------------------------------------------
import java.awt.image.BufferedImage;
import java.awt.Graphics;
import java.io.File;
import javax.imageio.ImageIO;
import javax.lang.model.element.ModuleElement.DirectiveVisitor;
public class Goomba extends Sprite
{
static BufferedImage image, fire_image;
Model model;
int px, py, direction;
double vert_vel, speed;
int numFramesOnFire;
boolean isOnFire;
public Goomba(int x, int y, Model m)
{
//update();
direction = 1;
vert_vel = 12.0;
speed = 7.0;
this.x = x;
this.y = y;
w = 99;
h = 118;
this.model = m;
numFramesOnFire = 0;
isOnFire = false;
if(image == null)
image = View.loadImage("goomba.png");
if (fire_image == null)
fire_image = View.loadImage("goomba_fire.png");
}
public Goomba(Json ob, Model m)
{
direction = 1;
vert_vel = 12.0;
speed = 7.0;
x = (int)ob.getLong("x");
y = (int)ob.getLong("y");
w = 99;
h = 118;
model = m;
numFramesOnFire = 0;
isOnFire = false;
if (image == null)
image = View.loadImage("goomba.png");
if (fire_image == null)
fire_image = View.loadImage("goomba_fire.png");
System.out.println("You've loaded Goomba at (" + x + ", " + y + ")");
}
@Override
boolean isGoomba()
{
return true;
}
//----------------------------------------------
// Method that saves the previous coordinates
// of Goomba. This method will be helpful in
// determining whether or not Goomba collided
// with a tube.
//----------------------------------------------
void savePreviousCoordinates()
{
px = this.x;
py = this.y;
}
void update()
{
this.y += vert_vel;
this.x += speed * direction;
if (this.y > 400 - h)
{
vert_vel = 0;
this.y = 400 - h; //snap back to the ground
}
if(this.y < 0)
{
this.y = 0;
vert_vel += 12;
}
}
void draw(Graphics g)
{
if (isOnFire)
{
g.drawImage(fire_image, x - model.mario.x + model.mario.marioOffset, y, null);
numFramesOnFire++;
speed = 0;
}
else
{
g.drawImage(image, x - model.mario.x + model.mario.marioOffset, y, null);
isOnFire = false;
}
}
Json marshal()
{
Json ob = Json.newObject();
ob.add("x", x);
ob.add("y", y);
return ob;
}
}