TGC Codebase Backup



Simple example of conditions, loops, colors, shapes and variables (complete remarks) by Yskonyn

9th Feb 2006 20:48
Summary

Simple example of how to make conditions give feedback on screen and learn to play with remarks, colors, shapes, variables, loops and IF statements.



Description

This little example draws a box on screen and checks for two conditions:
1) the mouse cursor needs to be over the box
2) the left mouse button needs to be pressed
If both are true then the programs gives feedback in the form of changing color.
The box changes to a green color indicating the action was correct.

The program also shows how you can incorporate a simple counter.
Every time you click on the box the counter add 1 unit to its amount.

Feel free to play around with the code, expand on it and make funny variations.
It's a good way to learn to play with various elements.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    REM -Created by R. Ph. Kraak on 09-02-06-
REM -RKGAMESProductions (RKGP) 2006-
REM -------------------------------------

REM Setup main program

cls                           `clear the screen from rubbish
set display mode 1024,768,32  `set display resolution
show mouse                    `keep the mouse visible

REM Setup initial counter conditions

counter=0                           `counter for amount of clicks
set cursor 500,500                  `define position of the counter on screen
ink rgb(0,255,0),0                  `make sure the color is green
print "Successful clicks: ",counter `create the counter on screen

REM Now we're going to make the technical bits

REMSTART
In the following part we've setup a simple loop
which checks for the left mousebutton being pressed
and checks the position of the mousecursor.
If it's pressed while over the box then all conditions
are met and it will change the color of the box to
green, plus a counter will show up.
REMEND

do
if mouseclick()=1 AND MOUSEX()=>100 AND MOUSEX()=<200 AND MOUSEY()=>100 AND MOUSEY()=<200
   cls                                 `make sure nothing gets overlapped
   counter=counter+1                   `increase counter by one with every successful click
   set cursor 500,500                  `position cursor to display text at specific loc
   print "Successful clicks: ",counter `update the counter
   ink rgb(0,255,0),0                  `change to green color
   box 100,100,200,200                 `and update the box
      else ink rgb(255,0,0),0          `if there's no success turn the color back to red
      box 100,100,200,200              `and update the box
endif
loop