# DarkBASIC Programming/2D Game Programming Pt 1
### Day 15

The half way point, finally after all that coding and reading and days. This chapter we'll be making a text adventure using more text commands you'll now learn. Plus you'll learn how to clear the screen in various colors, and oh boy you're gonna enjoy this lesson.
You probably thought, my God does the text always have to be white!
There you are! I'm a Canadian but I still spell color as color instead of colour. What's the RGB for? It stands for Red, Green, Blue, look at your monitor with a lens you'll see lots of those pixels in those colors. The rgb must be separated by brackets and then a comma for the transparency value. The transparentcy ranges from 0 to 255. RGB values range from 0 to 255 also.
Here's Some Colors to Remember
To see more have a look in paint, view the rgbs values and fool around that's the way I found out, so you should find out too. Using these above values you should be able to make nice colors. The lower the value the darker, the higher the lighter.
Now after that you want a better way to Print right?
When using text, you need to use + instead of a semi-colon to separate variables. All values must be a string, remember to convert a value to a string use the str$ command as seen in Lesson 6.
The Right Way
The Wrong Way
We can change the font easily
We can make our text opaque easily too or allow us to write over other text values
Here's style changes
Here's how to change the size
Okay here's all those in a program
You assignment is to fool around with text values and colors, come back tomorrow

### Day 16

Okay, now we've learned lots about changing text values it's time to write your own text adventure. We'll call it "Dungeons of Doom", it'll have the player to escape the dank dungeons of a castle using numerous data commands and whatnot.
First let's do an outline:
Now we have an outline let's write a simple story:
Evil Elves have captured you in their prison, now you must escape the Dungeon of Doom. Beware some turns lead to doom, others lead to a way out.
There is only two ways to die in our game, since it's more like a maze anyways.
Now Let's Do Some Data For It:
This game is complete, all things should work if not feel free to email me at: thenerd2468@hotmail.com
Now then your assignment to show you know what's going on is to go back and add in comments describing what's happening in each. The final part in your assignment is to edit all the code and data statements to make a sequel, add rooms, and more. No this game is not a text role playing game, we'll make a text role playing game in the next lesson. I think tomorrow your gonna have a break-out of game programming.

### Day 17

Oh boy, oh boy, oh boy! We're going to make a Pong game today, a BreakOut game today, and your going to learn about images, sprites and more! Okay, so how can we load multimedia in DarkBASIC? Remember in the file manager program we had some confusing formats of files in there. One thing I didn't add was animations unfortunately.
Multimedia Example:
Go look at some more examples of multimedia in DarkBASIC, some more are 3dsound, and you can play music off your cd too. We'll be using some more examples of multimedia in DarkBASIC in later chapters for now we'll be focusing on the said above in the example.
Your main question may be what is a sprite? A sprite is a 2d character that is used in games. Basically a sprite is a image that does more, in DarkBASIC sprites are the lifeblood of the system.
Sprite Works Like
You cannot use load bitmap and use that as an image for your sprite, you can only use images loaded by the load image command.
Before you did not manipulate the x,y cords of a image in DarkBASIC well that's about to change. Before we start, if we leave the computer to take care of our game's framerate then our game will run slow and differently on different paced computers. Use sync on, to turn the framerate over too you and away from the computer. Every time the sync command is used the screen is updated constantly. Use the sync rate command, to set the rate the frame refreshes, mostly 30 is good for 3d games in DarkBASIC, and 40 for 2d games is also good too, but use 30 to make sure. There are a few commands in darkbasic that draws crude graphics, the commands we'll use are: line(line startingx,toendingx,startingy,toendingy), circle(x,y,radius), and dot(dot x,y). They draw these graphics in the default ink, if the ink is not set it'll use cyan as a default. There are more commands that draw different basic 2d shapes, but we won't be using them. If your curious go check them out under BASIC2d under the DarkBASIC command reference.
Here's an example of you being able to move a circle
Wow that worked out great eh? Let's get some sleep for now.

### Day 18

Before we start I'd just like to thank everybody for visiting this wikibook, taking time to read it and for knowing when I google "DarkBASIC Programming" I see my book on the first page. That's a great feeling! I hope you learn something, I'll try and get this book done very soon but I've been very busy with learning new things and my schoolwork. I've been learning Assembly, C++, Pascal, & Visual Basic I'm also considering buying a console building kit "The XGameStation" by Mr Lamothe or as you may know him Andre' Lamothe or Lord Necron. He's one my biggest inspirations for programming besides Lee Bamber(the visionary behind DarkBASIC). Okay let's start with the pong game, I must say it's been a challenge writing this pong game, I've had lots of bugs with it. You must use your own images, only the source code is included.
Understanding the Material Before I go ahead with the Pong game there is some things that I must, nay, need to explain to you. First, of all you need to understand what a "sprite" is, yes I know I mentioned it but not has in depth as I need to now, again that was just a basic example. Basically, put a sprite is nothing but an active image that allows more manipulation then standard bitmaps. In our terms, speaking a sprite is in most cases nothing but a 2d character. We can do more with sprites in DarkBASIC then we can simply using just plain images.
You already know how to setup a sprite. But you do not know how to delete sprites, how to detect collision with sprites, and have not used them very much yet. The syntax of deleting a sprite is simple: delete sprite spriteid. The sprite obviously must exist if not you'll get a runtime error stating that the "bob" or sprite does not exist. The same works for collisions with sprites: the precise and best way is by using this command sprite collision(spriteid1,spriteid2). Again they must exist has I stated, and you must have two, again I'm stating the obvious but there are pretty dumb people out there.
The other way works the same thing except it's not has precise and goes like this: sprite hit(spriteid1,spriteid2). Easy! What may not be so easy after reading the code below is what the random numbers are for. These random numbers simply put are so that the computer generates a number from 0 to 1 in which direction the ball should go. They are for both X axis and Y axis and you should know what those are already.
The Pong Game -
if you don't understand the material review previous lessons or consult the DarkBASIC help files.
Okay there you are Pong in all it's glory. Now it's time for a prolonged Quiz.

## Quiz

1 In Game Design What Is A 2d Character Called?
    A) Mario
    B) Chara
    C) Clip Art
    D) Sprite
2 True or False: 30 is a good sync rate for games on any computer
    T)rue
    F)alse
3 Which is the best way to manually setup framerate in a computer game
    A)Set the sync on, set it to an average rate such as 30, & use sync to refresh when need
    B)Let the computer handle it all
    C)Set the sync rate to 0
    D)Simply turn on sync
4 You can declare data statements how?
    A)Data datatype
    B)dat datatype
    C)godarkbasic data datatype
    D)data.db datatype
5 What kinds of data does data statements hold?
    A)Strings Only
    B)Arrays
    C)Strings, Integers, & Reals(floating point decimals or floats)
    D)Integers
6 In our text adventure you had to escape:
    A)Castles
    B)Prison
    C)Forest
    D)A Dungeon
Okay now, for the answers, if you cheat your on your own after you have this book completed so don't be a wimp and take the coward's way out.
Answers:
* D
* True
* A
* A
* C
* D
Finally we need to end this long hard-coding day, for another awaits with many new coding properties.