Permalink
Browse files

yup

  • Loading branch information...
severest committed Nov 19, 2012
1 parent 01357bb commit 565f4863eb87113d8430d9fd18440e9a1ed7593e
Showing with 51 additions and 15 deletions.
  1. +2 −1 .gitignore
  2. +21 −8 components.js
  3. +26 −4 game.js
  4. BIN imgs/sky_bg.png
  5. BIN imgs/striped_bg.png
  6. +2 −2 index.html
View
@@ -1 +1,2 @@
-.DS_STORE
+.DS_STORE
+imgs/.DS_Store
View
@@ -1,15 +1,20 @@
-// PROJECTILES
-Crafty.c("HurtForky" , {
- init: function () {
- this.requires("Collision")
- .onHit("Forky", function() {
- Crafty.e("2D, DOM, fireball, SpriteAnimation")
- .attr({x: this.x-50, y: this.y-50, z: 10})
+function createFireball(x,y) {
+ Crafty.e("2D, DOM, fireball, SpriteAnimation")
+ .attr({x: x, y: y, z: 10})
.animate("boom", 0, 0, 7)
.animate("boom", 20, 0)
.bind("AnimationEnd", function(reelId) {
this.destroy();
});
+}
+
+
+// PROJECTILES
+Crafty.c("HurtForky" , {
+ init: function () {
+ this.requires("Collision")
+ .onHit("Forky", function() {
+ createFireball(this.x-50, this.y-50);
this.destroy();
});
}
@@ -63,9 +68,17 @@ Crafty.c("LockingMissles", {
// ENEMIES
Crafty.c("EnemyBase", {
init: function () {
+ this.health = 100;
this.requires("Collision")
.onHit("ForkyBullet", function () {
- console.log("hithit");
+ var fork = this.hit('ForkyBullet')[0].obj;
+ createFireball(fork.x-25,fork.y-25);
+ //destroy fork bullet
+ fork.destroy()
+ this.health -= 50;
+ if (this.health < 0) {
+ this.destroy();
+ }
});
}
});
View
30 game.js
@@ -3,6 +3,8 @@ STAGE_HEIGHT = 600;
CLOUD_NUM = 6;
+SKY_BG_SPEED = 0.5;
+
window.onload = function () {
@@ -21,11 +23,10 @@ window.onload = function () {
Crafty.load(["imgs/bullet.png","imgs/cloud1.png",
"imgs/forky_ss.png", "imgs/burger_sheet.png", "imgs/main_title.png","imgs/play_button.png",
"imgs/fireball.png", "imgs/minifork.png", "imgs/bacon2.png", "imgs/peppermint.png",
- "imgs/onion_ss.png", "imgs/egg_ss.png"], function () {
+ "imgs/onion_ss.png", "imgs/egg_ss.png", "imgs/sky_bg.png"], function () {
Crafty.scene("title"); //when everything is loaded, run the main scene
});
- //black background with some loading text
Crafty.background("#a3e2ff");
Crafty.e("2D, DOM, Text").attr({ w: 700, h: 20, x: 0, y: 350 })
.text("Loading")
@@ -38,7 +39,7 @@ window.onload = function () {
//TITLE SCENE
Crafty.scene("title", function () {
- Crafty.e("2D, DOM, Image, Tween").attr({ x: -300, y: -300 }).image("imgs/main_title.png")
+ Crafty.e("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,6 +48,8 @@ window.onload = function () {
.bind('Click', function () {
Crafty.scene("main");
});
+
+ sky();
generateClouds();
});
@@ -61,6 +64,7 @@ window.onload = function () {
//MAIN GAME
Crafty.scene("main", function () {
+ sky();
generateClouds();
forky = Crafty.e("Forky, ForkyBase");
@@ -77,11 +81,29 @@ window.onload = function () {
/*****************
Helper functions
*****************/
+ function sky() {
+ Crafty.e("2D, DOM, Image")
+ .attr({x:0, y:0, z:0})
+ .image("imgs/sky_bg.png")
+ .bind("EnterFrame", function() {
+ this.y += SKY_BG_SPEED;
+ if (this.y > STAGE_HEIGHT)
+ this.y = -639;
+ });
+ Crafty.e("2D, DOM, Image")
+ .attr({x:0, y:-647, z:0})
+ .image("imgs/sky_bg.png")
+ .bind("EnterFrame", function() {
+ this.y += SKY_BG_SPEED;
+ if (this.y > STAGE_HEIGHT)
+ this.y = -639;
+ });
+ }
function generateClouds() {
for (var cloud=0; cloud < CLOUD_NUM; cloud++) {
Crafty.e("2D, DOM, Image")
- .attr({ x: Crafty.math.randomInt(-50, STAGE_WIDTH+50), y: Crafty.math.randomInt(-300, -50), z: 1 })
+ .attr({ x: Crafty.math.randomInt(-50, STAGE_WIDTH+50), y: Crafty.math.randomInt(-300, -50), z: 2 })
.image("imgs/cloud1.png")
.bind('EnterFrame', function () {
this.y += 2;
View
Binary file not shown.
View
Binary file not shown.
View
@@ -9,11 +9,11 @@
<title>Forky's Revenge</title>
<style>
body, html { font-family:Arial; font-size:14px; color: white;
- background:url('imgs/generator.png');
- background-color: black;
+ background:url('imgs/striped_bg.png'); /*
background-repeat:no-repeat;
background-attachment:fixed;
background-position:top-left;
+ */
}
#cr-stage {
height: 600px;

0 comments on commit 565f486

Please sign in to comment.