void T_Sprite::Initiate(SPRITEINFO spInfo) { SetPosition(spInfo.X, spInfo.Y); Visible = spInfo.Visible; dir = spInfo.Dir; active = spInfo.Active; speed = spInfo.Speed; dead = spInfo.Dead; level = spInfo.Level; score = spInfo.Score; frameRatio = spInfo.Ratio; frameRotate = spInfo.Rotation; frameAlpha = spInfo.Alpha; life=spInfo.Life; if(frameRatio>0) { colideWidth = GetRatioSize().cx; colideHeight = GetRatioSize().cy; } else { colideWidth = (int)GetWidth(); colideHeight = (int)GetHeight(); } }
void RichObject::InitSize(int cx, int cy, void *context) { Size sz; Size phsz = GetPixelSize(); if(cx || cy) sz = GetRatioSize(phsz, cx, cy); else sz = phsz; if(sz.cx > 2000 || sz.cy > 2000) sz = sz.cx > sz.cy ? GetRatioSize(phsz, 2000, 0) : GetRatioSize(phsz, 0, 2000); SetSize(sz); }
RichObject CreateImageObject(const Image& img, int cx, int cy) { RichObject o = RichObject("image", StoreImageAsString(img)); if(cx || cy) o.SetSize(GetRatioSize(o.GetPixelSize(), cx, cy)); return o; }
int T_Sprite::GetDir(POINT mousePT) { int dir = -1; POINT spNowXY = {(long)GetX(),(long)GetY()}; SIZE ratioFrameSize = GetRatioSize(); RECT SpriteRect; SpriteRect.left = (long)GetX(); SpriteRect.top = (long)GetY(); SpriteRect.right = (long)(GetX() + ratioFrameSize.cx); SpriteRect.bottom = (long)(GetY() + ratioFrameSize.cy); if( mousePT.x <= SpriteRect.left && mousePT.y >= SpriteRect.top && mousePT.y <= SpriteRect.bottom) { dir = DIR_LEFT; } else if(mousePT.x >= SpriteRect.right && mousePT.y >= SpriteRect.top && mousePT.y <= SpriteRect.bottom) { dir = DIR_RIGHT; } else if(mousePT.y <= (SpriteRect.bottom-ratioFrameSize.cy/2) && mousePT.x > SpriteRect.left && mousePT.x < SpriteRect.right) { dir = DIR_UP; } else if(mousePT.y > (SpriteRect.bottom-ratioFrameSize.cy/2) && mousePT.x > SpriteRect.left && mousePT.x < SpriteRect.right) { dir = DIR_DOWN; } else if(mousePT.x < SpriteRect.left && mousePT.y < SpriteRect.top) { dir = DIR_LEFT_UP; } else if(mousePT.x < SpriteRect.left && mousePT.y > SpriteRect.bottom) { dir = DIR_LEFT_DOWN; } else if(mousePT.x > SpriteRect.right && mousePT.y < SpriteRect.top) { dir = DIR_RIGHT_UP; } else if(mousePT.x > SpriteRect.right && mousePT.y > SpriteRect.bottom) { dir = DIR_RIGHT_DOWN; } else { dir = -1; } return dir; }
bool T_Sprite::MoveTo(IN POINT mousePT, IN POINT desPT, IN T_Map* map) { int xRatio, yRatio; if(active == true) { SIZE ratioFrameSize = GetRatioSize(); RECT HotRect; HotRect.left = (long)(desPT.x-5); HotRect.top = (long)(desPT.y-5); HotRect.right = (long)(desPT.x+5); HotRect.bottom = (long)(desPT.y+5); T_Util::GetBevelSpeed(desPT, mousePT, speed, xRatio, yRatio); BOOL ToDesPos = PtInRect(&HotRect, mousePT); if(ToDesPos == TRUE) { return true; } if(ToDesPos == FALSE) { int nextStepX = (int)xRatio; int nextStepY = (int)yRatio; int x =0; int y = 0; if(!CollideWith(map)) { x = GetX(); y = GetY(); Move(nextStepX, nextStepY); } if(CollideWith(map)) { SetPosition(x, y); } return false; } } return true; }
bool T_Sprite::MoveTo(IN POINT mousePT, IN POINT desPT, IN RECT Boundary) { int xRatio, yRatio; if(active == true) { SIZE ratioFrameSize = GetRatioSize(); RECT HotRect; HotRect.left = (long)(desPT.x-5); HotRect.top = (long)(desPT.y-5); HotRect.right = (long)(desPT.x+5); HotRect.bottom = (long)(desPT.y+5); T_Util::GetBevelSpeed(desPT, mousePT, speed, xRatio, yRatio); BOOL ToDesPos = PtInRect(&HotRect, mousePT); if(ToDesPos == TRUE) { return true; } if(ToDesPos == FALSE) { int nextStepX = (int)xRatio; int nextStepY = (int)yRatio; POINT nextPT = {(long)(GetX()+nextStepX), (long)(GetY()+nextStepY)}; if(nextPT.x <=Boundary.left) nextStepX = Boundary.left - (int)GetX(); if((nextPT.x+ratioFrameSize.cx) >=Boundary.right) nextStepX = Boundary.right - ratioFrameSize.cx - (int)GetX(); if(nextPT.y <=Boundary.top) nextStepY = Boundary.top - (int)GetY(); if((nextPT.y+ratioFrameSize.cy) >=Boundary.bottom) nextStepY = Boundary.bottom - ratioFrameSize.cy - (int)GetY(); Move(nextStepX, nextStepY); return false; } } return true; }