-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
202 lines (191 loc) · 3.75 KB
/
sketch.js
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
var stage = {width:window.innerWidth, height:window.innerHeight}
var gravity = 10
var speed = 8
var mee;
var mee2;
var pl= [];
var dif = 0
var minDistance = 200
var bunny1 = [[],[]]
var bunny2 = [[],[]]
var bg = []
var bgImage = []
var earth = []
var rektPlayer = 0
var img
var song
var score = 0
var started = false
function preload()
{
song = loadSound("sound/main.mp3")
}
function setup()
{
imageMode(CENTER)
bg.push(loadImage("img/bg1.png"))
bg.push(loadImage("img/bg2.png"))
bg.push(loadImage("img/bg3.png"))
bunny1[0].push(loadImage("img/bunny111.png"))
bunny1[0].push(loadImage("img/bunny121.png"))
bunny1[1].push(loadImage("img/bunny112.png"))
bunny1[1].push(loadImage("img/bunny122.png"))
bunny2[0].push(loadImage("img/bunny211.png"))
bunny2[0].push(loadImage("img/bunny221.png"))
bunny2[1].push(loadImage("img/bunny212.png"))
bunny2[1].push(loadImage("img/bunny222.png"))
earth.push(loadImage("img/platformBig.png"))
earth.push(loadImage("img/platformSmall.png"))
earth.push(loadImage("img/platformBigV.png"))
earth.push(loadImage("img/platformSmallV.png"))
img = loadImage("img/intro.png")
createCanvas(stage.width,stage.height-30)
mee = new player(1);
mee2 = new player(2);
imageMode(CORNER)
bgImage.push(new backG(2))
bgImage.push(new backG(1))
bgImage.push(new backG(0))
pl.push(new wall(stage.width/2-80,500,false,false));
pl.push(new wall(100,500,false,false));
pl.push(new wall(stage.width-30,300,true,false));
pl.push(new wall(stage.width/2-50,150,false,true));
makePlat();
}
function makePlat()
{
var x = Math.floor(Math.random() * (stage.width-380))
var y = -150
pl.push(new wall(x, y,false,false))
var tmp = Math.floor(Math.random() * (stage.width-380))
while(Math.abs(x-tmp) < minDistance)
{
tmp = Math.floor(Math.random() * (stage.width-380))
}
var one = Math.floor(Math.random()*2) == 0
var two = Math.floor(Math.random()*2) == 0
pl.push(new wall(tmp, y,one,two))
}
function draw()
{
background(72,188,214)
fill('white')
textSize(30)
text("Score:"+score,30,30)
if(frameCount > 80)
{
dif = 3
}
if(frameCount > 23*60)
{
dif = 6
}
for (var i = 0; i<bgImage.length; i++)
{
bgImage[i].y += dif/10*(i+2)
bgImage[i].show()
}
mee2.update()
mee2.show()
mee.update()
mee.show()
if(frameCount%(100/(dif/3)) == 0 && frameCount > 120)
{
makePlat();
}
for (var i = 0; i<pl.length; i++)
{
pl[i].y += dif
pl[i].show()
}
score += dif
if(!started)
{
frameRate(1)
imageMode(CENTER)
image(img,stage.width/2,stage.height/2)
}
if(mee.y > stage.height)
{
gameOver(1)
}
if(mee2.y > stage.height)
{
gameOver(2)
}
//handling keyboard input
if(keyIsDown(LEFT_ARROW))
{
mee.velx = -5
}
if(keyIsDown(RIGHT_ARROW))
{
mee.velx = 5
}
if(keyIsDown(65))
{
mee2.velx = -5
}
if(keyIsDown(68))
{
mee2.velx = 5
}
}
function gameOver(player)
{
text("hello", 0, 0);
console.log("RIP")
var s = "Game Over, Player "+ player +"\n GOT REKT";
console.log(s)
fill(255,130,130)
textAlign(CENTER)
textSize(50)
var t = text(s,stage.width/2,300)
//t.show()
//throw("Hello")
noLoop()
}
function mouseClicked()
{
if(started)
{
location.reload()
}
console.log("Game started")
started =true
frameRate(60)
song.loop()
}
function keyPressed()
{
if (keyCode == UP_ARROW)
{
//do the jump
if (mee.jumpCount >0)
{
mee.vely = -20
mee.jumpCount --
}
}
if (keyCode == 87)
{
//do the jump
if (mee2.jumpCount >0)
{
mee2.vely = -20
mee2.jumpCount --
}
}
}
function keyReleased()
{
//stop moving when release the key
if (keyCode != UP_ARROW)
{
mee.velx = 0
}
if (keyCode != 87)
{
mee2.velx = 0
}
}