-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflopper.html
More file actions
216 lines (152 loc) · 5.47 KB
/
flopper.html
File metadata and controls
216 lines (152 loc) · 5.47 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
<html>
<audio id="jump_sound" src="beep.mp3" preload="auto"></audio>
<div id="main_div" style="width: 1300px; height: 500px; border: 1px solid black;"></div>
<style>
#mario img {
width: 100%;
height: 100%;
object-fit: fill;
}
</style>
<script>
function play_jump() {
let audio = null && document.querySelector("#jump_sound")
// audio && (audio.play())
audio && (audio.cloneNode(true).play())
}
let current_row;
let prev_row;
let current_char;
let prev_char;
let main_div = document.querySelector('#main_div')
let height = 500;
let width = 1300;
let char_height = 50
let char_width = 50;
let div_c = 0;
let _screen_play = {}
// character appear even tho char is usually meant character in C. I am stupid. I know
function char_appear() {
let _d = document.createElement('div')
_d.id = 'mario'
_d.style.width = '' + char_width + 'px';
_d.style.height = '' + char_height + 'px'
_d.style.backgroundColor = 'red'
let _img = document.createElement('img')
// _img.src = 'https://icons.iconarchive.com/icons/ph03nyx/super-mario/256/Paper-Mario-icon.png'
// _d.appendChild(_img)
return _d
}
// mapped row-column relationship
let r_row_column = {}
let ii = 0
for(let i = char_height; i <= height; i += char_height) {
let row = document.createElement('div')
row.style.display = 'flex'
row.style.width = '' + width + 'px'
row.style.height = '' + char_height + 'px'
let jj = 0
for(let j = char_width; j <= width; j += char_width) {
let col = document.createElement('div')
col.style.width = '' + char_width + 'px'
col.style.height = '' + char_height + 'px'
col.style.backgroundColor = 'white'
row.appendChild(col)
r_row_column[jj] = r_row_column[jj] || {}
r_row_column[jj][ii] = r_row_column[jj][ii] || col
jj++
}
main_div.appendChild(row)
ii++
}
// NOTE: Drawing obstacle
setTimeout(() => {
console.log(r_row_column[8])
// obstacle linear row-coln
let ob_col = r_row_column[8]
for(let col_k in ob_col) {
col = ob_col[col_k]
if(col_k < 5) continue
if(col.style['background-color'] == 'green') {
break // reached the ground: green
}
console.log('col:', col)
col.style.backgroundColor = 'red'
}
}, 111)
div_c = main_div.children.length - 2 // NOTE: -2 so we could include the ground
console.log(main_div.children)
let main_children = Array.from(main_div.children)
current_row = main_children[div_c]
prev_row = current_row
// Char spawn
console.log('spawn: starting current_row:', current_row)
current_row.children[0].replaceWith(current_char = char_appear())
prev_char = current_char
const ground = main_children[main_children.length - 1].children
// build and grass
for(let ground_col of ground) {
ground_col.style.backgroundColor = 'green'
}
let current_row_c = 0
function character_up() {
// remove previous position
if(div_c <= 0) div_c = 1
prev_char && (prev_char.id = '', prev_char.style['background-color'] = 'white', prev_char.innerHTML = '')
// prev_char && prev_char.remove()
div_c--;
current_row = main_children[div_c]
// collision conditional on the way up
{
let col_px = current_row.children[current_row_c]
if(col_px.style['background-color'] == 'red') {
console.log("BLOCK")
document.body.innerHTML = 'YOU DIED. LOL'
return
}
}
current_row.children[current_row_c].replaceWith(current_char = char_appear())
prev_char = current_char
console.log('current_char_up:', current_char, div_c)
current_row_c++
}
function character_down() {
// remove previous position
if(div_c >= main_children.length - 2) {
// div_c = main_children.length - 2
return
}
prev_char && (prev_char.id = '', prev_char.style['background-color'] = 'white', prev_char.innerHTML = '')
// prev_char && prev_char.remove()
div_c++;
current_row = main_children[div_c]
// collision conditional on the way up
{
let col_px = current_row.children[current_row_c]
if(col_px.style['background-color'] == 'red') {
console.log("BLOCK")
document.body.innerHTML = 'YOU DIED. LOL'
return
}
}
current_row.children[current_row_c].replaceWith(current_char = char_appear())
prev_char = current_char
console.log('current_char_down:', current_char, div_c)
current_row_c++
}
setTimeout(() => {
setInterval(() => {
character_down()
}, 555)
}, 11)
// setInterval(() => {
// current_row_c++
// }, 111)
document.addEventListener('keydown', async function(event) {
if(event.code == 'Space') {
play_jump()
character_up()
}
})
</script>
</html>