From 7d79873fced40e8ce53fd0fc75d97adb3084b162 Mon Sep 17 00:00:00 2001 From: skalogryz Date: Mon, 25 Jan 2010 22:32:47 +0000 Subject: [PATCH] iphonelazext: improved iArkanoid sample graphics and performance git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1142 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../examples/iArkanoid/gameengine.pas | 18 ++++-------------- .../iphonelazext/examples/iArkanoid/iArk.pas | 15 ++++++++------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/components/iphonelazext/examples/iArkanoid/gameengine.pas b/components/iphonelazext/examples/iArkanoid/gameengine.pas index b55cdbc10..405c455a0 100644 --- a/components/iphonelazext/examples/iArkanoid/gameengine.pas +++ b/components/iphonelazext/examples/iArkanoid/gameengine.pas @@ -253,16 +253,8 @@ begin end; if (cy >= PaddleY-5) and (cx >= PaddleX) and (cx <= PaddleX + PaddleW) and (dy>0) then begin - t := (cx - PaddleX - PaddleW/2) / (PaddleW/2); - - if t > 1 then t := 1 - else if t < -1 then t:=-1; - - - if t < 0 then - t := pi/2 + pi/16 - t / 2 - else - t := pi/2 - pi/16 - t / 2; + t := (cx - PaddleX) / PaddleW; + t:=pi*(1-(t*0.8+0.1)); dx := cos(t)*ballVelocity; dy := -sin(t)*ballVelocity; cy := PaddleY-5; @@ -290,10 +282,8 @@ begin with Balls[i] do begin x := PaddleX+PaddleW/2; y := PaddleY-5; - //a := random*pi/4 + (pi/2 - pi/8); - //if cos(a)*5 < 0.1 then a := a + pi/5; - //a:=5*pi/4; - a:=3*pi/2; + a := random*pi/4 + (pi/2 - pi/8); + if cos(a)*5 < 0.1 then a := a + pi/5; dx := ballVelocity*cos(a); dy := ballVelocity*sin(a); sticked:=true; diff --git a/components/iphonelazext/examples/iArkanoid/iArk.pas b/components/iphonelazext/examples/iArkanoid/iArk.pas index a9d8451ad..bff7302ff 100644 --- a/components/iphonelazext/examples/iArkanoid/iArk.pas +++ b/components/iphonelazext/examples/iArkanoid/iArk.pas @@ -91,12 +91,8 @@ begin CGContextFillRect(ctx, r); for i := 0 to game.brickCount - 1 do begin - if game.bricks[i].flash > 0 then begin - MakeCGRect(game.bricks[i].bounds, r); - CGContextSetRGBFillColor(ctx, 1, 1, 1, 1); - CGContextFillRect(ctx, r); - dec(game.bricks[i].flash); - end else if game.bricks[i].health > 0 then begin + MakeCGRect(game.bricks[i].bounds, r); + if game.bricks[i].health > 0 then begin MakeCGRect(game.bricks[i].bounds, r); CGContextSetRGBFillColor(ctx, 1, 0, 0, 1); CGContextFillRect(ctx, r); @@ -107,6 +103,11 @@ begin CGContextSetRGBFillColor(ctx, 0.8, 0, 0, 1); CGContextFillRect(ctx, r); end; + if game.bricks[i].flash > 0 then begin + CGContextSetRGBFillColor(ctx, 1, 1, 1, 1/(game.bricks[i].flash+1)); + CGContextFillRect(ctx, r); + dec(game.bricks[i].flash); + end; end; end; @@ -124,7 +125,7 @@ procedure MyMainWindow.initObjects; begin { create timer } timer := NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats( - double(0.1), Self, objcselector(timerEvent_), nil, true); + double(0.075), Self, objcselector(timerEvent_), nil, true); game := TArkanoid.Create(300, 400); game.Init; end;