Sunday, July 21, 2013

Tutorial #6 - Data Tables

A very useful feature of Petit Computers BASIC is the DATA command. If you are programming a game this will allow you to set up a table filled with strings and integers to your hearts content. For example instead of manually typing IF cases for every line of text in a game, you can just store it in a data table and have your code READ what string needs to be printed and be done with it. I am going to keep this tutorial simple, but feel free to ask any questions you may have.


  1. ACLS:CLEAR:CLS 'Clear our setup

  2. RESTORE @MSGDATA 'This will load the data after @MSGDATA
  3. READ MSGCOUNT 'This will read the first variable stored in DATA, and that is our message count (3)
  4. FOR LOOP = 1 TO MSGCOUNT ' Loop through our data table
  5.  READ MSGX, MSGY ' This will read the X and Y locations of where our message should be printed into the variables MSGX and MSGY
  6.  READ MESSAGE$ ' Read the message string
  7.  LOCATE MSGX, MSGY 'Set our cursor to the stored X/Y location
  8.  PRINT MESSAGE$ ' Print off our message
  9. NEXT LOOP
  10. END

  11. @MSGDATA 'This is the label for our data table
  12. DATA 3 'This will store the #3, our message count
  13. DATA 0,0,"Hello" 'This will store the x, y, and string to print
  14. DATA 1,1,"How are you?"
  15. DATA 4,3,"Goodbye"

QR Code for this Tutorial

Homework

Topic 17 - Declarations and Assignment Commands
  • CLEAR
Topic 21 - Read
  • READ
  • DATA
  • RESTORE

Sunday, July 14, 2013

Tutorial #5 - Beginnings of a Game

In this tutorial I will be going over more complicated console functions, as well as for loops and playing sound. We are basically going to be making the main menu for a game. We will expand on this in later tutorials and when we are finished we will have a fully playable game. We will be introducing subroutines that basically take arguments by setting variables before we call them. This will allow us to reuse the same "functions" with different output depending on what we need. There will be a couple times in this tutorial where I will have things typed that wont be the same as what you will scan in the QR Code. PC has some characters that do not exist in standard unicode format such as a menu pointer finger. First though I will explain the For loop, it is very useful for programmers of all types. Basically it will be formatted as

  1. FOR VAR = 0 TO 5
  2. ...
  3. NEXT VAR
This will set the variable VAR to 0 and execute the code after 5 times, then continue.

  1. FOR VAR = 0 TO 10 STEP 2
  2. ...
  3. NEXT VAR
The above will do the same, only the variable will increase in increments of 2 as opposed to 1.
Alright, enough talk. Lets get to some code.


  1. ACLS:VISIBLE 1,1,0,0,0,0
  2. COLOR 15,11 'Set the color of the console to blue background with white characters
  3. CLS

  4. @MAINMENU
  5.  LOCATE 8,4 'Set our cursor position where we print to 8,4
  6.  PRINT "Petit Dungeon"
  7.  LOCATE 11,9 'Set our cursor position to 11,9
  8.  PRINT "> Start"
  9.  LOCATE 11,11
  10.  PRINT "  Quit"

  11.  'Set our Box X,Y, Width, and Height
  12.  BX=9:BY=7
  13.  BW=11:BH=6
  14.  GOSUB @DRAWBOX

  15.  BGMPLAY 0,4 'Play some background music, give it ID #0
  16.  CSRPOS = 1 'Set our default cursor position to 1(Top)

  17. @MMLOOP 'Our main menu loop
  18.  'If the up button was pressed, set the cursor position, play(beep) a sound effect, and update our pointer.
  19.  IF BUTTON(2) == 1 THEN CSRPOS = 1:BEEP 2:LOCATE 11,11:PRINT " ":LOCATE 11,9:PRINT ">"
  20.  'Move our cursor down if the down key is pressed
  21.  IF BUTTON(2) == 2 THEN CSRPOS = 2:BEEP 2:LOCATE 11,11:PRINT ">":LOCATE 11,9:PRINT " "
  22.  'If they press A and its cursor position 1(Top) then play the confirm sound and quit
  23.  IF BUTTON(2) == 16 AND CSRPOS == 1 THEN BEEP 3:GOSUB @ENDGAME
  24.  'If the buttom option is chosen, play the cancel sound and quit
  25.  IF BUTTON(2) == 16 AND CSRPOS == 2 THEN BEEP 4:GOSUB @ENDGAME
  26. GOTO @MMLOOP

  27. @ENDGAME
  28.  BGMSTOP 0 'Stop playing sound #0 (Our bg music)
  29. END

  30. 'Our function to draw a box
  31. 'Arguments: BX, BY, BW, BH
  32. @DRAWBOX
  33.  'Draw the top and bottom lines of our box
  34.  FOR LX = BX+1 TO BX+BW-1
  35.   LOCATE LX, BY
  36.   PRINT "─"
  37.   LOCATE LX, BY+BH
  38.   PRINT "─"
  39.  NEXT
  40.  'Draw the left and right sides
  41.  FOR LY = BY+1 TO BY+BH-1
  42.   LOCATE BX,LY
  43.   PRINT "│"
  44.   LOCATE BX+BW,LY
  45.   PRINT "│"
  46.  NEXT

  47.  'Draw our box corners
  48.  LOCATE BX,BY
  49.  PRINT "┌"
  50.  LOCATE BX+BW,BY
  51.  PRINT "┐"
  52.  LOCATE BX,BY+BH
  53.  PRINT "└"
  54.  LOCATE BX+BW,BY+BH
  55.  PRINT "┘"
  56. RETURN

Okay, so that might seem daunting and super confusing. Just take your time reading it and feel free to play around with the code. Change things, break things, fix them. That's what its all about, right? =)

QR Code for this Tutorial


Homework

Okay, I am going to start doing this a little differently. Rather than explain them here I think it is time to teach you about referencing stuff in the manual if you don't already. It will help you more in the long run. The way it works is you press the help icon in the bottom left of the screen and find the topic you need to know something about and then you find the command you need after you pick the topic. From here on I will tell you the topic that the new commands are located and want you to look them up yourself. You may know the old saying: "Give a man a fish, and he will eat tonight. Teach a man to fish, and he will eat forever."

Topic 9: Sound Related Table (For sound/music reference)
Topic 21: Repeat/Comparison
  • FOR~ TO~ STEP
Topic 23: Basic Console Commands
  • COLOR
  • LOCATE
Topic 43: Basic Audio Commands
  • BEEP
  • BGMPLAY
  • BGMSTOP

Wednesday, July 10, 2013

Project Update

Sorry this isn't another tutorial, but I am almost finished with the map editor for my project. Just thought I would post a little screenshot of it.
I promise the next post will be a tutorial, though. >_>

Tuesday, July 9, 2013

My Game Project

Just announcing that I am currently starting a full game project. I can tell you it is an RPG (Very old school, think mid-late 80s) and it is not based off of my demo, but rather I have started from scratch. I have got the basics working, and I am currently creating a map editor for the PC to help me out, as SCRED doesn't really do what I need.

I do also plan to release the source code for the editor when I release the game (Or maybe before, during development). I have chosen to write the editor in Visual Basic because I felt it would go with Petit Computer and maybe those of you who do not know any other languages can check it out and kind of segway into software development for the PC.

Anyways, stay tuned. More tutorials and information to come.

Sunday, July 7, 2013

Tutorial #4 - Getting Input

To do anything fun with your program you are going to need to receive input from the user. When your program receives input it can create changes that the user controls and thus makes your program infinitely more useful/fun. Input can be handled a couple of ways in Petit Computer. You can either receive text input from the onscreen keyboard/console or via button pressing. They are both straight forward and fairly easy to understand. Lets take a look at this sample program.

  1. INPUT "What is your name: ";NAME$ ' This asks the user for their name, and stores it in NAME$
  2. PRINT "Hello ";NAME$;"! Nice to meet you."
  3. INPUT "How old are are you?";AGE 'This will only accept a numeric answer, and store it in AGE
  4. IF AGE <= 12 THEN PRINT "Your parents must be proud of you."
  5. 'Okay, this will simply check if the variable AGE is Less Than < or equal to =
  6. 'THEN do a command if it is.
  7. GOTO @ENDPROGRAM 'We can skip ahead now
  8. IF AGE >= 13 OR AGE < 18 THEN PRINT "How are your studies?" ELSE PRINT "What are your plans?"
  9. 'This checks if your age is greater than or equal to 13, OR less than 18 and if its true print one thing, or do something ELSE.
  10. @ENDPROGRAM
  11. PRINT "Press the A key to quit."
  12. @LOOP
  13. IF BUTTON(0) == 16 THEN END
  14. 'This checks if a button (A Key = 16) was pressed. End the program if it was.
  15. GOTO @LOOP 'Keep doing this until it is pressed.
I hope this made some sense to you. If you play around with the code it shouldn't take long to understand.
As always if you have any questions or comments feel free to post them.

New Commands Used

INPUT - Obtain numbers or Strings
This will receive input from the onscreen keyboard and store it in one or multiple variables.
  • INPUT "string";received variable
  • INPUT "string";received variable$
  • INPUT "string";received variable, received variable2$
BUTTON() - This returns data from each button pressed.
This is how we get input from the DPAD, ABXY, LR, and Start buttons.
  • Variable = BUTTON(type)
Please consult the help in Petit Computer or the manual for a table of button types and return values. Under "Console Entry"

IF ~ THEN ~ ELSE - Conditional judgement.
Compare variables or numbers and execute a command based on the result. Must be on one line.
  • IF condition THEN command
  • IF condition THEN @label
  • IF condition THEN command ELSE command
  • IF condition THE @label ELSE @label

QR Code for this Tutorial


Friday, July 5, 2013

Tutorial #3 - Variables 101

Variables are essential for doing anything useful in Petit Computer. They are basically places to hold data, kind of like a file on a hard drive. You can read and write to a variable, and you can also have the user of your program do the same. A variable can hold (equal, =) either a number (ex: 132) or a string (ex: "Hey there!").

If you decide you want your variable to hold a number you simply have to set it like this.

  1. SOMEVAR = 132
If you decide you want it to be a string, you must end the variable name with $.
  1. SOMEVAR$ = "Hey there!"
There are plenty of things you can do with a variable, below are just a few examples.
  1. ANUMBER = 132
  2. ASTRING$ = "This is text"
  3. PRINT ANUMBER 'This will simply print: 132
  4. PRINT ASTRING$ 'This will simply print: "This is text"
  5. '-----------
  6. ASTRING$ = "Your number: " 'You can redefine a variable at any time
  7. ANUMBER = ANUMBER + 5 'You can also do math!
  8. PRINT ASTRING$;ANUMBER 'You can also print multiple variables at once, separate with ;
  9. 'The above will print: Your number: 137
  10. '----------
  11. STRINGA$ = "Hello "
  12. STRINGB$ = "there,"
  13. ASTRING$ = STRINGA$;STRINGB$ 'You can also join two strings together
  14. PRINT ASTRING$;" and thats all!" 'You can still manually add to your print command as well.
  15. 'The above will print: Hello there, and that is all!

I hope you understand this basic introduction into variables. If you have any questions feel free to comment and ask.

QR Code for this Tutorial


Thursday, July 4, 2013

Demo #1 - Eponick's RPG Demo

Here is a small demo I  made for everyone. Please feel free to look at the source code and play around with it. Maybe I will continue developing it into a full game eventually, but for now it is just for learning. You should zoom in to 200% for easy scanning.
Controls: Hold B to run, push A to interact.