Пример #1
0
void BallSprite::initBall() {
    _jet = CCParticleSystemQuad::create("cool.plist");
    
    // create box2d body
    b2BodyDef bodyDef;
    bodyDef.type = b2_dynamicBody;
    
    _body = _game->getWorld()->CreateBody(&bodyDef);
    _body->SetSleepingAllowed(true);
    _body->SetLinearDamping(1.2);
    _body->SetAngularDamping(0.8);
    
    // create circle shape
    b2CircleShape circle;
    circle.m_radius = BALL_RADIUS / PTM_RATIO;
    
    // define fixture
    b2FixtureDef fixtureDef;
    fixtureDef.shape = &circle;
    fixtureDef.density = 5;
    fixtureDef.restitution = 0.7;
    
    // add collision filter so only ball can be hit by player
    fixtureDef.filter.categoryBits = 0x0010;
    
    // set sprite texture
    this->initWithFile("puck.png");
    
    _body->CreateFixture(&fixtureDef);
    _body->SetUserData(this);
    
    setSpritePosition(_startPosition);
}
Пример #2
0
void PlayerSprite::initPlayer() {
    
    // create body
    b2BodyDef bodyDef;
    bodyDef.type = b2_dynamicBody;
    
    _body = _game->getWorld()->CreateBody(&bodyDef);
    _body->SetSleepingAllowed(true);
    _body->SetLinearDamping(8);
    _body->SetAngularDamping(5);
    
    // Define shape
    b2CircleShape circle;
    circle.m_radius = BALL_RADIUS/PTM_RATIO;
    
    //define fixture
    b2FixtureDef fixtureDef;
    fixtureDef.shape = &circle;
    fixtureDef.density = 5;
    fixtureDef.restitution = 0.7;
    
    fixtureDef.filter.categoryBits = 0x0100;
    
    this->initWithFile("mallet.png");
    
    _body->CreateFixture(&fixtureDef);
    _body->SetUserData(this);
    
    setSpritePosition(_startPosition);

}
Пример #3
0
	SpriteRenderer::SpriteRenderer(GameObject *g_object){
		this->position = g_object->getPosition();
		this->scale = g_object->getScale();

		setSpritePosition(this->position);
		setSpriteScale(this->scale);
	}
Пример #4
0
void BallSprite::reset() {
    if (_body) {
        _body->SetLinearVelocity(b2Vec2_zero);
        _body->SetAngularVelocity(0);
        _body->SetAwake(true);
    }
    setSpritePosition(_startPosition);
    setVisible(true);
}
Пример #5
0
	void SpriteRenderer::changeTexture(const sf::Texture& texture){
		this->sprite = sf::Sprite(texture);
		this->size.x = texture.getSize().x * this->scale.x;
		this->size.y = texture.getSize().y * this->scale.y;

		setOrigin(this->origin);
		setSpritePosition(this->position);
		this->sprite.setScale(this->scale.x, this->scale.y);
	}
Пример #6
0
void Ball::initBall() {
    
    //create box2d body
    b2BodyDef bodyDef;
    bodyDef.type = b2_dynamicBody;

    _body = _game->getWorld()->CreateBody(&bodyDef);
    _body->SetSleepingAllowed(true);
    _body->SetLinearDamping(1.2);
    _body->SetAngularDamping(0.8);
    
    //create circle shape
    b2CircleShape  circle;
    circle.m_radius = BALL_RADIUS/PTM_RATIO;
    
    //define fixture
    b2FixtureDef fixtureDef;
    fixtureDef.shape = &circle;
    fixtureDef.density = 5;
    fixtureDef.restitution = 0.7;
    
	//add collision filters so only white ball can be hit by cue
    if (_type == kSpriteBall) {
        fixtureDef.filter.categoryBits = 0x0010;
    } else if (_type == kSpritePlayer) {
    //white ball is tracked as bullet by simulation
        _body->SetBullet(true);
        fixtureDef.filter.categoryBits = 0x0100;
    }
    
    //set sprite texture
    switch (_color) {
        case kColorBlack:
            this->initWithSpriteFrameName("ball_black.png");
            break;
        case kColorRed:
            this->initWithSpriteFrameName("ball_red.png");
            break;
        case kColorYellow:
            this->initWithSpriteFrameName("ball_yellow.png");
            break;
        case kColorWhite:
            this->initWithSpriteFrameName("ball_white.png");
            break;
    }
    
    _body->CreateFixture(&fixtureDef);
    _body->SetUserData(this);
    
    setSpritePosition(_startPosition);
}
Пример #7
0
Audio::Audio(): mStateInput(StateInput::getInstance()),
    mMainBackground("Main", 1, 1),
    mInGameBackground("Ingame", 1, 1),
    mSoundVolume("SoundVolume", 1, 2),
    mEffectLeftArrow("LeftArrow", 1, 2),
    mEffectRightArrow("RightArrow", 1, 2),
    mEffectNumbers1("Numbers", 1, 20),
    mEffectNumbers10("Numbers", 1, 20),
    mEffectNumbers100("Numbers", 1, 20),
    mMusicVolume("MusicVolume", 1, 2),
    mMusicLeftArrow("LeftArrow", 1, 2),
    mMusicRightArrow("RightArrow", 1, 2),
    mMusicNumbers1("Numbers", 1, 20),
    mMusicNumbers10("Numbers", 1, 20),
    mMusicNumbers100("Numbers", 1, 20),
    mSoundMute("SoundMute", 1, 4),
    mMusicMute("MusicMute", 1, 4),
    mBack("Back", 1, 2),
    mBlip("Blip", 1, 1),
    mWindow(Window::getWindow()),
    mStatus(0),
    mBlipPos(240, 150),
    currentBackground(&mMainBackground),
    currentSelection(&mBack),
    mEVolume(100),
    mMVolume(100),
    mChangeVolume(false),
    mEffectNr1(0),
    mEffectNr10(0),
    mEffectNr100(1),
    mEffectHighlightNr(0),
    mMusicNr1(0),
    mMusicNr10(0),
    mMusicNr100(1),
    mMusicHighlightNr(0),
    mEMute(false),
    mMMute(false),
    mHighlight(1)

{
    setSpritePosition();
    setAnimate();
}
Пример #8
0
void Bat::initBat() {
    
    //create box2d body
    b2BodyDef bodyDef;
    bodyDef.type = b2_dynamicBody;
    
    _body = _game->getWorld()->CreateBody(&bodyDef);
    _body->SetSleepingAllowed(true);
    _body->SetLinearDamping(0.6);
    _body->SetAngularDamping(0.4);
    
    //set sprite texture
    this->initWithSpriteFrameName("bat_resized_straight.png");
    
    _body->SetUserData(this);
    
    /*
     //create shape
     string temp = "dhruv_Bat";
     GB2ShapeCache *sc = GB2ShapeCache::sharedGB2ShapeCache();
     sc->addFixturesToBody(_body, temp.c_str());
     this->setAnchorPoint(sc->anchorPointForShape(temp.c_str()));
     */
    
    
    //create rectangle shape
    b2PolygonShape box;
    box.SetAsBox(BOX_WIDTH/PTM_RATIO, BOX_HEIGHT/PTM_RATIO);
    
    //define fixture
    b2FixtureDef fixtureDef;
    fixtureDef.shape = &box;
    fixtureDef.density = 5;
    fixtureDef.restitution = 0.7;
    
    _body->CreateFixture(&fixtureDef);
    
    _body->SetUserData(this);
    
    setSpritePosition(_startPosition);
}
Пример #9
0
void Piece::setBoardSize(const sf::Vector2u &u) {
    Piece::board_size = u;
    setSpritePosition();

}
Пример #10
0
void Piece::setBoardPos(const sf::Vector2i &board_pos) {

    Piece::board_pos = board_pos;
    setSpritePosition();
}
Пример #11
0
void CRole::onPlaceOnMap(const Point& gridPos, const Point& position)
{
    setSpritePosition(position);
}
Пример #12
0
void Player::teleport(int mX, int mY){
	setSpritePosition(sf::Vector2f(mX - 16, mY - 16));
}
Пример #13
0
	void SpriteRenderer::updateComponent(){
		setSpritePosition(this->game_object->getPosition());
	}