void Chaser::Update() { bool before = IsOnScreen(); if ( _timer ) _timer--; if ( _timer <= 0 ) { _timer = TIME * ( _move + 1 ); _move = !_move; if ( _move ) { Ship* p = GetNearestPlayer(); _dir = p->GetPosition() - GetPosition(); _dir.Normalise(); _dir *= SPEED; } } if ( _move ) { Move( _dir ); if ( !before && IsOnScreen() ) { _move = false; } } else { Rotate( M_PT_ONE ); } }
void Menu::Update(void) { if (!IsOnScreen(m_focus)) { int dir = FindInList(m_topView, m_focus); if (dir == 0) { // Item not in list? Suspicious return; } if (dir < 0) { // First, move up until view is visible do { do { m_topView = m_topView->m_last; } while ((m_topView != NULL) && (!m_topView->Visible())); } while (!IsOnScreen(m_focus)); // Second, optionally find top label Control *label = m_topView->m_last; while ((label != NULL) && ((!label->Visible()) || label->CanFocus())) label = label->m_last; if (label != NULL) { Control *minTop = m_topView; m_topView = label; if (!IsOnScreen(m_focus)) m_topView = minTop; } } else { // Simply move down until item visible do { do { m_topView = m_topView->m_next; } while (!m_topView->Visible()); } while (!IsOnScreen(m_focus)); } } OnPaint(m_destination); }
/* * Returns true if the given point is visible from the given viewpoint. * * A point is visible if it will be on screen, and if it is not occluded by * other objects. * * Input: * point: The point whose visibility we want to check. * viewpoint: The viewpoint to check from. * * Returns: True if the point is visible from the viewpoint. */ bool VisibilityChecker::IsVisible(const Ogre::Vector3& point, const Viewpoint& viewpoint) { float screen_x; float screen_y; auto old_position = camera_->getPosition(); auto old_direction = camera_->getDirection(); camera_->setPosition(viewpoint.position()); camera_->lookAt(viewpoint.focus()); GetScreenPosition(point, &screen_x, &screen_y); bool result = false; if (IsOnScreen(screen_x, screen_y)) { Ogre::Ray ray; camera_->getCameraToViewportRay(screen_x, screen_y, &ray); Ogre::Vector3 hit; if (RaycastAABB(ray, &hit)) { auto dist = point.distance(hit); if (dist < kOcclusionThreshold) { result = true; } else { // Hit something, but too far away from the target. result = false; } } else { // No hits. The ray should hit the target, but if it doesn't, that usually // indicates visibility. This is because if the target is occluded, the // ray is likely to have hit the occluding object. result = true; } } else { // Not on screen result= false; } camera_->setPosition(old_position); camera_->setDirection(old_direction); return result; }
void FollowHub::Update() { _timer++; if ( _timer > ( _powerA ? TIMER / 2 : TIMER ) ) { _timer = 0; _count++; if ( IsOnScreen() ) { if ( _powerB ) Spawn( new Chaser( GetPosition() ) ); else Spawn( new Follow( GetPosition() ) ); PlaySoundRandom( Lib::SOUND_ENEMY_SPAWN ); } } if ( GetPosition()._x < 0 ) _dir.Set( 1, 0 ); else if ( GetPosition()._x > Lib::WIDTH ) _dir.Set( -1, 0 ); else if ( GetPosition()._y < 0 ) _dir.Set( 0, 1 ); else if ( GetPosition()._y > Lib::HEIGHT ) _dir.Set( 0, -1 ); else if ( _count > 3 ) { _dir.Rotate( -M_PI / M_TWO ); _count = 0; } fixed s = _powerA ? M_PT_ZERO_ONE * 5 + M_PT_ONE : M_PT_ZERO_ONE * 5; Rotate( s ); GetShape( 0 ).Rotate( -s ); Move( _dir * SPEED ); }
void Square::Update() { if ( GetNonWallCount() == 0 && IsOnScreen() ) _timer--; else _timer = GetLib().RandInt( 80 ) + 40; if ( _timer == 0 ) Damage( 4, false, 0 ); Vec2 pos = GetPosition(); if ( pos._x < 0 && _dir._x <= 0 ) { _dir._x = -_dir._x; if ( _dir._x <= 0 ) _dir._x = 1; } if ( pos._y < 0 && _dir._y <= 0 ) { _dir._y = -_dir._y; if ( _dir._y <= 0 ) _dir._y = 1; } if ( pos._x > Lib::WIDTH && _dir._x >= 0 ) { _dir._x = -_dir._x; if ( _dir._x >= 0 ) _dir._x = -1; } if ( pos._y > Lib::HEIGHT && _dir._y >= 0 ) { _dir._y = -_dir._y; if ( _dir._y >= 0 ) _dir._y = -1; } _dir.Normalise(); Move( _dir * SPEED ); SetRotation( _dir.Angle() ); }
bool RenderTarget::IsValid( const RenderResourceManager& renderResourceManager) const { return m_viewportRect.w > 0.0f && m_viewportRect.h > 0.0f && (IsOnScreen() || renderResourceManager.Get<FrameBufferRenderResource>( m_frameBufferHandle)); }
void Shielder::Update() { fixed s = _power ? M_PT_ZERO_ONE * 12 : M_PT_ZERO_ONE * 4; Rotate( s ); GetShape( 9 ).Rotate( -2 * s ); for ( int i = 0; i < 8; i++ ) GetShape( i ).Rotate( -s ); bool onScreen = false; if ( GetPosition()._x < 0 ) _dir.Set( 1, 0 ); else if ( GetPosition()._x > Lib::WIDTH ) _dir.Set( -1, 0 ); else if ( GetPosition()._y < 0 ) _dir.Set( 0, 1 ); else if ( GetPosition()._y > Lib::HEIGHT ) _dir.Set( 0, -1 ); else onScreen = true; if ( !onScreen && _rotate ) { _timer = 0; _rotate = false; } fixed speed = SPEED + ( _power ? M_PT_ONE * 3 : M_PT_ONE * 2 ) * ( 16 - GetHP() ); if ( _rotate ) { Vec2 d( _dir ); d.Rotate( ( _rDir ? 1 : -1 ) * ( TIMER - _timer ) * M_PI / ( M_TWO * TIMER ) ); _timer--; if ( _timer <= 0 ) { _timer = 0; _rotate = false; _dir.Rotate( ( _rDir ? 1 : -1 ) * M_PI / M_TWO ); } Move( d * speed ); } else { _timer++; if ( _timer > TIMER * 2 ) { _timer = TIMER; _rotate = true; _rDir = GetLib().RandInt( 2 ) != 0; } if ( IsOnScreen() && _timer % TIMER == TIMER / 2 && _power ) { Player* p = GetNearestPlayer(); Vec2 v = GetPosition(); Vec2 d = p->GetPosition() - v; d.Normalise(); Spawn( new SBBossShot( v, d * M_THREE, 0x33cc99ff ) ); PlaySoundRandom( Lib::SOUND_BOSS_FIRE ); } Move( _dir * speed ); } _dir.Normalise(); }
void RenderTarget::Finalize() const { if (!IsOnScreen()) { glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE); glClear(GL_COLOR_BUFFER_BIT); } }
void Wall::Update() { if ( GetNonWallCount() == 0 && _timer % 8 < 2 ) { if ( GetHP() > 2 ) PlaySound( Lib::SOUND_ENEMY_SPAWN ); Damage( GetHP() - 2, false, 0 ); } if ( _rotate ) { Vec2 d( _dir ); d.Rotate( ( _rdir ? _timer - TIMER : TIMER - _timer ) * M_PI / ( M_FOUR * TIMER ) ); SetRotation( d.Angle() ); _timer--; if ( _timer <= 0 ) { _timer = 0; _rotate = false; _dir.Rotate( _rdir ? -M_PI / M_FOUR : M_PI / M_FOUR ); } return; } else { _timer++; if ( _timer > TIMER * 6 ) { if ( IsOnScreen() ) { _timer = TIMER; _rotate = true; } else _timer = 0; } } Vec2 pos = GetPosition(); if ( ( pos._x < 0 && _dir._x < -M_PT_ZERO_ONE ) || ( pos._y < 0 && _dir._y < -M_PT_ZERO_ONE ) || ( pos._x > Lib::WIDTH && _dir._x > M_PT_ZERO_ONE ) || ( pos._y > Lib::HEIGHT && _dir._y > M_PT_ZERO_ONE ) ) { _dir = Vec2() - _dir; _dir.Normalise(); } Move( _dir * SPEED ); SetRotation( _dir.Angle() ); }
void RenderTarget::Setup( const RenderResourceManager& renderResourceManager) const { if (IsOnScreen()) { glBindFramebuffer(GL_FRAMEBUFFER, 0); } else { if (auto frameBuffer = renderResourceManager.Get<FrameBufferRenderResource>( m_frameBufferHandle)) { glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer->m_FBO); } else { assert(!"No frame buffer to bind."); } } glClearColor(128.0f / 255.0f, 168.0f / 255.0f, 248.0f / 255.0f, 1.0f); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CCW); glEnable(GL_DEPTH_TEST); glClearDepthf(1.0f); glDepthFunc(GL_LEQUAL); glViewport( m_viewportRect.x, m_viewportRect.y, m_viewportRect.w, m_viewportRect.h); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); }
void CLasagneEntity::Render( SDL_Surface *screen ) { if (!m_visible) return; if (!IsOnScreen()) return; if (m_noofFramesX + m_noofFramesY == 0) { // draw the entity in its 3d position SDL_Rect rcRect; rcRect.x = static_cast<Sint16>(m_screenPosition.x()); rcRect.y = static_cast<Sint16>(m_screenPosition.y()); SDL_BlitSurface(m_image, NULL, screen, &rcRect); } else { int xOffset = m_currentFrame; int yOffset = 0; while (xOffset > m_noofFramesX - 1) { yOffset++; xOffset -= m_noofFramesX; } // update aniamtion if (SDL_GetTicks() - m_lastFrameTime > m_fps) { m_lastFrameTime = SDL_GetTicks(); m_currentFrame++; if (m_currentAnimation.length() == 0) { if (m_currentFrame >= (m_noofFramesX * m_noofFramesY)) m_currentFrame = 0; } else { const AnimationData &animData = m_animation[m_currentAnimation]; IVec2 frames = animData.frames; if (m_currentFrame >= frames.y()) { if (animData.loop) m_currentFrame = frames.x(); else m_currentFrame = frames.y() - 1; } } } const int pixelOffset = ((m_image->w * m_frameSize.h) * yOffset) + (m_frameSize.w * xOffset); SDL_PixelFormat *const fmt = m_image->format; SDL_Surface *const frame = SDL_CreateRGBSurfaceFrom( (void*)((unsigned int*)m_image->pixels + pixelOffset), m_frameSize.w, m_frameSize.h, fmt->BitsPerPixel, m_image->pitch, fmt->Rmask, fmt->Gmask, fmt->Bmask, fmt->Amask ); SDL_Surface *rotateFrame = rotozoomSurface(frame, m_rotation, 1, 0); SDL_Rect rcRect; rcRect.x = static_cast<Sint16>(m_screenPosition.x()); rcRect.y = static_cast<Sint16>(m_screenPosition.y()); SDL_BlitSurface(rotateFrame, NULL, screen, &rcRect); SDL_FreeSurface(frame); SDL_FreeSurface(rotateFrame); } }
void Tractor::Update() { GetShape( 0 ).Rotate( M_PT_ZERO_ONE * 5 ); GetShape( 1 ).Rotate( -M_PT_ZERO_ONE * 5 ); if ( _power ) { GetShape( 3 ).Rotate( -M_PT_ZERO_ONE * 8 ); GetShape( 4 ).Rotate( M_PT_ZERO_ONE * 8 ); } if ( GetPosition()._x < 0 ) _dir.Set( 1, 0 ); else if ( GetPosition()._x > Lib::WIDTH ) _dir.Set( -1, 0 ); else if ( GetPosition()._y < 0 ) _dir.Set( 0, 1 ); else if ( GetPosition()._y > Lib::HEIGHT ) _dir.Set( 0, -1 ); else _timer++; if ( !_ready && !_spinning ) { Move( _dir * SPEED * ( IsOnScreen() ? M_ONE : M_TWO + M_HALF ) ); if ( _timer > TIMER * 8 ) { _ready = true; _timer = 0; } } else if ( _ready ) { if ( _timer > TIMER ) { _ready = false; _spinning = true; _timer = 0; _players = GetPlayers(); PlaySound( Lib::SOUND_BOSS_FIRE ); } } else if ( _spinning ) { Rotate( M_PT_ONE * 3 ); for ( unsigned int i = 0; i < _players.size(); i++ ) { if ( !( ( Player* )_players[ i ] )->IsKilled() ) { Vec2 d = GetPosition() - _players[ i ]->GetPosition(); d.Normalise(); _players[ i ]->Move( d * TRACTOR_SPEED ); } } if ( _timer % ( TIMER / 2 ) == 0 && IsOnScreen() && _power ) { Player* p = GetNearestPlayer(); Vec2 v = GetPosition(); Vec2 d = p->GetPosition() - v; d.Normalise(); Spawn( new SBBossShot( v, d * M_FOUR, 0xcc33ccff ) ); PlaySoundRandom( Lib::SOUND_BOSS_FIRE ); } if ( _timer > TIMER * 5 ) { _spinning = false; _timer = 0; } } }