SRL Archive - Game Development

Pong - A game made in Lazarus


Footy

2012-11-24 11:31:05

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:

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

NKN

2012-11-24 11:43:16

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

Footy

2012-11-24 11:46:04

Windows: 1
Mac: 0

I'm slowly learning Java, so when I'm experienced enough in that, I'll start making Java games.

masterBB

2012-11-24 11:56:47

lazarus supports mac iirc ^^

NKN

2012-11-24 12:05:04

From: masterBB
lazarus supports mac iirc ^^


Make a dmg!

Footy

2012-11-24 12:31:43

From: NKN
Make a dmg!


That directed at me? No clue what a dmg is, explain?

NKN

2012-11-24 12:44:16

From: Footy
That directed at me? No clue what a dmg is, explain?


What a mac uses instead of a .exe

ReadySteadyGo

2012-11-28 07:43:02

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.

Echo_

2012-11-29 16:31:46

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.

grats

2012-11-29 16:36:17

From: ReadySteadyGo
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