Skip to content

Instantly share code, notes, and snippets.

@Babsobar
Created November 23, 2016 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Babsobar/7d6583356a32943bfff486ec297e222a to your computer and use it in GitHub Desktop.
Save Babsobar/7d6583356a32943bfff486ec297e222a to your computer and use it in GitHub Desktop.
//terrain Variables
var terrain;
var terrainLayer;
var terrainPop;
var terrainLimbo
var currentLayer;
//First iteration of unit architecture, prototype for now
var biffinRed;
var army;
var corps;
//Keys
var marker;
var updateInput = true;
//default Tile on selector: water(0)
var currentTile = 0;
//Size of map; in tiles amount
var mapSizeX = 120;
var mapSizeY = 120;
// which tiles to use as a tileset (can be changed for skins)
var tileSetImage = 'terrain2'
//GUI variables
var tileSelector;
var menuX = window.innerWidth;
var menuY= window.innerHeight;
var zooming = false;
var zoomAmount = 0;
//activates keyboard input.
var keyboardInput;
BasicGame.Editor = function (editor) {
// When a State is added to Phaser it automatically has the following properties set on it, even if they already exist:
this.game; // a reference to the currently running game
this.add; // used to add sprites, text, groups, etc
this.camera; // a reference to the game camera
this.cache; // the game cache
this.input; // the global input manager (you can access this.input.keyboard, this.input.mouse, as well from it)
this.load; // for preloading assets
this.math; // lots of useful common math operations
this.sound; // the sound manager - add a sound, play one, set-up markers, etc
this.stage; // the game stage
this.time; // the clock
this.tweens; // the tween manager
this.state; // the state manager
this.world; // the game world
this.particles; // the particle manager
this.physics; // the physics manager
this.rnd; // the repeatable random number generator
// You can use any of these from any function within this State.
// But do consider them as being 'reserved words', i.e. don't create a property for your own game called "world" or you'll over-write the world reference.
};
BasicGame.Editor.prototype = {
create: function () {
keyboardInput = this.input.keyboard.createCursorKeys();
//========================== WORLD CREATOIN
//Make our game world and set it bounds
this.world.setBounds(0, 0, mapSizeX*32, mapSizeY*32);
// ========================== TERRAIN CREATION
//create Blank tilemap
terrainLayer = this.add.tilemap();
// add a tileset Image to the map
terrainLayer.addTilesetImage(tileSetImage);
//create the world as a layer
terrain = terrainLayer.create('level1', mapSizeX, mapSizeY, 32, 32);
terrainPop = terrainLayer.createBlankLayer('level2', mapSizeX,mapSizeY,32,32)
terrainLimbo = terrainLayer.createBlankLayer('limbo', mapSizeX,mapSizeY,32,32)
// Fills tilemap layer with default tile:HOLY WATER (6)
terrainLayer.fill(0, 0,0,mapSizeX,mapSizeY, 'level1');
currentLayer = terrain;
this.createArmy();
//sends callback
this.input.addMoveCallback(updateMarker, this);
///////////////////////// UNIT PROPERTIES AND CREATION. To be changed and tested most likely
// Adds basic background color for testin
this.stage.backgroundColor = '#2d2d2d';
//GUI Button creation /js/createButtons.js
this.createButtons();
//Tilestrip Creation; soon to be removed /js/tileSelector.js
this.createTileSelector();
},// End of Create
update: function () {
//for each direction, moves camera in world.
if (keyboardInput.up.isDown)
{
this.camera.y -= 4;
menuIncrementY -= 4;
}
else if (keyboardInput.down.isDown)
{
this.camera.y += 4;
menuIncrementY += 4;
}
if (keyboardInput.left.isDown)
{
this.camera.x -= 4;
menuIncrementX -= 4;
}
else if (keyboardInput.right.isDown)
{
this.camera.x += 4;
menuIncrementX += 4;
}
this.dynamicEditing();
},
resize: function (width, height) {
// If the game container is resized this function will be called automatically.
// You can use it to align sprites that should be fixed in place and other responsive display things.
var height = window.innerHeight;
var width = window.innerWidth;
menuX = width
menuY = height
startEditor.x = this.game.width - 512;
startEditor.y = this.game.height -256;
this.game.width = window.innerWidth;
this.game.height = window.innerHeight;
menuX = this.game.width ;
menuY = this.game.height;
this.scale.scaleMode = Phaser.ScaleManager.RESIZE;
this.scale.setShowAll()
this.scale.setGameSize(window.innerHeight,window.innerWidth)
this.scale.pageAlignHorizontally = true;
this.scale.pageAlignVertically = true;
console.log('resized.')
this.camera.width = this.game.width;
this.camera.height = this.game.height;
/*
/*
this.bg.width = width;
this.bg.height = height;
this.spriteMiddle.x = this.game.world.centerX;
this.spriteMiddle.y = this.game.world.centerY;
this.spriteTopRight.x = this.game.width;
this.spriteBottomLeft.y = this.game.height;
this.spriteBottomRight.x = this.game.width;
this.spriteBottomRight.y = this.game.height;
*/
},
quitGame: function (pointer) {
this.state.start('MainMenu');
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment