Need help with RPG!

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
crazydrivr
Newbie
Posts: 8
Joined: Sat May 06, 2006 8:32 pm

Need help with RPG!

Post by crazydrivr »

I know i posted earlier today about needing help with subs and thanks to Nathan1993 i sort of get it, but some more help with transfering money from one sub to another or how to use FUNCTIONS would really help.

I also realized that i need help with some more things. For starters, i need to put an area of random encounters (monsters) in a sub. I know I need RANDOMIZE TIMER and RND commands but don't really get how to use them. (I want unlimited encounters, and only possible to get into a fight if you move a space).

The last thing I need help with is that I want to have a status screen from the menu you can pull up. But I also want exp to appear on that screen and it needs to be totaled up from the sub where the monsters will go.

For you who know what Final Fantasy is, that is basically how I want my random encounters to occur.

If anyone can help me with anything, even a little would really help!
User avatar
Theophage
Coder
Posts: 44
Joined: Sun May 07, 2006 7:32 pm
Location: Tucson, AZ
Contact:

Post by Theophage »

Okay, you'll probably want to put the RANDOMIZE TIMER somewhere at the beginning of the main module. That's where I put it.

When you do random numbers, the random number generator makes a particular sequence of numbers that appears to be random based on a certain seed value. The problem is, the seed value is the same everytime you run the program, so the random numbers will always have the same values everytime you run the program.

What the RANDOMIZE TIMER statement does, is change the seed for the random numbers based on whatever the internal clock is reading. This means that the random number sequences will be different everytime you run the program, unless you start it at exactly the same time (I think it's down to the second) every day. Now that you know how to keep your random numbers random, lets look at how to get them with the RND statement:

To generate a number from 1 to 6 and assign it to a variable called Number, you would write:

Number = INT(RND*6)+1

RND picks a random floating point (that's a number with decimal places) number from 0 to a little less than 1. Multplying this by 6 gives you a random floating point number from 0 to a little less than 6. Since we wanted only integers (numbers without the decimal places) we enclose RND*6 in the INT (integer) function. This chops off the decimal places (not rounds, just chops them off) and gives us a number from 0 to 5. Finally we add 1 to this to give us our desired 1 to 6 range.

Suppose you wanted to pick a random number from three values like 30, 45, and 60. (I used this in a program just today!) Notice that these three numbers are equal to 2*15, 3*15, and 4*15. This means that if I can just make a random number from 2 to 4, then multiply that by 15, I'll have the numbers that I want. To do this, I wrote:

Size = INT(RND*3)+2*15

I did RND*3 because there are three numbers from 2 to 4. INT(RND*3) would give me one of three numbers from 0 to 2, so I had to add 2 to that to give me a number from 2 to 4. Lastly I multiplied that by 15 to give me a number that is either 30, 45, or 60.
Daniel "Theophage" Clark
theophage (at) geocities (dot) com

"God used to be my co-pilot, but our plane crashed in the mountains and I had to eat Him..."
crazydrivr
Newbie
Posts: 8
Joined: Sat May 06, 2006 8:32 pm

Post by crazydrivr »

Ok. That helps a little. Now I need to make it so that it picks a random number (1 through 10) every time I move on the screen and if the random number is 9, then it calls the battle sub. Any help with how to do that?
User avatar
Theophage
Coder
Posts: 44
Joined: Sun May 07, 2006 7:32 pm
Location: Tucson, AZ
Contact:

Post by Theophage »

Hmm...

Can you copy and paste some of your code? It's easier for me to edit already written code than to come up with it from scratch.

Remember, to get a random number from one to ten, you would write something like:

Number = INT(RND*10)+1
Daniel "Theophage" Clark
theophage (at) geocities (dot) com

"God used to be my co-pilot, but our plane crashed in the mountains and I had to eat Him..."
crazydrivr
Newbie
Posts: 8
Joined: Sat May 06, 2006 8:32 pm

Post by crazydrivr »

SUB wilderness

CLS

DIM wild$(15)
wild$(1) = "|------C--------------------|"
wild$(2) = "|-----I-----I---I----I-------|" 'there are I's scattered all over.
wild$(3) = "|--I--------I---I---I---I-----|" 'they represent trees.
wild$(4) = "|------------------------------|" 'yea i no, bad trees.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~'skipping down
wild$(15) = "|----------------------------|"

row = 2
column = 8

lOCATE 17, 1
PRINT "This is the Wilderness."
lOCATE 18, 1
PRINT "MONSTERS RESIDE HERE..."
LOCATE 19, 1
PRINT "YOU MAY HAVE TO FACE A FEW."

DO

LOCATE 1, 1
FOR COUNT = 1 TO 15
PRINT wild$(count)
NEXT count
LOCATE row, column
PRINT "CHR$(1) 'also if you have any ideas on a movable character that doesn't smile all the time?


oldRow = row
oldColumn = column

DO
keyed$ = INKEY$
LOOP UNTIL keyed$ <> ""

SELECT CASE keyed$
CASE IS = "w"
row = row - 1
CASE IS = "s"
row = row + 1
CASE IS = "a"
column = column - 1
CASE IS = "d"
column = column + 1
CASE IS = "m"
CALL menu
END SELECT

SELECT CASE MID$(wild$(row), column , 1)
CASE IS = "I"
row = oldRow
column = oldColumn
CASE IS = "_"
row = oldRow
column = oldColumn
CASE IS = "-"
row = oldRow
column = oldColumn
CASE IS = "P"
CALL nextcity
CASE IS = "C"
EXIT SUB

LOOP
END SUB


Ok. This is what I have for this level area. I want monsters in this area only. I also only want it so that the monsters can only attack you when you move and they wont show on the map. Also make it so that if you walk onto the same area if you restart the program that there won't always be the same monster in the same area. And if you notice I dont want ascII code 1 but it is the closest i have to a character that takes only one space. Any ideas?
User avatar
Theophage
Coder
Posts: 44
Joined: Sun May 07, 2006 7:32 pm
Location: Tucson, AZ
Contact:

Post by Theophage »

Okay, first off I noticed that the code as written won't run. I don't know if that is the case with what you've actually got or whether it is just a problem with the copy you posted here. So I've taken the liberty to fix some stuff to make it able to run. I'll explain what I added (or deleted) after the code.

Code: Select all

SUB wilderness
  
  DIM wild$(15)
  wild$(1) = "|------C--------------------|"
  wild$(2) = "|....T.....T...T....T.......|" 'there are I's scattered all over.
  wild$(3) = "|..T........T.T...T...T.....|" 'they represent trees.
  wild$(4) = "|...........................|" 'yea i no, bad trees.
  wild$(5) = "|....T.....T...T....T.......|" 
  wild$(6) = "|..T........T...T...T...T...|" 
  wild$(7) = "|...........................|" 
  wild$(8) = "|....T.....T...T....T.......|" 
  wild$(9) = "|..T..........T...T...T.....|" 
  wild$(10) = "|...........................|" 
  wild$(11) = "|....T.....T...T....T.......|" 
  wild$(12) = "|..T........TTT...T...T.....|" 
  wild$(13) = "|...........................|" 
  wild$(14) = "|...T......T...T...T........|" 
  wild$(15) = "|---------------------------|"
  
  row = 2
  column = 8
  
  lOCATE 17, 1
  PRINT "This is the Wilderness."
  lOCATE 18, 1
  PRINT "MONSTERS RESIDE HERE..."
  LOCATE 19, 1
  PRINT "YOU MAY HAVE TO FACE A FEW."
  
  DO
    CLS
    LOCATE 1, 1
    FOR COUNT = 1 TO 15
      PRINT wild$(count)
    NEXT count
    LOCATE row, column
    PRINT CHR$(1) 'also if you have any ideas on a movable character that doesn't smile all the time?
    
    oldRow = row
    oldColumn = column
    
    DO
      keyed$ = INKEY$
    LOOP UNTIL keyed$ <> ""
    
    SELECT CASE keyed$
    CASE IS = "w"
      row = row - 1
    CASE IS = "s"
      row = row + 1
    CASE IS = "a"
      column = column - 1
    CASE IS = "d"
      column = column + 1
    CASE IS = "m"
      CALL menu
    END SELECT
    
    SELECT CASE MID$(wild$(row), column , 1)
    CASE IS = "T"
      row = oldRow
      column = oldColumn
    CASE IS = "-"
      row = oldRow
      column = oldColumn
    CASE IS = "|"
      row = oldRow
      column = oldColumn
    CASE IS = "P"
      CALL nextcity
    END SELECT
    
  LOOP UNTIL keyed="C"
END SUB
Okay, I filled in more of the map (of course) and I changed the dashes to periods to represent clear terrain. I changed the trees to "T"s because they look more like trees to me, and because "T" can stand for "tree". :) You also had a stray quotation mark just before the chr$(1) that I deleted.

Also, it didn't seem like you had your map borders quite right. The sides used the "|" character, but the top and bottom needed special characters of their own. since I changed the "clear terrain" character to a period and since the top and bottom already consisted of dashes, I used dashes for the top and bottom borders.

Speaking of your second SELECT CASE section, it didn't have an END SELECT so the loop wouldn't loop. I also assumed that going back on the "C" spot would take you out of the wilderness, so I changed that case to make it a more structured exit.

It is good programming practice to enter and exit loops, subs and other structures at one (and only one) point. This means that even if you have a couple of places before the end where you could exit, you need to make some sort of flag to let the rest of the structure know that it has ended, but not actually exit until the end. So in a later version, you'll have to have a flag for the "C" case and the "P" case to let it know that the player has left the map, and then to let the main program know what to do once it is out of the wilderness sub (meaning the flag will probably be a global variable).

As for the player's ASCII character, rogue-like games often use a "@" to show this is where you are "at". I just had another thought, how about using the clubs playing card character for the trees? Or the spade? You could also use the heart as the player!

Now given this much, I will try to add in some random monster stuff in the next post.
Daniel "Theophage" Clark
theophage (at) geocities (dot) com

"God used to be my co-pilot, but our plane crashed in the mountains and I had to eat Him..."
User avatar
Theophage
Coder
Posts: 44
Joined: Sun May 07, 2006 7:32 pm
Location: Tucson, AZ
Contact:

Post by Theophage »

Okay, right before the DO loop that checks the INKEY$, I would put this:

IF INT(RND*10)=9 then wanderingMonster

This gives us 10 possibilities (0-9) and if the result is 9, go to the wandering monster sub. This makes a wandering monster appear approxiamately one out of every 10 steps the player makes.

Also, I forgot to mention that in the re-written program above, I moved the CLS statement when I really didn't need to.
Daniel "Theophage" Clark
theophage (at) geocities (dot) com

"God used to be my co-pilot, but our plane crashed in the mountains and I had to eat Him..."
crazydrivr
Newbie
Posts: 8
Joined: Sat May 06, 2006 8:32 pm

Post by crazydrivr »

Thanks again. My program wouldn't copy paste from there to the internet, so I had to type it again on the post page. So most of the problems I had on the last post is really on my program. I just must have skipped them. Thanks though that all really helps.
User avatar
Zim
Veteran
Posts: 98
Joined: Mon Dec 05, 2005 4:31 pm
Location: Wisconsin, USA
Contact:

copy and paste

Post by Zim »

Hmmm... if you're using Windows, you should be able to copy from the web page and paste into NotePad. This will create a .txt file. If you then rename the .txt file to the extention ".bas", you should be able to open it with QB (or any text or BASIC editor) and complete your paste from that point.
--- Zim ---
--- Time flies like an arrow, but fruit flies like a banana ---
User avatar
Theophage
Coder
Posts: 44
Joined: Sun May 07, 2006 7:32 pm
Location: Tucson, AZ
Contact:

Post by Theophage »

crazydrivr,

I know it is more fun to make an RPG from scratch, but here is a program that called "ASCIIQUEST Editor" by Jace Masula that you might be interested in anyway. It is a (relatively) simple RPG maker written in QBASIC that uses colorful ASCII text as the graphics. Check it out here: http://qb45.think-new.com/asciiquest.php

I just came across it today and it looks COOL!
Daniel "Theophage" Clark
theophage (at) geocities (dot) com

"God used to be my co-pilot, but our plane crashed in the mountains and I had to eat Him..."
crazydrivr
Newbie
Posts: 8
Joined: Sat May 06, 2006 8:32 pm

Post by crazydrivr »

Thanks for the tip. I am still kinda lost on how to use the editor, but it is really helping.
User avatar
Theophage
Coder
Posts: 44
Joined: Sun May 07, 2006 7:32 pm
Location: Tucson, AZ
Contact:

Post by Theophage »

Just email the creator, he's a nice guy.
Daniel "Theophage" Clark
theophage (at) geocities (dot) com

"God used to be my co-pilot, but our plane crashed in the mountains and I had to eat Him..."
Post Reply