program Swat_Game_Test_toAndroid; //********************************************************************* // Game to hit the invaders, loc's=370, ex. 239_ #locs:402 // strange worlds of mandelbrot, lorenz attractors & bifurcations;) //********************************************************************* (*RRRR EEEEEE AAAA DDDDD MM MM EEEEEE RR RR EE AA AA DD DD MMMM MMMM EE RRRRR EEEE AAAAAA DD DD MM MMM MM EEEE RR RR EE AA AA DD DD MM M MM EE RR RR EEEEEE AA AA DDDDD MM M MM EEEEEE *) const DAT = 1200; CHDAT = 450; crMaletUp = 5; crMaletDown = 6; MissedPoints = -2; HitPoints = 5; MissedCritter = -1; CritterSize = 72; type THole = record Time: integer; gone: boolean; end; var cFrm: TForm; time1, time2, diff: TDateTime; scaleX1, scaleX2, scaleY1, scaleY2: double; Score, Hits, Miss: integer; LiveTime, Frequence, GameTime: integer; IsGameOver, IsPause: Boolean; timer1: TTimer; Live, Gone, Test: TBitmap; holeInf: array[0..4] of THole; Holes: array[0..4] of TPoint; TimeLbl, HitsLbl, MissLbl, ScoreLbl: TLabel; mMenu1: TMainMenu; new1, options1, stop1, pause1: TMenuItem; procedure TSwatForm_WriteScore; forward; procedure ModelLorenzsetup(vForm: TForm); forward; procedure TSwatForm_Options1Click(Sender: TObject); var my: string; begin my:= intToStr(GameTime) if InputQuery('Change Speed and Time', 'Try about 150',my) then begin //showmessage(inttostr(gametime)) Timer1.Interval:= strtoInt(my); end; end; procedure TSwatForm_Pause1Click(Sender: TObject); begin if (IsGameOver) then Exit; if (IsPause) then begin IsPause:= false; Pause1.Caption:= '&Pause'; Stop1.Enabled:= true; Timer1.Enabled:= true; end else begin IsPause:= true; Pause1.Caption:= '&Continue'; Stop1.Enabled:= false; Timer1.Enabled:= false; end; end; procedure TSwatForm_Stop1Click(Sender: TObject); var i: integer; begin Timer1.Enabled:= false; IsPause:= false; IsGameOver:= true; Timer1.Tag:= GameTime; New1.Enabled:= true; //Options1.Enabled:= true; Stop1.Enabled:= false; for i:= 0 to 4 do if (holeInf[i].Time <> 0) then cFrm.Canvas.FillRect(Rect(Holes[i].x, Holes[i].y, Holes[i].x + Gone.Width, Holes[i].y + Gone.Height)); end; procedure TSwatForm_FormInit(Sender: TObject); begin Holes[0]:= Point( 80, 80 ); Holes[1]:= Point( 310, 70 ); Holes[2]:= Point( 170, 160 ); //middle Holes[3]:= Point( 30, 250 ); Holes[4]:= Point( 260, 250 ); //Screen.Cursors[crMaletUp]:= LoadCursor(HInstance, 'Malet'); //Screen.Cursors[crMaletDown]:= LoadCursor(HInstance, 'MaletDown'); //Loadcursor(TCursor(crMaletUp); Screen.Cursor:= TCursor(crMaletUp); Screen.Cursor:= crDefault; //Cursor = crHandPoint Randomize; //register hinstance Live:= TBitmap.Create; Live.LoadFromResourceName(getHInstance,'ROBOT');//'JVTIPOFDAYPIC1'); //TCHART') vpclockface Gone:= TBitmap.Create; Gone.LoadFromResourceName(getHInstance,'ROSES'); //'JVTIPOFDAYPIC2');//vpclockface Test:= TBitmap.Create; Test.LoadFromResourceName(getHInstance,'LED_RED_ON'); IsGameOver:= true; IsPause:= false; LiveTime:= 10; Frequence:= 20; GameTime:= 150; // fifteen seconds Application.OnMinimize:= @TSwatForm_Pause1Click; Application.OnRestore:= @TSwatForm_Pause1Click; end; procedure TSwatForm_Timer1Timer(Sender: TObject); var i: integer; begin Timer1.Tag:= Timer1.Tag + 1; i:= Random(Frequence); if (i < 5) then begin if (holeInf[i].Time = 0) then begin holeInf[i].Time:= Timer1.Tag + LiveTime; holeInf[i].Gone:= false; cFrm.Canvas.Draw(Holes[i].x, Holes[i].y, Live); end; end; for i:= 0 to 4 do begin if ((Timer1.Tag > holeInf[i].Time) and (holeInf[i].Time <> 0)) then begin holeInf[i].Time:= 0; if not(holeInf[i].Gone) then begin score:= score + missedcritter; //inc(Escaped); end; // cfrm.canvas.draw(Holes[i].x + Gone.Width, Holes[i].y + Gone.Height, // getbitmap(Exepath+'\examples\brightfullmoon.bmp')); cFrm.Canvas.Brush.Bitmap:= getbitmap(Exepath+'\examples\brightfullmoon.bmp'); cFrm.Canvas.FillRect(Rect(Holes[i].x, Holes[i].y, Holes[i].x + Gone.Width, Holes[i].y + Gone.Height)); //cFrm.canvas.refresh; end; end; TSwatForm_WriteScore; if (Timer1.Tag >= GameTime) then TSwatForm_Stop1Click(self); end; procedure TSwatForm_FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var i: integer; hit: boolean; begin //Screen.Cursor:= TCursor(crMaletDown); if (IsGameOver or IsPause) then Exit; hit:= false; for i:= 0 to 4 do if ((not holeInf[i].Gone) and (holeInf[i].Time <> 0)) then if (X > Holes[i].x) and (X < (Holes[i].x + Live.Width)) and (Y > Holes[i].y) and (Y < (Holes[i].y + Live.Height)) then begin //inc( Score, HitPoints ); Score:= Score + HitPoints; holeInf[i].Gone:= true; holeInf[i].Time:= Timer1.Tag + 2 * LiveTime; inc(Hits); hit:= true; cfrm.Canvas.Draw(Holes[i].x, Holes[i].y, Gone); end; if not (hit) then begin score:= score+ missedPoints; inc(Miss); end; TSwatForm_WriteScore; end; procedure TSwatForm_FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin //Screen.Cursor:= TCursor(crMaletUp); //cFrm.Cursor:= crMaletUp; //ModelLorenzsetup(cFrm); end; procedure FormClose(Sender: TObject; var Action: TCloseAction); begin TSwatForm_Stop1Click(self); live.Free; Gone.Free; test.Free; action:= caFree; end; procedure TSwatForm_New1Click(Sender: TObject); var i: integer; begin Timer1.Enabled:= true; Timer1.Tag:= 0; Score:= 0; Hits:= 0; Miss:= 0; ModelLorenzsetup(cFrm); //Escaped := 0; if (IsPause) then begin IsPause:= false; Pause1.Caption:= '&Pause'; end; IsGameOver:= false; //FillChar(holeInf, sizeof(holeInf), 0); see tetris for i:= 0 to 4 do holeInf[i].time:= 0; for i:= 0 to 4 do holeInf[i].Gone:= false; New1.Enabled:= false; //Options1.Enabled := false; Stop1.Enabled:= true; end; procedure LoadForm; begin cFrm:= TForm.create(self); try with cFrm do begin caption:= 'SWAT3 from Robots to Roses (((*)))'; height:= 500; width:= 500; color:= clblack; Position:= poScreenCenter; FormStyle:= fsStayOnTop; Show; canvas.stretchdraw(rect(0,0,width-20,height-80), getbitmap(Exepath+'\examples\brightfullmoon.bmp')); //Show; onMouseDown:= @TSwatForm_FormMouseDown; onMouseUp:= @TSwatForm_FormMouseUp; OnClose:= @FormClose; cursor:=crHandPoint; end; timer1:= TTimer.create(cFrm); timer1.onTimer:= @TSwatForm_Timer1Timer; Timer1.Interval:= GameTime; //as shorter the game as more speed timelbl:= TLabel.create(cFrm) with timelbl do begin parent:= cFrm; transparent:= true; //BackgroundColor:= false; //Brush.Color:= clBtnFace; setbounds(50,400,25,10) font.color:= clyellow; font.size:= 22; caption:= 'Time'; transparent:= true; end; //timelbl.caption.LoadFromResourceID(getHINSTANCE,'UNKNOWNFILE'); hitslbl:= TLabel.create(cFrm) with hitslbl do begin parent:= cFrm; setbounds(160,400,25,10) color:= clred; font.color:= clgreen; font.size:= 22; caption:= 'Hits'; end; misslbl:= TLabel.create(cFrm) with misslbl do begin parent:= cFrm; setbounds(260,400,25,10) font.color:= clred; font.size:= 22; caption:= 'Miss'; end; scorelbl:= TLabel.create(cFrm) with scorelbl do begin parent:= cFrm; setbounds(360,400,25,10) font.color:= clyellow; font.size:= 22; caption:= 'Score'; end; mmenu1:= TMainMenu.Create(cfrm) with mmenu1 do begin //parent:= frmMon; end; new1:= TMenuItem.Create(mmenu1) stop1:= TMenuItem.Create(mmenu1) pause1:= TMenuItem.Create(mmenu1) options1:= TMenuItem.Create(mmenu1) with new1 do begin Caption:='New Game'; Name:='ITEM'; mmenu1.Items.Add(new1); OnClick:= @TSwatForm_New1Click; end; with pause1 do begin Caption:='Pause Game'; Name:='ITEM2'; mmenu1.Items.Add(pause1) ; OnClick:= @TSwatForm_Pause1Click; end; with stop1 do begin Caption:='Stop Gamer'; Name:='ITEM3'; mmenu1.Items.Add(stop1); OnClick:= @TSwatForm_Stop1Click; end; with options1 do begin Caption:='Options'; Name:='ITEM4'; mmenu1.Items.Add(options1); OnClick:= @TSwatForm_Options1Click; end; Application.ProcessMessages; except Exit end end; procedure TSwatForm_WriteScore; begin TimeLbl.Caption:= IntToStr(GameTime - Timer1.Tag); HitsLbl.Caption:= IntToStr(Hits); MissLbl.Caption:= IntToStr(Miss); ScoreLbl.Caption:= IntToStr(Score); end; procedure scaleResults(const X, Y : double; var intX, intY : integer; width, height: integer); var scaledX, scaledY: double; begin scaledX:= (X-scaleX1)/(scaleX2-scaleX1); scaledY:= (Y-scaleY2)/(scaleY1-scaleY2); intX:= round(scaledX * width); intY:= round(scaledY * height); end; procedure Lorenz_process(var X, Y, Z: double; vForm: TForm); var intX, intY : integer; dX, dY, dZ: double; begin dY:= X * (28-Z)-Y; dX:= 10 * (Y-X); dZ:= X * Y- (8/3) * Z; scaleResults(X,Y,intX,intY, vForm.ClientWidth, vForm.ClientHeight); {$IFDEF LINUX} vForm.Canvas.DrawPoint(intX,intY); {$ELSE} vForm.Canvas.Pixels[intX, intY]:= clRed; {$ENDIF} X:= X+ 0.01 * dX; Y:= Y+ 0.01 * dY; Z:= Z+ 0.01 * Dz; end; procedure ModelLorenzsetup(vForm: TForm); var i: integer; x, y, z: double; begin scaleX1:=-20; scaleX2:=20; scaleY1:=-25; scaleY2:=30; X:= 0.1; Y:= 0.1; Z:= 0.1; for i:= 1 to 10500 do Lorenz_process(X,Y,Z, vForm); end; //main form theme begin //*************maXbox Game Series*********************************** processMessagesOff; with memo2 do begin height:= 190; color:= clblack; font.size:= 16; font.color:= clred; //clear; end; time1:= time; writeln(formatdatetime('"main start is:" hh:mm:ss:zzz', time)) TSwatForm_FormInit(self); LoadForm(); cfrm.canvas.stretchdraw(rect(0,0,cfrm.width,cfrm.height), getbitmap(Exepath+'\examples\brightfullmoon.bmp')); //cfrm.canvas.draw(cfrm.width,cfrm.height, // getbitmap(Exepath+'\examples\brightfullmoon.bmp')); TSwatForm_New1Click(Self); Sleep(2000); time2:= time; writeln(formatdatetime('"main stop is:" hh:mm:ss:zzz', time)) Diff:= time2 - time1; writeln(IntToStr(Trunc(Diff * 24)) + FormatDateTime('" h elapsed time is:" nn:ss:zzz',Diff)); //Voice('Chaos done and gone') Screen.Cursor:= crDefault; End. just inside maxbox ____ ___ _ ____ _ _ _ | _ \ | _| | | | _ \ | | | | | | | | . | | |_ | | | |_| | | |_| | | | | | | | | _| | | | __/ | _ | | | | |_. | | |_ | |__ | | | | | | | | |____/ |___| |____| |_| |_| |_| |_| performance start is: 17:25:09:093 performance stop is: 17:26:06:062 0 h elapsed run time is: 00:56:969 new record: performance start is: 11:56:14:171 performance stop is: 11:57:09:140 0 h elapsed run time is: 00:54:969  mX3 executed on: 07.10.2011 11:57:20  procedure TOptionsDlg.OKBtnClick(Sender: TObject); begin SwatForm.LiveTime := SpeedSet.Max + 1 - SpeedSet.Position; SwatForm.Frequence := PopulationSet.Position; SwatForm.GameTime := StrToInt(GameTimeSet.Text); // limit the value of GameTime to a reasonable length if (SwatForm.GameTime < 1) then SwatForm.GameTime := 150; if (SwatForm.GameTime > 9999) then SwatForm.GameTime := 9999; end; procedure TOptionsDlg.FormShow(Sender: TObject); begin SpeedSet.Position := SpeedSet.Max + 1 - SwatForm.LiveTime; PopulationSet.Position := SwatForm.Frequence; GameTimeSet.Text := inttoStr(SwatForm.GameTime); end; Cursors You can store mouse cursors as resources. If you use Image Editor, then be sure to change the names - the default names do not work. (It only took me 5 days of working on nothing else to discover this trick.) According to the Delphi 5 help (see TScreen.Cursors), this is how to use a cursor located in a resource file. Screen.Cursors[2] := LoadCursor(HInstance, 'Cursor2'); cursor := 2; (The resource name is not case sensitive.) The Delphi components use numbers instead of strings (see Delphi5\Lib\controls.res). Screen.Cursors[2] := LoadCursor(HInstance, MAKEINTRESOURCE(1234)); cursor := 2; Notice that in Image Editor, "1234" is a string, but in the command above, it is an integer (it also appears to be an integer in the *.res file). (Of course, you must make sure to select a number between 0 and 32K that no one else has ever used ... and that no one else WILL ever use. Yeah, right!) Strangely, this code also works Screen.Cursors[2] := LoadCursor(HInstance, PChar(1234)); cursor := 2; (Casting an integer as a null terminated string is definitely weird. The Resource Workshop Reference provided with Borland C++ 5.02 specifically says that "You must either typecast the integer into a long pointer to char or use [the MAKEINTRESOURCE] macro.") Use this code to draw the text onto the form instead of using the label component...put it into the form's OnPaint event: Canvas.Brush.Style := bsClear; Canvas.TextOut(0, 0, 'Whatever...'); You might find a problem if you want to update the the text later but the same is with a transparent label if used in a case like this... ref: "Quand un homme a faim, mieux vaut lui apprendre à pêcher que de lui donner un poisson" Confucius