Skip to content

Commit 7ed849d

Browse files
author
SirCodesALot
committed
added stuffs
1 parent 28b458b commit 7ed849d

File tree

3 files changed

+185
-88
lines changed

3 files changed

+185
-88
lines changed

index.html

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
<canvas width="80" height="80" id="store"></canvas>
3434
<h2 class="nexttext">Next:</h2>
3535
<h2 class="storetext">Store:</h2>
36+
<h2 class="linestext">Lines:</h2>
37+
<h2 id="lines">000000</h2>
38+
<h2 class="scoretext">Score:</h2>
39+
<h2 id="score">000000</h2>
3640
</body>
3741
<script src="main.js"></script>
3842
</html>

main.js

+157-83
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,11 @@
11
var canvas = document.getElementById("game")
22
var ctx = canvas.getContext("2d")
3+
ctx.globalAlpha = 1
34
var canvas2 = document.getElementById("next")
45
var ctx2 = canvas2.getContext("2d")
56
var canvas3 = document.getElementById("store")
67
var ctx3 = canvas3.getContext("2d")
78
var defurl = 'https://coderpro1234-2.github.io'
8-
var fx = 0
9-
var fy = 0
10-
var nxtt = 0
11-
var musicplay = 0
12-
var timer = 0
13-
var useswap = false
14-
var running = true
15-
var instout = false
16-
const gblocks = [
17-
0,0,0,0,0,0,0,0,0,0,
18-
0,0,0,0,0,0,0,0,0,0,
19-
0,0,0,0,0,0,0,0,0,0,
20-
0,0,0,0,0,0,0,0,0,0,
21-
0,0,0,0,0,0,0,0,0,0,
22-
0,0,0,0,0,0,0,0,0,0,
23-
0,0,0,0,0,0,0,0,0,0,
24-
0,0,0,0,0,0,0,0,0,0,
25-
0,0,0,0,0,0,0,0,0,0,
26-
0,0,0,0,0,0,0,0,0,0,
27-
0,0,0,0,0,0,0,0,0,0,
28-
0,0,0,0,0,0,0,0,0,0,
29-
0,0,0,0,0,0,0,0,0,0,
30-
0,0,0,0,0,0,0,0,0,0,
31-
0,0,0,0,0,0,0,0,0,0,
32-
0,0,0,0,0,0,0,0,0,0,
33-
0,0,0,0,0,0,0,0,0,0,
34-
0,0,0,0,0,0,0,0,0,0,
35-
0,0,0,0,0,0,0,0,0,0,
36-
0,0,0,0,0,0,0,0,0,0
37-
]
38-
fblock = [
39-
0,0,0,0,
40-
0,0,0,0,
41-
0,0,0,0,
42-
0,0,0,0
43-
]
44-
sblock = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
459
const tetrominoes = [
4610
[0,5,0,0,0,5,0,0,0,5,0,0,0,5,0,0],
4711
[0,0,0,0,0,3,3,0,0,3,3,0,0,0,0,0],
@@ -51,10 +15,63 @@ const tetrominoes = [
5115
[0,0,0,0,0,0,6,0,0,0,6,0,0,6,6,0],
5216
[0,0,0,0,7,7,7,0,0,7,0,0,0,0,0,0]
5317
]
18+
var fx = 0
19+
var fy = 0
20+
var nxtt = 0
21+
var musicplay = 0
22+
var timer = 0
23+
var lines = 0
24+
var score = 0
25+
var useswap = true
26+
var running = true
27+
var instout = true
28+
gblocks = []
29+
fblock = []
30+
sblock = []
31+
nxtt = 0
32+
function reset_vars() {
33+
fx = 0
34+
fy = 0
35+
nxtt = 0
36+
lines = 0
37+
score = 0
38+
useswap = false
39+
running = true
40+
instout = false
41+
gblocks = [
42+
0,0,0,0,0,0,0,0,0,0,
43+
0,0,0,0,0,0,0,0,0,0,
44+
0,0,0,0,0,0,0,0,0,0,
45+
0,0,0,0,0,0,0,0,0,0,
46+
0,0,0,0,0,0,0,0,0,0,
47+
0,0,0,0,0,0,0,0,0,0,
48+
0,0,0,0,0,0,0,0,0,0,
49+
0,0,0,0,0,0,0,0,0,0,
50+
0,0,0,0,0,0,0,0,0,0,
51+
0,0,0,0,0,0,0,0,0,0,
52+
0,0,0,0,0,0,0,0,0,0,
53+
0,0,0,0,0,0,0,0,0,0,
54+
0,0,0,0,0,0,0,0,0,0,
55+
0,0,0,0,0,0,0,0,0,0,
56+
0,0,0,0,0,0,0,0,0,0,
57+
0,0,0,0,0,0,0,0,0,0,
58+
0,0,0,0,0,0,0,0,0,0,
59+
0,0,0,0,0,0,0,0,0,0,
60+
0,0,0,0,0,0,0,0,0,0,
61+
0,0,0,0,0,0,0,0,0,0
62+
]
63+
fblock = [
64+
0,0,0,0,
65+
0,0,0,0,
66+
0,0,0,0,
67+
0,0,0,0
68+
]
69+
sblock = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
70+
nxtt = randnumber(0,6)
71+
}
5472
function randnumber(min, max) {
5573
return Math.floor(Math.random() * (max - min + 1) ) + min;
5674
}
57-
nxtt = randnumber(0,6)
5875
function checkmusic() {
5976
if (musicplay == 0) {
6077
tetrismusic.play()
@@ -143,6 +160,22 @@ function draw_store() {
143160
i ++
144161
}
145162
}
163+
function draw_ghost() {
164+
o_fy = fy
165+
i = 0
166+
while (i != -1) {
167+
fy=fy+1
168+
if (f_coll_g()){
169+
fy=fy-1
170+
i = -2
171+
}
172+
i++
173+
}
174+
ctx.globalAlpha = 0.5
175+
draw_fblock()
176+
ctx.globalAlpha = 1
177+
fy = o_fy
178+
}
146179
function g_xy(x, y) {
147180
if (y > 19 || x < 0 || x > 9) {
148181
return(1)
@@ -198,25 +231,54 @@ function sro(off, color) {
198231
function you_died() {
199232
c1 = 0
200233
c2 = 0
201-
setInterval(function(){
202-
sro(c1,c2+1)
203-
c1 += 1
204-
c2 += 1
205-
c2 = c2 % 7
206-
if (c1 == 20) {
207-
c1 = 0
208-
c2 = 0
209-
setTimeout(function(){
210-
window.location.reload()
211-
set_f(true)
212-
}, 400)
234+
const deathinter = setInterval(function(){
235+
if (running == false) {
236+
sro(c1,c2+1)
237+
c1 += 1
238+
c2 += 1
239+
c2 = c2 % 7
240+
if (c1 == 20) {
241+
c1 = 0
242+
c2 = 0
243+
setTimeout(function(){
244+
reset_vars()
245+
running = true
246+
gblocks = [
247+
0,0,0,0,0,0,0,0,0,0,
248+
0,0,0,0,0,0,0,0,0,0,
249+
0,0,0,0,0,0,0,0,0,0,
250+
0,0,0,0,0,0,0,0,0,0,
251+
0,0,0,0,0,0,0,0,0,0,
252+
0,0,0,0,0,0,0,0,0,0,
253+
0,0,0,0,0,0,0,0,0,0,
254+
0,0,0,0,0,0,0,0,0,0,
255+
0,0,0,0,0,0,0,0,0,0,
256+
0,0,0,0,0,0,0,0,0,0,
257+
0,0,0,0,0,0,0,0,0,0,
258+
0,0,0,0,0,0,0,0,0,0,
259+
0,0,0,0,0,0,0,0,0,0,
260+
0,0,0,0,0,0,0,0,0,0,
261+
0,0,0,0,0,0,0,0,0,0,
262+
0,0,0,0,0,0,0,0,0,0,
263+
0,0,0,0,0,0,0,0,0,0,
264+
0,0,0,0,0,0,0,0,0,0,
265+
0,0,0,0,0,0,0,0,0,0,
266+
0,0,0,0,0,0,0,0,0,0
267+
]
268+
set_f()
269+
update_screen()
270+
}, 400)
271+
}
272+
}
273+
else {
274+
clearInterval(deathinter)
275+
return
213276
}
214-
},100)
215-
277+
},70)
216278
}
217279
function swapinst() {
218280
instout = !instout
219-
txt = "Instrunctions:<br>Up Arrow / W to snap block to bottom.<br>Left or Right Arrows / A or D to move block left or right.<br>Down Arrow / S to move block one tile down.<br> X to rotate block clockwise.<br>Z to rotate block counter-clockwise.<br>Q to save block to store if it is empty.<br>E to swap block from store if it exists."
281+
txt = "Instrunctions:<br>Up Arrow / W to snap block to bottom.<br>Left or Right Arrows / A or D to move block left or right.<br>Down Arrow / S to move block one tile down.<br> X to rotate block clockwise.<br>Z to rotate block counter-clockwise.<br>Q or E tp add or swap the block in the store."
220282
if (instout) {
221283
document.getElementById("instructions").innerHTML = txt
222284
}
@@ -261,6 +323,7 @@ function set_f(t = false) {
261323
}
262324
}
263325
function check_line() {
326+
lcc = 0
264327
i = 0
265328
while (i < 20) {
266329
line = 0
@@ -272,18 +335,35 @@ function check_line() {
272335
i2 ++
273336
}
274337
if (line == 10) {
338+
lines ++
339+
lcc ++
275340
gblocks.splice(i*10, 10)
276341
gblocks.unshift(0,0,0,0,0,0,0,0,0,0)
277342
}
278343
i ++
279344
}
345+
if (lcc == 1) {
346+
score += 40
347+
}
348+
else if (lcc == 2) {
349+
score += 100
350+
}
351+
else if (lcc == 3) {
352+
score += 300
353+
}
354+
else if (lcc == 4) {
355+
score += 1200
356+
}
280357
}
281358
function update_screen() {
282359
check_line()
283360
draw_gblocks()
361+
draw_ghost()
284362
draw_fblock()
285363
draw_next()
286364
draw_store()
365+
document.getElementById("lines").innerHTML = (lines.toString()).padStart(6,"0")
366+
document.getElementById("score").innerHTML = (score.toString()).padStart(6,"0")
287367
}
288368
function mglt() {
289369
fy += 1
@@ -293,7 +373,29 @@ function mglt() {
293373
set_f()
294374
}
295375
}
376+
function check_swap() {
377+
i = 0
378+
e = 0
379+
while (i < 16) {
380+
if (sblock[i] != 0) {
381+
e += 1
382+
}
383+
i++
384+
}
385+
if (e == 0) {
386+
sblock = fblock
387+
set_f()
388+
useswap = true
389+
}
390+
else if (e != 0 && (!useswap)) {
391+
tmp = sblock
392+
sblock = fblock
393+
fblock = tmp
394+
useswap = true
395+
}
396+
}
296397
window.onload = function(){
398+
reset_vars()
297399
set_f()
298400
update_screen()
299401
setInterval(function(){
@@ -355,36 +457,8 @@ window.onload = function(){
355457
r_c()
356458
}
357459
}
358-
if (event.key == "q") {
359-
i = 0
360-
e = 0
361-
while (i < 16) {
362-
if (sblock[i] != 0) {
363-
e += 1
364-
}
365-
i++
366-
}
367-
if (e == 0) {
368-
sblock = fblock
369-
set_f()
370-
useswap = true
371-
}
372-
}
373-
if (event.key == "e") {
374-
i = 0
375-
e = 0
376-
while (i < 16) {
377-
if (sblock[i] != 0) {
378-
e += 1
379-
}
380-
i++
381-
}
382-
if (e != 0 && (!useswap)) {
383-
tmp = sblock
384-
sblock = fblock
385-
fblock = tmp
386-
useswap = true
387-
}
460+
if (event.key == "q" || event.key == "e" ) {
461+
check_swap()
388462
}
389463
update_screen()
390464
}

style.css

+24-5
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,47 @@ button {
3939
}
4040
.nexttext {
4141
position: relative;
42-
bottom: 285px;
42+
bottom: 305px;
4343
left: 77px
4444
}
4545
.storetext {
4646
position: relative;
47-
bottom: 470px;
47+
bottom: 480px;
48+
left: 77px
49+
}
50+
.linestext {
51+
position: relative;
52+
bottom: 275px;
53+
left: 77px
54+
}
55+
.scoretext {
56+
position: relative;
57+
bottom: 300px;
4858
left: 77px
4959
}
5060
.homebutton {
51-
5261
position: absolute;
5362
top: 10px;
5463
right: 10px;
5564
padding: 4px;
5665
}
5766
#next {
5867
position: relative;
59-
bottom: 140px;
68+
bottom: 160px;
6069
left: 12px
6170
}
6271
#store {
6372
position: relative;
64-
bottom: 280px;
73+
bottom: 290px;
6574
right: 87px
6675
}
76+
#lines {
77+
position: relative;
78+
bottom: 295px;
79+
left: 77px
80+
}
81+
#score {
82+
position: relative;
83+
bottom: 320px;
84+
left: 77px
85+
}

0 commit comments

Comments
 (0)