Skip to content

Commit 74fb72e

Browse files
committed
feat: first draft
1 parent c82c6b4 commit 74fb72e

File tree

5 files changed

+177
-147
lines changed

5 files changed

+177
-147
lines changed

assets/weapons.json

Lines changed: 87 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,89 @@
1-
{"frames": {
2-
3-
"firearm_0.png":
41
{
5-
"frame": {"x":19,"y":62,"w":14,"h":11},
6-
"rotated": true,
7-
"trimmed": true,
8-
"spriteSourceSize": {"x":6,"y":8,"w":14,"h":11},
9-
"sourceSize": {"w":29,"h":19},
10-
"anchor": {"x":0.35,"y":0.8}
11-
},
12-
"firearm_1.png":
13-
{
14-
"frame": {"x":1,"y":75,"w":14,"h":10},
15-
"rotated": false,
16-
"trimmed": true,
17-
"spriteSourceSize": {"x":6,"y":9,"w":14,"h":10},
18-
"sourceSize": {"w":29,"h":19},
19-
"anchor": {"x":0.35,"y":0.8}
20-
},
21-
"firearm_2.png":
22-
{
23-
"frame": {"x":1,"y":49,"w":19,"h":11},
24-
"rotated": false,
25-
"trimmed": true,
26-
"spriteSourceSize": {"x":6,"y":8,"w":19,"h":11},
27-
"sourceSize": {"w":29,"h":19},
28-
"anchor": {"x":0.35,"y":0.8}
29-
},
30-
"firearm_3.png":
31-
{
32-
"frame": {"x":1,"y":62,"w":16,"h":11},
33-
"rotated": false,
34-
"trimmed": true,
35-
"spriteSourceSize": {"x":6,"y":8,"w":16,"h":11},
36-
"sourceSize": {"w":29,"h":19},
37-
"anchor": {"x":0.35,"y":0.8}
38-
},
39-
"firearm_4.png":
40-
{
41-
"frame": {"x":22,"y":33,"w":19,"h":8},
42-
"rotated": true,
43-
"trimmed": true,
44-
"spriteSourceSize": {"x":6,"y":11,"w":19,"h":8},
45-
"sourceSize": {"w":29,"h":19},
46-
"anchor": {"x":0.35,"y":0.8}
47-
},
48-
"firearm_5.png":
49-
{
50-
"frame": {"x":1,"y":33,"w":19,"h":14},
51-
"rotated": false,
52-
"trimmed": true,
53-
"spriteSourceSize": {"x":6,"y":5,"w":19,"h":14},
54-
"sourceSize": {"w":29,"h":19},
55-
"anchor": {"x":0.35,"y":0.8}
56-
},
57-
"firearm_6.png":
58-
{
59-
"frame": {"x":1,"y":12,"w":23,"h":19},
60-
"rotated": false,
61-
"trimmed": true,
62-
"spriteSourceSize": {"x":6,"y":0,"w":23,"h":19},
63-
"sourceSize": {"w":29,"h":19},
64-
"anchor": {"x":0.35,"y":0.8}
65-
},
66-
"firearm_7.png":
67-
{
68-
"frame": {"x":1,"y":1,"w":28,"h":9},
69-
"rotated": false,
70-
"trimmed": true,
71-
"spriteSourceSize": {"x":0,"y":10,"w":28,"h":9},
72-
"sourceSize": {"w":29,"h":19},
73-
"anchor": {"x":0.35,"y":0.8}
74-
}},
75-
"animations": {
76-
"firearm": ["firearm_0.png","firearm_1.png","firearm_2.png","firearm_3.png","firearm_4.png","firearm_5.png","firearm_6.png","firearm_7.png"]
77-
},
78-
"meta": {
79-
"app": "https://www.codeandweb.com/texturepacker",
80-
"version": "1.0",
81-
"image": "weapons.png",
82-
"format": "RGBA8888",
83-
"size": {"w":31,"h":86},
84-
"scale": "1",
85-
"smartupdate": "$TexturePacker:SmartUpdate:d2b303a97f5c404613ee1d5a9d5391ca:339149f846c1b0239c395619b35d265b:ba48453f8b2235fdb166a51105f49255$"
86-
}
2+
"frames": {
3+
"firearm_5.png": {
4+
"frame": { "x": 19, "y": 62, "w": 14, "h": 11 },
5+
"rotated": true,
6+
"trimmed": true,
7+
"spriteSourceSize": { "x": 6, "y": 8, "w": 14, "h": 11 },
8+
"sourceSize": { "w": 29, "h": 19 },
9+
"anchor": { "x": 0.35, "y": 0.8 }
10+
},
11+
"firearm_0.png": {
12+
"frame": { "x": 1, "y": 75, "w": 14, "h": 10 },
13+
"rotated": false,
14+
"trimmed": true,
15+
"spriteSourceSize": { "x": 6, "y": 9, "w": 14, "h": 10 },
16+
"sourceSize": { "w": 29, "h": 19 },
17+
"anchor": { "x": 0.35, "y": 0.8 }
18+
},
19+
"firearm_6.png": {
20+
"frame": { "x": 1, "y": 49, "w": 19, "h": 11 },
21+
"rotated": false,
22+
"trimmed": true,
23+
"spriteSourceSize": { "x": 6, "y": 8, "w": 19, "h": 11 },
24+
"sourceSize": { "w": 29, "h": 19 },
25+
"anchor": { "x": 0.35, "y": 0.8 }
26+
},
27+
"firearm_3.png": {
28+
"frame": { "x": 1, "y": 62, "w": 16, "h": 11 },
29+
"rotated": false,
30+
"trimmed": true,
31+
"spriteSourceSize": { "x": 6, "y": 8, "w": 16, "h": 11 },
32+
"sourceSize": { "w": 29, "h": 19 },
33+
"anchor": { "x": 0.35, "y": 0.8 }
34+
},
35+
"firearm_1.png": {
36+
"frame": { "x": 22, "y": 33, "w": 19, "h": 8 },
37+
"rotated": true,
38+
"trimmed": true,
39+
"spriteSourceSize": { "x": 6, "y": 11, "w": 19, "h": 8 },
40+
"sourceSize": { "w": 29, "h": 19 },
41+
"anchor": { "x": 0.35, "y": 0.8 }
42+
},
43+
"firearm_4.png": {
44+
"frame": { "x": 1, "y": 33, "w": 19, "h": 14 },
45+
"rotated": false,
46+
"trimmed": true,
47+
"spriteSourceSize": { "x": 6, "y": 5, "w": 19, "h": 14 },
48+
"sourceSize": { "w": 29, "h": 19 },
49+
"anchor": { "x": 0.35, "y": 0.8 }
50+
},
51+
"firearm_7.png": {
52+
"frame": { "x": 1, "y": 12, "w": 23, "h": 19 },
53+
"rotated": false,
54+
"trimmed": true,
55+
"spriteSourceSize": { "x": 6, "y": 0, "w": 23, "h": 19 },
56+
"sourceSize": { "w": 29, "h": 19 },
57+
"anchor": { "x": 0.35, "y": 0.8 }
58+
},
59+
"firearm_2.png": {
60+
"frame": { "x": 1, "y": 1, "w": 28, "h": 9 },
61+
"rotated": false,
62+
"trimmed": true,
63+
"spriteSourceSize": { "x": 0, "y": 10, "w": 28, "h": 9 },
64+
"sourceSize": { "w": 29, "h": 19 },
65+
"anchor": { "x": 0.35, "y": 0.8 }
66+
}
67+
},
68+
"animations": {
69+
"firearm": [
70+
"firearm_0.png",
71+
"firearm_1.png",
72+
"firearm_2.png",
73+
"firearm_3.png",
74+
"firearm_4.png",
75+
"firearm_5.png",
76+
"firearm_6.png",
77+
"firearm_7.png"
78+
]
79+
},
80+
"meta": {
81+
"app": "https://www.codeandweb.com/texturepacker",
82+
"version": "1.0",
83+
"image": "weapons.png",
84+
"format": "RGBA8888",
85+
"size": { "w": 31, "h": 86 },
86+
"scale": "1",
87+
"smartupdate": "$TexturePacker:SmartUpdate:d2b303a97f5c404613ee1d5a9d5391ca:339149f846c1b0239c395619b35d265b:ba48453f8b2235fdb166a51105f49255$"
88+
}
8789
}

js/game/app/player.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ class Player {
7070
const right = keyboard('ArrowRight')
7171
const kRight = keyboard('d')
7272

73+
const nextWeapon = keyboard('e')
74+
const prevWeapon = keyboard('q')
75+
76+
nextWeapon.release = () => this.weapons.next()
77+
prevWeapon.release = () => this.weapons.prev()
78+
7379
kUp.press = up.press = () => (this.movements.up = true)
7480
kUp.release = up.release = () => (this.movements.up = false)
7581

@@ -207,9 +213,15 @@ class Player {
207213
)
208214

209215
setScoreDOM(this.score)
216+
217+
this.checkScoreForWeapons()
210218
}
211219
}
212220

221+
checkScoreForWeapons = () => {
222+
this.weapons.checkForUpgrade()
223+
}
224+
213225
damage = zombie => {
214226
let dmg
215227
if (zombie.isRegular) dmg = ZOMBIE_REGULAR_DAMAGE

js/game/app/weapons.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,18 @@ class Weapons {
8181

8282
next = () => {
8383
this.weaponIndex++
84-
this.weaponIndex %= WEAPON_COUNT
84+
this.weaponIndex %= this.maxWeaponCount
8585

8686
this.swapTexture()
87+
this.updateDOMWeaponName()
8788
}
8889

8990
prev = () => {
9091
this.weaponIndex--
91-
this.weaponIndex %= WEAPON_COUNT
92+
if (this.weaponIndex < 0) this.weaponIndex = this.maxWeaponCount - 1
9293

9394
this.swapTexture()
95+
this.updateDOMWeaponName()
9496
}
9597

9698
tryFire = () => {
@@ -148,7 +150,8 @@ class Weapons {
148150
bulletMass,
149151
bulletColor,
150152
bulletRadius,
151-
bulletDurability
153+
bulletDurability,
154+
scoreThreshold
152155
} = GUNS_DATA[i]
153156

154157
const graphics = new PIXI.Graphics()
@@ -164,13 +167,25 @@ class Weapons {
164167
radius: bulletRadius,
165168
damage: bulletDamage,
166169
durability: bulletDurability,
170+
threshold: scoreThreshold,
167171
texture: graphicsToTexture(graphics, this.player.game.getRenderer())
168172
}
169173

170174
this.bulletData.push(bulletDatum)
171175
}
172176
}
173177

178+
checkForUpgrade = () => {
179+
if (this.maxWeaponCount === WEAPON_COUNT) return
180+
181+
const nextWeaponData = this.bulletData[this.maxWeaponCount]
182+
183+
if (this.player.score >= nextWeaponData.threshold) {
184+
console.log('damn upgrade')
185+
this.upgrade()
186+
}
187+
}
188+
174189
upgrade = () => {
175190
this.maxWeaponCount++
176191
}

js/game/managers/zombieManager.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,21 @@ class ZombieManager {
4343
this.level++
4444

4545
const count = getZombieCount(this.level)
46-
console.log(count)
4746

4847
this.zombies.forEach(zombie => {
4948
const { x, y } = this.game.world.getRandomSpawner()
5049
zombie.revive(x, y)
51-
this.zombieCount++
5250
})
5351

5452
for (let i = this.zombies.size; i < count; i++) {
5553
const { x, y } = this.game.world.getRandomSpawner()
5654
const newZombie = new Zombie(this.game, x, y)
5755

5856
this.zombies.set(newZombie.id, newZombie)
59-
60-
this.zombieCount++
6157
}
6258

59+
this.zombieCount = count
60+
6361
this.updateZBDOM()
6462
this.updateLvlDOM()
6563
}

0 commit comments

Comments
 (0)