Skip to content

Commit

Permalink
TechDebt/refactor levels in order to sperate logic from content
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasz-rekawek committed Apr 7, 2017
1 parent 3fa9514 commit ff820e3
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 171 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ mongoose-free-6.5.exe
node_modules
dist/js/app.js
dist
npm-debug.log
109 changes: 31 additions & 78 deletions js/levels/level01.js
Original file line number Diff line number Diff line change
@@ -1,82 +1,35 @@
import {GameState} from '../gameState'
import {LevelPrototype} from './levelPrototype'
let gState = new GameState().state;
//set local pointers;

export class Level1{


constructor() {
this.playerStartingX = 10;
this.playerStartingY = 10;
}

addStartingText(){
var loadingLabel = game.add.text(80, 278, 'Kill the evil slime! -->', {font: '20px Courier', fill: '#fff'});
setTimeout(function(){
loadingLabel.kill();
}, 5000);
}

createBackground(){
game.world.setBounds(0, 0, 885, 376);

game.add.sprite(0, 0, 'game-background');
game.add.sprite(640, 0, 'game-background');
}

addPlatforms(){
gState.envObjects.platforms.create(0, 300, 'platform');
gState.envObjects.platforms.create(197, 300, 'platform2');
gState.envObjects.platforms.create(506, 300, 'platform');
gState.envObjects.platforms.create(646, 300, 'platform');
gState.envObjects.platforms.create(646, 112, 'tower1');
}

addArrows(arrows){
}

addRedSlimes(){
gState.enemies.redSlimes.create(670, 10, 'monster2');
}

addFallers(){
gState.envObjects.fallers.create(340, 282, 'faller');
}

addSlowFallers(){
}

addTrampolines(){
gState.envObjects.trampolines.create(600, 270, 'trampoline');
}

addLava(){
gState.envObjects.lava.create(141, 332, 'lava');
gState.envObjects.lava.create(254, 332, 'lava2');
gState.envObjects.lava.create(700, 332, 'lava2');
}

addSwitchFallers(){
}

addEndingText(){
game.add.text(gState.player.x - 200, 100, 'Great!',
{font: '40px Courier', fill: '#fff'});
game.add.text(gState.player.x - 200, 136, 'Time for the next one....',
{font: '20px Courier', fill: '#fff'});
}

addTnt(){
}

addRiders(){
}

handleRidersLogic(){
}

checkForCoolKillText(){
}


let lvl = {
platforms: [
{ x:0, y: 300, type: 'platform' },
{ x:197, y: 300, type: 'platform2' },
{ x:506, y: 300, type: 'platform' },
{ x:646, y: 300, type: 'platform' },
{ x:646, y: 112, type: 'tower1' }
],
redSlimes: [
{ x: 670,y: 10, type: 'monster2' }
],
fallers: [
{ x: 340, y: 282, type: 'faller' }
],
slowFallers: [],
trampolines: [ { x: 600, y: 270, type: 'trampoline' } ],
lava: [
{ x:141, y: 332, type: 'lava' },
{ x:254, y: 332, type: 'lava2' },
{ x:700, y: 332, type: 'lava2' }
],
tnt: [],
riders: [],
switchFallers: []
}
export class Level1 extends LevelPrototype {
constructor() {
super();
this.levelObj = lvl
}
}
90 changes: 42 additions & 48 deletions js/levels/level02.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,50 @@
import {GameState} from '../gameState'
import {LevelPrototype} from './levelPrototype'
let gState = new GameState().state;
export class Level2{

let lvl = {
platforms: [
{x: 754, y: 172, type: 'tower1' },
{x: 887, y: 300, type: 'platform' },
{x: 1169, y: 300, type: 'platform' },
{x: 1169, y: 272, type: 'tower1' },
{x: 1310, y: 300, type: 'platform' },
{x: 1451, y: 300, type: 'platform' },
{x: 1410, y: 112, type: 'tower1' }
],
redSlimes: [
{x: 1470, y: 10, type: 'monster2' },
{x: 390, y: 70, type: 'monster2' }
],
fallers: [
],
slowFallers: [
{x: 20, y: 282, type: 'faller' }
],
trampolines: [
{x: 50, y: 270, type: 'trampoline' },
{x: 950, y: 270, type: 'trampoline' }
],
lava: [
{x: 0, y: 332, type: 'lava2' },
{x: 252, y: 332, type: 'lava2' },
{x: 502, y: 332, type: 'lava2' },
{x: 754, y: 332, type: 'lava2' },
{x: 1000, y: 332, type: 'lava2' },
{x: 1510, y: 352, type: 'lava2' }
],
tnt: [],
riders: [],
arrows: [ {x: 1230, y: 240, type: 'arrow' } ],
switchFallers: []
}

export class Level2 extends LevelPrototype{


constructor() {
this.playerStartingX = 10;
this.playerStartingY = 10;
super();
this.levelObj = lvl
}

addStartingText(){
Expand All @@ -31,56 +70,11 @@ export class Level2{
game.add.sprite(1280, 0, 'game-background');
}

addPlatforms(){
gState.envObjects.platforms.create(754, 172, 'tower1');
gState.envObjects.platforms.create(887, 300, 'platform');
gState.envObjects.platforms.create(1169, 300, 'platform');
gState.envObjects.platforms.create(1169, 272, 'tower1');
gState.envObjects.platforms.create(1310, 300, 'platform');
gState.envObjects.platforms.create(1451, 300, 'platform');
gState.envObjects.platforms.create(1410, 112, 'tower1');
}

addArrows( arrows ){
arrows.create(1230, 240, 'arrow');
}

addRedSlimes(){
gState.enemies.redSlimes.create(1470, 10, 'monster2');
gState.enemies.redSlimes.create(390, 70, 'monster2');
}

addFallers(){
}

addTrampolines( trampolines){
trampolines.create(50, 270, 'trampoline');
trampolines.create(950, 270, 'trampoline');
}

addSlowFallers(){
gState.envObjects.slowFallers.create(20, 282, 'faller');
}


addLava(){
gState.envObjects.lava.create(0, 332, 'lava2');
gState.envObjects.lava.create(252, 332, 'lava2');
gState.envObjects.lava.create(502, 332, 'lava2');
gState.envObjects.lava.create(754, 332, 'lava2');
gState.envObjects.lava.create(1000, 332, 'lava2');
gState.envObjects.lava.create(1510, 352, 'lava2');
}

addRiders(){
this.rider1 = gState.envObjects.riders.create(490, 200, 'faller');
}

addSwitchFallers(){
}

addTnt(){
}

handleRidersLogic(){
if(this.rider1.x > 650){
Expand Down
83 changes: 38 additions & 45 deletions js/levels/level03.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,46 @@
import {GameState} from '../gameState'
import {LevelPrototype} from './levelPrototype'
let g = new GameState().state;
export class Level3{

let lvl = {
platforms: [
{x: 0, y: 112, type: 'tower1' },
{x: 1, y: 300, type: 'platform' },
{x: 421, y: 289, type: 'faller' }
],
redSlimes: [
{x: 350, y: 10, type: 'monster2' },
{x: 560, y: 10, type: 'monster2' }
],
fallers: [
],
slowFallers: [],
trampolines: [ ],
lava: [
{x: 142, y: 332, type: 'lava' },
{x: 198, y: 332, type: 'lava' },
{x: 254, y: 332, type: 'lava2' },
{x: 506, y: 332, type: 'lava2' }
],
tnt: [],
switchFallers: [
{x: 136, y: 242, type: 'faller' },
{x: 330, y: 112, type: 'faller' },
{x: 208, y: 242, type: 'platform' },
{x: 349, y: 289, type: 'faller' },
{x: 493, y: 289, type: 'faller' },
{x: 565, y: 289, type: 'faller' },
{x: 530, y: 32, type: 'tower1' }
],
riders: []
}

export class Level3 extends LevelPrototype{


constructor() {
this.playerStartingX = 10;
this.playerStartingY = 10;
super();
this.levelObj = lvl;
}

addStartingText(){
Expand All @@ -25,56 +60,14 @@ export class Level3{

createBackground(){
game.world.setBounds(0, 0, 640, 376);

game.add.sprite(0, 0, 'game-background');
}

addPlatforms(){
g.envObjects.platforms.create(0, 112, 'tower1');
g.envObjects.platforms.create(1, 300, 'platform');
g.envObjects.platforms.create(421, 289, 'faller');
}

addArrows( arrows){
}

addRedSlimes(){
g.enemies.redSlimes.create(350, 10, 'monster2');
g.enemies.redSlimes.create(560, 10, 'monster2');
}

addFallers(){
}

addTrampolines( trampolines){
trampolines.create(160, 10, 'trampoline');
}

addSlowFallers(){
}


addLava(){
g.envObjects.lava.create(142, 332, 'lava');
g.envObjects.lava.create(198, 332, 'lava');
g.envObjects.lava.create(254, 332, 'lava2');
g.envObjects.lava.create(506, 332, 'lava2');
}

addSwitchFallers(){
g.envObjects.switchFallers.create(136, 242, 'faller');
g.envObjects.switchFallers.create(330, 112, 'faller');

g.envObjects.switchFallers.create(208, 242, 'platform');
g.envObjects.switchFallers.create(349, 289, 'faller');
g.envObjects.switchFallers.create(493, 289, 'faller');
g.envObjects.switchFallers.create(565, 289, 'faller');
g.envObjects.switchFallers.create(530, 32, 'tower1');
}

addRiders(){
}

addTnt(){
g.envObjects.tnt = game.add.sprite(360, 150, 'tnt');
game.physics.arcade.enable( g.envObjects.tnt );
Expand Down
Loading

0 comments on commit ff820e3

Please sign in to comment.