void EnemyBug::Update(const orxCLOCK_INFO &_rstInfo) { // Always initialize thy variables orxVECTOR speed = orxVECTOR_0; // Set rotation, flip, and speed based on the object's // current direction of movement. switch (m_direction) { orxBOOL flipX, flipY; case NORTH: speed.fY = -m_movementSpeed; SetRotation (270 * orxMATH_KF_DEG_TO_RAD); SetFlip (false, false); break; case SOUTH: speed.fY = m_movementSpeed; SetRotation (90 * orxMATH_KF_DEG_TO_RAD); SetFlip (false, false); break; case WEST: speed.fX = -m_movementSpeed; SetRotation (0 * orxMATH_KF_DEG_TO_RAD); SetFlip (true, false); GetFlip (flipX, flipY); break; case EAST: speed.fX = m_movementSpeed; SetRotation (0); SetFlip (false, false); GetFlip (flipX, flipY); break; default: orxASSERT (false); } // Update object's speed of movement SetSpeed (speed); // Time since direction change exceeds interval of direction change? if ((m_timeSinceDirectionChange += _rstInfo.fDT) >= m_directionChangeInterval) { // Reset time m_timeSinceDirectionChange = 0; // Pick random number between bounds of Direction enum orxU32 randomNum = orxMath_GetRandomU32 (0, highDirection); // Update object's direction of movement m_direction = static_cast<Direction> (randomNum); } }
void hgeSprite::SetTextureRect(float x, float y, float w, float h, bool adjSize) { float tx1, ty1, tx2, ty2; bool bX,bY,bHS; tx=x; ty=y; if(adjSize) { width=w; height=h; } tx1=tx/tex_width; ty1=ty/tex_height; tx2=(tx+w)/tex_width; ty2=(ty+h)/tex_height; quad.v[0].tx=tx1; quad.v[0].ty=ty1; quad.v[1].tx=tx2; quad.v[1].ty=ty1; quad.v[2].tx=tx2; quad.v[2].ty=ty2; quad.v[3].tx=tx1; quad.v[3].ty=ty2; bX=bXFlip; bY=bYFlip; bHS=bHSFlip; bXFlip=false; bYFlip=false; SetFlip(bX,bY,bHS); }
void hgeAnimation::SetFrame(int n) { float tx1, ty1, tx2, ty2; bool bX, bY, bHS; int ncols = int(orig_width) / int(width); n = n % nFrames; if(n < 0) { n = nFrames + n; } nCurFrame = n; // calculate texture coords for frame n ty1 = ty; tx1 = tx + n*width; if(tx1 > orig_width-width) { n -= int(orig_width-tx) / int(width); tx1 = width * (n%ncols); ty1 += height * (1 + n/ncols); } tx2 = tx1 + width; ty2 = ty1 + height; tx1 /= tex_width; ty1 /= tex_height; tx2 /= tex_width; ty2 /= tex_height; quad.v[0].tx=tx1; quad.v[0].ty=ty1; quad.v[1].tx=tx2; quad.v[1].ty=ty1; quad.v[2].tx=tx2; quad.v[2].ty=ty2; quad.v[3].tx=tx1; quad.v[3].ty=ty2; bX=bXFlip; bY=bYFlip; bHS=bHSFlip; bXFlip=false; bYFlip=false; SetFlip(bX,bY,bHS); }
void hgeAnimation::SetFrame(int n) { float tx1, ty1, tx2, ty2; bool bX, bY, bHS; int ncols = int(m_orig_width) / int(m_width); n = n % m_frame_count; if (n < 0) n = m_frame_count + n; m_cur_frame = n; // calculate texture coords for frame n ty1 = m_tex_y; tx1 = m_tex_x + n * m_width; if (tx1 > m_orig_width - m_width) { n -= int(m_orig_width - m_tex_x) / int(m_width); tx1 = m_width * (n % ncols); ty1 += m_height * (1 + n / ncols); } tx2 = tx1 + m_width; ty2 = ty1 + m_height; tx1 /= m_tex_width; ty1 /= m_tex_height; tx2 /= m_tex_width; ty2 /= m_tex_height; m_quad.v[0].tx = tx1; m_quad.v[0].ty = ty1; m_quad.v[1].tx = tx2; m_quad.v[1].ty = ty1; m_quad.v[2].tx = tx2; m_quad.v[2].ty = ty2; m_quad.v[3].tx = tx1; m_quad.v[3].ty = ty2; bX = m_xflip; bY = m_yflip; bHS = m_hsflip; m_xflip = false; m_yflip = false; SetFlip(bX, bY, bHS); }
void hgeAnimation::SetFrame(int n) { const auto ncols = int(orig_width_) / int(width_); n = n % frames_; if (n < 0) { n = frames_ + n; } cur_frame_ = n; // calculate texture coords for frame n auto ty1 = ty_; auto tx1 = tx_ + n * width_; if (tx1 > orig_width_ - width_) { n -= int(orig_width_ - tx_) / int(width_); tx1 = width_ * (n % ncols); ty1 += height_ * (1 + n / ncols); } auto tx2 = tx1 + width_; auto ty2 = ty1 + height_; tx1 /= tex_width_; ty1 /= tex_height_; tx2 /= tex_width_; ty2 /= tex_height_; quad_.v[0].tx = tx1; quad_.v[0].ty = ty1; quad_.v[1].tx = tx2; quad_.v[1].ty = ty1; quad_.v[2].tx = tx2; quad_.v[2].ty = ty2; quad_.v[3].tx = tx1; quad_.v[3].ty = ty2; const auto b_x = x_flip_; const auto b_y = y_flip_; const auto b_hs = hs_flip_; x_flip_ = false; y_flip_ = false; SetFlip(b_x, b_y, b_hs); }
VOID hgeAnimation::SetFrame(INT n) { FLOAT tx1, ty1, tx2, ty2; BOOL bX, bY, bHS; INT ncols = INT(orig_width) / INT(width); n = n % nFrames; if(n < 0) n = nFrames + n; nCurFrame = n; // calculate texture coords for frame n ty1 = ty; tx1 = tx + n*width; if(tx1 > orig_width-width) { n -= INT(orig_width-tx) / INT(width); tx1 = width * (n%ncols); ty1 += height * (1 + n/ncols); } tx2 = tx1 + width; ty2 = ty1 + height; tx1 /= tex_width; ty1 /= tex_height; tx2 /= tex_width; ty2 /= tex_height; quad.v[0].tx=tx1; quad.v[0].ty=ty1; quad.v[1].tx=tx2; quad.v[1].ty=ty1; quad.v[2].tx=tx2; quad.v[2].ty=ty2; quad.v[3].tx=tx1; quad.v[3].ty=ty2; bX=bXFlip; bY=bYFlip; bHS=bHSFlip; bXFlip=FALSE; bYFlip=FALSE; SetFlip(bX,bY,bHS); }
void StaticSprite2D::SetFlipY(bool flipY) { SetFlip(flipX_, flipY); }
void StaticSprite2D::SetFlipX(bool flipX) { SetFlip(flipX, flipY_); }
int CPreRabbit::Play(void*) { if(m_bHide) return 0; if(Key_Down) { m_pBmp=&DownWaitBmp; SetFlip(0); m_Direct=0; } if(Key_Up) { m_pBmp=&UpWaitBmp; SetFlip(0); m_Direct=1; } if(Key_Left) { m_pBmp=&LeftRabbitBmp; AddXY(-m_v,0); SetIdx(g_I); SetFlip(0); m_Wait=0; m_Direct=3; } if(Key_Right) { m_pBmp=&LeftRabbitBmp; AddXY(m_v,0); SetIdx(g_I); SetFlip(1); m_Wait=0; m_Direct=2; } if(m_Wait>10) { switch(m_Direct) { case 0://向下 m_pBmp=&DownWaitBmp; SetFlip(0); break; case 1://向下 m_pBmp=&UpWaitBmp; SetFlip(0); break; case 2://向右 m_pBmp=&LeftWaitBmp; SetFlip(1); break; case 3://向左 m_pBmp=&LeftWaitBmp; SetFlip(0); break; } if(g_I%10==0) SetIdx((g_I/10)); } m_Wait++; if(m_x<15) { g_MazeWidth=16; g_MazeHeight=14; return 1; } if(m_x>625-64) { g_MazeWidth=80; g_MazeHeight=70; return 1; } return 0; }
void StaticSprite2D::SetSwapXY(bool swapXY) { SetFlip(flipX_, flipY_, swapXY); }