void UICheckBox::SetChecked( bool _checked, bool needDelegateCall) { checked = _checked; if(GetSprite()) { SetSpriteFrame((checked) ? 1 : 0); } if(checkboxDelegate && needDelegateCall) { checkboxDelegate->ValueChanged(this, checked); } }
void Actor::Update(int delta) { //motion if (motion.x && motion.y) { position += motion * delta * 0.71; //moving diagonally } else if (motion.x || motion.y) { position += motion * delta; //moving in a cardinal direction } //graphics if (motion != 0) { if (motion.y > 0) SetSpriteIndex(0); else if (motion.y < 0) SetSpriteIndex(1); else if (motion.x > 0) SetSpriteIndex(3); else if (motion.x < 0) SetSpriteIndex(2); //update the frame animator.Update(); } else { SetSpriteFrame(0); } }
Shape::Shape(Vector2 startingPosition) { SetName("Blocky"); SetPosition(startingPosition); _jumpTimeout = -1.0f; _onGround = true; _facingRight = true; _poweringUp = false; // int zoom = ((ShapeGameManager*)theWorld.GetGameManager())->WorldZoom; // SetSize((float)(zoom) * 0.5f, (float)(zoom) * 0.5f); SetSize(3.0f, ((3.0f * 1.1f) * (106.0f / 60.0f)) ); // SetColor(0.0f, 0.0f, 1.0f, 1.0f); SetColor(1.0f, 1.0f, 1.0f, 1.0f); // LoadSpriteFrames("Resources/Images/player_1/p1_01.png", GL_CLAMP, GL_NEAREST); // LoadSpriteFrames("Resources/Images/shapey/Shapey_01.png", GL_CLAMP, GL_NEAREST); LoadSpriteFrames("Resources/Images/Sprite_shapeyV01/Untitled-3_frame_0.png", GL_CLAMP, GL_NEAREST); // LoadSpriteFrames("Resources/Images/patch_01.png", GL_CLAMP, GL_NEAREST); SetSpriteFrame(0); // SetSprite("Resources/Images/red_texture.png"); SetDensity(0.1f); SetFriction(0.1f); SetRestitution(0.0f); SetFixedRotation(true); InitPhysics(); b2PolygonShape sensorShape; b2FixtureDef sensorFixtureDef; sensorFixtureDef.isSensor = true; sensorFixtureDef.shape = &sensorShape; sensorShape.SetAsBox((3.0f / 2), 0.5f, b2Vec2(0.0f, -(GetSize().Y * 0.5f)), 0.0f); _footSensor = GetBody()->CreateFixture(&sensorFixtureDef); _footSensor->SetUserData(this); sensorShape.SetAsBox((3.0f / 2), 0.5f, b2Vec2(0.0f, (GetSize().Y * 0.5f)), 0.0f); _headSensor = GetBody()->CreateFixture(&sensorFixtureDef); _headSensor->SetUserData(this); sensorShape.SetAsBox(0.5f, ((3.0f * 1.39f / 2) - 0.5f), b2Vec2((GetSize().X * 0.5f), 0.0f), 0.0f); _rightSensor = GetBody()->CreateFixture(&sensorFixtureDef); _rightSensor->SetUserData(this); sensorShape.SetAsBox(0.5f, ((3.0f * 1.39f / 2) - 0.5f), b2Vec2(-(GetSize().X * 0.5f), 0.0f), 0.0f); _leftSensor = GetBody()->CreateFixture(&sensorFixtureDef); _leftSensor->SetUserData(this); // SetDrawSize((float)zoom * 0.5f, (float)zoom * 0.5f); _jumpSound = theSound.LoadSample("Resources/Sounds/Jump.wav", false); _powerUpSound = theSound.LoadSample("Resources/Sounds/PowerUp.wav", false); _orbSound = theSound.LoadSample("Resources/Sounds/Picked_Coin_Echo.wav", false); // _bonkSound = theSound.LoadSample("Resources/Sounds/Bonk.wav", false); // Initialize inventory _inventory = new Inventory(); }
void Shape::Update(float dt) { if (_jumpTimeout > 0.0f) { _jumpTimeout -= dt; } b2Vec2 currentVelocity = GetBody()->GetLinearVelocity(); // ################# if (! _onGround) { // SetSpriteFrame(12); SetSpriteFrame(39); _spriteFrameDelay = 0.0f; } else if (MathUtil::FuzzyEquals(currentVelocity.x, 0.0f)) { SetSpriteFrame(10); _spriteFrameDelay = 0.0f; } else { if (!IsSpriteAnimPlaying()) { // PlaySpriteAnimation(0.1f, SAT_Loop, 1, 11); PlaySpriteAnimation(0.02f, SAT_Loop, 10, 30); } } if ((currentVelocity.x < 0.0f) && _facingRight) { FlipLeft(); } else if ((currentVelocity.x > 0.0f) && !_facingRight) { FlipRight(); } // ################# if (_poweringUp) { return; } float maxVel = theTuning.GetFloat("BlockyMaxSpeed"); float xVector = 0.0f; if (theController.IsConnected()) { bool dpad_left_down; bool dpad_right_down; dpad_left_down = theController.IsButtonDown(XINPUT_GAMEPAD_DPAD_LEFT); dpad_right_down = theController.IsButtonDown(XINPUT_GAMEPAD_DPAD_RIGHT); if (dpad_left_down) { xVector = -1.0f; } else if (dpad_right_down) { xVector = 1.0f; } else if (dpad_left_down && dpad_right_down) { xVector = 0.0f; } else { xVector = theController.GetLeftThumbVec2().X; } } if (theInput.IsKeyDown(ANGEL_KEY_RIGHTARROW)) { xVector = 1.0f; } if (theInput.IsKeyDown(ANGEL_KEY_LEFTARROW)) { xVector = -1.0f; } if (theInput.IsKeyDown(ANGEL_KEY_RIGHTARROW) && theInput.IsKeyDown(ANGEL_KEY_LEFTARROW)) { xVector = 0.0f; } float desiredVelocity = xVector * maxVel; float velocityChange = desiredVelocity - currentVelocity.x; float impulse = GetBody()->GetMass() * velocityChange; ApplyLinearImpulse(Vector2(impulse, 0), Vector2()); PhysicsActor::Update(dt); }