Permalink
Please sign in to comment.
Browse files
Added the ability to create plants by dragging and dropping them from…
… a menu.
- Loading branch information...
Showing
with
112 additions
and 52 deletions.
BIN
assets/textures/gui.back.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN
assets/textures/gui.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25
assets/textures/plants.json
BIN
assets/textures/plants.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN
assets/textures/zombie.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN
assets/textures/zombies_text.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3
js/Cursor.js
56
js/Gui.js
@@ -1,43 +1,71 @@ | ||
function Gui(state) { | ||
- this.heart = game.add.sprite(16, 16, 'plants'); | ||
- this.heart.width = 64; | ||
- this.heart.height = 64; | ||
+ this.manager = state.manager; | ||
+ | ||
+ this.plant_selected = false; | ||
+ | ||
+ //14 | ||
+ | ||
+ this.heart = game.add.sprite(48, 48, 'plants'); | ||
+ this.heart.width = 32; | ||
+ this.heart.height = 32; | ||
this.heart.animations.add('full', ['heart'], 2, true, false); | ||
this.heart.animations.add('med', ['heart'], 2, true, false); | ||
this.heart.animations.add('low', ['heart'], 2, true, false); | ||
this.heart.animations.play('full', 2, true); | ||
- this.sun = game.add.sprite(80, 16, 'plants'); | ||
- this.sun.width = 64; | ||
- this.sun.height = 64; | ||
+ this.guiSprite = game.add.sprite(32, 32, 'gui'); | ||
+ this.guiSprite.smoothed = false; | ||
+ this.guiSprite.width = 296; | ||
+ this.guiSprite.height = 128; | ||
+ | ||
+ this.sun = game.add.sprite(this.guiSprite.x + 22, this.guiSprite.y + 22, 'plants'); | ||
+ this.sun.width = 32; | ||
+ this.sun.height = 32; | ||
this.sun.animations.add('idle', ['sun'], 2, true, false); | ||
this.sun.animations.play('idle', 2, true); | ||
var self = this; var i = 0; | ||
['peashooter', 'sunflower', 'nut'].map(function(plant){ | ||
- var sprite = game.add.sprite(64 * i + 128, 16, 'plants'); | ||
+ // this doesn't do anything, it just sits there | ||
+ var placeholder_sprite = game.add.sprite(64 * i + 115, 60, 'plants'); | ||
+ placeholder_sprite.width = 64; | ||
+ placeholder_sprite.height = 64; | ||
+ placeholder_sprite.animations.add('idle', [plant + '_0'], 2, true, false); | ||
+ placeholder_sprite.animations.play('idle', 2, true); | ||
+ | ||
+ var sprite = game.add.sprite(placeholder_sprite.x, placeholder_sprite.y, 'plants'); | ||
sprite.width = 64; | ||
sprite.height = 64; | ||
sprite.inputEnabled = true; | ||
+ sprite.input.enableDrag(); | ||
- sprite.animations.add('unselected', [plant + '_0'], 2, true, false); | ||
- sprite.animations.add('selected', [plant + '_1'], 2, true, false); | ||
- sprite.animations.play('unselected', 2, true); | ||
+ sprite.animations.add('idle', [plant + '_0'], 2, true, false); | ||
+ sprite.animations.play('idle', 2, true); | ||
sprite.events.onInputDown.add(function(){ | ||
- sprite.animations.play('selected', 2, true); | ||
+ self.plant_selected = true; | ||
+ }, state); | ||
+ | ||
+ sprite.events.onInputUp.add(function(){ | ||
+ self.plant_selected = false; | ||
+ sprite.x = placeholder_sprite.x; | ||
+ sprite.y = placeholder_sprite.y; | ||
+ self.manager.addPlantAtMouse(plant); | ||
}, state); | ||
self[plant] = sprite; | ||
i++; | ||
}); | ||
- this.sunText = game.add.text(96, 128, '#FontFixBecauseExternalFontsDontWorkWellWithPhaser', { | ||
- 'font': '40px Arial', | ||
- 'fillStyle': 'black' | ||
+ this.sunText = game.add.text(this.sun.x - 2 + this.sun.width / 2, this.sun.y + 32 + this.sun.height / 2, '#FontFixBecauseExternalFontsDontWorkWellWithPhaser', { | ||
+ font: '20px Arial', | ||
+ fillStyle: 'black', | ||
+ align: 'center' | ||
}); | ||
+ this.sunText.anchor.set(0.5); | ||
+ | ||
} |
29
js/Sun.js
34
js/main.js
17
js/plants/Peashooter.js
0 comments on commit
9d9ac50