PDA

View Full Version : How To Make A Game In SCAR! *advanced ?



BazzBarrett
09-07-2008, 11:55 PM
How to make games in SCAR!
Hello, this is my first tut hope you like it please comment if u think I’ve left anything out. This is going to be fairly brief and I’m only going to cover the basics I will go more advanced later. I’ve made this tut because I don’t believe there is one I’ve searched but can’t find one =\

Set-up!

Lets start with variables the most important is the buffer witch needs to be an integer. I extremely recommend this been a global variable because otherwise almost all your functions are going to have to include it. Also all your bitmaps should be global variables and be named correctly and under 1 like eg:
var
Buffer, CarBmp, WallBmp, FinishlineBmp :integer;//Bitmaps and buffer
The easiest way of setting up your script is to call a procedure called setup:

procedure setup;//sets the script up.
begin
DisplayDebugImgWindow(300, 300);// display the screen can be any size you want but I recommend 300x300
Buffer := BitmapFromString(300, 300, '');//buffer to draw onto
//now load all the bitmaps you will be using the next section will cover how to make and insert them.
end;


Bitmaps!

I suggest making bitmaps in paint and keeping them simple because there easier to work with after you have made it. Save you bitmap and go back to scar and click: Tools > Picture to string

http://www.freeimagehosting.net/uploads/4ef710224f.png

Click open and find your picture and enter the name you want the variable to be in the “name of your bitmap” box.
You should now have you code in the box at the bottom e.g:
PlayerBmp := BitmapFromString(60, 60, 'beNrt2NENgDAIRdHVHI3' +
'NdQNjbNP2kXPDAOcTqJIkSZJadteV4nyZLO1p8u/aQ+T/wBvZI+Bd' +
'7DjzOHgxexZ4JTvOPBe8hs3MzMzMzGzfiDMn7qLuFDdsy19B6 E8m9' +
'/clSZIkNe8BxKq39w==');
Insert this into your setup function eg:
procedure setup;
begin
DisplayDebugImgWindow(300, 300);// display the screen
Buffer := BitmapFromString(300, 300, '');//buffer to draw onto
PlayerBmp := BitmapFromString(60, 60, 'beNrt2NENgDAIRdHVHI3' +
'NdQNjbNP2kXPDAOcTqJIkSZJadteV4nyZLO1p8u/aQ+T/wBvZI+Bd' +
'7DjzOHgxexZ4JTvOPBe8hs3MzMzMzGzfiDMn7qLuFDdsy19B6 E8m9' +
'/clSZIkNe8BxKq39w==');
End;


Scriptterminate!

In a new procedure call scriptterminate (the name is very important) insert a freebitmap for all of your bitmaps used eg:

procedure scriptterminate;
begin
freebitmap(PlayerBmp);
end;

Why is the name scriptterminate so important well every time the script ends for no mater what reason it will call that procedure don’t belive me? Run:
program New;

procedure scriptterminate;
begin
writeln('hi');
end;

begin
end.
it will write “hi” even though you haven’t called the procedure..

The Main loop


In the main loop (the bit witch ends with end.) I suggest using a repeat..Until for displaying frames a bit like this:

program MyGame;
var
Buffer, PlayerBmp :Integer;

procedure setup;
begin
DisplayDebugImgWindow(300, 300);// display the screen
Buffer := BitmapFromString(300, 300, '');//buffer to draw onto
PlayerBmp := BitmapFromString(60, 60, 'beNrt2NENgDAIRdHVHI3' +
'NdQNjbNP2kXPDAOcTqJIkSZJadteV4nyZLO1p8u/aQ+T/wBvZI+Bd' +
'7DjzOHgxexZ4JTvOPBe8hs3MzMzMzGzfiDMn7qLuFDdsy19B6 E8m9' +
'/clSZIkNe8BxKq39w==');
End;

procedure scriptterminate;//put the freebitmaps in here
begin
freebitmap(PlayerBmp);//prevents memory leak
end;

begin
setup;
repeat
FastDrawClear(Buffer, clGray);//Fills the buffer with gray (a must)
SafeDrawBitmap(Buffer, GetDebugCanvas, 0, 0);//display the final result
until(IsFKeyDown(12));
end.

The safedrawbitmap is used for drawing it onto the debug image just copy that line exsactuly =)

That’s the boring stuff over lets make our game =)

Movement!

so we have a character but how is he going to move?
Easy the best way to get the character to move (in my opinion is to a separate function and use the arrow keys. You can either use a procedure and have x and y as global variables (easier for beginners) but if u are bothered about your game running 0.001 seconds smoother then just use them as local and call the function with (var x, y :integer):Boolean; (don’t forget to include a result in there other wise you will get a “tip” every time you run it and that doesent look auful professional.)
procedure PlayerMovement;
Begin-
if(IsArrowDown(0))and(Y > 0)then y := y-speed; // Up 0 is were the boundry is
if(IsArrowDown(1))and(X < 240)then x := x+speed; //right
if(IsArrowDown(2))and(Y < 240)then y := y+speed; //down
if(IsArrowDown(3))and(X > 0)then x := x-speed; //left
//For the middle 2 take the boundry wall then take away the height/length
end;
I’ve used speed so you can alter it easy remember to set the speed and make it a variable.
(if you use more than 1 moving object remember to use xx, yy, xxx, yyy, x2, y2 respectively.)

Draw Objects!

If you making a very complex game I suggest skipping this step and just putting them in as the script goes along.

Make a new procedure called DrawToBuffer in it we will be drawing everything we need. All your bitmaps should be ready to put onto the screen so lets put them on! We will be using FastDrawTransparent to transfer the bitmap to the buffer like so:

procedure DrawToBuffer;
begin
FastDrawTransparent(x, y, PlayerBmp, Buffer);// x and y is the upper left
//hand corner of were ur bitmap starts.
//PlayerBmp is your bitmap and buffer is wat we draw to befor putting on
//the screen other wise it whont look as good and it will slow it down alot
end;

And we put it all together ;)


program MyGame;
var
Buffer, PlayerBmp :Integer;
X, y, speed :integer;

procedure Setup;
begin
DisplayDebugImgWindow(300, 300);// display the screen
Buffer := BitmapFromString(300, 300, '');//buffer to draw onto
PlayerBmp := BitmapFromString(60, 60, 'beNrt2NENgDAIRdHVHI3' +
'NdQNjbNP2kXPDAOcTqJIkSZJadteV4nyZLO1p8u/aQ+T/wBvZI+Bd' +
'7DjzOHgxexZ4JTvOPBe8hs3MzMzMzGzfiDMn7qLuFDdsy19B6 E8m9' +
'/clSZIkNe8BxKq39w==');
End;

procedure scriptterminate;//put the freebitmaps in here
begin
freebitmap(PlayerBmp);//prevents memory leak
end;

procedure PlayerMovement;
begin
if(IsArrowDown(0))and(Y > 0)then y := y-speed; // Up 0 is were the boundry is
if(IsArrowDown(1))and(X < 240)then x := x+speed; //right
if(IsArrowDown(2))and(Y < 240)then y := y+speed; //down
if(IsArrowDown(3))and(X > 0)then x := x-speed; //left
//For the middle 2 take the boundry wall then take away the height/length
end;

procedure DrawToBuffer;
begin
FastDrawTransparent(x, y, PlayerBmp, Buffer);// x and y is the upper left
//hand corner of were ur bitmap starts.
//PlayerBmp is your bitmap and buffer is wat we draw to befor putting on
//the screen other wise it whont look as good and it will slow it down alot
end;

begin
setup;
speed := 1;// increase to make ur guy go faster or slower.
x := 10;//so our guy starts inside to boundrys
y := 10;
repeat
FastDrawClear(Buffer, clGray);//Fills the buffer with gray (a must)
PlayerMovement;//our man whont move if u dnt put this in ;)
DrawToBuffer;//draw our Frame
SafeDrawBitmap(Buffer, GetDebugCanvas, 0, 0);//display the final result
wait(10);// reduce to make your game go faster or incress to make it go slower
//if your game
until(IsFKeyDown(12));
end.

Key Functions:


DisplayDebugImgWindow(Width, Heigth);// display the screen
BitmapFromString(Width, Heigth, string);//best let the bitmap tool do this
FreeBitmap(Bitmap);//prevents memory leak
IsArrowDown(0);//returns true if that arrow key is down
// 0 = up 1 = right 2 = down 3 = left
FastDrawTransparent(x, y, Bitmap, Buffer);// use this to draw onto the buffer.
FastDrawClear(Buffer, colour);//Fills the buffer with a colour (eg clblue)
SafeDrawBitmap(Buffer, GetDebugCanvas, 0, 0);//display the final result
IsFKeyDown(Num);//returns true if that f key is down (perfect for ending the script)
CreateBitmapFromText(String, UpChars, colour);//makes a bitmap from text
// I suggest keeping UpChars the same and for colours use the Cl colours (eg ClRed)


Thx for reading please return any comments as if u wish me to add anything or if u wish to add a part yourself and ill add it asap =) 1,205 words WOW that’s bigger than 2 average size essays for school ;)
Injoy it is hard it is annoying and you WILL come across faults/glitches (I came across to just writing the game for the tut XD)

Waddo
09-08-2008, 12:00 AM
Let me be the first one to congratulate you.
and well done for teaching people script terminate not many know that.

BazzBarrett
09-08-2008, 12:07 AM
thx and its a grate trick i had 2 include it plus u taught it me ;)

Dan Cardin
09-08-2008, 10:45 AM
huh. Nice, but simple tutorial.

Thanks for ScriptTerminate i had not known about that.

WhoCares357
09-08-2008, 11:06 AM
Someone else made a tutorial like this, but yours is still different. Thanks for posting.

BobboHobbo
09-08-2008, 11:32 AM
Interesting, :) GJ.

mastaraymond
09-08-2008, 12:14 PM
I don't agree on the DebugForm.. I think you should make your own form and draw on that..

Dan Cardin
09-08-2008, 06:29 PM
He's making it simple. It doesnt absolutely need to be on a form, though it does make things easier.

BazzBarrett
09-08-2008, 07:28 PM
if you were to use your own form/canvas then it would recuire more setting up but the pricipale is the same.. actuly im gonna go put that in if i still can..

nickardo
09-13-2008, 08:04 AM
Interesting, But there are more easier programs to make good games

bullzeye95
09-14-2008, 04:45 AM
Interesting, But there are more easier programs to make good games

But those are noob programs. Real games are made in real languages ;)

mastaraymond
09-14-2008, 12:01 PM
But those are noob programs. Real games are made in real languages ;)
Like scar ^_^.

bullzeye95
09-14-2008, 04:14 PM
Of course!

Melon
09-15-2008, 03:50 PM
nice tut...

lolletje
09-15-2008, 06:59 PM
Thnx It helps me ALOT! :)

Bam Bam
09-15-2008, 10:47 PM
I had no idea about that whole ScriptTerminate thing, thanks!
And, nice tutorial. :)