Permalink
Please sign in to comment.
Showing
with
296 additions
and 60 deletions.
- BIN assets/textures/background.ase
- BIN assets/textures/background.png
- BIN assets/textures/cloud.png
- BIN assets/textures/mario.png
- +1 −1 assets/textures/plants.json
- BIN assets/textures/spot.png
- +22 −0 assets/textures/zombie.json
- BIN assets/textures/zombie.png
- BIN assets/textures/zombie_scaled.png
- +1 −0 index.html
- +16 −10 js/Pea.js
- +58 −6 js/campers/Zomper.js
- +81 −30 js/main.js
- +23 −13 js/plants/Peashooter.js
- +85 −0 js/vector.js
- +9 −0 server.js
BIN
assets/textures/background.ase
Binary file not shown.
BIN
assets/textures/background.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/cloud.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/mario.png
Deleted file not rendered
2
assets/textures/plants.json
BIN
assets/textures/spot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22
assets/textures/zombie.json
@@ -0,0 +1,22 @@ | ||
+{ | ||
+ "frames": { | ||
+ "zombie_0": { | ||
+ "frame": {"x": 0, "y": 0, "w": 32, "h": 32} | ||
+ }, | ||
+ "zombie_1":{ | ||
+ "frame": {"x": 32, "y": 0, "w": 32, "h": 32} | ||
+ }, | ||
+ "zombie_2":{ | ||
+ "frame": {"x": 64, "y": 0, "w": 32, "h": 32} | ||
+ }, | ||
+ "zombie_3":{ | ||
+ "frame": {"x": 96, "y": 0, "w": 32, "h": 32} | ||
+ }, | ||
+ "zombie_hit_up":{ | ||
+ "frame": {"x": 0, "y": 0, "w": 32, "h": 32} | ||
+ }, | ||
+ "zombie_hit_down":{ | ||
+ "frame": {"x": 32, "y": 0, "w": 32, "h": 32} | ||
+ } | ||
+ } | ||
+} |
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/zombie_scaled.png
Deleted file not rendered
1
index.html
26
js/Pea.js
@@ -1,11 +1,17 @@ | ||
-function Pea(manager, column, row) { | ||
+function Pea(manager, sprite_x, sprite_y, damage, speed) { | ||
this.manager = manager; | ||
- this.column = column; | ||
- this.row = row; | ||
-} | ||
- | ||
-Pea.prototype.update = function() { | ||
- | ||
- this.sprite.x += this.movement_speed * game.time.elapsed; | ||
- | ||
-}; | ||
+ this.damage = damage; | ||
+ | ||
+ this.sprite = game.add.sprite(sprite_x, sprite_y, 'plants'); | ||
+ this.sprite.width = 64; | ||
+ this.sprite.height = 64; | ||
+ | ||
+ this.sprite.animations.add('idle', ['pea'], 2, true, false); | ||
+ this.sprite.animations.play('idle', 2, true); | ||
+ | ||
+ game.physics.arcade.enable(this.sprite); | ||
+ this.sprite.body.velocity.x = speed; | ||
+ this.sprite.body.width = 16; | ||
+ | ||
+ this.sprite.anchor.setTo(0.5, 0); | ||
+} |
64
js/campers/Zomper.js
@@ -1,18 +1,70 @@ | ||
function Zomper(manager, row, sprite_y) { | ||
+ // How many times we have to be hit before we go down | ||
+ this.maxHealth = 2; | ||
+ this.health = 2; | ||
this.manager = manager; | ||
- | ||
this.row = row; | ||
+ this.damage = 1; | ||
+ this.speed = 100; | ||
- this.movement_speed = 0.05; | ||
- this.health = 100; | ||
this.sprite = game.add.sprite(800, sprite_y, 'zombie'); | ||
- this.sprite.scale.x = -1; | ||
- | ||
+ this.sprite.smoothed = false; | ||
+ this.sprite.width = 64; | ||
+ this.sprite.height = 64; | ||
+ | ||
+ this.sprite.animations.add('idle', ['zombie_1', 'zombie_2'], 2, true, false); | ||
+ this.sprite.animations.add('hurt', ['zombie_3'], 2, true, false); | ||
+ this.sprite.animations.add('hit', ['zombie_0'], 2, true, false); | ||
+ this.sprite.animations.add('recoil', ['zombie_1'], 2, true, false); | ||
+ this.sprite.animations.play('idle', 2, true); | ||
+ | ||
+ game.physics.arcade.enable(this.sprite); | ||
+ this.sprite.body.velocity.x = -this.speed; | ||
+ | ||
+ this.sprite.anchor.setTo(0.5, 0); | ||
} | ||
+Zomper.prototype.hit = function(damage) { | ||
+ | ||
+ this.sprite.animations.play('hurt', 2, false); | ||
+ this.health -= damage; | ||
+ | ||
+ this.sprite.body.velocity.x += 175; | ||
+ | ||
+ if (this.health <= 0) { | ||
+ this.die = true; | ||
+ } | ||
+}; | ||
+ | ||
Zomper.prototype.update = function() { | ||
+ | ||
+ if(this.sprite.body.velocity.x < -this.speed) this.sprite.body.velocity.x = -this.speed; | ||
+ | ||
+ if(this.sprite.body.velocity.x > -this.speed) this.sprite.body.velocity.x -= 2; | ||
+ | ||
+ var time_since = game.time.now - this.time_since_cooldown; | ||
+ | ||
+ var plant = this.manager.getClosestPlant(this.sprite.x); | ||
+ | ||
+ // if theres a plant in this row and its 10 pixels away | ||
+ if(plant != null && Phaser.Math.difference(plant.sprite.x, this.sprite.x) < 10) { | ||
- this.sprite.x -= this.movement_speed * game.time.elapsed; | ||
+ var currentAnim = this.sprite.animations.currentAnim; | ||
+ if(currentAnim.name == 'idle' && time_since >= this.cooldown) { | ||
+ this.sprite.animations.play('hit', 4, false); | ||
+ } | ||
+ else if(currentAnim.isFinished && currentAnim.name == 'hit'){ | ||
+ plant.hit(1); | ||
+ this.sprite.animations.play('recoil', 2, false); | ||
+ } | ||
+ else if(currentAnim.isFinished && currentAnim.name == 'recoil'){ | ||
+ this.time_since_cooldown = game.time.now; | ||
+ this.sprite.animations.play('idle', 2, true); | ||
+ } | ||
+ } | ||
+ else { | ||
+ this.sprite.animations.play('idle', 2, true); | ||
+ } | ||
}; |
111
js/main.js
36
js/plants/Peashooter.js
85
js/vector.js
@@ -0,0 +1,85 @@ | ||
+// Initializes the vector with x and y as its coordinates | ||
+function Vector(x, y) { | ||
+ 'use strict'; | ||
+ this.x = x; | ||
+ this.y = y; | ||
+} | ||
+ | ||
+// Returns the magnitude or length of the vector. | ||
+Vector.prototype.magnitude = function () { | ||
+ 'use strict'; | ||
+ return Math.sqrt(this.x * this.x + this.y * this.y); | ||
+} | ||
+ | ||
+// Returns the square magnitude. Usefull when comparing lenghts of vectors, | ||
+// as comparing magnitudes is slower, and comparing square magnitudes has the | ||
+// same result. | ||
+Vector.prototype.squareMagnitude = function () { | ||
+ 'use strict'; | ||
+ return Math.sqrt(this.x * this.x + this.y * this.y); | ||
+} | ||
+ | ||
+// Returns this vector with a magnitude of 1. | ||
+Vector.prototype.normalized = function () { | ||
+ 'use strict'; | ||
+ return new Vector(this.x / this.magnitude(), this.y / this.magnitude()); | ||
+} | ||
+ | ||
+// Gives this vector a magnitude of 1 | ||
+Vector.prototype.normalize = function () { | ||
+ 'use strict'; | ||
+ this.x /= this.magnitude(); | ||
+ this.y /= this.magnitude(); | ||
+} | ||
+ | ||
+// Dot product of two vectors | ||
+function dot (a, b) { | ||
+ 'use strict'; | ||
+ if (a instanceof Vector && b instanceof Vector) { | ||
+ return a.x * b.x + a.y * b.y | ||
+ } | ||
+ | ||
+ return undefined; | ||
+} | ||
+ | ||
+// Adds two vectors together, component wise. | ||
+function add (a, b) { | ||
+ 'use strict'; | ||
+ if (a instanceof Vector && b instanceof Vector) { | ||
+ return new Vector(a.x + b.x, a.y + b.y); | ||
+ } | ||
+ | ||
+ return undefined | ||
+} | ||
+ | ||
+// Subtracts two vectors, component wise. | ||
+function subtract (a, b) { | ||
+ 'use strict'; | ||
+ if (a instanceof Vector && b instanceof Vector) { | ||
+ return new Vector(a.x - b.x, a.y - b.y); | ||
+ } | ||
+ | ||
+ return undefined; | ||
+} | ||
+ | ||
+// Scalar multiplication of two vectors, | ||
+function multiply (a, b) { | ||
+ 'use strict'; | ||
+ if (a instanceof Vector && b instanceof Vector) { | ||
+ return new Vector(a.x * b.x, a.y * b.y); | ||
+ } | ||
+ | ||
+ return undefined; | ||
+} | ||
+ | ||
+// Divides two vectors. | ||
+function divide (a, b) { | ||
+ 'use strict'; | ||
+ if (a instanceof Vector && b instanceof Vector) { | ||
+ return new Vector(a.x / b.x, a.y / b.y); | ||
+ } | ||
+ | ||
+ return undefined; | ||
+} | ||
+ | ||
+// TODO: distance calculation function |
9
server.js
@@ -0,0 +1,9 @@ | ||
+var express = require("express"); | ||
+var app = express(); | ||
+var fs = require('fs'); | ||
+ | ||
+// serve static files from the public directory | ||
+app.use(express.static(__dirname + '/')); | ||
+ | ||
+// bind the server to the port that c9 gives us | ||
+app.listen(process.env.PORT); |
0 comments on commit
b95d678