Skip to content

Commit

Permalink
feat(scenes): style first half of the screen to white
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jan 30, 2022
1 parent 9d5f71f commit 5ec4464
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
6 changes: 6 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export const color = {
white: '#fcfcfc',
whiteHex: 0xfcfcfc,
black: '#1d212d',
} as const;

export const key = {
image: {
spike: 'spike',
Expand Down
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import './style.css';

import Phaser from 'phaser';

import { color } from './constants';
import scenes from './scenes';

const isProduction = process.env.NODE_ENV === 'production';
Expand All @@ -10,8 +11,8 @@ const isProduction = process.env.NODE_ENV === 'production';
* https://photonstorm.github.io/phaser3-docs/Phaser.Types.Core.html#.GameConfig
*/
new Phaser.Game({
width: 1280, // 32 * 40
height: 640, // 32 * 20
width: 1280, // 32px * 40 tiles
height: 640, // 32px * 20 tiles
title: 'Mirror',
url: 'https://remarkablegames.org/mirror/',
version: process.env.VERSION,
Expand All @@ -26,7 +27,7 @@ new Phaser.Game({
},
},
disableContextMenu: isProduction,
backgroundColor: '#1d212d',
backgroundColor: color.black,
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.CENTER_BOTH,
Expand Down
31 changes: 21 additions & 10 deletions src/scenes/Main.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Phaser from 'phaser';

import { key } from '../constants';
import { color, key } from '../constants';
import { Player } from '../sprites';

export default class Main extends Phaser.Scene {
private groundLayer!: Phaser.Tilemaps.TilemapLayer;
private isPlayerDead!: boolean;
private playerA!: Player;
private playerB!: Player;
private isPlayerDead = false;
private groundLayer!: Phaser.Tilemaps.TilemapLayer;
private spikeGroup!: Phaser.Physics.Arcade.StaticGroup;

constructor() {
Expand All @@ -18,15 +18,24 @@ export default class Main extends Phaser.Scene {
this.isPlayerDead = false;

const map = this.make.tilemap({ key: key.tilemap.map });

// First half of screen has white background
this.add.rectangle(
0,
0,
map.widthInPixels,
map.heightInPixels * 2,
color.whiteHex
);

const tiles = map.addTilesetImage(
'0x72-industrial-tileset-32px-extruded',
key.image.tiles
);

map.createLayer('Objects', tiles);
this.groundLayer = map.createLayer('Ground', tiles);

// Instantiate a player instance at the location of the "Spawn Point" object in the Tiled map
// Instantiate a player instance at the location of the spawn point object in the Tiled map
const spawnPointA = map.findObject(
'Objects',
(obj) => obj.name === 'SpawnA'
Expand Down Expand Up @@ -70,10 +79,13 @@ export default class Main extends Phaser.Scene {
// The map has spikes rotated in Tiled (z key), so parse out that angle to the correct body
// placement
spike.rotation = tile.rotation;
if (spike.angle === 0) spike.body.setSize(32, 6).setOffset(0, 26);
else if (spike.angle === -90)
if (spike.angle === 0) {
spike.body.setSize(32, 6).setOffset(0, 26);
} else if (spike.angle === -90) {
spike.body.setSize(6, 32).setOffset(26, 0);
else if (spike.angle === 90) spike.body.setSize(6, 32).setOffset(0, 0);
} else if (spike.angle === 90) {
spike.body.setSize(6, 32).setOffset(0, 0);
}

this.groundLayer.removeTileAt(tile.x, tile.y);
}
Expand All @@ -85,9 +97,8 @@ export default class Main extends Phaser.Scene {
this.add
.text(16, 16, 'Arrow/WASD to move & jump', {
font: '18px monospace',
color: '#000',
color: color.black,
padding: { x: 20, y: 10 },
backgroundColor: '#fff',
})
.setScrollFactor(0);
}
Expand Down

0 comments on commit 5ec4464

Please sign in to comment.