Skip to content

Commit

Permalink
yup
Browse files Browse the repository at this point in the history
  • Loading branch information
severest committed Nov 19, 2012
1 parent 01357bb commit 565f486
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_STORE
.DS_STORE
imgs/.DS_Store
29 changes: 21 additions & 8 deletions components.js
Original file line number Diff line number Diff line change
@@ -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();
});
}
Expand Down Expand Up @@ -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();
}
});
}
});
Expand Down
30 changes: 26 additions & 4 deletions game.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ STAGE_HEIGHT = 600;

CLOUD_NUM = 6;

SKY_BG_SPEED = 0.5;

window.onload = function () {


Expand All @@ -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")
Expand All @@ -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 })
Expand All @@ -47,6 +48,8 @@ window.onload = function () {
.bind('Click', function () {
Crafty.scene("main");
});

sky();
generateClouds();

});
Expand All @@ -61,6 +64,7 @@ window.onload = function () {

//MAIN GAME
Crafty.scene("main", function () {
sky();
generateClouds();

forky = Crafty.e("Forky, ForkyBase");
Expand All @@ -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;
Expand Down
Binary file added imgs/sky_bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/striped_bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 565f486

Please sign in to comment.