-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinal.js
More file actions
150 lines (129 loc) 路 4.78 KB
/
Copy pathfinal.js
File metadata and controls
150 lines (129 loc) 路 4.78 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
import k from './kaboom.js'
import { DEFAULTS } from './config.js'
import { createPlayer } from './entities/player.js'
import { setupMovementControls, setupDashControls } from './systems/controls.js'
import { setupAttackControls } from './systems/combat.js'
import { setupCameraFollow } from './systems/camera.js'
export default function final () {
let MOVE_SPEED = DEFAULTS.moveSpeed
let JUMP_FORCE = DEFAULTS.jumpForce
let DIR = 'right'
let SHIELD = 5
let DASH_SPEED = DEFAULTS.dashSpeed
layers(['bg', 'obj'], 'obj')
const player = createPlayer({ x: 60, y: 200 })
const getDir = () => DIR
const setDir = (dir) => {
DIR = dir
}
const getMageScale = () => DEFAULTS.finalMageScale
const map = [
'===============================================================================',
'= =',
'= =',
'= =',
'= =',
'= =',
'= =',
'= =',
'= =',
'= =',
'= >> =',
'= >>> >> > =',
'= >> # =',
'===============================================================================',
]
const levelConfig = {
width: 20,
height: 20,
'=': [sprite('brick'), solid(), 'wall'],
'>': [sprite('block'), solid(), 'wall'],
'#': [sprite('boss1'), solid(), scale(1.5), 'ghost', body(), 'danger', { dir: -1, timer: 0 }],
}
addLevel(map, levelConfig)
add([sprite('bg'), layer('bg')])
setupCameraFollow(player)
setupMovementControls({ player, getDir, setDir, moveSpeed: MOVE_SPEED, jumpForce: JUMP_FORCE })
setupDashControls({ player, getDir, dashSpeed: DASH_SPEED })
setupAttackControls({ player, getDir, getMageScale })
player.collides('danger', () => {
go('die')
})
collides('mage', 'ghost', (k, s) => {
camShake(10)
s.jump(300, 100)
if (DIR === 'right') {
s.move(1000, 0)
}
if (DIR === 'left') {
s.move(-1000, 0)
}
if (SHIELD === 5) {
add([text('OUCH'), pos(player.pos.x, player.pos.y)])
s.changeSprite('boss2')
wait(1, () => {
SHIELD = SHIELD - 1
})
}
if (SHIELD === 4) {
add([text('STOP DUDE!'), pos(player.pos.x, player.pos.y)])
s.changeSprite('boss3')
wait(1, () => {
SHIELD = SHIELD - 1
})
}
if (SHIELD === 3) {
add([text('OMG'), pos(player.pos.x, player.pos.y)])
s.changeSprite('boss4')
wait(1, () => {
SHIELD = SHIELD - 1
})
}
if (SHIELD === 2) {
add([text('AHHHHHHHHHHH'), pos(player.pos.x, player.pos.y)])
s.changeSprite('boss5')
wait(1, () => {
SHIELD = SHIELD - 1
})
}
if (SHIELD === 1) {
add([text('FUUUUUUUUUUUUUCK'), pos(player.pos.x, player.pos.y)])
destroy(s)
go('win')
}
})
action('ghost', (s) => {
if (SHIELD === 2) {
s.move(s.dir * 300, 0)
s.timer -= dt()
if (s.timer <= 0) {
s.dir = - s.dir
s.timer = rand(3)
s.jump(400, 0)
}
} else if (SHIELD === 1) {
s.move(s.dir * 400, 0)
s.timer -= dt()
if (s.timer <= 0) {
s.dir = - s.dir
s.timer = rand(2)
s.jump(450, 0)
}
} else {
s.move(s.dir * 100, 0)
s.timer -= dt()
if (s.timer <= 0) {
s.dir = - s.dir
s.timer = rand(4)
s.jump(350, 0)
}
}
})
collides('danger', 'wall', (s) => {
s.dir = -s.dir
})
action('mage', (m) => {
const value = 10
m.move(value, 0)
})
}