Hey guys,
This is the first program I made in lazarus. It's a simple game where the objective is to click the ball, and as you advance, the ball gets faster and faster. Click carefully though, because if you miss the ball, you lose a life. Advancing levels gives you two lives. The game is made by me, and Vinyl Scratch helped debug it. He also made some sound tracks, but I don't know how to add them.
Heres the source for any interested, and below is a zipped file with the source code file(If you have Lazarus) and the .exe, along with the other stuff it built with...
Let me know what I can improve on, and what you think I should add to this game!
Known Bugs:
None, looking for suggestions.
Source code:
Code:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Image1: TImage;
Image2: TImage;
Image3: TImage;
Label1: TLabel;
Label2: TLabel;
Timer1: TTimer;
Timer2: TTimer;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Image1Click(Sender: TObject);
procedure Image2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
var
Up, Right:boolean;
z, Level, fails:integer;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if Up = True then
Image1.Top := Image1.Top - z
else
Image1.Top := Image1.Top + z;
if Right = True then
Image1.Left := Image1.Left + z
else
Image1.Left := Image1.Left - z;
if Image1.Top <= 0 then
Up := False;
if Image1.Top + Image1.Height >= Form1.Height then
Up := True;
if Image1.Left <= 0 then
Right := True;
if Image1.Left + Image1.Width >= Form1.Width then
Right := False;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
begin
Image2.visible := true;
Timer2.Enabled := false;
end;
procedure TForm1.Image1Click(Sender: TObject);
begin
Level := Level + 1;
Image1.Visible := False;
Showmessage('Winner! Next level! Two lives gained!');
Fails := (Fails - 2);
Label2.Caption := IntToStr(10 - Fails);
ShowMessage('Current Level: ' + IntToStr(Level));
Timer1.Enabled := False;
Button1.Caption := 'Next Level';
Button1.Visible := True;
z := z + 1;
end;
procedure TForm1.Image2Click(Sender: TObject);
begin
Fails := Fails + 1;
Label2.Caption := IntToStr(10 - Fails);
Image2.visible := false;
Timer2.Enabled := true;
Image3.visible := true;
if Fails >= 10 then
begin
showmessage('Failed 10 times! Game over!');
Image1.Visible := False;
Timer1.Enabled := False;
Button1.Visible := True;
Label2.Caption := '10';
Button1.Caption := 'Start Game';
z := 5;
Level := 1;
Fails := 0;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Randomize;
case random(2) of
1: up := true;
0: up := False;
end;
Case random(2) of
1: Right := True;
0: Right := False;
end;
Timer1.Enabled := true;
Button1.Visible := False;
Image1.Top := 50;
Image1.Left := 50;
Image1.Visible := True;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Application.Terminate;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Image3.Visible := false;;
Timer1.Enabled := False;
Image1.Visible := False;
Top := 100;
z := 5;
Level := 1
end;
end.
Sorry I couldn't attach the files, they are too big. Here they are:
.EXE(if you don't have laz): http://speedy.sh/ZgS68/Catch.exe
Zipped file with source stuff: http://www.2shared.com/file/gNi0Bzvw/Catch.html