Permalink
Browse files

jojos

  • Loading branch information...
1 parent e5d6180 commit 12a3703310a68807b60f76da000b6486f8e7e101 @severest severest committed Nov 25, 2012
Showing with 71 additions and 27 deletions.
  1. +14 −15 components.js
  2. +57 −12 game.js
View
@@ -68,6 +68,8 @@ Crafty.c("LockingMissles", {
// ENEMIES
Crafty.c("EnemyBase", {
init: function () {
+ enemiesAlive++;
+
this.health = 100;
this.requires("Collision")
.onHit("ForkyBullet", function () {
@@ -77,29 +79,32 @@ Crafty.c("EnemyBase", {
fork.destroy()
this.health -= 50;
if (this.health < 0) {
+ enemiesAlive--;
this.destroy();
gameScore += 100;
}
+ })
+ .onHit("Forky", function() {
+ console.log("ouch, bullet");
+ });
+
+ this.requires("2D").requires("DOM")
+ .bind('EnterFrame' , function () {
+ if (this.y > STAGE_HEIGHT) {
+ this.destroy();
+ }
});
}
});
Crafty.c("SimpleEnemy", {
init: function () {
this.requires("RealDelay");
this.realDelay(this.fireWeapon, 1000);
- this.requires("Collision")
- .onHit("Forky", function() {
- console.log("ouch, bullet");
- });
},
setSpeed: function(speed) {
this.bind('EnterFrame', function () {
this.y += speed;
-
- if (this.y > STAGE_HEIGHT) {
- this.destroy();
- }
});
return this;
},
@@ -119,12 +124,6 @@ Crafty.c("RandomMover", {
this.realDelay(this.nextLocation, 1000);
- // kill Forky on hit
- this.requires("Collision")
- .onHit("Forky", function() {
- console.log("ouch, bullet");
- });
-
// fire bullets 100 ms after moving to new position
this.bind("TweenEnd", function () {
this.realDelay(this.fireWeapon, 100);
@@ -166,7 +165,7 @@ Crafty.c("ForkyBase", {
bulletSpeed: 3,
init: function () {
this.canFire = true;
- this.fireTimeout = 200;
+ this.fireTimeout = 50;
this.requires("2D").requires("DOM").requires("forkysprite").requires("SpriteAnimation").requires("OnJetpack").requires("Keyboard").requires("RealDelay")
.attr({ x: 580, y: 100, z: 2})
View
69 game.js
@@ -11,6 +11,20 @@ window.onload = function () {
Crafty.init(STAGE_WIDTH, STAGE_HEIGHT);
//Crafty.canvas.init();
+
+ Crafty.sprite(76, 173, "imgs/forky_ss.png", {forkysprite:[0,0]});
+ Crafty.sprite(20, 80, "imgs/bacon2.png", {firebacon:[0,0]});
+ Crafty.sprite(120, "imgs/burger_sheet.png", {burg:[0,0]});
+ Crafty.sprite(100,91, "imgs/egg_ss.png", {egg:[0,0]});
+ Crafty.sprite(120,107, "imgs/onion_ss.png", {onion:[0,0]});
+ Crafty.sprite(100, "imgs/fireball.png", {fireball:[0,0]});
+ Crafty.sprite(39,36, "imgs/peppermint.png", {peppermint:[0,0]});
+
+
+
+
+
+
//LOADING SCENE
//the loading screen that will display while our assets load
Crafty.scene("loading", function () {
@@ -34,7 +48,7 @@ window.onload = function () {
//TITLE SCENE
Crafty.scene("title", function () {
- Crafty.e("2D, DOM, Image, Tween").attr({ x: -300, y: -300, z: 2}).image("imgs/main_title.png")
+ Crafty.e("Title, 2D, DOM, Image, Tween").attr({ x: -300, y: -300, z: 2}).image("imgs/main_title.png")
.tween({x:20, y:20}, 80);
Crafty.e("2D, DOM, Image, Mouse").attr({ x: 0, y: 350, z:10 })
@@ -47,24 +61,24 @@ window.onload = function () {
this.image("imgs/play_button.png");
})
.bind('Click', function () {
- Crafty.scene("main");
+ this.destroy();
+ Crafty("Title").destroy();
+ showInstructions();
});
sky();
generateClouds();
});
- Crafty.sprite(76, 173, "imgs/forky_ss.png", {forkysprite:[0,0]});
- Crafty.sprite(20, 80, "imgs/bacon2.png", {firebacon:[0,0]});
- Crafty.sprite(120, "imgs/burger_sheet.png", {burg:[0,0]});
- Crafty.sprite(100,91, "imgs/egg_ss.png", {egg:[0,0]});
- Crafty.sprite(120,107, "imgs/onion_ss.png", {onion:[0,0]});
- Crafty.sprite(100, "imgs/fireball.png", {fireball:[0,0]});
- Crafty.sprite(39,36, "imgs/peppermint.png", {peppermint:[0,0]});
+
//MAIN GAME
Crafty.scene("main", function () {
+ difficultyLvl = 0;
+ waveNum = 1;
+ enemiesAlive = 0;
+
sky();
generateClouds();
@@ -75,12 +89,13 @@ window.onload = function () {
powerUpGen = Crafty.e("PowerupFactory, RealDelay");
powerUpGen.realDelay(spawnPowerup, Crafty.math.randomInt(1000,5000));
-
+
+ // HUD
gameScore = 0;
gameScoreTxt = 0;
- scoreTxt = Crafty.e("Score, 2D, DOM, Text").attr({x: 10, y: STAGE_HEIGHT-50, w: 300, z:20})
- .textFont({family: 'Impact', size: '24px'})
+ scoreTxt = Crafty.e("Score, 2D, DOM, Text").attr({x: 10, y: STAGE_HEIGHT-40, w: 300, z:20})
.textColor('#000000')
+ .text("Score: 0")
.bind("EnterFrame", function () {
if (gameScore > gameScoreTxt) {
if (gameScore - gameScoreTxt > 10)
@@ -91,10 +106,27 @@ window.onload = function () {
this.text("Score: " + gameScoreTxt);
}
});
+ cornerLevelTxt = Crafty.e("cornerLevel, 2D, DOM, Text").attr({x: 10, y: 10, w: 300, z:20})
+ .textColor('#000000')
+ .css({"font-size": '10px'});
+
+ upgradeDiffcultyLvl();
});
};
+function upgradeDiffcultyLvl() {
+ difficultyLvl++;
+ cornerLevelTxt.text("Level " + difficultyLvl);
+ Crafty.e("2D, DOM, Text, Tween").attr({x: STAGE_WIDTH/2, y: STAGE_HEIGHT/2, w: 500, z:20})
+ .css({"font-size": '64px',"color":"#fff", "text-shadow":"2px 2px 20px black"})
+ .text("Level "+difficultyLvl)
+ .tween({alpha: 0}, 150)
+ .bind("TweenEnd", function () {
+ this.destroy();
+ });
+}
+
/*****************
Helper functions
*****************/
@@ -132,6 +164,19 @@ function generateClouds() {
}
}
+function showInstructions() {
+ Crafty.e("2D, DOM, Text, Keyboard").attr({x: 0, y: STAGE_HEIGHT/2, w: STAGE_WIDTH, z:20})
+ .textFont({family: 'Impact', size: '24px'})
+ .css({"text-align:": "center" })
+ .textColor('#000000')
+ .text("Move = Arrows, Shoot = Space")
+ .bind('EnterFrame', function () {
+ if (this.isDown("SPACE"))
+ Crafty.scene("main");
+ });
+
+}
+
function spawnSimpleEnemy() {
Crafty.e("Enemy, 2D, DOM, onion, SpriteAnimation, EnemyBase, SimpleEnemy")
.attr({ x: Crafty.math.randomInt(20, STAGE_WIDTH), y: -50, z: 2})

0 comments on commit 12a3703

Please sign in to comment.