This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 207
/
Copy pathSquare shooter
178 lines (168 loc) · 3.76 KB
/
Square shooter
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
var x=window.innerWidth;
var width=x;
var y=window.innerHeight;
var height=y;
x=x/2-25;
y=y-100;
var up=0;
var down=0;
var left=0;
var right=0;
var playerspeed=6;
var enemyx=0;
var enemyy=-50;
var bulletchangey=1;
var bulletshoot=1;
var enemyy=-50;
var enemyx=-50;
var count=0;
var enemyspeed=6;
var enemylist=[];
(function () {
var you = document.createElement('div');
var body = document.getElementsByTagName('body')[0];
body.appendChild(you);
you.style.position = 'fixed';
you.style.top = ''+y+'px';
you.style.left = ''+x+'px';
you.style.paddingTop = '10px';
you.style.width = '50px';
you.style.height = '50px';
you.style.zIndex = 10000;
you.style.opacity = 1;
you.style.color = 'white';
you.style.backgroundColor = 'black';
you.style.border = '0px solid white';
you.style.textAlign = 'center';
you.id = 'you';
you.style.display = 'block';
you.innerText = '';
}());
window.addEventListener("keydown", function(event) {
if (event.key == "ArrowUp") {
up=1;
}
if (event.key == "ArrowDown") {
down=1;
}
if (event.key == "ArrowLeft") {
left=1;
}
if (event.key == "ArrowRight") {
right=1;
}
});
window.addEventListener("keyup", function(event) {
if (event.key == "ArrowUp") {
up=0;
}
if (event.key == "ArrowDown") {
down=0;
}
if (event.key == "ArrowLeft") {
left=0;
}
if (event.key == "ArrowRight") {
right=0;
}
});
function move(){
if (up==1){
y=y-playerspeed;
you.style.top = ''+y+'px';
you.style.left = ''+x+'px';
}
if (down==1){
y=y+playerspeed;
you.style.top = ''+y+'px';
you.style.left = ''+x+'px';
}
if (left==1){
x=x-playerspeed;
you.style.top = ''+y+'px';
you.style.left = ''+x+'px';
}
if (right==1){
x=x+playerspeed;
you.style.top = ''+y+'px';
you.style.left = ''+x+'px';
}
if (bulletchangey==1){
}
}
setInterval(move,15);
window.addEventListener("keyup", function(event) {
if (event.key == "s") {
if (bulletshoot==1){
(function () {
var bullet = document.createElement('div');
var body = document.getElementsByTagName('body')[0];
body.appendChild(bullet);
bullet.style.position = 'fixed';
var a=y-10;
bullet.style.top = ''+a+'px';
var z=x+25-7;
bullet.style.left = ''+z+'px';
bullet.style.paddingTop = '10px';
bullet.style.width = '7px';
bullet.style.height = '10px';
bullet.style.zIndex = 10000;
bullet.style.opacity = 1;
bullet.style.color = 'red';
bullet.style.backgroundColor = 'red';
bullet.style.border = '0px solid white';
bullet.style.textAlign = 'center';
bullet.id = 'bullet';
bullet.style.display = 'block';
bullet.innerText = '';
function moveup(){
a=a-6;
bullet.style.top = ''+a+'px';
if (a<=0){
bulletshoot=1;
}
}
setInterval(moveup,15);
bulletshoot=0;
}());
}
}
});
function makeenemy(){
(function () {
enemylist.push(enemy.style.top);
enemylist.push(enemy.style.left);
var enemy = document.createElement('div');
var body = document.getElementsByTagName('body')[0];
body.appendChild(enemy);
enemyx=Math.floor(Math.random()*(width-0+1)+0);
enemy.style.position = 'fixed';
enemy.style.top = ''+enemyy+'px';
enemy.style.left = ''+enemyx+'px';
enemy.style.paddingTop = '10px';
enemy.style.width = '50px';
enemy.style.height = '50px';
enemy.style.opacity = 1;
enemy.style.color = 'blue';
enemy.style.backgroundColor = 'blue';
enemy.style.border = '0px solid white';
enemy.style.textAlign = 'center';
count=count+1;
enemy.id = 'enemy'+count;
enemy.style.display = 'block';
enemy.innerText = '';
function starting(){
function movedown(){
enemylist[count+1]=enemylist[count+1]+enemyspeed;
enemy.style.top = ''+enemylist[count+1]+'px';
enemylist[count]=enemy.style.left;
if (enemylist[count+1]>=height){
makeenemy();
}
}
setInterval(movedown,15);
}
setTimeout(starting,500);
}());
}
makeenemy();