Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / A tutorial for intermediates

Author
Message
Cave Man
18
Years of Service
User Offline
Joined: 22nd Aug 2006
Location: North Carolina, US
Posted: 20th Dec 2006 04:59 Edited at: 21st Dec 2006 16:25
I decided to write this tutorial because i got tempted to.



Read the stickies if you want more tutorials.

Note: Because i didn't use sode snippets for everything, there is no indention. I encourage you to indent the code as you type it.

Chapter I: Simple Graphics
I'm gonna explain some non-media drawing routines. If you already know these, you can go ahead and skip to the next chapter.

You draw a solid rectangle on the screen by using the box command.


e.g. (run this if you like)

box 20,20,100,200
wait key



There are also four more optional parameters you can use.
color1,color2,color3,color4

You can use them to draw a gradient.

Here's what each color affects:


e.g. (run this)

box 0,0,100,100,RGB(255,0,0),RGB(0,255,0),RGB(0,0,255),RGB(255,255,0)
wait key



If you don't use those parameters, use the "ink" command before you use box (or any other 2d drawing routine) to color the rectangle.

e.g. (run this)

ink RGB(255,255,0), 0
box 20,20,100,200
wait key



Other 2d drawing routines are "ellipse", "circle", "line", "dot"
The help files will cover those.(Highlight a command and press F1 to see help for the command)

To draw text on the screen at a specific location, use the "text" command.
The help files will cover this also.
Cave Man
18
Years of Service
User Offline
Joined: 22nd Aug 2006
Location: North Carolina, US
Posted: 20th Dec 2006 05:12 Edited at: 21st Dec 2006 16:27
Chapter II: Base engine
We're gonna make a capture the flag game. There won't be any external graphics. Just circles and boxes.



We start by making the main loop(don't bother running it yet, just type it)
A do loop will go down to loop, then skip back to do, until we end the program.

We also make the declarations section line

set display mode 1024,768,32 `if this isn't your maximum resolution, set it to your max.
sync on
sync rate 0 `i always use a custom timer, but thats just me
`^^^^^^^^^^^^^^^^^^^Declarations^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

do
sync
loop



Add the custom timer since i'm using sync rate 0
The timer makes it wait x milliseconds before refreshing again.


set display mode 1024,768,32 `if this isn't your maximum resolution, set it to your max.
sync on `let us refresh at our own, custom rate
sync rate 0 `i always use a custom timer, but thats just me

`^^^^^^^^^^^^^^^^^^^Declarations^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

time = timer() `this timer allowes us to choose the minimum of milliseconds between each sync
do
if timer() - time > 10 `timer() increases 1 every millisecond, our "time" variable doesn't
`so when timer() is 10 bigger that "time" timer() - time = 10

sync
time = timer() `reset the "time" variable
endif
loop



Now we should add the player.

We'll use a UDT(user-defined type) array to hold all the stats for each player. This includes x position, y position, angle("dire"),team number,time 'till another shot may be fired("lsc"), and health


Add this into the declarations section:

type Entity

x as float `x and y are floats because i use a float for the speed also.
y as float
dire as float
team as integer
lsc as integer `last shot countdown
health as integer
endtype

dim prs(0) as Entity `currently only one player(slot 0) (prs = players)


We should make the player visible now
We will draw a circle for the player and a line from the center of the player, pointing the direction that the player is.

For the line, we must make use of sine and cosine

The following function loops through all Players and draws them.
Add the drawplayers function.

function drawplayers()
lock pixels `lock the pixels for faster drawing
for i = 0 to array count(prs()) `loop throught all the players
if prs(i).team = 1 `team 1 is the user's team
ink RGB(0,0,255),0 `blue is the user's team color
else
ink RGB(255,0,0),0 `red is the enemy's color
endif
if i = 0 then ink RGB(0,255,0),0 `slot 0 is the user, so if its the user, ink it green

circle prs(i).x,prs(i).y, 5 `draw a circle at the players position
line prs(i).x,prs(i).y,prs(i).x+(sin(prs(i).dire))*12,prs(i).y+(-cos(prs(i).dire))*12 `make a line to show which direction the player is pointing(use -cos because it returns 1 for up and -1 for down)
next
unlock pixels `you have to unlock pixels when we're done drawing
endfunction


Call drawplayers() in the main loop.

Now add this right below the "dim prs" to position the player at 20,20

prs(0).x = 20
prs(0).y = 20



Now that we're drawing the player, we should clear the screen every loop. Otherwise Nothing will be cleared and the player will leave a trail if moved.
add cls 0
in the main loop.(before you call anything that draws)


This is what you should have now.



Now run it.

Thats all for now. I'll continue it asap.

Next chapter : User Control
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 20th Dec 2006 06:07
Good start mate

Cave Man
18
Years of Service
User Offline
Joined: 22nd Aug 2006
Location: North Carolina, US
Posted: 20th Dec 2006 13:53 Edited at: 20th Dec 2006 13:59
Thanks.

Can you change the title from "Intermediates" to "Begginers"? I was sleepy when i posted.

Login to post a reply

Server time is: 2024-09-25 15:30:21
Your offset time is: 2024-09-25 15:30:21