//player.h
#ifndef FirstProject_player_h
#define FirstProject_player_h
#include “define.h”
#include “cocos2d.h”
using namespace cocos2d;
class player : public CCSprite
{
public:
virtual bool init();
Movement state;
CCRect body;
float x;
int flag;
void jump(float);
void slide();
void scale(float);
void move(float,float);
void applyMovement(float);
virtual void setPosition(const CCPoint& pos);
void backToNormal();
};
#endif
//player.cpp
//
// player.cpp
// FirstProject
//
// Created by Unanimous studio on 05/02/13.
//
//
#include “player.h”
#include “SimpleAudioEngine.h”
#include “HelloWorldScene.h”
using namespace cocos2d;
using namespace CocosDenshion;
// on “init” you need to initialize your instance
bool player::init()
{
//////////////////////////////
// 1. super init first
if ( !CCSprite::init() )
{
return false;
}
return true;
// CCLOG (“player ka init”);
};
void player::jump(float a)
{
this~~>state=Jump;
CCJumpBy* jump = CCJumpBy::create;
this~~>runAction(CCSequence::create(jump,CCCallFuncN::create(this,callfuncN_selector(player::backToNormal)),NULL));
//this~~>runAction;
}
void player::slide
{
// CCLOG ("slide ");
flag=0;
x=1;
//CCLOG;
this~~>schedule(schedule_selector(player::scale),0.1);
}
void player::scale(float dt)
{
// CCLOG (“update %f”,x);
if(x>=0.5 && flag0)
{
x=x-0.1;
this->setScaleY(x);
}
else if(x\<0.5 || flag1)
{
flag=1;
x=x+0.1;
if(x1)
{
flag=0;
this->unscheduleAllSelectors();
}
this-\>setScaleY(x);
}
}
void player::move(float v , float swipVel)
{
int rightmove=0;
if(v\>0)
{
//right move
rightmove=1;
}
// CCLOG(“Rightmove value %d”,rightmove);
CCSize size = CCDirector::sharedDirector()->getWinSize();
if((this-\>getPositionX()\>size.width/4 && rightmove0) || (rightmove==1 && this~~\>getPositionX\< size.width/1.4))
{
float moveFactor = swipVel/80;
CCLOG (“moveFactor = %f”,moveFactor);
int x=v*moveFactor;
if+x < size.width/1.4 || this~~>getPositionX()+x > size.width/4)
{
this~~>state=Move;
CCMoveTo* walk = CCMoveTo::create+x,this~~>getPositionY()));
//this~~>runAction;
this~~>runAction(CCSequence::create(walk,CCCallFuncN::create(this,callfuncN_selector(player::backToNormal)),NULL));
}
}
}
void player::backToNormal()
{
state = Normal;
}
void player::setPosition(const CCPoint& pos)
{
CCSprite::setPosition(pos);
body = CCRectMake(this~~>getPositionX, this~~>getPositionY(), this~~>getContentSize.width, this~~>getContentSize().height);
}
//helloworld.cpp
player* shadow = (player*)player::create(“Prisoner_shadow.png”);
shadow->setPosition( ccp(size.width/2, size.height/2-t) );
//when the above code in “HelloWorld” executes it goes to the setposition of “ccsprite” rather than goin to my overriden method in “player class”.