Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Waitscreen while loading #36

Open
wants to merge 109 commits into
base: refactor-traits
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
988e17f
Sync with published result of episode 24.
pomle May 5, 2020
d1fe6a3
Fixed positioning of text in dashboard.
bouveng May 29, 2020
f7eafac
Made coin use new traits getter.
bouveng May 29, 2020
04b7941
Spawn entities when they enter the screen.
bouveng May 29, 2020
7391a90
Correct jump height for Mario.
bouveng May 29, 2020
efe4cb2
Fixed total time and speed for time counter.
bouveng May 29, 2020
165e7ce
Fixed positioning of x and mario in progresslayer.
bouveng May 29, 2020
c843762
New tiles.png. Updated spritesheet and patterns.
bouveng May 29, 2020
1d26f66
Tile definition "empty" renamed to "metal".
bouveng May 30, 2020
8b3ac36
Added new sprites.png. Updated spritesheets.
bouveng May 29, 2020
935ffe1
Changed flip for bullet to work with new sprite.
bouveng May 30, 2020
97bf0d8
Added new music and sound effects.
bouveng May 29, 2020
349755a
Goomba blue, brown. Koopa green, blue.
bouveng May 29, 2020
b686710
Add Levels, Patterns, and Music sheets
bouveng Jun 1, 2020
67a80b4
Added font for points.
bouveng May 29, 2020
51c1b10
Remove unused contructor
pomle May 13, 2020
5b499a6
Refactor entity loader
pomle May 13, 2020
6028719
Use async/await for loadEntities
pomle May 13, 2020
e4ba578
Simplify setup function in loadEntities
pomle May 13, 2020
33b7415
Add SpriteSheet for Brick Shrapnel
pomle Jun 6, 2020
eb52a39
Reintroduce entity loader promise chain
pomle Jun 6, 2020
603a65b
Add initial BrickShrapnel entity
pomle Jun 6, 2020
832a6f7
Load BrickShrapnel
pomle Jun 6, 2020
235fa5d
Update brick tile to emit shrapnel
pomle Jun 6, 2020
f94bc91
Show Bricks staying in the level indefinitely
pomle Jun 6, 2020
c2161b3
Add LifeLimit trait
pomle Jun 6, 2020
2b7dca1
Add LifeLimit trait to BrickShrapnel
pomle Jun 6, 2020
3121879
Add BrickShrapnel SoundBoard
pomle Jun 6, 2020
f2afcbc
Add Brick Destroy sound to Brick tile
pomle Jun 6, 2020
f72bfea
Remove position logging
pomle Jun 6, 2020
014a525
Add entity pooling and set size to 2
pomle Jun 6, 2020
1d7c36a
Increase brick pool to 2
pomle Jun 6, 2020
9915955
Set brick pool to 8
pomle Jun 7, 2020
6429f95
Add Keymap to input setup
pomle Jun 7, 2020
59752d6
Only call draw if exists
pomle Jun 7, 2020
f764c3e
Remove PlayerEnv/Controller
pomle Jun 7, 2020
fcc2d22
Never remove Mario when killed
pomle Jun 7, 2020
ecb1817
Added new font. Added compability for text output.
bouveng May 29, 2020
2b50366
Force uppercase in font class. Using × instead of x.
bouveng Jun 6, 2020
d1502d0
No function parameter overwrite
pomle Jun 7, 2020
0bc269e
Use pattern chocolate-stack-4h.
bouveng Jun 7, 2020
2bb1f21
Remove space from x in player-progress.
bouveng Jun 7, 2020
d0cd2fa
Added missing small coin icon for underworld.
bouveng Jun 7, 2020
f03661a
Clamp camera scroll to level bounds
pomle Jun 7, 2020
a66d156
Changed playerPosition to checkpoints.
bouveng Jun 7, 2020
db1400d
Checkpoints is array of arrays.
bouveng Jun 7, 2020
9491ee5
Handle checkpoints
pomle Jun 7, 2020
c3343f9
Correct position for "WORLD" and level name.
bouveng Jun 8, 2020
b5dc588
Remove unused imports
pomle Jun 7, 2020
e1a9c24
Throw error when entity not found
pomle Jun 7, 2020
23c0fa0
Remove duplicate EventBuffer from constructor
pomle Jun 7, 2020
d4081a1
Avoid repeating traits.get(Go) in Mario anim
pomle Jun 7, 2020
84f19b8
Move LevelTimer to Player
pomle Jun 7, 2020
e6edb5c
Keep track if LevelTimer was used on level
pomle Jun 8, 2020
2aede1c
Add equals method to Vec2
pomle Jun 7, 2020
37d6193
Add direction enum
pomle Jun 7, 2020
eed889e
Add tick to GameContext
pomle Jun 8, 2020
fd40eac
Add missing princess.ogg.
bouveng Jun 8, 2020
543f570
Add PipePortal SoundBoard
pomle Jun 7, 2020
d4f20c4
Add Pipe and PipeTraveller trait
pomle Jun 7, 2020
d7801b6
Add PipeTraveller trait to Mario
pomle Jun 7, 2020
66d8858
Route input to PipeTraveller trait
pomle Jun 7, 2020
53ce5e9
Add PipePortal entity
pomle Jun 7, 2020
d92d990
Add PipePortal entity to Pipe debug level
pomle Jun 7, 2020
dc5981b
Keep track of travellers in pipe
pomle Jun 7, 2020
f5d3efa
Add Travelling animation to Pipe
pomle Jun 7, 2020
65346db
Use direction from props
pomle Jun 7, 2020
1cfccd3
Add Event to Pipe
pomle Jun 7, 2020
af4d79a
Add Event complete to Level
pomle Jun 7, 2020
e6d3a3a
Copy props to Entity for pipe
pomle Jun 7, 2020
4d95d2c
Connect coin-room-1 pipe
pomle Jun 7, 2020
6b31f3c
Handle Mario animation with Pipe
pomle Jun 7, 2020
8f3dd97
Player world
pomle Jun 7, 2020
e9afd38
Paint sprites one layer below last layer
pomle Jun 7, 2020
f5af371
Add test pipes
pomle Jun 7, 2020
eeb2198
Provide default checkpoint
pomle Jun 8, 2020
4cfe51f
Provide auto enter pipe setting
pomle Jun 8, 2020
028acff
Provide explicit enter pipe method
pomle Jun 8, 2020
0c2170f
Replace auto enter with linking explicitly to pipe
pomle Jun 10, 2020
776d44a
Support getting and setting center of BoundingBox
pomle Jun 10, 2020
dc6838a
Add Align-utility
pomle Jun 10, 2020
a29660d
Increase PipePortal height
pomle Jun 10, 2020
232ebae
Add connectEntity utility to Pipe trait
pomle Jun 10, 2020
6fa1dfc
Only allow entering pipe from within bounds
pomle Jun 10, 2020
c8fd124
Route Mario anim properly so as to not jump while travelling
pomle Jun 10, 2020
5c72f45
Tweak debug level
pomle Jun 10, 2020
f19abcb
Add fixed aspect ratios for screen.
bouveng Jun 12, 2020
ab9f28c
Move css from index to main.css
bouveng Jun 12, 2020
48b3f56
Only play pipe.ogg when entering pipes.
bouveng Jun 12, 2020
e2e1179
Include last tile's width when calculating camera pan max
pomle Jun 16, 2020
09d42bd
Rename tile "type" to "behavior".
bouveng Jun 13, 2020
27fafb0
Rename tile "name" to "style".
bouveng Jun 16, 2020
f7181d9
Add distance method to Vec2
pomle Jun 14, 2020
ef4b212
Add Piranha Plant sprite sheet
pomle Jun 14, 2020
9ae6a6c
Add Piranha Plant logic
pomle Jun 14, 2020
975560a
Load Piranha Plant
pomle Jun 14, 2020
be93d03
Add Piranha Plant to level
pomle Jun 14, 2020
d7e2e9e
Add FlagPole SoundBoard
pomle Jun 10, 2020
6585199
Add FlagPole entity
pomle Jun 10, 2020
daf9ca5
Load flag pole
pomle Jun 10, 2020
83f916e
Add flag debug level
pomle Jun 10, 2020
5dd31aa
Add meridian and equator to BoundingBox
pomle Jun 10, 2020
c15e7af
Add Pole and PoleTraveller traits
pomle Jun 10, 2020
0ff8d60
Add Pole trait to Pole entity
pomle Jun 10, 2020
18a326d
Add PoleTraveller to Mario
pomle Jun 10, 2020
74f88db
Handle heading for pole
pomle Jun 10, 2020
c01a737
Show climb frame when pole sliding
pomle Jun 10, 2020
de072ca
Animate climb when on flag pole
pomle Jun 16, 2020
6b9af05
Fix typo in underwater-pattern.
bouveng Jun 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed public/audio/coin.ogg
Binary file not shown.
Binary file added public/audio/fx/1up.ogg
Binary file not shown.
Binary file added public/audio/fx/bowser-die.ogg
Binary file not shown.
Binary file added public/audio/fx/bowser-fire.ogg
Binary file not shown.
Binary file added public/audio/fx/brick-bump.ogg
Binary file not shown.
Binary file added public/audio/fx/brick-destroy.ogg
Binary file not shown.
Binary file added public/audio/fx/coin.ogg
Binary file not shown.
Binary file added public/audio/fx/fireball.ogg
Binary file not shown.
Binary file added public/audio/fx/fireworks.ogg
Binary file not shown.
Binary file added public/audio/fx/flagpole.ogg
Binary file not shown.
Binary file added public/audio/fx/jump-large.ogg
Binary file not shown.
Binary file added public/audio/fx/jump.ogg
Binary file not shown.
Binary file added public/audio/fx/kick.ogg
Binary file not shown.
Binary file added public/audio/fx/pause.ogg
Binary file not shown.
Binary file added public/audio/fx/pipe.ogg
Binary file not shown.
Binary file added public/audio/fx/power-up-appears.ogg
Binary file not shown.
Binary file added public/audio/fx/power-up-consume.ogg
Binary file not shown.
Binary file added public/audio/fx/stomp.ogg
Binary file not shown.
Binary file added public/audio/fx/thwomp.ogg
Binary file not shown.
Binary file added public/audio/fx/vine.ogg
Binary file not shown.
Binary file removed public/audio/jump.ogg
Binary file not shown.
Binary file added public/audio/music/castle-clear.ogg
Binary file not shown.
Binary file added public/audio/music/castle.ogg
Binary file not shown.
Binary file added public/audio/music/die.ogg
Binary file not shown.
Binary file added public/audio/music/game-over.ogg
Binary file not shown.
Binary file modified public/audio/music/hurry.ogg
Binary file not shown.
Binary file added public/audio/music/level-clear.ogg
Binary file not shown.
Binary file modified public/audio/music/overworld.ogg
Binary file not shown.
Binary file added public/audio/music/princess.ogg
Binary file not shown.
Binary file added public/audio/music/starman.ogg
Binary file not shown.
Binary file added public/audio/music/underwater.ogg
Binary file not shown.
Binary file modified public/audio/music/underworld.ogg
Binary file not shown.
Binary file added public/audio/music/uw-entrance.ogg
Binary file not shown.
Binary file removed public/audio/stomp.ogg
Binary file not shown.
Binary file removed public/audio/thwomp.ogg
Binary file not shown.
22 changes: 22 additions & 0 deletions public/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
body {
background: #000;
margin: 0;
}

#screen {
display: block;
image-rendering: pixelated;
margin: auto;
width: 100vw;
max-height: 100vh;
}

.aspect-4-3 {
height: 75vw;
max-width: 133.3vh;
}

.aspect-16-9 {
height: 56.25vw;
max-width: 177.7vh;
}
Binary file removed public/img/characters.gif
Binary file not shown.
Binary file modified public/img/font.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/points.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/sprites.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/img/tiles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 2 additions & 14 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,10 @@
<html>
<head>
<title>Super Mario</title>
<style>
body {
background: #000;
margin: 0;
}

#screen {
display: block;
image-rendering: pixelated;
height: 100vh;
margin: auto;
}
</style>
<link rel="stylesheet" href="/css/main.css"/>
<script type="module" src="/js/main.js"></script>
</head>
<body>
<canvas id="screen" width="256" height="240"></canvas>
<canvas id="screen" width="256" height="240" class="aspect-4-3"></canvas>
</body>
</html>
27 changes: 27 additions & 0 deletions public/js/BoundingBox.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Vec2 } from "./math.js";

export default class BoundingBox {
constructor(pos, size, offset) {
this.pos = pos;
Expand All @@ -12,6 +14,31 @@ export default class BoundingBox {
&& this.right > box.left;
}

getCenter() {
return new Vec2(this.meridian, this.equator);
}

setCenter(vec2) {
this.meridian = vec2.x;
this.equator = vec2.y;
}

get meridian() {
return this.pos.x + this.offset.x + this.size.x / 2;
}

set meridian(c) {
this.pos.x = c - (this.size.x / 2 + this.offset.x);
}

get equator() {
return this.pos.y + this.offset.y + this.size.y / 2;
}

set equator(c) {
this.pos.y = c - (this.size.y / 2 + this.offset.y);
}

get bottom() {
return this.pos.y + this.size.y + this.offset.y;
}
Expand Down
3 changes: 3 additions & 0 deletions public/js/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ export default class Camera {
constructor() {
this.pos = new Vec2(0, 0);
this.size = new Vec2(256, 224);

this.min = new Vec2(0, 0);
this.max = new Vec2(Infinity, Infinity);
}
}
31 changes: 24 additions & 7 deletions public/js/Entity.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
import {Vec2} from './math.js';
import Trait from './Trait.js';
import AudioBoard from './AudioBoard.js';
import BoundingBox from './BoundingBox.js';
import EventBuffer from './EventBuffer.js';
import Trait from './Trait.js';

export const Align = {
center(target, subject) {
subject.bounds.setCenter(target.bounds.getCenter());
},

bottom(target, subject) {
subject.bounds.bottom = target.bounds.bottom;
},

top(target, subject) {
subject.bounds.top = target.bounds.top;
},

left(target, subject) {
subject.bounds.left = target.bounds.left;
},

right(target, subject) {
subject.bounds.right = target.bounds.right;
},
};

export const Sides = {
TOP: Symbol('top'),
Expand All @@ -13,12 +35,11 @@ export const Sides = {

export default class Entity {
constructor() {
this.id = null;
this.audio = new AudioBoard();
this.events = new EventBuffer();
this.sounds = new Set();

this.events = new EventBuffer();

this.pos = new Vec2(0, 0);
this.vel = new Vec2(0, 0);
this.size = new Vec2(0, 0);
Expand All @@ -45,10 +66,6 @@ export default class Entity {
});
}

draw() {

}

finalize() {
this.events.emit(Trait.EVENT_TASK, this);

Expand Down
23 changes: 19 additions & 4 deletions public/js/Level.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,49 @@
import Camera from './Camera.js';
import Compositor from './Compositor.js';
import EventEmitter from './EventEmitter.js';
import MusicController from './MusicController.js';
import EntityCollider from './EntityCollider.js';
import Scene from './Scene.js';
import TileCollider from './TileCollider.js';
import { clamp } from './math.js';
import { findPlayers } from './player.js';

function focusPlayer(level) {
for (const player of findPlayers(level.entities)) {
level.camera.pos.x = Math.max(0, player.pos.x - 100);
level.camera.pos.x = clamp(
player.pos.x - 100,
level.camera.min.x,
level.camera.max.x - level.camera.size.x);
}
}

class EntityCollection extends Set {
get(id) {
for (const entity of this) {
if (entity.id === id) {
return entity;
}
}
}
}

export default class Level extends Scene {
static EVENT_TRIGGER = Symbol('trigger');
static EVENT_COMPLETE = Symbol('complete');

constructor() {
super();

this.name = "";

this.checkpoints = [];

this.gravity = 1500;
this.totalTime = 0;

this.camera = new Camera();

this.music = new MusicController();

this.entities = new Set();
this.entities = new EntityCollection();

this.entityCollider = new EntityCollider(this.entities);
this.tileCollider = new TileCollider();
Expand Down
2 changes: 1 addition & 1 deletion public/js/TileCollider.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default class TileCollider {
level,
};

const handler = handlers[match.tile.type];
const handler = handlers[match.tile.behavior];
if (handler) {
handler[index](tileCollisionContext);
}
Expand Down
69 changes: 57 additions & 12 deletions public/js/entities.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,68 @@
import {loadMario} from './entities/Mario.js';
import {loadGoomba} from './entities/Goomba.js';
import {loadKoopa} from './entities/Koopa.js';
import {loadGoombaBrown, loadGoombaBlue} from './entities/Goomba.js';
import {loadKoopaGreen, loadKoopaBlue} from './entities/Koopa.js';
import {loadPiranhaPlant} from './entities/PiranhaPlant.js';
import {loadBullet} from './entities/Bullet.js';
import {loadCannon} from './entities/Cannon.js';
import {loadBrickShrapnel} from './entities/BrickShrapnel.js';
import {loadPipePortal} from './entities/PipePortal.js';
import {loadFlagPole} from './entities/FlagPole.js';

export function loadEntities(audioContext) {
function createPool(size) {
const pool = [];

return function createPooledFactory(factory) {
for (let i = 0; i < size; i++) {
pool.push(factory());
}

let count = 0;
return function pooledFactory() {
const entity = pool[count++ % pool.length];
entity.lifetime = 0;
return entity;
}
}
}

export async function loadEntities(audioContext) {
const entityFactories = {};

function setup(loader) {
return loader(audioContext);
}

function addAs(name) {
return factory => entityFactories[name] = factory;
return function addFactory(factory) {
entityFactories[name] = factory;
}
}

return Promise.all([
loadMario(audioContext).then(addAs('mario')),
loadGoomba(audioContext).then(addAs('goomba')),
loadKoopa(audioContext).then(addAs('koopa')),
loadBullet(audioContext).then(addAs('bullet')),
loadCannon(audioContext).then(addAs('cannon')),
await Promise.all([
setup(loadMario)
.then(addAs('mario')),
setup(loadPiranhaPlant)
.then(addAs('piranha-plant')),
setup(loadGoombaBrown)
.then(addAs('goomba-brown')),
setup(loadGoombaBlue)
.then(addAs('goomba-blue')),
setup(loadKoopaGreen)
.then(addAs('koopa-green')),
setup(loadKoopaBlue)
.then(addAs('koopa-blue')),
setup(loadBullet)
.then(addAs('bullet')),
setup(loadCannon)
.then(addAs('cannon')),
setup(loadPipePortal)
.then(addAs('pipe-portal')),
setup(loadFlagPole)
.then(addAs('flag-pole')),
setup(loadBrickShrapnel)
.then(createPool(8))
.then(addAs('brickShrapnel')),
]);

])
.then(() => entityFactories);
return entityFactories;
}
35 changes: 35 additions & 0 deletions public/js/entities/BrickShrapnel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Entity from '../Entity.js';
import LifeLimit from '../traits/LifeLimit.js';
import Gravity from '../traits/Gravity.js';
import Velocity from '../traits/Velocity.js';
import {loadAudioBoard} from '../loaders/audio.js';
import {loadSpriteSheet} from '../loaders/sprite.js';

export function loadBrickShrapnel(audioContext) {
return Promise.all([
loadSpriteSheet('brick-shrapnel'),
loadAudioBoard('brick-shrapnel', audioContext),
])
.then(([sprite, audio]) => {
return createFactory(sprite, audio);
});
}

function createFactory(sprite, audio) {
const spinBrick = sprite.animations.get('spinning-brick');

function draw(context) {
sprite.draw(spinBrick(this.lifetime), context, 0, 0);
}

return function createBrickShrapnel() {
const entity = new Entity();
entity.audio = audio;
entity.size.set(8, 8);
entity.addTrait(new LifeLimit());
entity.addTrait(new Gravity());
entity.addTrait(new Velocity());
entity.draw = draw;
return entity;
};
}
6 changes: 3 additions & 3 deletions public/js/entities/Bullet.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Entity, {Sides} from '../Entity.js';
import Entity from '../Entity.js';
import Trait from '../Trait.js';
import Killable from '../traits/Killable.js';
import Stomper from '../traits/Stomper.js';
import Gravity from '../traits/Gravity.js';
import Stomper from '../traits/Stomper.js';
import Velocity from '../traits/Velocity.js';
import {loadSpriteSheet} from '../loaders/sprite.js';

Expand Down Expand Up @@ -44,7 +44,7 @@ class Behavior extends Trait {

function createBulletFactory(sprite) {
function drawBullet(context) {
sprite.draw('bullet', context, 0, 0, this.vel.x < 0);
sprite.draw('bullet', context, 0, 0, this.vel.x > 0);
}

return function createBullet() {
Expand Down
24 changes: 24 additions & 0 deletions public/js/entities/FlagPole.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Entity from '../Entity.js';
import Pole from '../traits/Pole.js';
import {loadAudioBoard} from '../loaders/audio.js';

export function loadFlagPole(audioContext) {
return Promise.all([
loadAudioBoard('flag-pole', audioContext),
])
.then(([audio]) => {
return createFactory(audio);
});
}

function createFactory(audio) {
return function createFlagPole() {
const entity = new Entity();
const pole = new Pole();
entity.audio = audio;
entity.size.set(8, 144);
entity.offset.set(4, 0);
entity.addTrait(pole);
return entity;
};
}
Loading