-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mario.pde
164 lines (153 loc) · 2.67 KB
/
Mario.pde
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
import processing.sound.*;
SoundFile file;
SoundFile sad;
SoundFile victory;
PImage mario;
PImage marior;
PImage mariol;
PImage bg;
PImage normPlat;
PImage fallPlat;
int mx;
int my;
int finish;
int mxspeed;
int myspeed;
int msize;
int jumpHeight;
int fallSpeed;
boolean sadM;
boolean winM;
boolean mright = false;
boolean mleft = false;
boolean onPlat = false;
boolean mjump = false;
ArrayList<Platform> platList;
int scrollLim;
void setup()
{
size(800, 800);
rectMode(CENTER);
imageMode(CENTER);
textMode(CENTER);
textSize(100);
platList = new ArrayList<Platform>();
if (winM)
{
winM = false;
victory.stop();
}
if (sadM)
{
sadM = false;
sad.stop();
}
marior = loadImage("Mario_8Bit.png");
mariol = loadImage("Mario_8Bitl.png");
bg = loadImage("clouds.png");
normPlat = loadImage("platform.png");
fallPlat = loadImage("platform2.png");
file = new SoundFile(this, "mariotheme.mp3");
sad = new SoundFile(this, "sad.mp3");
victory = new SoundFile(this, "Victory2.mp3");
mx = 400;
my = 600;
finish = -3100;
msize = 40;
myspeed = 0;
mxspeed = 5;
jumpHeight = 15;
fallSpeed = 2;
scrollLim = 400;
int platSize = 100;
marior.resize(msize, msize);
mariol.resize(msize, msize);
mario = marior;
bg.resize(800, 800);
new Platform(width/2, 700, 20, platSize, normPlat, false);
for (int i = 0; i < 100; i++)
{
int y2 = height - i * 40;
for (int j = 0; j < int(random(1, 5 - i/20 + 1)); j++)
{
int x2 = int(random(0, 100))*8;
if (int(random(0, 5)) == 2)
{
new Platform(x2, y2, 20, platSize, fallPlat, true);
} else
{
new Platform(x2, y2, 20, platSize, normPlat, false);
}
}
}
file.play();
}
void draw()
{
background(#00B9FF);
image(mario, mx, my);
wrap();
for (Platform p : platList)
{
p.app();
}
if (my <= scrollLim)
{
scrollDown();
}
moveMario();
gravity();
fill(#13FA00);
rect(width/2, finish, width, 20);
if (my <= finish)
{
if (!winM)
{
winM = true;
file.stop();
victory.play();
}
my = finish;
myspeed = 0;
fill(#E9FF00);
textAlign(CENTER);
text("You win!", 400, 400);
}
marioDead();
}
void marioDead()
{
if (my > height)
{
my = height + 100;
background(0, 0, 0);
fill(255, 0, 0);
textAlign(CENTER);
text("You lost!", 400, 400);
if (!sadM)
{
file.stop();
sad.play();
sadM = true;
}
}
}
void moveMario()
{
if (mright)
{
mx += mxspeed;
mario = marior;
}
if (mleft)
{
mx -= mxspeed;
mario = mariol;
}
if (mjump && onPlat)
{
myspeed = jumpHeight * -1;
mjump = false;
}
my += myspeed;
}