This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class KeyboardEvents { | |
static get KEY_UP() { | |
return 'keyup'; // actual event name, don't change | |
} | |
static get KEY_DOWN() { | |
return 'keydown'; // actual event name, don't change | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Keyboard } from '../'; | |
let canvasInstance; | |
class CanvasSingleton { | |
constructor() { | |
if(!canvasInstance) { | |
console.log('Canvas instance created'); | |
let canv = document.createElement('canvas'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Canvas from './Canvas'; | |
export default class Scene extends Canvas { | |
constructor(x=0, y=0, width, height) { | |
super(); | |
this.children = []; | |
this.x = x; | |
this.y = y; | |
// store initial width and height |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Game, Scene } from '../engine'; | |
require('../../scss/styles.scss'); | |
let movementMultiplier = 1; | |
class Square extends Scene { | |
constructor(x=0, y=0, size=40, color='#900') { | |
super(); | |
this.x = x; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class VerletModel { | |
constructor(x=0, y=0) { | |
this.previousX = x; | |
this.previousY = y; | |
this.xPos = x; | |
this.yPos = y; | |
} | |
get vx() { | |
return this.xPos - this.previousX; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { SquareModel, SquareCtrl, SquareView } from './square'; | |
import { Game, Scene } from '../engine'; | |
require('../../scss/styles.scss'); | |
const scene = new Scene(20, 33, 400, 200); | |
const game = new Game(scene); | |
const squareModel = new SquareModel(); | |
const squareCtrl = new SquareCtrl(squareModel); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Scene } from '../../engine'; | |
export default class SquareView extends Scene { | |
constructor(model, ctrl) { | |
super(); | |
this.model = model; | |
this.ctrl = ctrl; | |
} | |
update() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { VerletModel } from '../../engine'; | |
export default class SquareModel extends VerletModel { | |
constructor() { | |
super(); | |
this.temporaryX = 0; | |
this.temporaryY = 0; | |
this.frictionX = 0; | |
this.frictionY = 0; | |
this.friction = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Keyboard, KeyboardEvents } from '../../engine'; | |
export default class SquareCtrl extends Keyboard { | |
constructor(model) { | |
super(); | |
const onKeyUp = () => { | |
if(this.UP || this.DOWN) { | |
this.model.accelerationY = 0; | |
this.model.friction = 0.94; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Scene from './Scene'; | |
export default class DisplayObject extends Scene { | |
constructor() { | |
super(); | |
this.children = []; | |
} | |
add(elem) { | |
if(elem.constructor === Array) { | |
for(let el of elem) { |