-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.html
More file actions
223 lines (218 loc) · 9.09 KB
/
Copy pathgame.html
File metadata and controls
223 lines (218 loc) · 9.09 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
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="script.js"></script>
<style>
@import url('https://fonts.googleapis.com/css?family=Bubbler+One');
body{
background-color: #1b0e29;
color: aliceblue;
font-family: 'Bubbler One', sans-serif;
}
canvas {
margin-left: calc(50vw - 45vw);
width: 90vw;
border: 2px black solid;
border-radius: 20px;
background-image: url(http://selfhacker.net/wp-content/uploads/2015/06/space.jpg);
background-size: cover;
}
button{
background-color: #1b0e29;
border: none;
color: aliceblue;
}
.shop{
background-image: url(https://wallperz.com/wp-content/uploads/2017/01/20/wallperz.com-20170120234525.jpg);
}
</style>
</head>
<body>
<h1>
Mini game
</h1>
<p>
S - пауза<br> управление - стрелка вправо/влево
</p>
<input type='button' value='Изменить' onclick='messageShow()'/>
<button type='button' value='Начать игру' onclick='StartGame()' />
<canvas width="600" height="300" id="my_game"></canvas>
<script>
function messageShow() {
document.getElementById('my_game').style.backgroundImage=" url(http://www.wallpaperhd.pk/wp-content/uploads/2015/08/meteorites-cosmos-sci-fi-wallpaper.jpg)";
}
function StartGame(){
"use strict";
var gm = my_game.getContext("2d");
//Переменные для шарика
var
x = 400,
y = 100,
vx = 2,
vy = 4,
pl = 10;
//Платформа игрока
var
pc_x = 400,
pc_y = 250;
//Просчёт физики и прорисовк
var
bl_x = 0,
bl_y = 0;
var
bl_2x = 102,
bl_2y = 0;
var
bl_3x = 204,
bl_3y = 0;
var
bl_4x = 306,
bl_4y = 0;
var
bl_5x = 408,
bl_5y = 0;
var
bl_6x = 510,
bl_6y = 0;
//Second
var
bl_x_2 = 0,
bl_y_2 = 22;
var
bl_2x_2 = 102,
bl_2y_2 = 22;
var
bl_3x_2 = 204,
bl_3y_2 = 22;
var
bl_4x_2 = 306,
bl_4y_2 = 22;
var
bl_5x_2 = 408,
bl_5y_2 = 22;
var
bl_6x_2 = 510,
bl_6y_2 = 22;
//Third
var
bl_x_3 = 0,
bl_y_3 = 44;
var
bl_2x_3 = 102,
bl_2y_3 = 44;
var
bl_3x_3 = 204,
bl_3y_3 = 44;
var
bl_4x_3 = 306,
bl_4y_3 = 44;
var
bl_5x_3 = 408,
bl_5y_3 = 44;
var
bl_6x_3 = 510,
bl_6y_3 = 44;
//счет
var
chet = 0;
var
rep = 0;
alert("Press OK to start")
function animation() {
//задаём таймер
window.requestAnimationFrame(animation);
//очистка canvas
gm.clearRect(0, 0, my_game.width, my_game.height);
//рисуем шарик
gm.beginPath();
gm.arc(x, y, 10, 0, 2 * Math.PI, true);
gm.fill();
//изменяем положения шарика
x = x + vx;
y = y + vy;
if ((x > my_game.width - 10) || (x < 10)) vx = -vx;
if ((y > my_game.height - 10) || (y < 10)) vy = -vy;
if (y > my_game.height - 10) alert("Lose"), chet = 0, x = -400, y = 100, vx = 0, vy = 0;
//шарик отталкивается от платформы
if ((y > pc_y - 10) && (pc_x - 10 < x) && (pc_x + 100 > x) && (vx < 0)) vy = -vy, vx = vx + (vx - pc_x) / 1000, pl = pl + 1;
if ((y > pc_y - 10) && (pc_x - 10 < x) && (pc_x + 100 > x) && (vx > 0)) vy = -vy, vx = vx - (vx - pc_x) / 1000, pl = pl + 1;
//рисуем платформу
gm.fillRect(pc_x, pc_y, 100, 20);
//кубик
gm.fillStyle = "black";
if ((y < bl_y + 30) && (y > bl_y - 10) && (bl_x - 10 < x) && (bl_x + 100 > x)) vy = -vy, bl_x = -300, chet = chet + 200;
gm.fillRect(bl_x, bl_y, 100, 20);
//2
if ((y < bl_2y + 30) && (y > bl_2y - 10)&& (bl_2x - 10 < x) && (bl_2x + 100 > x)) vy = -vy, bl_2x = -300, chet = chet + 200;
gm.fillRect(bl_2x, bl_2y, 100, 20);
//3
if ((y < bl_3y + 30) && (y > bl_3y - 10)&& (bl_3x - 10 < x) && (bl_3x + 100 > x)) vy = -vy, bl_3x = -300, chet = chet + 200;
gm.fillRect(bl_3x, bl_3y, 100, 20);
//4
if ((y < bl_4y + 30) && (y > bl_4y - 10)&& (bl_4x - 10 < x) && (bl_4x + 100 > x)) vy = -vy, bl_4x = -300, chet = chet + 200;
gm.fillRect(bl_4x, bl_4y, 100, 20);
//5
if ((y < bl_5y + 30) && (y > bl_5y - 10)&& (bl_5x - 10 < x) && (bl_5x + 100 > x)) vy = -vy, bl_5x = -300, chet = chet + 200;
gm.fillRect(bl_5x, bl_5y, 100, 20);
//6
if ((y < bl_6y + 30) && (y > bl_6y - 10)&& (bl_6x - 10 < x) && (bl_6x + 100 > x)) vy = -vy, bl_6x = -300, chet = chet + 200;
gm.fillRect(bl_6x, bl_6y, 100, 20);
vx = vx;
vy = vy;
//Second
//кубик
gm.fillStyle = "black";
if ((y < bl_y_2 + 30) && (y > bl_y_2 - 10) && (bl_x_2 - 10 < x) && (bl_x_2 + 100 > x)) vy = -vy, bl_x_2 = -300, chet = chet + 200, vx = vx + 0.1, vy = vy + 0.2;
gm.fillRect(bl_x_2, bl_y_2, 100, 20);
//2
if ((y < bl_2y_2 + 30) && (y > bl_2y_2 - 10)&& (bl_2x_2 - 10 < x) && (bl_2x_2 + 100 > x)) vy = -vy, bl_2x_2 = -300, chet = chet + 200, vx = vx + 0.1, vy = vy + 0.2;
gm.fillRect(bl_2x_2, bl_2y_2, 100, 20);
//3
if ((y < bl_3y_2 + 30) && (y > bl_3y_2 - 10)&& (bl_3x_2 - 10 < x) && (bl_3x_2 + 100 > x)) vy = -vy, bl_3x_2 = -300, chet = chet + 200, vx = vx + 0.1, vy = vy + 0.2;
gm.fillRect(bl_3x_2, bl_3y_2, 100, 20);
//4
if ((y < bl_4y_2 + 30) && (y > bl_4y_2 - 10)&& (bl_4x_2 - 10 < x) && (bl_4x_2 + 100 > x)) vy = -vy, bl_4x_2 = -300, chet = chet + 200, vx = vx + 0.1, vy = vy + 0.2;
gm.fillRect(bl_4x_2, bl_4y_2, 100, 20);
//5
if ((y < bl_5y_2 + 30) && (y > bl_5y_2 - 10)&& (bl_5x_2 - 10 < x) && (bl_5x_2 + 100 > x)) vy = -vy, bl_5x_2 = -300, chet = chet + 200, vx = vx + 0.1, vy = vy + 0.2;
gm.fillRect(bl_5x_2, bl_5y_2, 100, 20);
//6
if ((y < bl_6y_2 + 30) && (y > bl_6y_2 - 10)&& (bl_6x_2 - 10 < x) && (bl_6x_2 + 100 > x)) vy = -vy, bl_6x_2 = -300, chet = chet + 200, vx = vx + 0.1, vy = vy + 0.2;
gm.fillRect(bl_6x_2, bl_6y_2, 100, 20);
// Third
if ((y < bl_y_3 + 30) && (y > bl_y_3 - 10) && (bl_x_3 - 10 < x) && (bl_x_3 + 100 > x)) vy = -vy, bl_x_3 = -300, chet = chet + 200, vx = vx + 0.1, vy = vy + 0.2;
gm.fillRect(bl_x_3, bl_y_3, 100, 20);
//2
if ((y < bl_2y_3 + 30) && (y > bl_2y_3 - 10)&& (bl_2x_3 - 10 < x) && (bl_2x_3 + 100 > x)) vy = -vy, bl_2x_3 = -300, chet = chet + 200, vx = vx + 0.1, vy = vy + 0.2;
gm.fillRect(bl_2x_3, bl_2y_3, 100, 20);
//3
if ((y < bl_3y_3 + 30) && (y > bl_3y_3 - 10)&& (bl_3x_3 - 10 < x) && (bl_3x_3 + 100 > x)) vy = -vy, bl_3x_3 = -300, chet = chet + 200, vx = vx + 0.1, vy = vy + 0.2;
gm.fillRect(bl_3x_3, bl_3y_3, 100, 20);
//4
if ((y < bl_4y_3 + 30) && (y > bl_4y_3 - 10)&& (bl_4x_3 - 10 < x) && (bl_4x_3 + 100 > x)) vy = -vy, bl_4x_3 = -300, chet = chet + 200, vx = vx + 0.1, vy = vy + 0.2;
gm.fillRect(bl_4x_3, bl_4y_3, 100, 20);
//5
if ((y < bl_5y_3 + 30) && (y > bl_5y_3 - 10)&& (bl_5x_3 - 10 < x) && (bl_5x_3 + 100 > x)) vy = -vy, bl_5x_3 = -300, chet = chet + 200, vx = vx + 0.1, vy = vy + 0.2;
gm.fillRect(bl_5x_3, bl_5y_3, 100, 20);
//6
if ((y < bl_6y_3 + 30) && (y > bl_6y_3 - 10)&& (bl_6x_3 - 10 < x) && (bl_6x_3 + 100 > x)) vy = -vy, bl_6x_3 = -300, chet = chet + 200, vx = vx + 0.1, vy = vy + 0.2;
gm.fillRect(bl_6x_3, bl_6y_3, 100, 20);
if (chet == 3600) alert("You WIN");
}
window.requestAnimationFrame(animation);
function navigate(event) {
if (event.keyCode == 39) pc_x = pc_x + pl;
if (event.keyCode == 37) pc_x = pc_x - pl;
if (pc_x + 100 > 600) pc_x = pc_x - 10, gm.fillStyle = "red";;
if (pc_x < 0) pc_x = pc_x + 10, gm.fillStyle = "red";;
}
function che(event) {
if (event.keyCode == 83) alert(chet);
}
document.addEventListener("keydown", navigate);
document.addEventListener("keydown", che);
}
</script>
</body>
</html>