Results 1 to 10 of 10

Thread: Pong - A game made in Lazarus

  1. #1
    Join Date
    Jun 2012
    Posts
    2,182
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Cool Pong - A game made in Lazarus

    Hey Guys,

    Here's my second game in Lazarus! The objective of the game is to keep the ball in play as long as you can. When it touches the red at the bottom, you lose! I'll upload the .exe, source code is below. If someone can teach me how to upload it to github, that would be great. If anyone wants the Lazarus source files, I can upload those as well.

    Let me know how it is, what score you get, and most importantly, things I can improve on and things you suggest I add!

    Thanks guys!
    Footy

    Source Code:

    Code:
    unit Unit1;
    
    {$mode objfpc}{$H+}
    
    interface
    
    uses
      Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
      StdCtrls, ComCtrls;
    
    type
    
      { TForm1 }
    
      TForm1 = class(TForm)
        Image1: TImage;
        Image2: TImage;
        Image3: TImage;
        Image4: TImage;
        Image5: TImage;
        Label1: TLabel;
        Label2: TLabel;
        Label3: TLabel;
        Label4: TLabel;
        ProgressBar1: TProgressBar;
        Timer1: TTimer;
        Timer2: TTimer;
        Timer3: TTimer;
        Timer4: TTimer;
        procedure FormCreate(Sender: TObject);
        procedure Image5Click(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
        procedure Timer2Timer(Sender: TObject);
        procedure Timer3Timer(Sender: TObject);
        procedure Timer4Timer(Sender: TObject);
      private
        { private declarations }
      public
        { public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.lfm}
    
    { TForm1 }
    
    var
      z, sec, min:integer;
      Up, Right:boolean;
    
    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      Image3.Left := (Mouse.CursorPos.x - 130);
    end;
    
    procedure TForm1.Timer2Timer(Sender: TObject);
    
    begin
      if Up = True then
          Image2.Top := Image2.Top - z + random(2)
        else
          Image2.Top := Image2.Top + z + random(2);
    
        if Right = True then
          Image2.Left := Image2.Left + z + random(2)
        else
          Image2.Left := Image2.Left - z + random(2);
    
    
        if Image2.Top <= 0 then
          Up := False;
    
        if (Image2.Top + Image2.Height >= Image3.Top) and
          (Image2.Left + (Image2.Width / 2) > Image3.Left) and
          (Image2.Left + (Image2.Width / 2) < Image3.Left + Image3.Width)  then
          Up := true;
    
        if Image2.Top + Image2.Height >= Form1.Height then
          begin
            ProgressBar1.Visible := True;
            Progressbar1.Position := 0;
            Timer1.Enabled := False;
            Timer2.Enabled := False;
            Timer3.enabled := False;
            Timer4.enabled := False;
            Screen.Cursor := CrDefault;
            Image2.Top := 20;
            Image2.Left := 24;
            Image5.Visible := True;
            Showmessage('Game Over! You Lasted ' + Label2.Caption + ' Minute(s) and ' +
            Label4.Caption + ' Second(s)!');
            Label2.Caption := '0';
            Label4.Caption := '0';
            z := 2;
            Exit;
          end;
    
        if Image2.Left <= 0 then
          Right := True;
    
        if Image2.Left + Image2.Width >= Form1.Width then
          Right := False;
    
    end;
    
    procedure TForm1.Timer3Timer(Sender: TObject);
    begin
      Sec := StrToInt(Label4.Caption);
      if Sec = 59 then
        begin
          Label4.Caption := IntToStr(0);
          Min := StrToInt(Label2.Caption);
          Label2.Caption := IntToStr(Min + 1)
        end else
          Label4.Caption := IntToStr(Sec + 1);
    end;
    
    procedure TForm1.Timer4Timer(Sender: TObject);
    begin
      z := z + 1
    end;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      Timer1.Enabled := False;
      Timer2.Enabled := False;
      z := 2;
      case random(2) of
        0: up := true;
        1: up := false;
      end;
    
      case random(2) of
        0: Right := True;
        1: Right := False;
      end;
    
      Image2.Top := 20;
      Image2.Left := 24;
    
    
    
    end;
    
    procedure TForm1.Image5Click(Sender: TObject);
    begin
      repeat
        Progressbar1.Position := Progressbar1.Position + random(2);
        Sleep(Random(5));
      until(ProgressBar1.Position = 1000);
      Progressbar1.visible := False;
      Image5.Visible := False;
      Timer1.Enabled := True;
      Timer2.Enabled := True;
      Timer3.Enabled := True;
      Timer4.Enabled := True;
      Screen.Cursor := crnone;
    
    end;
    
    end.
    .exe: http://speedy.sh/KrHew/project1.exe
    Thx Euphemism and Vinyl for the awesome siggy and avatar!

  2. #2
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    3,383
    Mentioned
    95 Post(s)
    Quoted
    717 Post(s)

    Default

    Should use a language so it's Mac compatible. </3

  3. #3
    Join Date
    Jun 2012
    Posts
    2,182
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Windows: 1
    Mac: 0

    I'm slowly learning Java, so when I'm experienced enough in that, I'll start making Java games.
    Thx Euphemism and Vinyl for the awesome siggy and avatar!

  4. #4
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    lazarus supports mac iirc ^^
    Working on: Tithe Farmer

  5. #5
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    3,383
    Mentioned
    95 Post(s)
    Quoted
    717 Post(s)

    Default

    Quote Originally Posted by masterBB View Post
    lazarus supports mac iirc ^^
    Make a dmg!

  6. #6
    Join Date
    Jun 2012
    Posts
    2,182
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by NKN View Post
    Make a dmg!
    That directed at me? No clue what a dmg is, explain?
    Thx Euphemism and Vinyl for the awesome siggy and avatar!

  7. #7
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    3,383
    Mentioned
    95 Post(s)
    Quoted
    717 Post(s)

    Default

    Quote Originally Posted by Footy View Post
    That directed at me? No clue what a dmg is, explain?
    What a mac uses instead of a .exe

  8. #8
    Join Date
    Aug 2008
    Location
    London, UK
    Posts
    456
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Actually a .dmg is just a disk image. Mac OSX is unix which doesn't have a .* extension for executables, you just need to compile in lazarus on the mac. You can also create a package with the .app extension.

  9. #9
    Join Date
    Jan 2011
    Location
    Denver, CO
    Posts
    1,351
    Mentioned
    2 Post(s)
    Quoted
    72 Post(s)

    Default

    I found how to cross compile from linux to mac, but not windows to mac:
    http://wiki.freepascal.org/Cross_compiling

    So like RSG said, you're best bet is to just compile it on the target platform.

  10. #10
    Join Date
    Feb 2007
    Location
    Colorado, USA
    Posts
    3,716
    Mentioned
    51 Post(s)
    Quoted
    624 Post(s)

    Default

    Quote Originally Posted by ReadySteadyGo View Post
    Actually a .dmg is just a disk image. Mac OSX is unix which doesn't have a .* extension for executables, you just need to compile in lazarus on the mac. You can also create a package with the .app extension.
    Yea, something I feel windows should have implemented many years ago with the .iso format.. would make software a lot nicer imo


    @OP should do in javascript & html5 so you can have multiplayer across web.. instead of java :P
    The only true authority stems from knowledge, not from position.

    You can contact me via matrix protocol: @grats:grats.win or you can email me at the same domain, any user/email address.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •