MajorGeeks Support Forums

Go Back   MajorGeeks Support Forums > ----------= PC, Desktop and Laptop Support =---------- > Software
Register FAQ Members List Calendar Casino Mark Forums Read

Software Software such as operating systems like Windows XP, Windows Vista, Windows 7 etc., or specific programs.


Reply
 
Thread Tools Display Modes
  #1  
Old 06-06-05, 19:33
rpgfan3233 rpgfan3233 is offline
Private E-2
 
Join Date: Jun 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default QBasic problem: Randomizing PUT statements efficiently

Yeah, I know, it's a dead language, but I have a craving to learn more! :D

I have 3 BSAVEd graphics that are BLOADed into a file. I'm using PUT statements to display them. The problem is the fact that each graphic is stored in a different array, which means 3 different arrays, and I'm using a random number to call a set of IF...THEN...ELSE statements which call a certain PUT statement based on the number. I was wondering if there was a way to call a single PUT statement, with a certain array as the target array based on the random number. I'm only using 3 graphics (which will eventually grow larger over time), so I'm basically just asking for code optimization, if that's possible.
Here is the code (note the redundancies when you look at the PUT statements):
Code:
SCREEN 13
  CLS
  
  DIM blbelt(901) AS INTEGER, blmage(937) AS INTEGER, fighter(937) AS INTEGER
  
  ' "Fast Palette Swapping" technique
  '$INCLUDE: 'colors.bi'
  
  DEF SEG = VARSEG(blbelt(0))
  BLOAD "bl_belt.bsv", 0
  DEF SEG
  
  DEF SEG = VARSEG(blmage(0))
  BLOAD "bl_mage.bsv", 0
  DEF SEG
  
  DEF SEG = VARSEG(fighter(0))
  BLOAD "fighter.bsv", 0
  DEF SEG
  
  FOR drawcharsY% = 0 TO 140 STEP 70
  	FOR drawcharsX% = 0 TO 280 STEP 40
  		RANDOMIZE TIMER
  		char% = INT(RND * 3) + 1
  		IF char% = 1 THEN
  			PUT (drawcharsX%, drawcharsY%), blbelt
  		ELSEIF char% = 2 THEN
  			PUT (drawcharsX%, drawcharsY%), blmage
  		ELSEIF char% = 3 THEN
  			PUT (drawcharsX%, drawcharsY%), fighter
  		END IF
  	NEXT drawcharsX%
  NEXT drawcharsY%
Okay, the idea I'm having is to do something like this:
PUT (drawcharsX%, drawcharsY%), arrayName(char%)
where arrayName is an array that can be referenced to fetch one of the arrays that hold graphics, based on the value of "char%".

For example:
Code:
	char% = 1
  	PUT (drawcharsX%, drawcharsY%), arrayName(char%) ' fetches the "blbelt" array
  	char% = 2
  	PUT (drawcharsX%, drawcharsY%), arrayName(char%) ' fetches the "blmage" array
  	char% = 3
  	PUT (drawcharsX%, drawcharsY%), arrayName(char%) ' fetches the "fighter" array
I hope somebody can help or give ideas. I also hope I explained it well enough...
Reply With Quote
Sponsored links
  #2  
Old 06-07-05, 11:20
rpgfan3233 rpgfan3233 is offline
Private E-2
 
Join Date: Jun 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default Re: QBasic problem: Randomizing PUT statements efficiently

I was able to change it:
Code:
SCREEN 13
 CLS
 
 upperbound% = 3
 lowerbound% = 1
 
 REDIM chars%(937)
 
 ' "Fast Palette Swapping" technique
 '$INCLUDE: 'C:\WINDOWS\Desktop\colors.bi'
 
 FOR drawcharsY% = 0 TO 140 STEP 70
 	FOR drawcharsX% = 0 TO 280 STEP 40
 		RANDOMIZE TIMER
 		char% = INT(RND * (upperbound% - lowerbound% + 1)) + lowerbound%
 		found% = 0
 		images% = 0
 		DO
 			images% = images% + 1
 			SELECT CASE char%
 				CASE images%
 		    		fileName$ = RIGHT$(STR$(images%), (LEN(STR$(images%)) - 1))
 		    		IF images% < 10 THEN fileName$ = "0" + fileName$
 		    		fileName$ = "[path\]prefix" + fileName$ + ".bsv"
 					found% = 1
 			END SELECT
 		LOOP UNTIL found% = 1
 		DEF SEG = VARSEG(chars%(0))
 		BLOAD fileName$, VARPTR(chars%(0))
 		DEF SEG
 		PUT (drawcharsX%, drawcharsY%), chars%
 		ERASE chars%
 		REDIM chars%(937)
 	NEXT drawcharsX%
 NEXT drawcharsY%
If anybody needs help understanding it, just ask.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 20:59.

MajorGeeks.Com Menu

MajorGeeks.Com \ All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ NEW! PC Games \ System Tools \ Macintosh \ Demonews.Com \ Top Downloads

MajorGeeks.Com \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds


Powered by vBulletin® Version 3.8.4
Copyright © 2009 vBulletin Solutions, Inc. All rights reserved.
Ad Management by RedTyger