1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183:
| procedure TFormMain.MoveBall(pCollisionObject: array of TPanel); var tempObject,CollisionRect,BallAlt: TRect; I,: Integer; begin BallAlt.Top:=Ball.Top; BallAlt.Bottom:=Ball.Bottom; BallAlt.Left:=Ball.Left; BallAlt.Right:=Ball.Right; oldXCor:=XCor; oldYCor:=YCor; sball.left:=sball.left+XCor; Ball.Left:=SBall.Left; Ball.Right:=SBall.Left+SBall.Width; if sball.left < (PLinks.Left+PLinks.Width) then begin sball.left := (PLinks.Left+PLinks.Width); Xcor := -Xcor; end; if sball.left > PRechts.Left - sball.width then begin sball.left := (PRechts.Left - sball.width); XCor := -XCor; end; sball.top := sball.top+YCor; Ball.Top:=SBall.Top; Ball.Bottom:=SBall.Top+SBall.Height; if sball.top < (POben.Top+POben.Height) then begin sball.Top := (POben.Top+POben.Height); YCor := -YCor; end; if sball.top > (self.height - sball.height) then begin sball.top := (self.height - sball.height); YCor := -YCor; end; if IntersectRect(Collision,Ball,Stick) then begin sball.top := (PStick.top - sball.height); YCor:= -YCor; XCor:= XCor-1; end; for I := 0 to High(pCollisionObject) - 1 do begin tempObject.Left:=pCollisionObject[I].Left; tempObject.Right:=pCollisionObject[I].Left+pCollisionObject[I].Width; tempObject.Top:=pCollisionObject[I].Top; tempObject.Bottom:=pCollisionObject[I].Top+pCollisionObject[I].Height; if IntersectRect(CollisionRect,tempObject,Ball) then begin TMover.Enabled:=False; case Richtung of 0: begin if LineCollision(BallAlt.Left,BallAlt.Top,Ball.Left,Ball.Top, pCollisionObject[I].Left,pCollisionObject[I].Top, pCollisionObject[I].Left+pCollisionObject[I].Width, pCollisionObject[I].Top)=TRUE then begin SBall.Top:=(pCollisionObject[I].Top-SBall.Height); YCor:= -YCor; end else begin SBall.Left:=(pCollisionObject[I].Left-SBall.Width); XCor:= -XCor; end; end; 1: begin if LineCollision(BallAlt.Left,BallAlt.Top,Ball.Left,Ball.Top, pCollisionObject[I].Left, pCollisionObject[I].Top+pCollisionObject[I].Height, pCollisionObject[I].Left+pCollisionObject[I].Width, pCollisionObject[I].Top+pCollisionObject[I].Height) =TRUE then begin SBall.Top:=(pCollisionObject[I].Top+SBall.Height); YCor:= -YCor; end else begin SBall.Left:=(pCollisionObject[I].Left-SBall.Width); XCor:= -XCor; end; end; 2: begin if LineCollision(BallAlt.Left,BallAlt.Top,Ball.Left,Ball.Top, pCollisionObject[I].Left, pCollisionObject[I].Top+pCollisionObject[I].Height, pCollisionObject[I].Left+pCollisionObject[I].Width, pCollisionObject[I].Top+pCollisionObject[I].Height) =TRUE then begin SBall.Top:=(pCollisionObject[I].Top+SBall.Height); YCor:= -YCor; end else begin SBall.Left:=(pCollisionObject[I].Left+SBall.Width); XCor:= -XCor; end; end; 3: begin if LineCollision(BallAlt.Left,BallAlt.Top,Ball.Left,Ball.Top, pCollisionObject[I].Left,pCollisionObject[I].Top, pCollisionObject[I].Left+pCollisionObject[I].Width, pCollisionObject[I].Top)=TRUE then begin SBall.Top:=(pCollisionObject[I].Top-SBall.Height); YCor:= -YCor; end else begin SBall.Left:=(pCollisionObject[I].Left+SBall.Width); XCor:= -XCor; end; end; end; TMover.Enabled:=TRUE; end; end; if Sball.Top > PStick.Top then begin SBall.Visible:=False; TMover.Enabled:=False; MessageDLG('Game Over!',mtWarning,[mbOk],0); SpawnBall; end; if ((BallAlt.Left-Ball.Left)<0) then begin if ((BallAlt.Top-Ball.Top)<0) then begin Richtung:=3; end else begin if ((BallAlt.Top-Ball.Top)>0) then begin Richtung:=2; end; end; end else begin if ((BallAlt.Left-Ball.Left)>0) then begin if ((BallAlt.Top-Ball.Top)<0) then begin Richtung:=0; end else begin if ((BallAlt.Top-Ball.Top)>0) then begin Richtung:=1; end; end; end; end; end; |