Procedure TForm144.FormCreate(Sender: TObject) īallShape := TBallShape.Create(Self, pnlArena) Ĭonstructor TBallShape.Create(AOwner: TComponent AParent: TWinControl) ShpEnemy.Left := shpEnemy.Left + ixMove * shpEnemy.xDirec // Change pos of enemy shapes ShpEnemy.Top := shpEnemy.Top + iyMove * shpEnemy.yDirec If bAbove or bBelow or bFarLeft or bFarRight then Knowing this you could probably guess now that ball will cross the left border of its world when shpEnemy.Left pnlArena.Height īFarLeft := shpEnemy.Left pnlArena.Width So if your window coordinate system origin is top left then the far most left of the pnlArena equals to 0 ( pnlArena.Left = 0) and the far most top is also 0 ( pnlArena.Top = 0). To explain it in different words: ball doesn't know anything about the outside world, pnlArena is the whole world for ball. The important thing to know here is that the ball position is relative to its parent ( pnlArena in this case). You are not calculating correctly the conditions ( bAbove, bBelow etc.) responsible for the change of ball direction.ShpEnemy.Left := shpEnemy.Left + ixMove * ixDirec // Change pos of enemy shapes ShpEnemy.Top := shpEnemy.Top + iyMove * iyDirec if shape is outside swop relavent direction If bAbove=true or bBelow=true or bFarLeft=true or bFarRight=true then IxMove, iyMove, iyDirec : integer īAbove := > pnlArena.Height īBelow := pnlArena.Height pnlArena.Width īFarRight := pnlArena.Width < shpEnemy.Left Thank you procedure TFrmGamePage.EnemyBall(shpEnemy: TShape) īOutside, bAbove, bBelow, bFarLeft, bFarRight : Boolean My problem is that the random balls are not staying within the frame and I am not sure what I am doing wrong. I have built a game which purpose it to avoid your primary ball from crashing into the random balls that generate every 30 seconds. Working on a school project and need some help please.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |