From 0448a77f5c36dfc3e019caa6cc7c85532a9fd654 Mon Sep 17 00:00:00 2001 From: Johan Bouveng Date: Fri, 19 Jun 2020 00:03:22 +0200 Subject: [PATCH 1/6] Add cheep-cheep sprite sheets. --- public/sprites/cheep-gray.json | 25 +++++++++++++++++++++++++ public/sprites/cheep-red.json | 25 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 public/sprites/cheep-gray.json create mode 100644 public/sprites/cheep-red.json diff --git a/public/sprites/cheep-gray.json b/public/sprites/cheep-gray.json new file mode 100644 index 00000000..f0c3e10c --- /dev/null +++ b/public/sprites/cheep-gray.json @@ -0,0 +1,25 @@ +{ + "imageURL": "/img/sprites.png", + + "frames": [ + { + "name": "swim-1", + "rect": [48, 32, 16, 16] + }, + { + "name": "swim-2", + "rect": [64, 32, 16, 16] + } + ], + + "animations": [ + { + "name": "swim", + "frameLen": 0.13, + "frames": [ + "swim-1", + "swim-2" + ] + } + ] +} diff --git a/public/sprites/cheep-red.json b/public/sprites/cheep-red.json new file mode 100644 index 00000000..65087860 --- /dev/null +++ b/public/sprites/cheep-red.json @@ -0,0 +1,25 @@ +{ + "imageURL": "/img/sprites.png", + + "frames": [ + { + "name": "swim-1", + "rect": [48, 0, 16, 16] + }, + { + "name": "swim-2", + "rect": [64, 0, 16, 16] + } + ], + + "animations": [ + { + "name": "swim", + "frameLen": 0.13, + "frames": [ + "swim-1", + "swim-2" + ] + } + ] +} From 4860a1586f05ff53f3b6d2eab414d94bfd05fe22 Mon Sep 17 00:00:00 2001 From: Johan Bouveng Date: Fri, 19 Jun 2020 00:39:14 +0200 Subject: [PATCH 2/6] Add cheep-cheep entity. --- public/js/entities/CheepCheep.js | 155 +++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 public/js/entities/CheepCheep.js diff --git a/public/js/entities/CheepCheep.js b/public/js/entities/CheepCheep.js new file mode 100644 index 00000000..5b22d1c0 --- /dev/null +++ b/public/js/entities/CheepCheep.js @@ -0,0 +1,155 @@ +import Entity from '../Entity.js'; +import Trait from '../Trait.js'; +import Killable from '../traits/Killable.js'; +import {loadSpriteSheet} from '../loaders/sprite.js'; + +export function loadCheepSlow() { + return loadSpriteSheet('cheep-gray') + .then(createCheepSlowFactory); +} + +export function loadCheepSlowWavy() { + return loadSpriteSheet('cheep-gray') + .then(createCheepSlowWavyFactory); +} + +export function loadCheepFast() { + return loadSpriteSheet('cheep-red') + .then(createCheepFastFactory); +} + +export function loadCheepFastWavy() { + return loadSpriteSheet('cheep-red') + .then(createCheepFastWavyFactory); +} + +class Behavior extends Trait { + + collides(us, them) { + if(them.traits.has(Killable)) { + them.traits.get(Killable).kill(); + } + } + + update(entity, gameContext, level) { + const {deltaTime} = gameContext; + entity.pos.x += entity.vel.x * deltaTime; + } + +} + +class Wavy extends Trait { + constructor() { + super(); + this.amplitude = 16; + this.direction = 1; + this.offset = 0; + this.speed = 0.5; + } + + update(entity, gameContext, level) { + const {deltaTime} = gameContext; + const movementY = (entity.vel.x * deltaTime * this.direction) * this.speed; + entity.pos.y += movementY; + + this.offset += movementY; + if (Math.abs(this.offset) > this.amplitude) { + this.direction = -this.direction; + } + } +} + +function createCheepSlowFactory(sprite) { + const swimAnim = sprite.animations.get('swim'); + + function routeAnim(entity) { + return swimAnim(entity.lifetime); + } + + function drawCheepSlow(context) { + sprite.draw(routeAnim(this), context, 0, 0, true); + } + + return function createCheepSlow() { + const entity = new Entity(); + entity.size.set(16, 16); + entity.vel.x = -16; + entity.addTrait(new Behavior()); + entity.draw = drawCheepSlow; + + return entity; + }; +} + +function createCheepSlowWavyFactory(sprite) { + const swimAnim = sprite.animations.get('swim'); + + function routeAnim(entity) { + return swimAnim(entity.lifetime); + } + + function drawCheepSlowWavy(context) { + sprite.draw(routeAnim(this), context, 0, 0, true); + } + + return function createCheepSlowWavy() { + const entity = new Entity(); + entity.size.set(16, 16); + entity.vel.x = -16; + + entity.addTrait(new Behavior()); + entity.addTrait(new Wavy()); + + entity.draw = drawCheepSlowWavy; + + return entity; + }; +} + +function createCheepFastFactory(sprite) { + const swimAnim = sprite.animations.get('swim'); + + function routeAnim(entity) { + return swimAnim(entity.lifetime); + } + + function drawCheepFast(context) { + sprite.draw(routeAnim(this), context, 0, 0, true); + } + + return function createCheepFast() { + const entity = new Entity(); + entity.size.set(16, 16); + entity.vel.x = -32; + entity.addTrait(new Behavior()); + entity.draw = drawCheepFast; + + return entity; + }; +} + +function createCheepFastWavyFactory(sprite) { + const swimAnim = sprite.animations.get('swim'); + + function routeAnim(entity) { + return swimAnim(entity.lifetime); + } + + function drawCheepFastWavy(context) { + sprite.draw(routeAnim(this), context, 0, 0, true); + } + + return function createCheepFastWavy() { + const entity = new Entity(); + entity.size.set(16, 16); + entity.vel.x = -32; + + entity.addTrait(new Behavior()); + entity.addTrait(new Wavy()); + entity.traits.get(Wavy).speed = 0.25; + + entity.draw = drawCheepFastWavy; + + return entity; + }; +} From 7c9e5d5aa87095ddf2c8eb3c5efde460bb134e04 Mon Sep 17 00:00:00 2001 From: Johan Bouveng Date: Fri, 19 Jun 2020 00:41:48 +0200 Subject: [PATCH 3/6] Load cheep slow, fast, slow-wavy and fast-wavy. --- public/js/entities.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/public/js/entities.js b/public/js/entities.js index 42a3a27d..5e5403f6 100644 --- a/public/js/entities.js +++ b/public/js/entities.js @@ -1,6 +1,7 @@ import {loadMario} from './entities/Mario.js'; import {loadGoombaBrown, loadGoombaBlue} from './entities/Goomba.js'; import {loadKoopaGreen, loadKoopaBlue} from './entities/Koopa.js'; +import {loadCheepSlow, loadCheepFast, loadCheepSlowWavy, loadCheepFastWavy} from './entities/CheepCheep.js'; import {loadPiranhaPlant} from './entities/PiranhaPlant.js'; import {loadBullet} from './entities/Bullet.js'; import {loadCannon} from './entities/Cannon.js'; @@ -51,6 +52,14 @@ export async function loadEntities(audioContext) { .then(addAs('koopa-green')), setup(loadKoopaBlue) .then(addAs('koopa-blue')), + setup(loadCheepSlow) + .then(addAs('cheep-slow')), + setup(loadCheepFast) + .then(addAs('cheep-fast')), + setup(loadCheepSlowWavy) + .then(addAs('cheep-slow-wavy')), + setup(loadCheepFastWavy) + .then(addAs('cheep-fast-wavy')), setup(loadBullet) .then(addAs('bullet')), setup(loadCannon) From 85f56ff2782f8595da585ecdb5e69a3578523142 Mon Sep 17 00:00:00 2001 From: Johan Bouveng Date: Fri, 19 Jun 2020 01:33:04 +0200 Subject: [PATCH 4/6] Add cheep-cheep to level. --- public/levels/2-2.json | 77 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/public/levels/2-2.json b/public/levels/2-2.json index 591ebc96..20afdeea 100644 --- a/public/levels/2-2.json +++ b/public/levels/2-2.json @@ -115,7 +115,80 @@ ] } ], - - "entities": [], + + "entities": [ + { + "name": "cheep-slow", + "pos": [1184, 112] + }, + { + "name": "cheep-slow", + "pos": [1376, 160] + }, + { + "name": "cheep-slow", + "pos": [1664, 160] + }, + { + "name": "cheep-fast", + "pos": [1184, 144] + }, + { + "name": "cheep-fast", + "pos": [1616, 64] + }, + { + "name": "cheep-slow-wavy", + "pos": [1248, 112] + }, + { + "name": "cheep-slow-wavy", + "pos": [1552, 96] + }, + { + "name": "cheep-slow-wavy", + "pos": [1872, 80] + }, + { + "name": "cheep-fast-wavy", + "pos": [2048, 160] + }, + { + "name": "cheep-slow-wavy", + "pos": [2098, 176] + }, + { + "name": "cheep-slow", + "pos": [2192, 128] + }, + { + "name": "cheep-slow-wavy", + "pos": [2320, 144] + }, + { + "name": "cheep-fast", + "pos": [2400, 80] + }, + { + "name": "cheep-slow", + "pos": [2624, 48] + }, + { + "name": "cheep-fast", + "pos": [2672, 160] + }, + { + "name": "cheep-slow-wavy", + "pos": [2800, 128] + }, + { + "name": "cheep-fast", + "pos": [2928, 64] + }, + { + "name": "cheep-fast-wavy", + "pos": [2976, 128] + } + ], "triggers": [] } From 7579a0bbaa0b362d5fb2d1c88d712106f8ac7791 Mon Sep 17 00:00:00 2001 From: Johan Bouveng Date: Fri, 19 Jun 2020 01:33:31 +0200 Subject: [PATCH 5/6] Fix coin range position. --- public/levels/2-2.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/levels/2-2.json b/public/levels/2-2.json index 20afdeea..95fb2180 100644 --- a/public/levels/2-2.json +++ b/public/levels/2-2.json @@ -98,7 +98,7 @@ [36, 3, 12], [67, 3, 10], [101, 3, 11], - [113, 3, 4], + [113, 3, 6], [134, 3, 12], [133, 11], [137, 11], From 0cfc5c9da54b3b69fc2fd71bc33d4fd14dd178fb Mon Sep 17 00:00:00 2001 From: Johan Bouveng Date: Fri, 19 Jun 2020 01:34:20 +0200 Subject: [PATCH 6/6] Add empty tile layer. --- public/levels/2-2.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/public/levels/2-2.json b/public/levels/2-2.json index 95fb2180..5706b7da 100644 --- a/public/levels/2-2.json +++ b/public/levels/2-2.json @@ -113,6 +113,9 @@ ] } ] + }, + { + "tiles": [] } ],