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
| const http = require('http') | |
| const port = process.env.PORT || 3001 | |
| http.createServer((req, res) => { | |
| res.write('Hello World!') | |
| res.end() | |
| }).listen(port, () => { | |
| console.log(`server start at port ${port}`) | |
| }) |
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
| const args = ['-v', 'fileA', 'fileB', 'fileC', 'fileD', 'fileE', 'fileF', '-h', '-l', 'ro']; // process.argv.slice(2); | |
| // supported arguments and their respective methods | |
| const knownArgs = { | |
| '-v': (files) => console.log('files', files), | |
| '-l': (langs) => console.log('langs', langs), | |
| '-h': () => console.log('help'), | |
| }; | |
| // parse arguments and provided values |
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 PickerUtils { | |
| /** | |
| * Converts a hex color to RGB format | |
| * @param {string} hex A hex color (shorthand allowed) | |
| * @returns {object|null} Containing the RGB channels | |
| */ | |
| static hexToRGB(hex) { | |
| const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; | |
| const rgb = hex.replace( | |
| shorthandRegex, |
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
| const decimalZip = (a, b) => { | |
| const MAX_INT = 100000000; | |
| if (typeof a !== 'number' || typeof b !== 'number') { | |
| throw new Error('Only integers are allowed'); | |
| } | |
| if (a < 0 || b < 0) { | |
| throw new Error('Only positive integers are allowed'); | |
| } | |
| if (a > MAX_INT || b > MAX_INT) { | |
| throw new Error(`Integer value should not exceed ${MAX_INT}`); |
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, AssetsLoader } from '../engine'; | |
| import Player from './objects/Player'; | |
| import StarField from './objects/StarField'; | |
| import RockField from './objects/RockField'; | |
| import Map from './objects/Map'; | |
| import PlayerModel from './models/PlayerModel'; | |
| require('../../scss/styles.scss'); | |
| let assetsLoader = new AssetsLoader(); |
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, Particle } from '../../engine'; | |
| export default class Bullet extends Particle { | |
| constructor(model) { | |
| super(3, '#ff0'); | |
| this.x = model.x; | |
| this.y = model.y; | |
| this.angle = model.angle + Math.PI*0.5; | |
| this.speed = 5; | |
| this.created = Date.now(); |
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, DisplayObject, AssetsLoader, KeyboardEvents } from '../../engine'; | |
| import Bullet from './Bullet'; | |
| export default class Player extends DisplayObject { | |
| constructor(model) { /* ... */ } | |
| update() { | |
| /* ... */ | |
| if(this.SPACE) { | |
| this.model.fire = true; |
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 { DisplayObject } from '../../engine'; | |
| export default class Map extends DisplayObject { | |
| constructor(markerSize=4, mapScaleFactor=0.2) { | |
| super(); | |
| this.markerSize = markerSize; | |
| this.mapScaleFactor = mapScaleFactor; | |
| } | |
| 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 { Scene, DisplayObject } from '../../engine'; | |
| import Rock from './Rock'; | |
| import RockModel from '../models/RockModel'; | |
| export default class RockField extends DisplayObject { | |
| constructor(model, amount=10) { | |
| super(); | |
| this.model = model; | |
| this.amount = amount; | |
| this.rocks = []; |
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, DisplayObject } from '../../engine'; | |
| export default class Rock extends DisplayObject { | |
| constructor(model) { | |
| super(); | |
| this.model = model; | |
| } | |
| update() { |