kiwiengine 0.5.2 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ko.md +2 -2
- package/README.md +2 -2
- package/examples/auto-battle/assets/bgm/battle.mp3 +0 -0
- package/examples/auto-battle/assets/bitmap-fonts/white-peaberry.fnt +107 -0
- package/examples/auto-battle/assets/bitmap-fonts/white-peaberry.png +0 -0
- package/examples/auto-battle/assets/joystick/joystick.png +0 -0
- package/examples/auto-battle/assets/joystick/knob.png +0 -0
- package/examples/auto-battle/assets/sfx/hero/die/die.wav +0 -0
- package/examples/auto-battle/assets/sfx/hero/heal/heal.wav +0 -0
- package/examples/auto-battle/assets/sfx/hero/hit/hit1.wav +0 -0
- package/examples/auto-battle/assets/sfx/hero/hit/hit2.wav +0 -0
- package/examples/auto-battle/assets/sfx/hero/hit/hit3.wav +0 -0
- package/examples/auto-battle/assets/sfx/hero/miss/miss1.wav +0 -0
- package/examples/auto-battle/assets/sfx/hero/miss/miss2.wav +0 -0
- package/examples/auto-battle/assets/sfx/hero/miss/miss3.wav +0 -0
- package/examples/auto-battle/assets/sfx/orc/die/die.wav +0 -0
- package/examples/auto-battle/assets/sfx/orc/hit/hit1.wav +0 -0
- package/examples/auto-battle/assets/sfx/orc/hit/hit2.wav +0 -0
- package/examples/auto-battle/assets/sfx/orc/hit/hit3.wav +0 -0
- package/examples/auto-battle/assets/sfx/orc/miss/miss1.wav +0 -0
- package/examples/auto-battle/assets/sfx/orc/miss/miss2.wav +0 -0
- package/examples/auto-battle/assets/sfx/orc/miss/miss3.wav +0 -0
- package/examples/auto-battle/assets/spritesheets/hero-atlas.json +246 -0
- package/examples/auto-battle/assets/spritesheets/hero.png +0 -0
- package/examples/auto-battle/assets/spritesheets/orc-atlas.json +246 -0
- package/examples/auto-battle/assets/spritesheets/orc.png +0 -0
- package/examples/auto-battle/assets/spritesheets/potion-atlas.json +68 -0
- package/examples/auto-battle/assets/spritesheets/potion.png +0 -0
- package/examples/auto-battle/dist/game.js +2 -0
- package/examples/auto-battle/dist/game.js.LICENSE.txt +35 -0
- package/examples/auto-battle/hud/damage-text.ts +46 -0
- package/examples/auto-battle/hud/heal-text.ts +46 -0
- package/examples/auto-battle/hud/hp-bar.ts +38 -0
- package/examples/auto-battle/index.ts +41 -0
- package/examples/auto-battle/objects/character.ts +95 -0
- package/examples/auto-battle/objects/hero.ts +119 -0
- package/examples/auto-battle/objects/orc.ts +107 -0
- package/examples/auto-battle/objects/potion.ts +27 -0
- package/examples/auto-battle/stage.ts +366 -0
- package/examples/battle-benchmark-matterjs/assets/bgm/battle.mp3 +0 -0
- package/examples/battle-benchmark-matterjs/assets/bitmap-fonts/white-peaberry.fnt +107 -0
- package/examples/battle-benchmark-matterjs/assets/bitmap-fonts/white-peaberry.png +0 -0
- package/examples/battle-benchmark-matterjs/assets/joystick/joystick.png +0 -0
- package/examples/battle-benchmark-matterjs/assets/joystick/knob.png +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/hero/die/die.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/hero/heal/heal.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/hero/hit/hit1.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/hero/hit/hit2.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/hero/hit/hit3.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/hero/miss/miss1.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/hero/miss/miss2.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/hero/miss/miss3.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/orc/die/die.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/orc/hit/hit1.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/orc/hit/hit2.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/orc/hit/hit3.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/orc/miss/miss1.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/orc/miss/miss2.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/sfx/orc/miss/miss3.wav +0 -0
- package/examples/battle-benchmark-matterjs/assets/spritesheets/hero-atlas.json +246 -0
- package/examples/battle-benchmark-matterjs/assets/spritesheets/hero.png +0 -0
- package/examples/battle-benchmark-matterjs/assets/spritesheets/orc-atlas.json +246 -0
- package/examples/battle-benchmark-matterjs/assets/spritesheets/orc.png +0 -0
- package/examples/battle-benchmark-matterjs/assets/spritesheets/potion-atlas.json +68 -0
- package/examples/battle-benchmark-matterjs/assets/spritesheets/potion.png +0 -0
- package/examples/battle-benchmark-matterjs/dist/game.js +2 -0
- package/examples/battle-benchmark-matterjs/dist/game.js.LICENSE.txt +35 -0
- package/examples/battle-benchmark-matterjs/hud/damage-text.ts +46 -0
- package/examples/battle-benchmark-matterjs/hud/heal-text.ts +46 -0
- package/examples/battle-benchmark-matterjs/hud/hp-bar.ts +38 -0
- package/examples/battle-benchmark-matterjs/index.html +24 -0
- package/examples/battle-benchmark-matterjs/index.ts +41 -0
- package/examples/battle-benchmark-matterjs/objects/character.ts +95 -0
- package/examples/battle-benchmark-matterjs/objects/hero.ts +111 -0
- package/examples/battle-benchmark-matterjs/objects/orc.ts +107 -0
- package/examples/battle-benchmark-matterjs/objects/potion.ts +27 -0
- package/examples/battle-benchmark-matterjs/stage.ts +177 -0
- package/examples/battle-benchmark-separation/assets/bgm/battle.mp3 +0 -0
- package/examples/battle-benchmark-separation/assets/bitmap-fonts/white-peaberry.fnt +107 -0
- package/examples/battle-benchmark-separation/assets/bitmap-fonts/white-peaberry.png +0 -0
- package/examples/battle-benchmark-separation/assets/joystick/joystick.png +0 -0
- package/examples/battle-benchmark-separation/assets/joystick/knob.png +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/hero/die/die.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/hero/heal/heal.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/hero/hit/hit1.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/hero/hit/hit2.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/hero/hit/hit3.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/hero/miss/miss1.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/hero/miss/miss2.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/hero/miss/miss3.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/orc/die/die.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/orc/hit/hit1.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/orc/hit/hit2.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/orc/hit/hit3.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/orc/miss/miss1.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/orc/miss/miss2.wav +0 -0
- package/examples/battle-benchmark-separation/assets/sfx/orc/miss/miss3.wav +0 -0
- package/examples/battle-benchmark-separation/assets/spritesheets/hero-atlas.json +246 -0
- package/examples/battle-benchmark-separation/assets/spritesheets/hero.png +0 -0
- package/examples/battle-benchmark-separation/assets/spritesheets/orc-atlas.json +246 -0
- package/examples/battle-benchmark-separation/assets/spritesheets/orc.png +0 -0
- package/examples/battle-benchmark-separation/assets/spritesheets/potion-atlas.json +68 -0
- package/examples/battle-benchmark-separation/assets/spritesheets/potion.png +0 -0
- package/examples/battle-benchmark-separation/dist/game.js +2 -0
- package/examples/battle-benchmark-separation/dist/game.js.LICENSE.txt +35 -0
- package/examples/battle-benchmark-separation/hud/damage-text.ts +46 -0
- package/examples/battle-benchmark-separation/hud/heal-text.ts +46 -0
- package/examples/battle-benchmark-separation/hud/hp-bar.ts +38 -0
- package/examples/battle-benchmark-separation/index.html +24 -0
- package/examples/battle-benchmark-separation/index.ts +41 -0
- package/examples/battle-benchmark-separation/objects/character.ts +225 -0
- package/examples/battle-benchmark-separation/objects/hero.ts +110 -0
- package/examples/battle-benchmark-separation/objects/orc.ts +213 -0
- package/examples/battle-benchmark-separation/objects/potion.ts +27 -0
- package/examples/battle-benchmark-separation/stage.ts +178 -0
- package/examples/battle-benchmark-separation2/assets/bgm/battle.mp3 +0 -0
- package/examples/battle-benchmark-separation2/assets/bitmap-fonts/white-peaberry.fnt +107 -0
- package/examples/battle-benchmark-separation2/assets/bitmap-fonts/white-peaberry.png +0 -0
- package/examples/battle-benchmark-separation2/assets/joystick/joystick.png +0 -0
- package/examples/battle-benchmark-separation2/assets/joystick/knob.png +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/hero/die/die.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/hero/heal/heal.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/hero/hit/hit1.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/hero/hit/hit2.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/hero/hit/hit3.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/hero/miss/miss1.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/hero/miss/miss2.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/hero/miss/miss3.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/orc/die/die.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/orc/hit/hit1.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/orc/hit/hit2.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/orc/hit/hit3.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/orc/miss/miss1.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/orc/miss/miss2.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/sfx/orc/miss/miss3.wav +0 -0
- package/examples/battle-benchmark-separation2/assets/spritesheets/hero-atlas.json +246 -0
- package/examples/battle-benchmark-separation2/assets/spritesheets/hero.png +0 -0
- package/examples/battle-benchmark-separation2/assets/spritesheets/orc-atlas.json +246 -0
- package/examples/battle-benchmark-separation2/assets/spritesheets/orc.png +0 -0
- package/examples/battle-benchmark-separation2/assets/spritesheets/potion-atlas.json +68 -0
- package/examples/battle-benchmark-separation2/assets/spritesheets/potion.png +0 -0
- package/examples/battle-benchmark-separation2/dist/game.js +2 -0
- package/examples/battle-benchmark-separation2/dist/game.js.LICENSE.txt +35 -0
- package/examples/battle-benchmark-separation2/hud/damage-text.ts +46 -0
- package/examples/battle-benchmark-separation2/hud/heal-text.ts +46 -0
- package/examples/battle-benchmark-separation2/hud/hp-bar.ts +38 -0
- package/examples/battle-benchmark-separation2/index.html +24 -0
- package/examples/battle-benchmark-separation2/index.ts +41 -0
- package/examples/battle-benchmark-separation2/objects/character.ts +195 -0
- package/examples/battle-benchmark-separation2/objects/hero.ts +110 -0
- package/examples/battle-benchmark-separation2/objects/orc.ts +213 -0
- package/examples/battle-benchmark-separation2/objects/potion.ts +27 -0
- package/examples/battle-benchmark-separation2/stage.ts +178 -0
- package/examples/dom-sprite-test/index.ts +6 -9
- package/examples/simple-battle/assets/spritesheets/hero-atlas.json +180 -223
- package/examples/simple-battle/assets/spritesheets/orc-atlas.json +180 -223
- package/examples/simple-battle/assets/spritesheets/potion-atlas.json +46 -61
- package/examples/simple-battle/hud/damage-text.ts +1 -0
- package/examples/simple-battle/hud/heal-text.ts +1 -0
- package/examples/simple-battle/objects/character.ts +3 -3
- package/examples/simple-battle/objects/hero.ts +3 -5
- package/examples/simple-battle/objects/orc.ts +3 -5
- package/examples/simple-battle/objects/potion.ts +0 -2
- package/examples/simple-battle/stage.ts +2 -4
- package/examples/sprite-test/index.ts +6 -9
- package/examples/webpack.config.js +4 -1
- package/lib/asset/loaders/audio.js +4 -1
- package/lib/asset/loaders/audio.js.map +1 -1
- package/lib/asset/loaders/binary.js +4 -1
- package/lib/asset/loaders/binary.js.map +1 -1
- package/lib/asset/loaders/bitmap-font.js +24 -21
- package/lib/asset/loaders/bitmap-font.js.map +1 -1
- package/lib/asset/loaders/font.js +3 -0
- package/lib/asset/loaders/font.js.map +1 -1
- package/lib/asset/loaders/spritesheet.js +12 -1
- package/lib/asset/loaders/spritesheet.js.map +1 -1
- package/lib/asset/loaders/text.js +3 -0
- package/lib/asset/loaders/text.js.map +1 -1
- package/lib/asset/loaders/texture.js +21 -26
- package/lib/asset/loaders/texture.js.map +1 -1
- package/lib/asset/preload.js.map +1 -1
- package/lib/collision/check-collision.js +16 -16
- package/lib/collision/check-collision.js.map +1 -1
- package/lib/dom/dom-animated-sprite.js +21 -36
- package/lib/dom/dom-animated-sprite.js.map +1 -1
- package/lib/dom/dom-game-object.js +9 -7
- package/lib/dom/dom-game-object.js.map +1 -1
- package/lib/dom/dom-particle.js.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/node/core/dirty-number.js +0 -19
- package/lib/node/core/dirty-number.js.map +1 -1
- package/lib/node/core/renderable.js +7 -0
- package/lib/node/core/renderable.js.map +1 -1
- package/lib/node/core/transform.js +22 -11
- package/lib/node/core/transform.js.map +1 -1
- package/lib/node/ext/animated-sprite.js +3 -22
- package/lib/node/ext/animated-sprite.js.map +1 -1
- package/lib/node/ext/bitmap-text.js +7 -3
- package/lib/node/ext/bitmap-text.js.map +1 -1
- package/lib/node/ext/circle.js +18 -3
- package/lib/node/ext/circle.js.map +1 -1
- package/lib/node/ext/deplay.js +2 -0
- package/lib/node/ext/deplay.js.map +1 -1
- package/lib/node/ext/dom-container.js +2 -2
- package/lib/node/ext/dom-container.js.map +1 -1
- package/lib/node/ext/interval.js +2 -0
- package/lib/node/ext/interval.js.map +1 -1
- package/lib/node/ext/particle.js.map +1 -1
- package/lib/node/ext/rectangle.js +24 -4
- package/lib/node/ext/rectangle.js.map +1 -1
- package/lib/node/physics/physics-object.js +9 -29
- package/lib/node/physics/physics-object.js.map +1 -1
- package/lib/node/physics/physics-world.js +2 -0
- package/lib/node/physics/physics-world.js.map +1 -1
- package/lib/node/physics/rigidbodies.js +7 -0
- package/lib/node/physics/rigidbodies.js.map +1 -0
- package/lib/renderer/renderer.js +3 -2
- package/lib/renderer/renderer.js.map +1 -1
- package/lib/types/animation-atlas.js +2 -0
- package/lib/types/animation-atlas.js.map +1 -0
- package/lib/types/asset/loaders/audio.d.ts +1 -0
- package/lib/types/asset/loaders/audio.d.ts.map +1 -1
- package/lib/types/asset/loaders/binary.d.ts +1 -0
- package/lib/types/asset/loaders/binary.d.ts.map +1 -1
- package/lib/types/asset/loaders/bitmap-font.d.ts +1 -0
- package/lib/types/asset/loaders/bitmap-font.d.ts.map +1 -1
- package/lib/types/asset/loaders/font.d.ts +1 -0
- package/lib/types/asset/loaders/font.d.ts.map +1 -1
- package/lib/types/asset/loaders/spritesheet.d.ts +11 -3
- package/lib/types/asset/loaders/spritesheet.d.ts.map +1 -1
- package/lib/types/asset/loaders/text.d.ts +1 -0
- package/lib/types/asset/loaders/text.d.ts.map +1 -1
- package/lib/types/asset/loaders/texture.d.ts +1 -1
- package/lib/types/asset/loaders/texture.d.ts.map +1 -1
- package/lib/types/asset/preload.d.ts +2 -2
- package/lib/types/asset/preload.d.ts.map +1 -1
- package/lib/types/atlas copy.js +2 -0
- package/lib/types/atlas copy.js.map +1 -0
- package/lib/types/atlas.js +2 -0
- package/lib/types/atlas.js.map +1 -0
- package/lib/types/dom/dom-animated-sprite.d.ts +4 -10
- package/lib/types/dom/dom-animated-sprite.d.ts.map +1 -1
- package/lib/types/dom/dom-game-object.d.ts +1 -1
- package/lib/types/dom/dom-game-object.d.ts.map +1 -1
- package/lib/types/dom/dom-particle.d.ts.map +1 -1
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/node/core/dirty-number.d.ts +0 -8
- package/lib/types/node/core/dirty-number.d.ts.map +1 -1
- package/lib/types/node/core/renderable.d.ts +1 -0
- package/lib/types/node/core/renderable.d.ts.map +1 -1
- package/lib/types/node/core/transform.d.ts +4 -2
- package/lib/types/node/core/transform.d.ts.map +1 -1
- package/lib/types/node/ext/animated-sprite.d.ts +4 -10
- package/lib/types/node/ext/animated-sprite.d.ts.map +1 -1
- package/lib/types/node/ext/bitmap-text.d.ts.map +1 -1
- package/lib/types/node/ext/circle.d.ts +3 -3
- package/lib/types/node/ext/circle.d.ts.map +1 -1
- package/lib/types/node/ext/deplay.d.ts.map +1 -1
- package/lib/types/node/ext/dom-container.d.ts +1 -1
- package/lib/types/node/ext/dom-container.d.ts.map +1 -1
- package/lib/types/node/ext/interval.d.ts.map +1 -1
- package/lib/types/node/ext/particle.d.ts.map +1 -1
- package/lib/types/node/ext/rectangle.d.ts +4 -4
- package/lib/types/node/ext/rectangle.d.ts.map +1 -1
- package/lib/types/node/physics/physics-object.d.ts +2 -2
- package/lib/types/node/physics/physics-object.d.ts.map +1 -1
- package/lib/types/node/physics/physics-world.d.ts.map +1 -1
- package/lib/types/node/physics/rigidbodies.d.ts +23 -0
- package/lib/types/node/physics/rigidbodies.d.ts.map +1 -0
- package/lib/types/renderer/renderer.d.ts.map +1 -1
- package/lib/types/sprite-atlas.js +2 -0
- package/lib/types/sprite-atlas.js.map +1 -0
- package/lib/types/types/animation-atlas.d.ts +14 -0
- package/lib/types/types/animation-atlas.d.ts.map +1 -0
- package/lib/types/types/atlas copy.d.ts +12 -0
- package/lib/types/types/atlas copy.d.ts.map +1 -0
- package/lib/types/types/atlas.d.ts +16 -0
- package/lib/types/types/atlas.d.ts.map +1 -0
- package/lib/types/types/sprite-atlas.d.ts +13 -0
- package/lib/types/types/sprite-atlas.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/asset/loaders/audio.ts +5 -2
- package/src/asset/loaders/binary.ts +5 -1
- package/src/asset/loaders/bitmap-font.ts +33 -27
- package/src/asset/loaders/font.ts +4 -0
- package/src/asset/loaders/spritesheet.ts +18 -5
- package/src/asset/loaders/text.ts +4 -0
- package/src/asset/loaders/texture.ts +19 -27
- package/src/asset/preload.ts +4 -8
- package/src/collision/check-collision.ts +16 -16
- package/src/dom/dom-animated-sprite.ts +24 -45
- package/src/dom/dom-game-object.ts +9 -6
- package/src/dom/dom-particle.ts +1 -1
- package/src/index.ts +2 -0
- package/src/node/core/dirty-number.ts +0 -24
- package/src/node/core/renderable.ts +7 -0
- package/src/node/core/transform.ts +23 -11
- package/src/node/ext/animated-sprite.ts +9 -29
- package/src/node/ext/bitmap-text.ts +7 -3
- package/src/node/ext/circle.ts +18 -3
- package/src/node/ext/deplay.ts +1 -0
- package/src/node/ext/dom-container.ts +2 -2
- package/src/node/ext/interval.ts +1 -0
- package/src/node/ext/particle.ts +1 -1
- package/src/node/ext/rectangle.ts +24 -4
- package/src/node/physics/physics-object.ts +11 -40
- package/src/node/physics/physics-world.ts +1 -0
- package/src/node/physics/rigidbodies.ts +14 -0
- package/src/renderer/renderer.ts +4 -3
- package/src/types/atlas.ts +17 -0
- package/examples/flappy-cat/assets/bgm/bgm.ogg +0 -0
- package/examples/flappy-cat/assets/images/base.png +0 -0
- package/examples/flappy-cat/assets/images/bg.png +0 -0
- package/examples/flappy-cat/assets/images/cat.png +0 -0
- package/examples/flappy-cat/assets/images/pipe-green.png +0 -0
- package/examples/flappy-cat/assets/images/pipe-red.png +0 -0
- package/examples/flappy-cat/assets/sfx/die.wav +0 -0
- package/examples/flappy-cat/assets/sfx/hit.wav +0 -0
- package/examples/flappy-cat/assets/sfx/point.wav +0 -0
- package/examples/flappy-cat/assets/sfx/wing.wav +0 -0
- package/examples/flappy-cat/dist/game.js +0 -0
- package/examples/flappy-cat/index.ts +0 -0
- /package/examples/{flappy-cat → auto-battle}/index.html +0 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* matter-js 0.20.0 by @liabru
|
|
3
|
+
* http://brm.io/matter-js/
|
|
4
|
+
* License MIT
|
|
5
|
+
*
|
|
6
|
+
* The MIT License (MIT)
|
|
7
|
+
*
|
|
8
|
+
* Copyright (c) Liam Brummitt and contributors.
|
|
9
|
+
*
|
|
10
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
* in the Software without restriction, including without limitation the rights
|
|
13
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
* furnished to do so, subject to the following conditions:
|
|
16
|
+
*
|
|
17
|
+
* The above copyright notice and this permission notice shall be included in
|
|
18
|
+
* all copies or substantial portions of the Software.
|
|
19
|
+
*
|
|
20
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
26
|
+
* THE SOFTWARE.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* tiny-lru
|
|
31
|
+
*
|
|
32
|
+
* @copyright 2025 Jason Mulligan <jason.mulligan@avoidwork.com>
|
|
33
|
+
* @license BSD-3-Clause
|
|
34
|
+
* @version 11.4.5
|
|
35
|
+
*/
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { BitmapTextNode, GameObjectOptions } from '../../../src/index'
|
|
2
|
+
|
|
3
|
+
export type DamageTextOptions = {
|
|
4
|
+
damage: number
|
|
5
|
+
} & GameObjectOptions
|
|
6
|
+
|
|
7
|
+
export class DamageText extends BitmapTextNode {
|
|
8
|
+
#velocityY = -50
|
|
9
|
+
#gravity = 100
|
|
10
|
+
#lifetime = 1.0
|
|
11
|
+
#elapsed = 0
|
|
12
|
+
#fadeStart = 0.5
|
|
13
|
+
#initialScale = 1.0
|
|
14
|
+
#targetScale = 1.2
|
|
15
|
+
|
|
16
|
+
constructor(options: DamageTextOptions) {
|
|
17
|
+
super({
|
|
18
|
+
...options,
|
|
19
|
+
text: `-${options.damage}`,
|
|
20
|
+
fnt: 'assets/bitmap-fonts/white-peaberry.fnt',
|
|
21
|
+
src: 'assets/bitmap-fonts/white-peaberry.png'
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
protected override update(dt: number) {
|
|
26
|
+
if (this.paused) return
|
|
27
|
+
super.update(dt)
|
|
28
|
+
|
|
29
|
+
this.#elapsed += dt
|
|
30
|
+
this.#velocityY += this.#gravity * dt
|
|
31
|
+
this.y += this.#velocityY * dt
|
|
32
|
+
|
|
33
|
+
const progress = Math.min(this.#elapsed / this.#lifetime, 1)
|
|
34
|
+
const scale = this.#initialScale + (this.#targetScale - this.#initialScale) * progress
|
|
35
|
+
this.scale = scale
|
|
36
|
+
|
|
37
|
+
if (this.#elapsed > this.#fadeStart) {
|
|
38
|
+
const fadeProgress = (this.#elapsed - this.#fadeStart) / (this.#lifetime - this.#fadeStart)
|
|
39
|
+
this.alpha = Math.max(1 - fadeProgress, 0)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (this.#elapsed >= this.#lifetime) {
|
|
43
|
+
this.remove()
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { BitmapTextNode, GameObjectOptions } from '../../../src/index'
|
|
2
|
+
|
|
3
|
+
export type HealTextOptions = {
|
|
4
|
+
hp: number
|
|
5
|
+
} & GameObjectOptions
|
|
6
|
+
|
|
7
|
+
export class HealText extends BitmapTextNode {
|
|
8
|
+
#velocityY = -50
|
|
9
|
+
#gravity = 100
|
|
10
|
+
#lifetime = 1.0
|
|
11
|
+
#elapsed = 0
|
|
12
|
+
#fadeStart = 0.5
|
|
13
|
+
#initialScale = 1.0
|
|
14
|
+
#targetScale = 1.2
|
|
15
|
+
|
|
16
|
+
constructor(options: HealTextOptions) {
|
|
17
|
+
super({
|
|
18
|
+
...options,
|
|
19
|
+
text: `+${options.hp}`,
|
|
20
|
+
fnt: 'assets/bitmap-fonts/white-peaberry.fnt',
|
|
21
|
+
src: 'assets/bitmap-fonts/white-peaberry.png'
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
protected override update(dt: number) {
|
|
26
|
+
if (this.paused) return
|
|
27
|
+
super.update(dt)
|
|
28
|
+
|
|
29
|
+
this.#elapsed += dt
|
|
30
|
+
this.#velocityY += this.#gravity * dt
|
|
31
|
+
this.y += this.#velocityY * dt
|
|
32
|
+
|
|
33
|
+
const progress = Math.min(this.#elapsed / this.#lifetime, 1)
|
|
34
|
+
const scale = this.#initialScale + (this.#targetScale - this.#initialScale) * progress
|
|
35
|
+
this.scale = scale
|
|
36
|
+
|
|
37
|
+
if (this.#elapsed > this.#fadeStart) {
|
|
38
|
+
const fadeProgress = (this.#elapsed - this.#fadeStart) / (this.#lifetime - this.#fadeStart)
|
|
39
|
+
this.alpha = Math.max(1 - fadeProgress, 0)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (this.#elapsed >= this.#lifetime) {
|
|
43
|
+
this.remove()
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { GameObject, GameObjectOptions, RectangleNode } from '../../../src'
|
|
2
|
+
|
|
3
|
+
const HP_BAR_WIDTH = 26
|
|
4
|
+
|
|
5
|
+
export type HpBarOptions = {
|
|
6
|
+
maxHp: number
|
|
7
|
+
hp: number
|
|
8
|
+
} & GameObjectOptions
|
|
9
|
+
|
|
10
|
+
export class HpBar extends GameObject {
|
|
11
|
+
#bg = new RectangleNode({ width: HP_BAR_WIDTH, height: 4, fill: '#000000', alpha: 0.4 })
|
|
12
|
+
#fg = new RectangleNode({ width: HP_BAR_WIDTH, height: 4, fill: '#ff3b30' })
|
|
13
|
+
|
|
14
|
+
#maxHp: number
|
|
15
|
+
#hp: number
|
|
16
|
+
|
|
17
|
+
constructor(options: HpBarOptions) {
|
|
18
|
+
super(options)
|
|
19
|
+
this.#maxHp = options.maxHp
|
|
20
|
+
this.#hp = options.hp
|
|
21
|
+
this.add(this.#bg, this.#fg)
|
|
22
|
+
this.#updateFg()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
#updateFg() {
|
|
26
|
+
const ratio = Math.max(0, Math.min(1, this.#hp / this.#maxHp))
|
|
27
|
+
const newWidth = HP_BAR_WIDTH * ratio
|
|
28
|
+
this.#fg.width = newWidth
|
|
29
|
+
this.#fg.x = -(HP_BAR_WIDTH - newWidth) / 2
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
set hp(hp: number) {
|
|
33
|
+
this.#hp = hp
|
|
34
|
+
this.#updateFg()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get hp() { return this.#hp }
|
|
38
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { enableDebug, preload, Renderer } from '../../src'
|
|
2
|
+
import heroAtlas from './assets/spritesheets/hero-atlas.json'
|
|
3
|
+
import orcAtlas from './assets/spritesheets/orc-atlas.json'
|
|
4
|
+
import potionAtlas from './assets/spritesheets/potion-atlas.json'
|
|
5
|
+
import { Stage } from './stage'
|
|
6
|
+
|
|
7
|
+
if (process.env.NODE_ENV === 'development') {
|
|
8
|
+
enableDebug()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
await preload([
|
|
12
|
+
{ src: 'assets/spritesheets/hero.png', atlas: heroAtlas },
|
|
13
|
+
{ src: 'assets/spritesheets/orc.png', atlas: orcAtlas },
|
|
14
|
+
{ src: 'assets/spritesheets/potion.png', atlas: potionAtlas },
|
|
15
|
+
{ fnt: 'assets/bitmap-fonts/white-peaberry.fnt', src: 'assets/bitmap-fonts/white-peaberry.png' },
|
|
16
|
+
'assets/bgm/battle.mp3',
|
|
17
|
+
'assets/sfx/hero/hit/hit1.wav',
|
|
18
|
+
'assets/sfx/hero/hit/hit2.wav',
|
|
19
|
+
'assets/sfx/hero/hit/hit3.wav',
|
|
20
|
+
'assets/sfx/hero/miss/miss1.wav',
|
|
21
|
+
'assets/sfx/hero/miss/miss2.wav',
|
|
22
|
+
'assets/sfx/hero/miss/miss3.wav',
|
|
23
|
+
'assets/sfx/hero/heal/heal.wav',
|
|
24
|
+
'assets/sfx/hero/die/die.wav',
|
|
25
|
+
'assets/sfx/orc/hit/hit1.wav',
|
|
26
|
+
'assets/sfx/orc/hit/hit2.wav',
|
|
27
|
+
'assets/sfx/orc/hit/hit3.wav',
|
|
28
|
+
'assets/sfx/orc/miss/miss1.wav',
|
|
29
|
+
'assets/sfx/orc/miss/miss2.wav',
|
|
30
|
+
'assets/sfx/orc/miss/miss3.wav',
|
|
31
|
+
'assets/sfx/orc/die/die.wav',
|
|
32
|
+
])
|
|
33
|
+
|
|
34
|
+
const renderer = new Renderer(document.body, {
|
|
35
|
+
backgroundColor: '#304C79',
|
|
36
|
+
layers: [
|
|
37
|
+
{ name: 'hud', drawOrder: 1 }
|
|
38
|
+
],
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
renderer.add(new Stage())
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { EventMap } from '@webtaku/event-emitter'
|
|
2
|
+
import { AnimatedSpriteNode, debugMode, DelayNode, PhysicsObject, PhysicsObjectOptions, RectangleCollider, RectangleNode, RectangleRigidbody } from '../../../src'
|
|
3
|
+
import { DamageText } from '../hud/damage-text'
|
|
4
|
+
import { HealText } from '../hud/heal-text'
|
|
5
|
+
import { HpBar } from '../hud/hp-bar'
|
|
6
|
+
|
|
7
|
+
export type CharacterOptions = {
|
|
8
|
+
maxHp: number
|
|
9
|
+
hp: number
|
|
10
|
+
rigidbody: RectangleRigidbody
|
|
11
|
+
hitbox: RectangleCollider
|
|
12
|
+
hurtbox: RectangleCollider
|
|
13
|
+
} & PhysicsObjectOptions
|
|
14
|
+
|
|
15
|
+
export abstract class Character<E extends EventMap = EventMap> extends PhysicsObject<E & {
|
|
16
|
+
changeHp: (damage: number) => void
|
|
17
|
+
dead: () => void
|
|
18
|
+
}> {
|
|
19
|
+
maxHp: number
|
|
20
|
+
hp: number
|
|
21
|
+
dead = false
|
|
22
|
+
|
|
23
|
+
hitbox: RectangleCollider
|
|
24
|
+
hurtbox: RectangleCollider
|
|
25
|
+
|
|
26
|
+
#hpBar: HpBar
|
|
27
|
+
protected _sprite?: AnimatedSpriteNode
|
|
28
|
+
#hitboxDebugNode?: RectangleNode
|
|
29
|
+
#tintDelay?: DelayNode
|
|
30
|
+
|
|
31
|
+
constructor(options: CharacterOptions) {
|
|
32
|
+
super({ ...options, fixedRotation: true, useYSort: true })
|
|
33
|
+
this.maxHp = options.maxHp
|
|
34
|
+
this.hp = options.hp
|
|
35
|
+
this.hitbox = options.hitbox
|
|
36
|
+
this.hurtbox = options.hurtbox
|
|
37
|
+
|
|
38
|
+
this.#hpBar = new HpBar({ y: -30, maxHp: options.maxHp, hp: options.hp, layer: 'hud' })
|
|
39
|
+
this.add(this.#hpBar)
|
|
40
|
+
|
|
41
|
+
if (debugMode) {
|
|
42
|
+
this.add(new RectangleNode({ ...options.rigidbody, stroke: 'yellow', alpha: 0.5, layer: 'hud' }))
|
|
43
|
+
this.#hitboxDebugNode = new RectangleNode({ ...this.hitbox, stroke: 'red', alpha: 0.5, layer: 'hud' })
|
|
44
|
+
this.add(this.#hitboxDebugNode)
|
|
45
|
+
this.add(new RectangleNode({ ...this.hurtbox, stroke: 'green', alpha: 0.5, layer: 'hud' }))
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
set hitboxX(x: number) {
|
|
50
|
+
this.hitbox.x = x
|
|
51
|
+
if (this.#hitboxDebugNode) this.#hitboxDebugNode.x = x
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
takeDamage(damage: number) {
|
|
55
|
+
if (this.dead) return
|
|
56
|
+
|
|
57
|
+
this.hp -= damage
|
|
58
|
+
this.#hpBar.hp = this.hp
|
|
59
|
+
|
|
60
|
+
if (this._sprite) {
|
|
61
|
+
this._sprite.tint = 0xff0000
|
|
62
|
+
this.#tintDelay?.remove()
|
|
63
|
+
this.#tintDelay = new DelayNode(0.1, () => this._sprite!.tint = 0xffffff)
|
|
64
|
+
this.add(this.#tintDelay)
|
|
65
|
+
}
|
|
66
|
+
(this as any).emit('changeHp', damage)
|
|
67
|
+
|
|
68
|
+
this.add(new DamageText({ y: -20, damage, layer: 'hud' }))
|
|
69
|
+
|
|
70
|
+
if (this.hp <= 0) {
|
|
71
|
+
this.dead = true
|
|
72
|
+
this.onDie();
|
|
73
|
+
(this as any).emit('dead')
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
heal(amount: number) {
|
|
78
|
+
if (this.dead) return
|
|
79
|
+
|
|
80
|
+
this.hp = Math.min(this.maxHp, this.hp + amount)
|
|
81
|
+
this.#hpBar.hp = this.hp
|
|
82
|
+
|
|
83
|
+
if (this._sprite) {
|
|
84
|
+
this._sprite.tint = 0x00ff00
|
|
85
|
+
this.#tintDelay?.remove()
|
|
86
|
+
this.#tintDelay = new DelayNode(0.1, () => this._sprite!.tint = 0xffffff)
|
|
87
|
+
this.add(this.#tintDelay)
|
|
88
|
+
}
|
|
89
|
+
(this as any).emit('changeHp', amount)
|
|
90
|
+
|
|
91
|
+
this.add(new HealText({ y: -20, hp: amount, layer: 'hud' }))
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
protected abstract onDie(): void
|
|
95
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { AnimatedSpriteNode, ColliderType, DelayNode, GameObjectOptions, RigidbodyType, sfxPlayer } from '../../../src/index'
|
|
2
|
+
import heroAtlas from '../assets/spritesheets/hero-atlas.json'
|
|
3
|
+
import { Character } from './character'
|
|
4
|
+
|
|
5
|
+
const HERO_MOVE_SPEED = 200 as const
|
|
6
|
+
const HERO_HITBOX_X = 24 as const
|
|
7
|
+
const HERO_ATTACK_DAMAGE = 60 as const
|
|
8
|
+
|
|
9
|
+
export class Hero extends Character<{
|
|
10
|
+
hit: (damage: number) => void
|
|
11
|
+
dead: () => void
|
|
12
|
+
}> {
|
|
13
|
+
protected _sprite: AnimatedSpriteNode
|
|
14
|
+
|
|
15
|
+
#cachedVelX = 0
|
|
16
|
+
#cachedVelY = 0
|
|
17
|
+
#prevX = this.x
|
|
18
|
+
#attacking = false
|
|
19
|
+
|
|
20
|
+
constructor(options?: GameObjectOptions) {
|
|
21
|
+
super({
|
|
22
|
+
...options,
|
|
23
|
+
maxHp: 1000,
|
|
24
|
+
hp: 1000,
|
|
25
|
+
rigidbody: { type: RigidbodyType.Rectangle, width: 30, height: 30 },
|
|
26
|
+
hitbox: { type: ColliderType.Rectangle, width: 32, height: 52, x: HERO_HITBOX_X, y: -8 },
|
|
27
|
+
hurtbox: { type: ColliderType.Rectangle, width: 24, height: 40, x: 0, y: -4 },
|
|
28
|
+
isStatic: true
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
this._sprite = new AnimatedSpriteNode({
|
|
32
|
+
src: 'assets/spritesheets/hero.png',
|
|
33
|
+
atlas: heroAtlas,
|
|
34
|
+
animation: 'idle',
|
|
35
|
+
scale: 2
|
|
36
|
+
})
|
|
37
|
+
this._sprite.on('animationend', (animation) => {
|
|
38
|
+
if (animation.startsWith('attack')) {
|
|
39
|
+
this.#attacking = false
|
|
40
|
+
this._sprite.animation = 'idle'
|
|
41
|
+
} else if (animation === 'die') {
|
|
42
|
+
this.emit('dead')
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
this.add(this._sprite)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
moveTo(x: number, y: number) {
|
|
49
|
+
if (this.dead) return
|
|
50
|
+
|
|
51
|
+
const dx = x - this.x
|
|
52
|
+
const dy = y - this.y
|
|
53
|
+
const radian = Math.atan2(dy, dx)
|
|
54
|
+
this.#cachedVelX = Math.cos(radian) * HERO_MOVE_SPEED
|
|
55
|
+
this.#cachedVelY = Math.sin(radian) * HERO_MOVE_SPEED
|
|
56
|
+
|
|
57
|
+
const scale = Math.abs(this._sprite.scaleX)
|
|
58
|
+
this._sprite.scaleX = dx > 0 ? scale : -scale
|
|
59
|
+
this.hitboxX = dx > 0 ? HERO_HITBOX_X : -HERO_HITBOX_X
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
stop() {
|
|
63
|
+
this.#cachedVelX = 0
|
|
64
|
+
this.#cachedVelY = 0
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
attack() {
|
|
68
|
+
if (this.dead || this.#attacking) return
|
|
69
|
+
this.#attacking = true
|
|
70
|
+
|
|
71
|
+
this._sprite.animation = Math.floor(Math.random() * 2) ? 'attack1' : 'attack2'
|
|
72
|
+
|
|
73
|
+
this.add(new DelayNode(0.3, () => this.emit('hit', HERO_ATTACK_DAMAGE)))
|
|
74
|
+
|
|
75
|
+
sfxPlayer.playRandom(
|
|
76
|
+
'assets/sfx/hero/miss/miss1.wav',
|
|
77
|
+
'assets/sfx/hero/miss/miss2.wav',
|
|
78
|
+
'assets/sfx/hero/miss/miss3.wav',
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
protected override update(dt: number) {
|
|
83
|
+
if (this.paused) return
|
|
84
|
+
super.update(dt)
|
|
85
|
+
|
|
86
|
+
this.x += this.#cachedVelX * dt
|
|
87
|
+
this.y += this.#cachedVelY * dt
|
|
88
|
+
|
|
89
|
+
if (this._sprite && this.x !== this.#prevX) {
|
|
90
|
+
const scale = Math.abs(this._sprite.scaleX)
|
|
91
|
+
this._sprite.scaleX = this.x > this.#prevX ? scale : -scale
|
|
92
|
+
this.hitboxX = this.x > this.#prevX ? HERO_HITBOX_X : -HERO_HITBOX_X
|
|
93
|
+
}
|
|
94
|
+
this.#prevX = this.x
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
override takeDamage(damage: number) {
|
|
98
|
+
super.takeDamage(damage)
|
|
99
|
+
sfxPlayer.playRandom(
|
|
100
|
+
'assets/sfx/hero/hit/hit1.wav',
|
|
101
|
+
'assets/sfx/hero/hit/hit2.wav',
|
|
102
|
+
'assets/sfx/hero/hit/hit3.wav'
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
override heal(amount: number) {
|
|
107
|
+
super.heal(amount)
|
|
108
|
+
sfxPlayer.play('assets/sfx/hero/heal/heal.wav')
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
protected override onDie() {
|
|
112
|
+
this._sprite.animation = 'die'
|
|
113
|
+
this.#cachedVelX = 0
|
|
114
|
+
this.#cachedVelY = 0
|
|
115
|
+
this.disableCollisions()
|
|
116
|
+
|
|
117
|
+
sfxPlayer.play('assets/sfx/hero/die/die.wav')
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { AnimatedSpriteNode, ColliderType, DelayNode, GameObjectOptions, RigidbodyType, sfxPlayer } from '../../../src/index'
|
|
2
|
+
import orcAtlas from '../assets/spritesheets/orc-atlas.json'
|
|
3
|
+
import { Character } from './character'
|
|
4
|
+
|
|
5
|
+
const ORC_MOVE_VELOCITY = 3 as const
|
|
6
|
+
const ORC_HITBOX_X = 24 as const
|
|
7
|
+
const ORC_ATTACK_DAMAGE = 15 as const
|
|
8
|
+
|
|
9
|
+
export class Orc extends Character<{
|
|
10
|
+
hit: (damage: number) => void
|
|
11
|
+
dead: () => void
|
|
12
|
+
}> {
|
|
13
|
+
protected _sprite: AnimatedSpriteNode
|
|
14
|
+
|
|
15
|
+
#cachedVelX = 0
|
|
16
|
+
#cachedVelY = 0
|
|
17
|
+
#attacking = false
|
|
18
|
+
|
|
19
|
+
constructor(options?: GameObjectOptions) {
|
|
20
|
+
super({
|
|
21
|
+
...options,
|
|
22
|
+
maxHp: 100,
|
|
23
|
+
hp: 100,
|
|
24
|
+
rigidbody: { type: RigidbodyType.Rectangle, width: 30, height: 30 },
|
|
25
|
+
hitbox: { type: ColliderType.Rectangle, width: 32, height: 52, x: ORC_HITBOX_X, y: -8 },
|
|
26
|
+
hurtbox: { type: ColliderType.Rectangle, width: 24, height: 32, x: 0, y: 0 },
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
this._sprite = new AnimatedSpriteNode({
|
|
30
|
+
src: 'assets/spritesheets/orc.png',
|
|
31
|
+
atlas: orcAtlas,
|
|
32
|
+
animation: 'idle',
|
|
33
|
+
scale: 2
|
|
34
|
+
})
|
|
35
|
+
this._sprite.on('animationend', (animation) => {
|
|
36
|
+
if (animation.startsWith('attack')) {
|
|
37
|
+
this.#attacking = false
|
|
38
|
+
this._sprite.animation = 'idle'
|
|
39
|
+
} else if (animation === 'die') {
|
|
40
|
+
this.emit('dead')
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
this.add(this._sprite)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
moveTo(x: number, y: number) {
|
|
47
|
+
if (this.dead) return
|
|
48
|
+
|
|
49
|
+
const dx = x - this.x
|
|
50
|
+
const dy = y - this.y
|
|
51
|
+
const radian = Math.atan2(dy, dx)
|
|
52
|
+
this.#cachedVelX = Math.cos(radian) * ORC_MOVE_VELOCITY
|
|
53
|
+
this.#cachedVelY = Math.sin(radian) * ORC_MOVE_VELOCITY
|
|
54
|
+
|
|
55
|
+
const scale = Math.abs(this._sprite.scaleX)
|
|
56
|
+
this._sprite.scaleX = dx > 0 ? scale : -scale
|
|
57
|
+
this.hitboxX = dx > 0 ? ORC_HITBOX_X : -ORC_HITBOX_X
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
stop() {
|
|
61
|
+
this.#cachedVelX = 0
|
|
62
|
+
this.#cachedVelY = 0
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
attack() {
|
|
66
|
+
if (this.dead || this.#attacking) return
|
|
67
|
+
this.#attacking = true
|
|
68
|
+
|
|
69
|
+
this.#cachedVelX = 0
|
|
70
|
+
this.#cachedVelY = 0
|
|
71
|
+
|
|
72
|
+
this._sprite.animation = Math.floor(Math.random() * 2) ? 'attack1' : 'attack2'
|
|
73
|
+
|
|
74
|
+
this.add(new DelayNode(0.3, () => this.emit('hit', ORC_ATTACK_DAMAGE)))
|
|
75
|
+
|
|
76
|
+
sfxPlayer.playRandom(
|
|
77
|
+
'assets/sfx/orc/miss/miss1.wav',
|
|
78
|
+
'assets/sfx/orc/miss/miss2.wav',
|
|
79
|
+
'assets/sfx/orc/miss/miss3.wav'
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
protected override update(dt: number) {
|
|
84
|
+
if (this.paused) return
|
|
85
|
+
super.update(dt)
|
|
86
|
+
this.velocityX = this.#cachedVelX
|
|
87
|
+
this.velocityY = this.#cachedVelY
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
override takeDamage(damage: number) {
|
|
91
|
+
super.takeDamage(damage)
|
|
92
|
+
sfxPlayer.playRandom(
|
|
93
|
+
'assets/sfx/orc/hit/hit1.wav',
|
|
94
|
+
'assets/sfx/orc/hit/hit2.wav',
|
|
95
|
+
'assets/sfx/orc/hit/hit3.wav'
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
protected override onDie() {
|
|
100
|
+
this._sprite.animation = 'die'
|
|
101
|
+
this.#cachedVelX = 0
|
|
102
|
+
this.#cachedVelY = 0
|
|
103
|
+
this.disableCollisions()
|
|
104
|
+
|
|
105
|
+
sfxPlayer.play('assets/sfx/orc/die/die.wav')
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AnimatedSpriteNode, CircleCollider, CircleNode, ColliderType, debugMode, GameObject, GameObjectOptions } from '../../../src'
|
|
2
|
+
import potionAtlas from '../assets/spritesheets/potion-atlas.json'
|
|
3
|
+
|
|
4
|
+
export type PotionOptions = {
|
|
5
|
+
healAmount?: number
|
|
6
|
+
} & GameObjectOptions
|
|
7
|
+
|
|
8
|
+
export class Potion extends GameObject {
|
|
9
|
+
triggerCollider: CircleCollider = { type: ColliderType.Circle, radius: 16 }
|
|
10
|
+
healAmount: number
|
|
11
|
+
|
|
12
|
+
constructor(options?: PotionOptions) {
|
|
13
|
+
super({ ...options, useYSort: true })
|
|
14
|
+
this.healAmount = options?.healAmount ?? 100
|
|
15
|
+
|
|
16
|
+
this.add(new AnimatedSpriteNode({
|
|
17
|
+
src: 'assets/spritesheets/potion.png',
|
|
18
|
+
atlas: potionAtlas,
|
|
19
|
+
animation: 'animation',
|
|
20
|
+
scale: 2
|
|
21
|
+
}))
|
|
22
|
+
|
|
23
|
+
if (debugMode) {
|
|
24
|
+
this.add(new CircleNode({ ...this.triggerCollider, stroke: 'green', alpha: 0.5, layer: 'hud' }))
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|