Advertisement
MaksNew

Untitled

Feb 10th, 2021
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.34 KB | None | 0 0
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.     Form1.DoubleBuffered:=true;
  4. end;
  5.  
  6. procedure SetOncomingCarSpeed(Meteor:TImage);
  7. var
  8.     Speed: Integer;
  9. Begin
  10.     Speed := RandomRange(3, 9);
  11.     Meteor.Top:=Meteor.Top+Speed
  12. End;
  13.  
  14. procedure MeteorSpawn(Meteor:TImage; LeftPosition: Integer);
  15. Begin
  16.     if (Meteor.Top>form1.Height) then
  17.     begin
  18.         Meteor.Top:=-70;
  19.         Meteor.Left:=LeftPosition;
  20.     end;
  21. End;
  22.  
  23. procedure CollisionDetection(OncomingCar, Car: TImage; Timer: TTimer);
  24. begin
  25.     if ((OncomingCar.top+OncomingCar.Height>Car.top) and(OncomingCar.top<Car.top+Car.Height) and(OncomingCar.Left+OncomingCar.Width>Car.left) and (OncomingCar.left<Car.Left+Car.Width)) then
  26.     begin
  27.         //timer.Enabled:=false;
  28.        { fire.Picture.LoadFromFile('fire.png');
  29.         fire.Top:=Rocket.top-32;
  30.         fire.Left:=Rocket.Left;
  31.         button1.Visible:=true;
  32.         sndPlaySound('sounds\explosion.wav',SND_NODEFAULT Or SND_ASYNC);  }
  33.     end;
  34. end;
  35.  
  36. procedure PlayerControl(Car: TImage);
  37. begin
  38.     if GetaSyncKeyState($25)<>0 then     //влево
  39.         if not(Car.Left<220) then
  40.             Car.Left:=Car.Left-7;
  41.  
  42.     if GetaSyncKeyState($27)<>0 then    //вправо
  43.         if not(Car.Left>460) then
  44.             Car.Left:=Car.Left+7;
  45.  
  46.     if GetaSyncKeyState($26)<>0 then     //вверх
  47.         if (Car.Top>50) then
  48.             Car.Top:=Car.Top-7;
  49.  
  50.     if GetaSyncKeyState($28)<>0 then    //вниз
  51.         if (Car.Top<530) then
  52.             Car.Top:=Car.Top+7;
  53. end;
  54.  
  55. procedure InfiniteGeneration(Road, BufRoad: TImage);
  56. var
  57.     Speed: Integer;
  58. Begin
  59.     Speed := 5;
  60.     BufRoad.Top:= Road.Top-Form1.Height+35;
  61.     Road.Top := Road.Top + Speed;
  62.     BufRoad.Top := BufRoad.Top + Speed;
  63.     if Road.Top > Form1.Height-40 then
  64.         Road.Top := 0;
  65. End;
  66.  
  67. procedure TForm1.TimerTimer(Sender: TObject);
  68. begin
  69.     BufRoad.SendToBack;
  70.     InfiniteGeneration(Road, BufRoad);
  71.     SetOncomingCarSpeed(OncomingCar1);
  72.     SetOncomingCarSpeed(OncomingCar2);
  73.     SetOncomingCarSpeed(OncomingCar3);
  74.  
  75.     MeteorSpawn(OncomingCar1, 220);
  76.     MeteorSpawn(OncomingCar2, 340);
  77.     MeteorSpawn(OncomingCar3, 460);
  78.  
  79.     PlayerControl(Car);
  80.  
  81.     CollisionDetection(OncomingCar1, Car, Timer);
  82.     CollisionDetection(OncomingCar2, Car, Timer);
  83.     CollisionDetection(OncomingCar3, Car, Timer);
  84. end;
  85.  
  86. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement