-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMario.java
More file actions
102 lines (92 loc) · 2.2 KB
/
Mario.java
File metadata and controls
102 lines (92 loc) · 2.2 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
/*
Name: Creighton Young
Date: 9/24/2020
Assigment: Make a bunch of pipes appear
*/
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.IOException;
import java.io.File;
import java.awt.Graphics;
public class Mario extends Sprite
{
int x;
int y;
double vert_vel; //mario's vertical velocity
int frameCounter;
int height;
int width;
boolean onGround;
boolean onTube;
static BufferedImage [] mario_images=null;
int marioImage=0;
boolean rightKeyPress=false;
boolean leftKeyPress=false;
Mario(int x, int y)
{
this.x=x;
this.y=y;
frameCounter=0;
width=60;
height=95;
vert_vel=0;
super.type="mario";
if (mario_images==null)
{
mario_images=new BufferedImage[5];
}
mario_images[0] = View.loadImage("mario1.png");
mario_images[1] = View.loadImage("mario2.png");
mario_images[2] = View.loadImage("mario3.png");
mario_images[3] = View.loadImage("mario4.png");
mario_images[4] = View.loadImage("mario5.png");
}
void update()
{
//mario jumping
if (frameCounter>0 && frameCounter<10)
{
vert_vel-=2.5;
y+=vert_vel;
frameCounter++;
onTube=false;
onGround=false;
}
else if(y >= 350)
{
vert_vel = 0.0;
y = 350; // snap back to the ground
frameCounter=0;
onTube=false;
onGround=true;
}
else if (onTube)
{
vert_vel=0;
onGround=true;
}
else
{
vert_vel += .9;
y += vert_vel;
}
}
void drawYourself(Graphics g)
{
g.drawImage(mario_images[marioImage],50,y,null);
if (rightKeyPress)
{
if (marioImage==4)
marioImage=0;
else
marioImage++;
}
else if (leftKeyPress)
{
if (marioImage==0)
marioImage=4;
else
marioImage--;
}
}
}