Sayfayı Yazdır | Pencereyi Kapat

Çarpışma Olmadığı Halde Olmuş Gibi Bildirim Verme

Nereden Yazdırıldığı: Clomosy | Forum
Kategori: Genel Programlama
Forum Adı: Genel İşlemler
Forum Tanımlaması: TRObject dili ile programlama yaparken karşılaşılan genel işlemler
URL: https://forum.clomosy.com.tr/forum_posts.asp?TID=642
Tarih: 06 Ocak 2025 Saat 12:18
Program Versiyonu: Web Wiz Forums 12.07 - https://www.webwizforums.com


Konu: Çarpışma Olmadığı Halde Olmuş Gibi Bildirim Verme
Mesajı Yazan: steelwing
Konu: Çarpışma Olmadığı Halde Olmuş Gibi Bildirim Verme
Mesaj Tarihi: 11 Temmuz 2024 Saat 14:44
var
  MyForm: TclGameForm;
  ImgBall, ImgHole, Imgmeteor, Imgmeteor2, Imgmeteor3: TclProImage;
  DeviceMotionSensor: TClMotionSensor;
  LblDisplay: TclLabel;
  GameTimer, MeteorTimer: TclTimer;
  BtnStartGame: TclButton;
  geribtn: TClProButton;
  SoundIndex: Integer;
  myDeviceManager: TclDeviceManager;
  HoleMin_X, HoleMax_X: Single; // Ball must be placed inside these coordinates
  HoleMin_Y, HoleMax_Y: Single;
  number, BallSpeed: Integer;
  meteorSpeed: Single; // Variable for meteor movement
  meteorDirection1, meteorDirection2, meteorDirection3: Integer; // Directions for meteors

procedure geriprcdr;
begin
  TclProButton(MyForm.clFindComponent('BtnGoBack')).Click;
end;

function isBallinTheHole: Boolean;
var
  centX, CentY: Single;
begin
  Result := False;
  centX := ImgBall.Position.X + (ImgBall.Width / 2);
  centY := ImgBall.Position.Y + (ImgBall.Height / 2);
  if (centX <= HoleMax_X) and (centX >= HoleMin_X) and
     (centY <= HoleMax_Y) and (centY >= HoleMin_Y) then
    Result := True;
end;

function isBallCrashed: Boolean;
begin
  Result := False;

  if (ImgBall.Position.X + ImgBall.Width > Imgmeteor.Position.X) and
     (ImgBall.Position.X < Imgmeteor.Position.X + Imgmeteor.Width) and
     (ImgBall.Position.Y + ImgBall.Height > Imgmeteor.Position.Y) and
     (ImgBall.Position.Y < Imgmeteor.Position.Y + Imgmeteor.Height) then
  begin
    Result := True;
    Exit;
  end;

  if (ImgBall.Position.X + ImgBall.Width > Imgmeteor2.Position.X) and
     (ImgBall.Position.X < Imgmeteor2.Position.X + Imgmeteor2.Width) and
     (ImgBall.Position.Y + ImgBall.Height > Imgmeteor2.Position.Y) and
     (ImgBall.Position.Y < Imgmeteor2.Position.Y + Imgmeteor2.Height) then
  begin
    Result := True;
    Exit;
  end;

  if (ImgBall.Position.X + ImgBall.Width > Imgmeteor3.Position.X) and
     (ImgBall.Position.X < Imgmeteor3.Position.X + Imgmeteor3.Width) and
     (ImgBall.Position.Y + ImgBall.Height > Imgmeteor3.Position.Y) and
     (ImgBall.Position.Y < Imgmeteor3.Position.Y + Imgmeteor3.Height ) then
  begin
    Result := True;
    Exit;
  end;
end;

procedure randomNumber;
begin
  number := Random(TForm(MyForm).ClientWidth);
end;

procedure MoveMeteors;
begin
  // Update meteor positions
  Imgmeteor.Position.X := Imgmeteor.Position.X + (meteorSpeed * meteorDirection1);
  Imgmeteor2.Position.X := Imgmeteor2.Position.X + (meteorSpeed * meteorDirection2);
  Imgmeteor3.Position.X := Imgmeteor3.Position.X + (meteorSpeed * meteorDirection3);

  // Check boundaries and reverse direction if needed
  if (Imgmeteor.Position.X <= 0) or (Imgmeteor.Position.X + Imgmeteor.Width >= TForm(MyForm).ClientWidth) then
    meteorDirection1 := -meteorDirection1;

  if (Imgmeteor2.Position.X <= 0) or (Imgmeteor2.Position.X + Imgmeteor2.Width >= TForm(MyForm).ClientWidth) then
    meteorDirection2 := -meteorDirection2;

  if (Imgmeteor3.Position.X <= 0) or (Imgmeteor3.Position.X + Imgmeteor3.Width >= TForm(MyForm).ClientWidth) then
    meteorDirection3 := -meteorDirection3;
end

procedure ProcOnGameTimer;
const
  BallSpeed = 5;
begin
  if Clomosy.PlatformIsMobile then
  begin
    case DeviceMotionSensor.GetDirectionX of
      1: ImgBall.Position.X := ImgBall.Position.X - BallSpeed; // Move left
      2: ImgBall.Position.X := ImgBall.Position.X + BallSpeed; // Move right
    end;

    case DeviceMotionSensor.GetDirectionY of
      1: ImgBall.Position.Y := ImgBall.Position.Y + BallSpeed; // Move up
      2: ImgBall.Position.Y := ImgBall.Position.Y - BallSpeed; // Move down
    end;

    if (ImgBall.Position.X + ImgBall.Width > TForm(MyForm).ClientWidth) then
      ImgBall.Position.X := TForm(MyForm).ClientWidth - ImgBall.Width;
    if (ImgBall.Position.X < 0) then
      ImgBall.Position.X := 0;
    if (ImgBall.Position.Y + ImgBall.Height > TForm(MyForm).ClientHeight) then
      ImgBall.Position.Y := TForm(MyForm).ClientHeight - ImgBall.Height;
    if (ImgBall.Position.Y < 0) then
      ImgBall.Position.Y := 0;

    if isBallinTheHole then
    begin
      GameTimer.Enabled := False;
      ImgBall.Position.X := HoleMin_X * 1.75;
      ImgBall.Position.Y := HoleMin_Y;
      if Clomosy.PlatformIsMobile then
        DeviceMotionSensor.Active := False; // game stopped
      BtnStartGame.Text := 'START GAME';
      MyForm.PlayGameSound(SoundIndex);
      myDeviceManager.Vibrate(1000);
      ShowMessage('Tebrikler');
      randomNumber;
    end
    else if isBallCrashed then
    begin
      GameTimer.Enabled := False;
      MeteorTimer.Enabled := False;
      if Clomosy.PlatformIsMobile then
        DeviceMotionSensor.Active := False; // game stopped
      ShowMessage('Tekrar deneyiniz');
      BtnStartGame.Text := 'START GAME';
    end;
  end;
end;

procedure MeteorTimerProc;
begin
  // Update meteor positions
  MoveMeteors;
end;

procedure BtnStartGameClick;
begin
  GameTimer.Enabled := not GameTimer.Enabled;

  if GameTimer.Enabled then
    BtnStartGame.Text := 'STOP GAME'
  else
    BtnStartGame.Text := 'START GAME';

  if GameTimer.Enabled then
  begin
    ImgBall.Align := alNone;
    ImgBall.Position.X := number;
    ImgBall.Position.Y := 0;
    if Clomosy.PlatformIsMobile then
      DeviceMotionSensor.Active := True;
    MeteorTimer.Enabled := True;
  end else
  begin
    if Clomosy.PlatformIsMobile then
      DeviceMotionSensor.Active := False; // game stopped
    MeteorTimer.Enabled := False;
  end;
  end;

procedure InitializeComponents;
begin
  MyForm := TclGameForm.Create(Self);
  myDeviceManager := TclDeviceManager.Create;
  MyForm.SetFormBGImage(' https://clomosy.com/educa/bg3.png" rel="nofollow - https://clomosy.com/educa/bg3.png ');
  MyForm.AddGameAssetFromUrl(' https://www.clomosy.com/game/assets/win.wav" rel="nofollow - https://www.clomosy.com/game/assets/win.wav ');
  SoundIndex := MyForm.RegisterSound('win.wav');
  MyForm.SoundIsActive := True;

  LblDisplay := MyForm.AddNewLabel(MyForm, 'LblDisplay', '--');
  LblDisplay.Align := alTop;
  LblDisplay.Visible := False;

  BtnStartGame := MyForm.AddNewButton(MyForm, 'BtnStartGame', 'START GAME');
  BtnStartGame.Align := alBottom;
  BtnStartGame.Height := 30;
  BtnStartGame.StyledSettings := ssFamily;
  BtnStartGame.TextSettings.FontColor := clAlphaColor.clHexToColor('#FFFFFF');
  BtnStartGame.Margins.Bottom := 50;
  MyForm.AddNewEvent(BtnStartGame, tbeOnClick, 'BtnStartGameClick');

  geribtn := MyForm.AddNewProButton(MyForm, 'geribtn', '');
  clComponent.SetupComponent(geribtn, '{"Align" : "None","Width":70,"Height":50,"ImgUrl":" https://clomosy.com/demos/goback.png" rel="nofollow - https://clomosy.com/demos/goback.png" }');
  MyForm.AddNewEvent(geribtn, tbeOnClick, 'geriprcdr');
  geribtn.Position.X := 5;
  geribtn.Position.Y := 7;

  ImgHole := MyForm.AddNewProImage(MyForm, 'ImgHole');
  ImgHole.clSetImage(' https://clomosy.com/educa/station.png" rel="nofollow - https://clomosy.com/educa/station.png ');
  ImgHole.Margins.Top := 120;
  ImgHole.Properties.AutoSize := True;
  ImgHole.Align := alCenter;

  ImgBall := MyForm.AddNewProImage(MyForm, 'ImgBall');
  ImgBall.clSetImage(' https://clomosy.com/educa/ufo.png" rel="nofollow - https://clomosy.com/educa/ufo.png ');
  ImgBall.Width := 50;
  ImgBall.Height := 50;
  ImgBall.Align := alCenter;

  Imgmeteor := MyForm.AddNewProImage(MyForm, 'Imgmeteor');
  Imgmeteor.clSetImage(' https://i.imgur.com/7nBXGfb.png" rel="nofollow - https://i.imgur.com/7nBXGfb.png ');
  Imgmeteor.Width := 150;
  Imgmeteor.Height := 270;
  Imgmeteor.Align := alNone;
  Imgmeteor.Position.X := 200;
  Imgmeteor.Position.Y := 370;
  Imgmeteor.RotationAngle := -90;

  Imgmeteor2 := MyForm.AddNewProImage(MyForm, 'Imgmeteor2');
  Imgmeteor2.clSetImage(' https://i.imgur.com/7nBXGfb.png" rel="nofollow - https://i.imgur.com/7nBXGfb.png ');
  Imgmeteor2.Width := 100;
  Imgmeteor2.Height := 100;
  Imgmeteor2.Align := alNone;
  Imgmeteor2.Position.X := 10;
  Imgmeteor2.Position.Y := 120;
  Imgmeteor2.RotationAngle := -270;

  Imgmeteor3 := MyForm.AddNewProImage(MyForm, 'Imgmeteor3');
  Imgmeteor3.clSetImage(' https://i.imgur.com/7nBXGfb.png" rel="nofollow - https://i.imgur.com/7nBXGfb.png ');
  Imgmeteor3.Width := 150;
  Imgmeteor3.Height := 50;
  Imgmeteor3.Align := alNone;
  Imgmeteor3.Position.X := 100;
  Imgmeteor3.Position.Y := 50;
  Imgmeteor3.RotationAngle := -180;

  HoleMin_X := ImgBall.Position.X / 1.75;
  HoleMax_X := HoleMin_X + (ImgBall.Width * 5); // Ball must be placed inside these coordinates
  HoleMin_Y := ImgBall.Position.Y + 18; // LblDisplay.Visible true oldugunda orta nokta alınırken android de yanlış hesaplanıyor
  HoleMax_Y := HoleMin_Y + ImgBall.Height;
  ImgBall.Position.Y := HoleMin_Y;

  DeviceMotionSensor := MyForm.AddNewSensorsMotion(MyForm, 'DeviceMotionSensor');

  GameTimer := MyForm.AddNewTimer(MyForm, 'GameTimer', 1000);
  GameTimer.Interval := 30; // 30 milliseconds interval
  GameTimer.Enabled := False;
  MyForm.AddNewEvent(GameTimer, tbeOnTimer, 'ProcOnGameTimer');

  MeteorTimer := MyForm.AddNewTimer(MyForm, 'MeteorTimer', 10);
  MeteorTimer.Interval := 10; // 10 milliseconds interval for meteor movement
  MeteorTimer.Enabled := True;
  MyForm.AddNewEvent(MeteorTimer, tbeOnTimer, 'MeteorTimerProc');

  // Initialize meteor directions
  meteorDirection1 := 1; // Move right initially
  meteorDirection2 := 1; // Move right initially
  meteorDirection3 := 1; // Move right initially

  meteorSpeed := 1; // Set meteor speed

  if Clomosy.PlatformIsMobile then 
    MyForm.Run;
end;

begin
  InitializeComponents;
end;




Sayfayı Yazdır | Pencereyi Kapat

Forum Software by Web Wiz Forums® version 12.07 - https://www.webwizforums.com
Copyright ©2001-2024 Web Wiz Ltd. - https://www.webwiz.net