Permalink
Browse files

RAINBOWSS

  • Loading branch information...
1 parent 36a687a commit bea636251f67509185db60a9c1a10450f96398fc @severest severest committed Dec 1, 2012
Showing with 169 additions and 50 deletions.
  1. +79 −34 components.js
  2. +90 −16 game.js
  3. BIN imgs/rainbow_starburst.png
View
@@ -51,10 +51,11 @@ Crafty.c("LockingMissles", {
else
this.speedX -= this.sluggishSpeed;
- if (forky.attr('y') > this.y)
- this.speedY += this.sluggishSpeed;
- else
- this.speedY -= this.sluggishSpeed;
+ // bullets won't come back from bottom of screen
+ // if (forky.attr('y') > this.y)
+// this.speedY += this.sluggishSpeed;
+// else
+// this.speedY -= this.sluggishSpeed;
if (this.speedX > this.maxSpeed)
this.speedX = this.maxSpeed;
@@ -84,7 +85,7 @@ Crafty.c("EnemyBase", {
createFireball(fork.x-25,fork.y-25);
//destroy fork bullet
fork.destroy()
- this.health -= 50;
+ this.health -= forkDamage;
if (this.health <= 0) {
enemiesAlive--;
this.animate("death",50,0);
@@ -112,7 +113,7 @@ Crafty.c("SimpleEnemy", {
init: function () {
this.requires("EnemyBase");
this.requires("RealDelay");
- this.realDelay(this.fireWeapon, 1000);
+ this.realDelay(this.fireWeapon, 3000);
this.scoreForKill = 100;
},
@@ -131,10 +132,61 @@ Crafty.c("SimpleEnemy", {
.attr({ x: this.x+(this.w/2), y: this.y+(this.h/2), z: 4, rotation: Crafty.math.randomInt(0, 360)})
.setSpeed(0,5,Crafty.math.randomInt(1, 5))
.origin("center");
+ this.realDelay(this.fireWeapon, 3000);
+ }
+});
+Crafty.c("MediumEnemy", {
+ init: function () {
+ this.requires("EnemyBase");
+ this.requires("RealDelay");
+ this.realDelay(this.blink, Crafty.math.randomInt(3000, 5000));
+
+ this.scoreForKill = 200;
+ },
+ setSpeed: function(speed) {
+ this.bind('EnterFrame', function () {
+ this.y += speed;
+ });
+ return this;
+ },
+ blink: function () {
+ this.animate("blink", 30, 0);
+ this.bind("AnimationEnd", function() {
+ this.animate("idle", 30, 0);
+ });
+ this.realDelay(this.blink, Crafty.math.randomInt(3000, 5000));
+ }
+
+});
+Crafty.c("HardEnemy", {
+ init: function () {
+ this.requires("EnemyBase");
+ this.requires("RealDelay");
+ this.realDelay(this.fireWeapon, 1000);
+
+ this.scoreForKill = 300;
+
+ this.yStop = Crafty.math.randomInt(50, STAGE_HEIGHT/2-100);
+ },
+
+ setSpeed: function(speed) {
+ this.bind('EnterFrame', function () {
+ if (this.y < this.yStop)
+ this.y += speed;
+ });
+ return this;
+ },
+
+ fireWeapon: function() {
+ Crafty.e("Bullet, 2D, DOM, Image, StraightBullets, HurtForky")
+ .image("imgs/icecube.png")
+ .attr({ x: this.x+(this.w/2), y: this.y+(this.h/2), z: 4, rotation: Crafty.math.randomInt(0, 360)})
+ .setSpeed(0,5,Crafty.math.randomInt(1, 5))
+ .origin("center");
this.realDelay(this.fireWeapon, 1000);
}
});
-Crafty.c("RandomMover", {
+Crafty.c("Boss", {
init: function () {
this.requires("RealDelay");
this.requires("Tween");
@@ -145,10 +197,13 @@ Crafty.c("RandomMover", {
this.bind("TweenEnd", function () {
this.realDelay(this.fireWeapon, 100);
});
+
+ this.requires("EnemyBase");
+ this.scoreForKill = 1000;
},
nextLocation: function() {
- this.tween({x: Crafty.math.randomInt(10, STAGE_WIDTH), y: Crafty.math.randomInt(10, STAGE_HEIGHT/2)}, 40);
+ this.tween({x: Crafty.math.randomInt(50, STAGE_WIDTH), y: Crafty.math.randomInt(10, STAGE_HEIGHT/2-100)}, 40);
this.realDelay(this.nextLocation, 3000);
},
@@ -157,19 +212,16 @@ Crafty.c("RandomMover", {
Crafty.e("Bullet, 2D, DOM, firebacon, SpriteAnimation, LockingMissles")
.attr({ x: this.x, y: this.y, z: 4})
.animate("baconani", 0, 0, 3)
- .animate("baconani", 3, 0, 0)
.animate("baconani", 20, -1)
.setSpeed(0,5);
Crafty.e("Bullet, 2D, DOM, firebacon, SpriteAnimation, LockingMissles")
.attr({ x: this.x, y: this.y, z: 4})
.animate("baconani", 0, 0, 3)
- .animate("baconani", 3, 0, 0)
.animate("baconani", 20, -1)
.setSpeed(2,5);
Crafty.e("Bullet, 2D, DOM, firebacon, SpriteAnimation, LockingMissles")
.attr({ x: this.x, y: this.y, z: 4})
.animate("baconani", 0, 0, 3)
- .animate("baconani", 3, 0, 0)
.animate("baconani", 20, -1)
.setSpeed(-2,5);
}
@@ -182,23 +234,26 @@ Crafty.c("ForkyBase", {
bulletSpeed: 3,
init: function () {
this.canFire = true;
- this.fireTimeout = 50;
+ this.fireTimeout = 200;
- this.requires("2D").requires("DOM").requires("forkysprite").requires("SpriteAnimation").requires("OnJetpack").requires("Keyboard").requires("RealDelay")
- .attr({ x: 580, y: 100, z: 2})
- .animate("idle", 0, 0, 4)
- .animate("lean", 4, 0, 7)
- .animate("idle", 20, -1)
- .configMovement(0.1,10)
+ this.requires("OnJetpack").requires("Keyboard").requires("RealDelay")
.bind('EnterFrame', function () {
if (this.isDown("SPACE") && this.canFire) {
this.canFire = false;
this.realDelay(function(){this.canFire = true;},this.fireTimeout); // fire weapon timeout
this.fireBaseWeapon();
}
});
+ this.realDelay(this.blink, Crafty.math.randomInt(3000, 5000));
+
+ },
+ blink: function () {
+ this.animate("blink", 30, 0);
+ this.bind("AnimationEnd", function() {
+ this.animate("idle", 30, 0);
+ });
+ this.realDelay(this.blink, Crafty.math.randomInt(3000, 5000));
},
-
fireBaseWeapon: function() {
Crafty.e("ForkyBullet, 2D, DOM, Image, StraightBullets")
.image("imgs/minifork.png")
@@ -257,21 +312,11 @@ Crafty.c("OnJetpack", {
this.bind('EnterFrame', function () {
if (this.movingLeft) {
this.speedX -= acell;
-
- // leaning animation
- // if (!this.isPlaying("lean")) {
-// this.stop();
-// this.animate("lean",20,0);
-// }
+
}
else if (this.movingRight) {
this.speedX += acell;
- // leaning
- // if (!this.isPlaying("lean")) {
-// this.stop();
-// this.animate("lean",20,0);
-// }
}
else {
if (this.speedX < 0) {
@@ -285,10 +330,6 @@ Crafty.c("OnJetpack", {
else
this.speedX = 0;
}
- if (!this.isPlaying("idle")) {
- this.stop();
- this.animate("idle",20,-1);
- }
}
if (this.movingUp)
@@ -311,8 +352,12 @@ Crafty.c("OnJetpack", {
if (this.speedX > maxSpeed)
this.speedX = maxSpeed;
+ if (this.speedX < -maxSpeed)
+ this.speedX = -maxSpeed;
if (this.speedY > maxSpeed)
this.speedY = maxSpeed;
+ if (this.speedY < -maxSpeed)
+ this.speedY = -maxSpeed;
this.x += this.speedX;
this.y += this.speedY;
View
106 game.js
@@ -20,6 +20,7 @@ window.onload = function () {
Crafty.sprite(80,71, "imgs/onion_ss.png", {onion:[0,0]});
Crafty.sprite(100, "imgs/fireball.png", {fireball:[0,0]});
Crafty.sprite(100,82, "imgs/peppermint_glow.png", {peppermint:[0,0]});
+ Crafty.sprite(120,144, "imgs/drink.png", {drink:[0,0]});
@@ -34,7 +35,8 @@ window.onload = function () {
"imgs/forky_ss.png", "imgs/burger_sheet.png", "imgs/main_title.png","imgs/play_button.png", "imgs/play_button_on.png",
"imgs/fireball.png", "imgs/minifork.png", "imgs/bacon2.png", "imgs/peppermint.png",
"imgs/onion_ss.png", "imgs/egg_ss.png", "imgs/eggbullet.png", "imgs/sky_bg.png",
- "imgs/space_bar.png","imgs/arrow_keys.png"], function () {
+ "imgs/space_bar.png","imgs/arrow_keys.png","imgs/icecube.png","imgs/drink.png",
+ "imgs/rainbow_starburst.png"], function () {
Crafty.scene("title"); //when everything is loaded, run the main scene
});
@@ -80,13 +82,21 @@ window.onload = function () {
waveNum = 1;
enemiesAlive = 0;
+ enemiesPerWave = 2;
+ forkDamage = 100;
+
sky();
generateClouds();
- forky = Crafty.e("Forky, ForkyBase");
+ forky = Crafty.e("Forky, 2D, DOM, forkysprite, SpriteAnimation, ForkyBase")
+ .attr({ x: STAGE_WIDTH/2, y: STAGE_HEIGHT/2+50, z: 2})
+ .animate("idle", 0, 0, 0)
+ .animate("blink", 0, 0, 4)
+ .animate("idle", 20, -1)
+ .configMovement(1,10);
- simpleEnemyGen = Crafty.e("SimpleEnemyFactory, RealDelay");
- simpleEnemyGen.realDelay(spawnSimpleEnemy, Crafty.math.randomInt(200, 3000));
+ simpleEnemyGen = Crafty.e("SimpleEnemyFactory, RealDelay");
+ simpleEnemyGen.realDelay(spawnEnemies, 3000);
powerUpGen = Crafty.e("PowerupFactory, RealDelay");
powerUpGen.realDelay(spawnPowerup, Crafty.math.randomInt(1000,5000));
@@ -120,6 +130,9 @@ window.onload = function () {
function upgradeDiffcultyLvl() {
difficultyLvl++;
+ enemiesPerWave++;
+ forkDamage = forkDamage/2;
+
cornerLevelTxt.text("Level " + difficultyLvl);
Crafty.e("2D, DOM, Text, Tween").attr({x: STAGE_WIDTH/2-20, y: STAGE_HEIGHT/2, w: 500, z:20})
.css({"font-size": '64px',"color":"#fff", "text-shadow":"2px 2px 20px black"})
@@ -130,6 +143,35 @@ function upgradeDiffcultyLvl() {
});
}
+function spawnEnemies() {
+ if (enemiesAlive == 0) {
+ if (waveNum == 5) {
+ waveNum = 1;
+ upgradeDiffcultyLvl();
+ }
+ switch (waveNum) {
+ case 1:
+ for (var num=0; num < enemiesPerWave; num++)
+ spawnSimpleEnemy();
+ break;
+ case 2:
+ for (var num=0; num < enemiesPerWave; num++)
+ spawnMediumEnemy();
+ break;
+ case 3:
+ for (var num=0; num < enemiesPerWave; num++)
+ spawnHardEnemy();
+ break;
+ case 4:
+ spawnBurger();
+ break;
+ }
+ waveNum++;
+ }
+
+ simpleEnemyGen.realDelay(spawnEnemies, 1000);
+}
+
/*****************
Helper functions
*****************/
@@ -194,43 +236,75 @@ function showInstructions() {
}
function spawnSimpleEnemy() {
- Crafty.e("Enemy, 2D, DOM, egg, SpriteAnimation, EnemyBase, SimpleEnemy")
- .attr({ x: Crafty.math.randomInt(20, STAGE_WIDTH-20), y: -50, z: 2})
+ Crafty.e("Enemy, 2D, DOM, egg, SpriteAnimation, SimpleEnemy")
+ .attr({ x: Crafty.math.randomInt(20, STAGE_WIDTH-20), y: -Crafty.math.randomInt(50, 500), z: 2})
.animate("idle", 0, 0, 3)
.animate("death", 4, 0, 8)
.animate("idle", 20, -1)
- .setSpeed(1.5);
- spawnMediumEnemy();
-
- simpleEnemyGen.realDelay(spawnSimpleEnemy, Crafty.math.randomInt(200, 3000));
+ .setSpeed(0.5);
+
}
function spawnMediumEnemy() {
- Crafty.e("Enemy, 2D, DOM, onion, SpriteAnimation, EnemyBase, SimpleEnemy")
- .attr({ x: Crafty.math.randomInt(20, STAGE_WIDTH), y: -50, z: 2})
- .animate("idle", 0, 0, 4)
+ Crafty.e("Enemy, 2D, DOM, onion, SpriteAnimation, MediumEnemy")
+ .attr({ x: Crafty.math.randomInt(20, STAGE_WIDTH), y: -Crafty.math.randomInt(50, 500), z: 2})
+ .animate("idle", 4, 0, 0)
+ .animate("blink", 0, 0, 4)
.animate("death", 5, 0, 9)
.animate("idle", 30, -1)
- .setSpeed(1.5);
+ .setSpeed(0.5);
}
+function spawnHardEnemy() {
+ Crafty.e("Enemy, 2D, DOM, drink, SpriteAnimation, HardEnemy")
+ .attr({ x: Crafty.math.randomInt(20, STAGE_WIDTH-20), y: -Crafty.math.randomInt(50, 500), z: 2})
+ .animate("idle", 0, 0, 9)
+ .animate("death", 0, 0, 9)
+ .animate("idle", 70, -1)
+ .setSpeed(3);
+
+}
+
+
function spawnBurger() {
- Crafty.e("Enemy, 2D, DOM, burg, SpriteAnimation, EnemyBase, RandomMover")
+ Crafty.e("Enemy, 2D, DOM, burg, SpriteAnimation, Boss")
.attr({ x: Crafty.math.randomInt(20, STAGE_WIDTH), y: -100, z: 2})
.animate("burger", 0, 0, 22)
+ .animate("death", 0, 0, 22)
.animate("burger", 60, -1);
}
function spawnPowerup() {
- Crafty.e("Powerup, 2D, DOM, peppermint, SpriteAnimation")
+ Crafty.e("Powerup, 2D, DOM, peppermint, SpriteAnimation, Collision")
.animate("spin", 0 , 0, 13)
.animate("spin", 40, -1)
.attr({ x: Crafty.math.randomInt(20, STAGE_WIDTH-20), y: -50, z: 2})
.bind("EnterFrame", function () {
this.y += 5;
if (this.y > STAGE_HEIGHT)
this.destroy();
+ })
+ .onHit("Forky", function() {
+ rainbowStarburst();
+ this.destroy();
});
powerUpGen.realDelay(spawnPowerup, Crafty.math.randomInt(1000,5000));
}
+function rainbowStarburst() {
+ Crafty.e("2D, DOM, Tween, Image")
+ .image("imgs/rainbow_starburst.png")
+ .origin("center")
+ .attr({x: 5000, y: 5000, z: 1, alpha: 0})
+ .tween({rotation: 360, alpha: 0.8}, 40)
+ .bind("TweenEnd", function () {
+ this.tween({rotation: -270, alpha: 0}, 75);
+ this.bind("TweenEnd", function () {
+ this.destroy();
+ });
+ })
+ .bind("EnterFrame", function () {
+ this.x = forky.attr('x')-110;
+ this.y = forky.attr('y')-150;
+ });
+}
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bea6362

Please sign in to comment.