Permalink
Browse files

adding background, waves and boat

  • Loading branch information...
luizgustavolino committed Nov 19, 2012
1 parent 5785dfe commit 1c503554af80074ea2effe8823d3957835938778
Showing with 871 additions and 15 deletions.
  1. +4 −1 Classes/AppDelegate.js
  2. +39 −0 Classes/Capn.js
  3. +34 −9 Classes/GameScene.js
  4. +18 −1 Classes/PirateMutiny.js
  5. +44 −0 Classes/SpriteUtils.js
  6. +144 −0 Classes/World.js
  7. +566 −0 Resources/pm.plist
  8. BIN Resources/pm.png
  9. +7 −4 cocos2d.js
  10. +15 −0 server.py
View
@@ -13,7 +13,10 @@ cc.AppDelegate = cc.Application.extend({
var director = cc.Director.sharedDirector();
director.setDisplayFPS(false);
- director.setAnimationInterval(1.0 / 60);
+ director.setAnimationInterval(1.0/32.0);
+
+ var spriteCache = cc.SpriteFrameCache.sharedSpriteFrameCache();
+ spriteCache.addSpriteFramesWithFile("Resources/pm.plist", "Resources/pm.png");
var scene = GameScene.scene();
director.runWithScene(scene);
View
@@ -0,0 +1,39 @@
+var Capn = cc.Sprite.extend({
+
+ init: function(){
+ this._super();
+
+ // IDLE ANIMATION
+ var animFrames = [];
+ var str = "";
+ for (var i = 1; i < 5; i++) {
+ str = "capn_idle" + (i < 10 ? ("0" + i) : i) + ".png";
+ var frame = cc.SpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(str);
+ animFrames.push(frame);
+ }
+ var animation = cc.Animation.create(animFrames, 0.15);
+ cc.AnimationCache.sharedAnimationCache().addAnimation(animation, "capnIdle");
+
+ // RUN ANIMATION
+ var animCache = cc.AnimationCache.sharedAnimationCache();
+ var idle_anm = animCache.animationByName("capnIdle");
+ var animN = cc.Animate.create(idle_anm);
+ var repeat = cc.RepeatForever.create(animN);
+ this.runAction(repeat);
+
+ this.scheduleUpdate();
+
+ },
+
+ update:function(dt){
+
+ }
+
+});
+
+Capn.spriteWithSpriteFrameName = function (spriteFrameName) {
+ var pFrame = cc.SpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(spriteFrameName);
+ var sprite = new Capn();
+ sprite.initWithSpriteFrame(pFrame);
+ return sprite;
+};
View
@@ -1,31 +1,56 @@
var GameScene = cc.Layer.extend({
- helloLabel:null,
-
+ waves: null,
+ wavesBG: null,
+ sky: null,
+ boat: null,
init:function () {
this._super();
var size = cc.Director.sharedDirector().getWinSize();
- this.helloLabel = cc.LabelTTF.create("Game layarrr!", "Arial", 28);
- this.helloLabel.setPosition(cc.ccp(size.width / 2, size.height - 40));
- this.addChild(this.helloLabel);
+
+ this.sky = new Sky();
+ this.sky.setPosition(cc.ccp(0, 30));
+ this.addChild(this.sky);
+
+ this.wavesBG = new WaterBG();
+ this.wavesBG.setPosition(cc.ccp(0, -12));
+ this.addChild(this.wavesBG);
+
+ this.boat = new Boat();
+ this.boat.setPosition(cc.ccp(0,0));
+ this.addChild(this.boat);
+
+ var upDownAction = cc.RepeatForever.create(
+ cc.Sequence.create(
+ cc.EaseOut.create(cc.MoveBy.create(.92, cc.ccp(0,10)),1.2),
+ cc.EaseOut.create(cc.MoveBy.create(.92, cc.ccp(0,-10)),1.2)
+ ));
+ this.boat.runAction(upDownAction);
+
+ this.waves = new Water();
+ this.waves.setPosition(cc.ccp(0, 0));
+ this.addChild(this.waves);
this.schedule(this.update);
return true;
-
},
update:function(dt){
- dpad.update();
- if(dpad.keys.up.state == dpad.stateKeyDown){
- console.log("Up Down!");
+
+ if(dpad.keys.left.state == dpad.stateKeyPressed){
+ this.boat.capn.setPosition(cc.ccp(this.boat.capn._position.x-1,this.boat.capn._position.y));
+ }else if(dpad.keys.right.state == dpad.stateKeyPressed){
+ this.boat.capn.setPosition(cc.ccp(this.boat.capn._position.x+1,this.boat.capn._position.y));
}
+
+ dpad.update();
}
});
View
@@ -1,2 +1,19 @@
-var PM = PM || {};
+var PM = PM || {};
+
+PM.PLAYER_STATE = {
+ WAITING:0,
+ WALK_LEFT:1,
+ WALK_RIGHT:2,
+ JUMP:3,
+ LOWER:4,
+ HIT:5,
+ DEAD:6
+}
+
+PM.GAME_SCENE = {
+ MENU:0,
+ GAME:1,
+ RESULTS:2,
+ HISCORE:3
+}
View
@@ -0,0 +1,44 @@
+var RepeatXSprite = cc.Node.extend({
+
+ build: function(refImageName, tileFunc){
+
+ var spriteRef = cc.SpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(refImageName);
+
+ var tileW = spriteRef._rect.size.width;
+ var totalW = this._contentSize.width;
+ var count = Math.ceil(totalW/tileW);
+
+ for(var i = 0; i < count; i++){
+ var aTile = new tileFunc.spriteWithSpriteFrameName(refImageName);
+ aTile.setAnchorPoint(cc.ccp(0,0));
+ aTile.setPosition(cc.ccp(i*tileW,0));
+ this.addChild(aTile);
+ }
+
+ }
+
+});
+
+
+var setupSpriteAnimation = function(imageName, frames){
+
+ var animFrames = [];
+ var str = "";
+ for (var i = 1; i <= frames; i++) {
+ str = imageName + (i < 10 ? ("0" + i) : i) + ".png";
+ var frame = cc.SpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(str);
+ animFrames.push(frame);
+ }
+
+ var animation = cc.Animation.create(animFrames, 0.15);
+ cc.AnimationCache.sharedAnimationCache().addAnimation(animation, imageName);
+
+ // RUN ANIMATION
+ var animCache = cc.AnimationCache.sharedAnimationCache();
+ var idle_anm = animCache.animationByName(imageName);
+ var animN = cc.Animate.create(idle_anm);
+ var repeat = cc.RepeatForever.create(animN);
+ return repeat;
+
+};
+
View
@@ -0,0 +1,144 @@
+// BOAT
+
+var Boat = function(){
+
+ var node = new cc.Node();
+ var size = cc.Director.sharedDirector().getWinSize();
+
+ // BOAT
+ var boatFrame = cc.SpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName("boat01.png");
+ var boatSprite = new cc.Sprite();
+ boatSprite.initWithSpriteFrame(boatFrame);
+ boatSprite.setPosition(cc.ccp(0,0));
+ boatSprite.setAnchorPoint(cc.ccp(0, 0));
+ node.addChild(boatSprite);
+
+ // SAIL
+ var sail = new Sail();
+ sail.setAnchorPoint(cc.ccp(0, 1));
+ sail.setPosition(cc.ccp(0, size.height));
+ node.addChild(sail);
+
+ // CAPN
+ var capn = Capn.spriteWithSpriteFrameName("capn_idle01.png");
+ capn.setAnchorPoint(cc.ccp(0, 0));
+ capn.setPosition(cc.ccp(280, 202));
+ node.addChild(capn);
+
+ // PLANK
+ var plankFrame = cc.SpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName("plank01.png");
+ var plankSprite = new cc.Sprite();
+ plankSprite.initWithSpriteFrame(plankFrame);
+ plankSprite.setPosition(cc.ccp(-90,188));
+ plankSprite.setAnchorPoint(cc.ccp(0, 0));
+ node.addChild(plankSprite);
+
+
+ // REFERENCES
+ node.capn = capn;
+ node.sail = sail;
+ node.boat = boatSprite;
+
+ return node;
+}
+
+// SAIL
+var Sail = function(){
+ var pFrame = cc.SpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName("sail01.png");
+ var sprite = new SailSprite();
+ sprite.initWithSpriteFrame(pFrame);
+ return sprite;
+}
+
+SailSprite = cc.Sprite.extend({
+ init: function(){
+ this._super();
+ var animationAction = setupSpriteAnimation("sail", 4);
+ this.runAction(animationAction);
+ }
+});
+
+// SKY
+
+var Sky = function(){
+
+ var size = cc.Director.sharedDirector().getWinSize();
+
+ var sky = new RepeatXSprite();
+ sky.setContentSize(cc.SizeMake(size.width, 450));
+ sky.setAnchorPoint(cc.ccp(0, 0));
+ sky.build("background_sky.png", SkyTile);
+
+ return sky;
+}
+
+var SkyTile = cc.Sprite.extend({
+
+});
+
+SkyTile.spriteWithSpriteFrameName = function (spriteFrameName) {
+ var pFrame = cc.SpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(spriteFrameName);
+ var sprite = new SkyTile();
+ sprite.initWithSpriteFrame(pFrame);
+ return sprite;
+};
+
+
+// FOREGROUND WAVES
+
+var Water = function(){
+
+ var size = cc.Director.sharedDirector().getWinSize();
+
+ var waves = new RepeatXSprite();
+ waves.setContentSize(cc.SizeMake(size.width, 32));
+ waves.setAnchorPoint(cc.ccp(0, 0));
+ waves.build("waterwave01.png", WaterTile);
+
+ return waves;
+}
+
+var WaterTile = cc.Sprite.extend({
+ init: function(){
+ this._super();
+ var animationAction = setupSpriteAnimation("waterwave", 4);
+ this.runAction(animationAction);
+ }
+});
+
+WaterTile.spriteWithSpriteFrameName = function (spriteFrameName) {
+ var pFrame = cc.SpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(spriteFrameName);
+ var sprite = new WaterTile();
+ sprite.initWithSpriteFrame(pFrame);
+ return sprite;
+};
+
+
+// BACKGROUND WAVES
+
+var WaterBG = function(){
+
+ var size = cc.Director.sharedDirector().getWinSize();
+
+ var waves = new RepeatXSprite();
+ waves.setContentSize(cc.SizeMake(size.width, 68));
+ waves.setAnchorPoint(cc.ccp(0, 0));
+ waves.build("background_wave01.png", WaterTileBG);
+
+ return waves;
+}
+
+var WaterTileBG = cc.Sprite.extend({
+ init: function(){
+ this._super();
+ var animationAction = setupSpriteAnimation("background_wave", 6);
+ this.runAction(animationAction);
+ }
+});
+
+WaterTileBG.spriteWithSpriteFrameName = function (spriteFrameName) {
+ var pFrame = cc.SpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(spriteFrameName);
+ var sprite = new WaterTileBG();
+ sprite.initWithSpriteFrame(pFrame);
+ return sprite;
+};
Oops, something went wrong.

0 comments on commit 1c50355

Please sign in to comment.