MenuItemSprite::MenuItemSprite(MenuSprite* pMenu,BOOL bWithText,CString strText,MenuFunction mfFunc) :Sprite(bWithText?g_pMenuTextBitmap:g_pMenuNullBitmap),m_bWithText(bWithText),m_strText(strText),m_pMenu(pMenu),m_mfFunc(mfFunc) { if(bWithText) m_stType=stMENUITEM; if(bWithText) SetNumFrames(10); else SetNumFrames(7); }
void SIFSprite::DeleteFrame(int index) { if (index < 0 || index >= nframes) return; if (index < (nframes - 1)) { int copy_len = ((nframes - 1) - index) * sizeof(SIFFrame); memmove(&frame[index], &frame[index+1], copy_len); } SetNumFrames(nframes - 1); }
void PierrobotGear::Spawn(jvis::AnimatedSprite& player) { Enemy::Spawn(player); _direction = (player.GetPosition().x - m_SpawnPos.x <= 0) ? Mega::Direction::LEFT : Mega::Direction::RIGHT; SetNumColumns(1); SetNumFrames(2); SetDelay(160); SetSize(jmath::vec2(32)); SetRectangle(jmath::vec4(72, 68, 32, 32)); GetRigidBody()->SetCollisionType(jphys::BOX_REACTIVE); GetRigidBody()->SetVelocity(0); }
void SIFSprite::InsertFrame(SIFFrame *newframe, int insertbefore) { if (insertbefore < 0) return; if (insertbefore >= nframes - 1) { AddFrame(newframe); return; } // copy newframe now--if it's a pointer to one of our own frames, it might get // invalidated in a moment when SetNumFrames realloc's. SIFFrame insertframe = *newframe; SetNumFrames(nframes + 1); int copy_len = ((nframes - 1) - insertbefore) * sizeof(SIFFrame); memmove(&frame[insertbefore+1], &frame[insertbefore], copy_len); frame[insertbefore] = insertframe; }
void SIFSprite::AddFrame(SIFFrame *newframe) { int frameno = nframes; SetNumFrames(nframes + 1); memcpy(&frame[frameno], newframe, sizeof(SIFFrame)); }
//called to load in a sprite file and build up information about it bool CSpriteFile::Load(const char* pszFilename) { //open up the file #if _MSC_VER >= 1300 std::ifstream InFile( pszFilename, std::ios::in | std::ios::binary ); #else ifstream InFile(pszFilename, ios::in | ios::nocreate | ios::binary); #endif //check the open if(!InFile) return false; //now read in the header data uint32 nTempVal; //read in the number of frames InFile.read((char*)&nTempVal, sizeof(nTempVal)); //resize accordingly if(!SetNumFrames(nTempVal)) return false; //read in the rest of the header InFile.read((char*)&m_nFrameRate, sizeof(m_nFrameRate)); InFile.read((char*)&nTempVal, sizeof(nTempVal)); m_bTransparent = !!nTempVal; InFile.read((char*)&nTempVal, sizeof(nTempVal)); m_bTranslucent = !!nTempVal; InFile.read((char*)&m_nKey, sizeof(m_nKey)); //now read in all the names for(uint32 nCurrFrame = 0; nCurrFrame < m_nNumFrames; nCurrFrame++) { //the name of the frame char pszFrame[MAX_PATH + 1]; //the length of the name uint16 nStrLen = 0; //read in the name InFile.read((char*)&nStrLen, sizeof(nStrLen)); //now read in each character for(uint32 nCurrChar = 0; nCurrChar < nStrLen; nCurrChar++) { char ch; InFile.read(&ch, sizeof(ch)); if(nCurrChar < MAX_PATH) { pszFrame[nCurrChar] = ch; pszFrame[nCurrChar + 1] = '\0'; } } //now set this name SetFrame(nCurrFrame, pszFrame); } //success return true; }
// Set the relevant animation depending on the state of the player following the update loop void Player::SetAnimationFrame() { PlayerState state; AnimationState newState; if (p_Window->GetKey(Mega::Keys::MOVE_LEFT) == JKEY_HOLD) SetDrawFlags(jvis::Sprite::DrawFlags::FlipHorizontal); else if (p_Window->GetKey(Mega::Keys::MOVE_RIGHT) == JKEY_HOLD) RemoveDrawFlags(jvis::Sprite::DrawFlags::FlipHorizontal); if (m_TimerDeath.ElapsedMilliseconds() > 0) newState = AnimationState::SPAWNING; // Been hit else if (m_TimerInvincibility.ElapsedMilliseconds() < INVINCIBILITY_TIME / 2.5f) newState = AnimationState::INVINCIBLE; else if (m_HasCollidedBelow) { if (m_TimerBulletAnimationDelay.ElapsedMilliseconds() < FIRING_ANIMATION_DELAY) { // Running and gunning if (p_Window->GetKey(Mega::Keys::MOVE_LEFT) == JKEY_HOLD || p_Window->GetKey(Mega::Keys::MOVE_RIGHT) == JKEY_HOLD) newState = AnimationState::SHOOTRUN; else // Still firing newState = AnimationState::SHOOTSTILL; } else { // Running if (p_Window->GetKey(Mega::Keys::MOVE_LEFT) == JKEY_HOLD || p_Window->GetKey(Mega::Keys::MOVE_RIGHT) == JKEY_HOLD) newState = AnimationState::RUN; else // standing still newState = AnimationState::STILL; } } else { // Firing and jumping if (m_TimerBulletAnimationDelay.ElapsedMilliseconds() < FIRING_ANIMATION_DELAY) newState = AnimationState::SHOOTJUMP; else // Just jumping newState = AnimationState::JUMP; } if (newState != m_AnimationState) { m_AnimationState = newState; SetDelay(120); SetNumColumns(3); SetCurrentFrame(1); switch (m_AnimationState) { case INVINCIBLE: SetRectangle(jmath::vec4(0, 146, 32, 30)); SetNumFrames(2); SetDelay(20); break; case STILL: SetRectangle(jmath::vec4(0, 38, 32, 30)); SetNumFrames(1); break; case RUN: SetRectangle(jmath::vec4(0, 6, 32, 30)); SetNumFrames(3); break; case JUMP: SetRectangle(jmath::vec4(0, 106, 32, 30)); SetNumFrames(1); break; case SHOOTSTILL: SetRectangle(jmath::vec4(64, 38, 32, 30)); SetNumFrames(1); break; case SHOOTRUN: SetRectangle(jmath::vec4(0, 70, 32, 30)); SetNumFrames(3); break; case SHOOTJUMP: SetRectangle(jmath::vec4(32, 102, 32, 30)); SetNumFrames(1); break; case SPAWNING: SetNumFrames(3); SetNumColumns(1); SetCurrentFrame(1); SetDelay(10000); break; } } }