SRL Archive - Other Scripts

SCAR game - click it


Awkwardsaw

2009-07-22 07:00:27

this is my first scar game, im still trying to get used to canvases and such :)

i got the idea from cazax's click it game in the games folder in scar

and i got some code from yakman's, and solemn's tuts, so i have to give them some credit :D

goal: click the black box as many times as you can within 30 seconds

every thing else is explained in the script.

program Akwardsawclickit;

var Buffer,Line,x, y, a, b, m :integer;

//thanks to cazax for creating ClickEm - gave me the idea
//and yakman, and solemn for creating tuts on canvases :D

//instructions: hit play, and click the black box as many times as you can within
// 30 seconds. clicking the white area decreases your score!

procedure draw;
begin
Line:=BitmapFromString(10 + random(40),10 + random(40),'');
FastDrawClear(Buffer,16777215);
FastDrawTransparent(0 + random(300),y + random(300),Line,Buffer);
SafeDrawBitmap(Buffer,getdebugcanvas,0,0);
wait(10);
end;

var time: integer;

procedure check;
begin
if IsMouseButtonDown(true) then
begin
getmousepos(a, b);
while IsMouseButtonDown(true) do wait(10);
if getcolor(a, b) = 0 then inc(m) else dec(m);
draw;
end;
end;

begin
Buffer:=BitmapFromString(400,400,'');
FastDrawClear(Line,0);
DisplayDebugImgWindow(400,400);
m := 1;
time:= GetSystemTime;
repeat
check;
disguise('Clicks: ' + inttostr(m));
until (getsystemtime - time) > 30000;
writeln('You have got: ' + inttostr(m) + ' Clicks!');
end.

enjoy :) also post feedback, and ways to make it better so i can be more edumacated :p

senrath

2009-07-22 07:06:56

You have got: 318 Clicks!

And no, I did not edit that number in the slightest.

Awkwardsaw

2009-07-22 07:09:07

begin
repeat
findcolor(x, y, 0, x1, y1, x2, y2);
clickmouse(x, y, true);
wait(10);
until false;
end.
? haha

senrath

2009-07-22 07:10:43

From: Awkwardsaw
begin
repeat
findcolor(x, y, 0, x1, y1, x2, y2);
clickmouse(x, y, true);
wait(10);
until false;
end.
? haha


<.< >.> Maaaaaybe.

Awkwardsaw

2009-07-22 07:12:15

so uh, hows the script itsself? :p

senrath

2009-07-22 07:19:08

Well, it works well for what it is. But it is rather dull. Try having it generate random colors, or something like that, instead of just black all the time.

D1zl3

2009-07-22 07:24:32

add something like click the red one, and theres like a red, pink, orange, and yellow one, and theres like a 3 second timer :)

Awkwardsaw

2009-07-22 07:26:31

thats just like cazax's though :p i'm working on different colors though atm

Ron

2009-08-15 04:21:16

Cool game. I modified it a bit so the objects are different colors and the code seems more understandable.


//thanks to cazax for creating ClickEm - gave me the idea
//and yakman, and solemn for creating tuts on canvases :D

//instructions: hit play, and click the black box as many times as you can within
// 30 seconds. clicking the white area decreases your score!

{
to do:
+ make rectangles different colors
- statistics, how many hit and how many missed
- work TCanvas into script
- display score on canvas
- display seconds remaining
- replace rectangle with an image of a target
- display more than 1 object at a time
- make objects move
- move in patterns with multiple objects
- even better, make a form and then set a drawing area and put the
game there
- buttons to restart game
- high scores
- ending animation after clicking objects
}
program AkwardsawClickitAndModdedByRon;

const
// # of seconds to play the game
PlayTime = 30;
// miscellaneous
GameWidth = 400;
GameHeight = 400;
BackgroundColor = 16777215;

var
Buffer, Line, Time, Score, secPlayTime, LineColor : Integer;
//Canvas : TCanvas;

// displays score, hopefully later it will show the score on the debug image
procedure ShowScore;
begin
Disguise('Score: ' + IntToStr(Score));
end;

// creates an object at a certain x and y
// -1, -1 will make the object appear in a random spot
procedure CreateObject(x, y : Integer);
begin
Line := BitmapFromString(10 + Random(40), 10 + Random(40), '');
FastDrawClear(Buffer, BackgroundColor);
if ( x = -1 ) and ( y = -1 ) then // if x and y are -1 then randomize x and y
begin
x := Random(GameWidth);
y := Random(GameHeight);
WriteLn('Drawn at (' + IntToStr(x) + ', ' + IntToStr(y) + ').');
end;
// random color
LineColor := RGBToColor(Random(225), Random(225), Random(225));
FastDrawClear(Line, LineColor);
FastDrawTransparent(x, y, Line, Buffer);
FreeBitmap(Line);
SafeDrawBitmap(Buffer, GetDebugCanvas, 0, 0);
//SafeDrawBitmap(Buffer, Canvas, 0, 0);
end;

// Adds 1 to score if the object is clicked, if not then subtracts 1
// Creates a new object
procedure ObjectClicked;
var
a, b : Integer;
begin
GetMousePos(a, b);
while IsMouseButtonDown(True) do
Wait(10);
if (GetColor(a, b) = LineColor) then
Inc(Score)
else
Dec(Score);
ShowScore;
//Canvas.TextOut(0, 0, 'Hey');
CreateObject(-1, -1); // -1, -1 will randomize the obj's x and y location
end;

// sets up variables, buffer, and the canvas
procedure Setup;
begin
secPlayTime := PlayTime * 1000;
Buffer := BitmapFromString(GameWidth, GameHeight, '');
FastDrawClear(Buffer, BackgroundColor);
//Canvas := GetDebugCanvas;
DisplayDebugImgWindow(GameWidth, GameHeight);
Time := GetSystemTime;
Score := 1;
end;

begin
ClearDebug;
Setup;
GetSelf.WindowState := wsMinimized;
repeat
if( IsMouseButtonDown(True) ) then
ObjectClicked;
until ((GetSystemTime - Time) > secPlayTime) or (IsFKeyDown(12));
GetSelf.WindowState := wsNormal;
WriteLn('Your score is ' + IntToStr(Score) + '.');
end.

What do you think?

~Ron

Cazax

2009-08-15 04:37:08

I recommend you to use Canvas.Rectangle procedure to make the rectangles so you don't need to load and free bitmaps. If you want color use Canvas.Brush so they will appear with colors. The game in the SCAR folder is the first version, here is the second one:
program ClickEm;

Var
Canvas : TCanvas;
C, CurrScore, Background, T, Timer : Integer;

Function RColor: Integer;
Begin
Result := Random(ClWhite);
End;

Procedure DrawSquare;
Var
Rw, Rh, Col : Integer;
Begin
Col := RColor;
Rh := Random(390) + 100;
Rw := Random(390) + 20;
GetDebugCanvas.Brush.Color := RColor;
Case Random(2) Of
0: getDebugCanvas.Rectangle((Rh - 1) - Random(20), (Rw - 1) - Random(20), (Rh + 1) + Random(20), (Rw + 1) + Random(20));
1: getDebugCanvas.Ellipse((Rh - 1) - Random(20), (Rw - 1) - Random(20), (Rh + 1) + Random(20), (Rw + 1) + Random(20));
End;
End;

Procedure ClearScreen;
Var
BmpCanv : TCanvas;
Begin
BmpCanv := GetBitmapCanvas(BackGround);
SafeCopyCanvas(BmpCanv, GetDebugCanvas, 0, 0, 499, 499, 1, 13, 499, 499);
End;

Procedure DelScore;
Begin
SafeCopyCanvas(GetBitmapCanvas(Background), GetDebugCanvas, 0, 0, 150, 20, 0, 0, 150, 20);
End;

Procedure DebugScore(Score : Integer);
Var
W, H : Integer;
Begin
DelScore;
Score := CreateBitmapMaskFromText('Your Score: ' + IntToStr(Score), UpChars);
GetBitmapSize(Score, W, H);
SafeCopyCanvas(GetBitmapCanvas(Score), Canvas, 0, 0, W, H, 0, 0, W, H);
FreeBitmap(Score);
End;

Procedure Winner;
Begin
DebugScore(CurrScore);
ClearScreen;
DrawSquare;
End;

function GetLValue(Color : TColor): Integer;
Var
H, S, L : Extended;
Begin
ColorToHSL(Color, H, S, L);
Result := Round(L);
End;

Procedure OnClick(Proc : Procedure);
Var
X, Y : Integer;
Begin
GetMousePos(X, Y);
If GetColor(X, Y) = 0 Then
Exit;
If (X < 0) Or (Y < 0) Or (X > 399) Or (Y > 459) Then //No Cheats
Exit;
IncEx(C, GetLValue(GetColor(X, Y)));
CurrScore := CurrScore + C;
Proc();
C := 0;
End;

Procedure CheckIt;
Begin
OnClick(@Winner);
End;

begin
DisplayDebugImgWindow(500, 500);
FindWindow('Debug Image');
Canvas := GetDebugCanvas;
Background := BitmapFromString(499, 499, '');
SafeCopyCanvas(GetBitmapCanvas(Background), Canvas, 0, 0, 499, 499, 0, 0, 499, 499);
T := GetTickCount;
DrawSquare;
Repeat
Timer := GetTickCount;
While GetTickCount - Timer < 751 Do
Begin
CheckIt;
Wait(33);
End;
ClearScreen;
DrawSquare;
Until (GetTickCount - T) >= 30000;
FreeBitmap(Background);
Writeln('Your score was: ' + IntToStr(CurrScore));
end.
And this was the post of the update:
From: Cazax
New version is out, faster canvas drawing. Now it won't only show squares, can show rectangles, circles and squares. Now the score is based on the color luminance, so the brightest a color is, the highest score you will get. No more color cheaters(:rolleyes:)! please try it out :)


Good luck with yours! :)

Awkwardsaw

2009-08-15 05:57:57

oo thanks for the feed back guys :D i'm interested in updating this.. i'll take a look at both you yours right now :)