From dbdfaafc447a4d09377619a7c824b87539453007 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Wed, 14 Dec 2016 20:13:11 +0200 Subject: Make Xmas fork --- src/engine.js | 18 +++++++++++++++++- src/gameobject.js | 10 +++++++--- src/objecttypes.js | 14 +++++++------- src/player.js | 7 ++++++- src/settings.js | 3 ++- 5 files changed, 39 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/engine.js b/src/engine.js index 30d7d7a..b75886a 100644 --- a/src/engine.js +++ b/src/engine.js @@ -56,8 +56,19 @@ Engine.prototype.makeStageClickable = function() { this.clickLayer.touchstart = this.clickLayer.mousedown = this.buttonPressed.bind(this); } +Engine.prototype.randomizePlayer = function() { + this.removeSprite(player.sprite); + var number = Math.floor((Math.random() * Settings.PLAYER_COUNT) + 1); + var newTexture = PIXI.Texture.fromImage("res/players/player" + number + ".png"); + player.sprite = new PIXI.Sprite(newTexture); + this.unitsContainer.addChild(player.sprite); +} + Engine.prototype.activateMenu = function() { this.state = MENU; + + this.randomizePlayer(); + player.score = 0 console.log("changed to menu!"); logo1.sprite.visible = true; @@ -97,6 +108,10 @@ Engine.prototype.activateGameOver = function() { this.sound.play("explosion") } +Engine.prototype.removeSprite = function(sprite) { + this.unitsContainer.removeChild(sprite); +} + Engine.prototype.removeIntegral = function(integral) { var i = this.gameObjectList.indexOf(integral); this.gameObjectList.splice(i, 1); @@ -198,6 +213,7 @@ Engine.prototype.setupGameObjects = function() { // add player to gameobjectlist this.gameObjectList = []; + this.unitsContainer.addChild(player.sprite); this.menuContainer.addChild(logo1.sprite); this.menuContainer.addChild(logo2.sprite); @@ -214,4 +230,4 @@ Engine.prototype.setupGameObjects = function() { this.stage.updateLayersOrder(); } -var engine = new Engine(); \ No newline at end of file +var engine = new Engine(); diff --git a/src/gameobject.js b/src/gameobject.js index 0b50553..43218b1 100644 --- a/src/gameobject.js +++ b/src/gameobject.js @@ -1,12 +1,16 @@ function GameObject(texture) { - this.texture = PIXI.Texture.fromImage("res/" + texture + ".png"); - this.sprite = new PIXI.Sprite(this.texture); + this.updateTexture(texture); this.initPosition(); this.active = true; this.objectType = "gameobject"; } +GameObject.prototype.updateTexture = function(name) { + this.texture = PIXI.Texture.fromImage("res/" + name + ".png"); + this.sprite = new PIXI.Sprite(this.texture); +} + GameObject.prototype.initPosition = function() { this.sprite.anchor.x = 0.5; this.sprite.anchor.y = 0.5; @@ -17,4 +21,4 @@ GameObject.prototype.initPosition = function() { GameObject.prototype.update = function() { -} \ No newline at end of file +} diff --git a/src/objecttypes.js b/src/objecttypes.js index d7b0df4..e9f69f0 100644 --- a/src/objecttypes.js +++ b/src/objecttypes.js @@ -53,15 +53,15 @@ scoreBg.beginFill(0xAAAAAA, 1.0); scoreBg.visible = false; // score display -var scoreText = new PIXI.Text("W", { font: '35px Arial', fill: 'black', align: 'left' }); +var scoreText = new PIXI.Text("W", { font: '35px Arial', fill: 'white', align: 'left' }); scoreText.visible = false; scoreText.update = function() { - this.text = "W = " + player.score + " J"; + this.text = "Tomia vältelty " + player.score + " tuntia"; } scoreText.moveToCorner = function() { - this.position.x = Settings.STAGE_WIDTH * 0.7; - this.position.y = Settings.STAGE_HEIGHT * 0.1; + this.position.x = Settings.STAGE_WIDTH * 0.5; + this.position.y = Settings.STAGE_HEIGHT * 0.05; } scoreText.moveToCenter = function() { @@ -71,14 +71,14 @@ scoreText.moveToCenter = function() { scoreText.moveToCorner(); // gameover screen title text -var gameOverText = new PIXI.Text("Nettovoiman tekemä työ:", { font: '35px Arial', fill: 'black', align: 'center' }); +var gameOverText = new PIXI.Text("Onneksi olkoon!", { font: '35px Arial', fill: 'black', align: 'center' }); gameOverText.visible = false; gameOverText.position.x = Settings.STAGE_WIDTH * 0.5 - gameOverText.width / 2;; gameOverText.position.y = Settings.STAGE_HEIGHT * 0.4 - gameOverText.height / 2;; // move the gameover bg box now that we now the width of the text var yDiff = scoreText.position.y - gameOverText.position.y + gameOverText.height; -scoreBg.drawRect(gameOverText.position.x - 10, gameOverText.position.y - 10, gameOverText.width + 20, -yDiff); +scoreBg.drawRect(Settings.STAGE_WIDTH * 0.2, gameOverText.position.y - 10, Settings.STAGE_WIDTH * 0.6, -yDiff); // integral sign function Integral(y) { @@ -104,4 +104,4 @@ Integral.prototype.initPosition = function() { Integral.prototype.update = function() { this.sprite.position.x += this.speed; -} \ No newline at end of file +} diff --git a/src/player.js b/src/player.js index 64f00f8..e3a43b4 100644 --- a/src/player.js +++ b/src/player.js @@ -64,4 +64,9 @@ Player.prototype.update = function() { } } -var player = new Player("player"); \ No newline at end of file +Player.prototype.updateSprite = function(sprite) { + this.sprite = sprite; +} + +var number = Math.floor((Math.random() * Settings.PLAYER_COUNT) + 1); +var player = new Player("players/player" + number); diff --git a/src/settings.js b/src/settings.js index b515171..e0c8609 100644 --- a/src/settings.js +++ b/src/settings.js @@ -2,6 +2,7 @@ var Settings = function() {} Settings.STAGE_WIDTH = 800; Settings.STAGE_HEIGHT = 600; Settings.STAGE_BGCOLOR = 0xA0A0A0; +Settings.PLAYER_COUNT = 11; var lastTime = Date.now(); var dt = 0.0; @@ -12,4 +13,4 @@ function updateDeltaTime() { lastTime = current; dt = current - last; -} \ No newline at end of file +} -- cgit v1.3