[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 264: mysqli_fetch_assoc(): Couldn't fetch mysqli_result [phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 326: mysqli_free_result(): Couldn't fetch mysqli_result [phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 264: mysqli_fetch_assoc(): Couldn't fetch mysqli_result [phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 326: mysqli_free_result(): Couldn't fetch mysqli_result [phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4149: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3027) [phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4149: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3027) [phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4149: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3027) [phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4149: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3027) [phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 264: mysqli_fetch_assoc(): Couldn't fetch mysqli_result [phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 326: mysqli_free_result(): Couldn't fetch mysqli_result My first project needs a li'l help - Pete's QBASIC Site
Hi everyone, nice to meet ya! I'm fairly new to qbasic and I'm doing my first "game" to figure things out and I must say it's alot of fun, hard but fun. Anyway, I'm doing a simple virtual pet, so far the things I've got down is a small selection of randomly chosen names of the "pet", as well as a randomly selected appearance. The first thing I'd like some pointers on is how do I make this creature move about on it's own? I have a vague idea about it involving a randomized timer but I can't get the hang of it, am I right in my assumption that I need to do something like this?:
CLS
num1! = INT(RND * 10) + 1
PRINT "NAME:";
IF num1! = 1 THEN PRINT "BOB"
IF num1! = 2 THEN PRINT "JOE"
IF num1! = 3 THEN PRINT "RICHARD"
IF num1! = 4 THEN PRINT "WILL"
IF num1! = 5 THEN PRINT "QBERT"
IF num1! = 6 THEN PRINT "ROGER"
IF num1! = 7 THEN PRINT "SVEN"
IF num1! = 8 THEN PRINT "GUNTHER"
IF num1! = 9 THEN PRINT "BARNEY"
IF num1 = 10 THEN PRINT "FRED"
num2! = INT(RND * 10) + 1
LOCATE 18, 40
IF num2! = 1 THEN PRINT "(`-`)"
IF num2! = 2 THEN PRINT "(^o^)"
IF num2! = 3 THEN PRINT "(-_-)"
IF num2! = 4 THEN PRINT "(>_<)"
IF num2! = 5 THEN PRINT "(T_T)"
IF num2! = 6 THEN PRINT "(X_X)"
IF num2! = 7 THEN PRINT "(x_X)"
IF num2! = 8 THEN PRINT "(~_~)"
IF num2! = 9 THEN PRINT "(`o`)"
IF num2! = 10 THEN PRINT "(p_-)"
Expanding on the previous post, below is a way to go about making the pets randomly walk around the screen.
I used a TYPE struct to hold all the information related to the pet under one "animal" type. You could also just use independent variables if you wanted but I like keeping related variables housed together.
Comments in code. Written in QB4.5. (Never used QB64 so I don't know if they syntax is different)
CLS
'arbritrary max screen positions
CONST MAXX = 40
CONST MAXY = 20
RANDOMIZE TIMER
'create type struct to hold pet info
TYPE animal
petName AS STRING * 8
gfxString AS STRING * 5
x AS INTEGER
y AS INTEGER
END TYPE
DIM pet AS animal
'set initial pet location
pet.x = 15
pet.y = 15
'random number used to define pet
num% = INT(RND * 4 + 1)
'define pet based on num%
SELECT CASE num%
CASE 1:
pet.petName = "BOB"
pet.gfxString = "('-')"
CASE 2:
pet.petName = "Joe"
pet.gfxString = "(^o^)"
CASE 3:
pet.petName = "RICHARD"
pet.gfxString = "(-_-)"
CASE 4:
pet.petName = "WILL"
pet.gfxString = "(>_<)"
'etc..
END SELECT
'display pet name in upper left corner
LOCATE 1, 1
PRINT pet.petName
'move pet 15 times and quit.
FOR i% = 0 TO 15 STEP 1
'mask old draw location with black text
LOCATE pet.x, pet.y
COLOR 0
PRINT pet.gfxString
'set potential new pet xy location.
'pet new location can be +- 3 spots.
pet.x = pet.x + (INT(RND * 6) - 3)
pet.y = pet.y + (INT(RND * 6) - 3)
'error checking to see if they went off screen
IF (pet.x <= 0) THEN pet.x = 1
IF (pet.x >= MAXX) THEN pet.x = MAXX - 3
IF (pet.y <= 0) THEN pet.y = 1
IF (pet.y >= MAXY) THEN pet.y = MAXY - 3
'draw pet at new location
LOCATE pet.x, pet.y
COLOR 15
PRINT pet.gfxString
'wait a second before next loop
SLEEP 1
NEXT i%
END