You are on page 1of 4

unit game; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, jpeg,

StdCtrls, MPlayer, Menus; type TForm1 = class(TForm) lakon: TImage; musuh1: TImage; tm_lakon: TTimer; tm_musuh1: TTimer; musuh2: TImage; lb_nilai: TLabel; win: TImage; tm_win: TTimer; lg_kena: TMediaPlayer; lg_main: TMediaPlayer; musuh3: TImage; tm_pm3: TTimer; pm3: TImage; MainMenu1: TMainMenu; File1: TMenuItem; Exit1: TMenuItem; Label1: TLabel; Label2: TLabel; lb_nyawa: TLabel; procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure tm_musuh1Timer(Sender: TObject); procedure tm_lakonTimer(Sender: TObject); procedure tm_winTimer(Sender: TObject); procedure tm_pm3Timer(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormShow(Sender: TObject); procedure Exit1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; var overlay:Trect; x:integer; implementation uses Math, Unit3, Unit4, Types; {$R *.dfm} procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if key = vk_left then

lakon.Left:= lakon.Left -15 else if key = vk_right then lakon.Left:= lakon.Left +15 else if key= vk_up then lakon.top:= lakon.Top -15 else if key= vk_down then lakon.Top:= lakon.Top +15 end; procedure TForm1.tm_musuh1Timer(Sender: TObject); var bilrandom : Integer ; begin if musuh1.Left<=0 then musuh1.Left:=form1.Width - musuh1.Width - 30 else musuh1.Left:=musuh1.Left - 50; if musuh2.Left>=form1.Width then musuh2.Left:=form1.Width - musuh2.Width - 870 else musuh2.Left:= musuh2.Left + 30; if musuh3.Left <=0 then musuh3.Left :=form1.Width - 40 else musuh3.Left:=musuh1.Left - 80; bilrandom := RandomRange(1,1000); if (bilrandom mod 122 = 0) and (pm3.Top = musuh3.Top) then begin pm3.Top := musuh3.Top ; pm3.Left := musuh3.Left ; pm3.Visible := true; tm_pm3.Enabled := True ; end; end; procedure TForm1.tm_lakonTimer(Sender: TObject); var nilai:integer; var nyawa:Integer; begin if (IntersectRect(overlay, lakon.BoundsRect,musuh2.BoundsRect)) or (IntersectRect(overlay, lakon.BoundsRect,musuh1.BoundsRect)) or (IntersectRect(overlay, lakon.BoundsRect,musuh3.BoundsRect)) or (IntersectRect(overlay, lakon.BoundsRect,pm3.BoundsRect)) then begin lakon.Hide; musuh1.Hide; musuh2.Hide;

musuh3.Hide; pm3.Hide; lg_main.Stop; lg_kena.Play; tm_lakon.Enabled:= False ; tm_musuh1.Enabled:= False ; tm_pm3.Enabled := False ; nilai:=StrToInt(lb_nilai.caption); nilai:= nilai-10; lb_nilai.Caption:=IntToStr(nilai); nyawa:=StrToInt(lb_nyawa.caption); nyawa:= nyawa-10; lb_nyawa.Caption:=IntToStr(nyawa); if nyawa = 0 then begin ShowMessage('Game Over!!') ; Form1.Hide; lg_main.Stop; lg_kena.Play; form2.edit1.Text := lb_nilai.Caption ; Form1.Close; Form2.Show; end; ShowMessage('Fault. Try Again??') ; lakon.Show; musuh1.Show; musuh2.Show; musuh3.Show; pm3.Show; lg_main.Play; lg_kena.Stop; tm_lakon.Enabled:= True ; tm_musuh1.Enabled:= True ; tm_pm3.Enabled := True ; lakon.Top:=form1.height - lakon.height - 50; end; end; procedure TForm1.tm_winTimer(Sender: TObject); var nilai:integer ; begin if (IntersectRect(overlay, lakon.BoundsRect,win.BoundsRect)) then begin nilai:=StrToInt(lb_nilai.caption); nilai:= nilai+10; lb_nilai.Caption:=IntToStr(nilai); lakon.Top:=form1.height - lakon.height - 50; if nilai>99 then begin ShowMessage('Congratulations.Ready for Next Level!!') ; Form1.Hide; lg_main.Stop;

Form4.Label1.Caption := lb_nilai.Caption ; Form4.show; Form1.Close; end; end; end; procedure TForm1.tm_pm3Timer(Sender: TObject); begin pm3.Top := pm3.Top +5; if pm3.Top >= form1.Height then begin tm_pm3.Enabled := false; pm3.Visible := false; pm3.Top := musuh3.Top ; pm3.Left := musuh3.Left ; end; end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin form2.edit1.Text := lb_nilai.Caption ; lg_main.Stop; end; procedure TForm1.FormShow(Sender: TObject); begin lg_main.Play; end; procedure TForm1.Exit1Click(Sender: TObject); begin Close; end; end.

You might also like