Active Forums => QB64 Discussion => Topic started by: ironwolfe on April 10, 2019, 09:48:45 pm
Title: object detection in ascii based game
Post by: ironwolfe on April 10, 2019, 09:48:45 pm
I'm a newcomer to QB64 and i'm trying to solve a problem with moving my player "P" around a text generated maze at 1280,720,32 and avoid hitting other objects. I have been able to get it all working in 1280,720,256 , but when i try to load it in 32 bit color i can still load map correctly and move player, but player no longer detects objects and passes right through them . If there is a fix for this problem it would be greatly appreciated.
Title: Re: object detection in ascii based game
Post by: Raven_Singularity on April 10, 2019, 10:16:15 pm
How are you detecting the characters? POINT?
Most likely the issue is 256 colour mode uses a numbered palette (0 to 255 for colours), while 32bit uses _RGB() values. You will need to modify your code to detect the full colour value of the pixels, there are no palette entries in 32bit.
Title: Re: object detection in ascii based game
Post by: ironwolfe on April 10, 2019, 10:24:04 pm
im using "select case", with " if then "statements to detect string variable "#" or my wall in map.,this works as mentioned when i change back 256 mode. i had to change color values to _rgb when drawing maze but other than that nothing else has changed.
Title: Re: object detection in ascii based game
Post by: ironwolfe on April 10, 2019, 10:30:35 pm
thanks for the reply the only reason i wanted to change the color was i cant seem to _putimage in 256 mode.
Title: Re: object detection in ascii based game
Post by: Raven_Singularity on April 10, 2019, 10:48:10 pm
8bit mode has a palette. 32bit mode has no palette.
_PUTIMAGE should work fine in 8bit or 32bit modes, though your image should contain less than 256 colours, and you may need to load a custom palette, I'm not sure.
I only use 32bit mode in QB64, as there don't seem to be any advantages to 8bit mode (other then cycling the palette colours as an effect).
What do you mean by "statements to detect string variable '#' or my wall in map"?
What is the actual code you're using for that part?
POINT does not work the same in 8bit and 32bit modes:
CASE shop COLOR shopcolor CASE wall COLOR wallcolor CASE home COLOR homecolor CASE door COLOR doorcolor CASE tree COLOR treecolor CASE player COLOR playercolor
END SELECT ' LOCATE 2, col(y)
LOCATE y, 65 + x: PRINT MID$(mase(y, level), x, 1)
'NEXT col
' NEXT i
NEXT x NEXT y
LOOP UNTIL y > 43
Title: Re: object detection in ascii based game
Post by: ironwolfe on April 10, 2019, 11:15:45 pm
i'm using this this code to move player on map.
player.r = 4 player.c = 72
oldplayer.r = player.r oldplayer.c = player.c
wall = "#"
DO
LOCATE player.r, player.c: COLOR playercolor: PRINT ; player
DO
k$ = INKEY$
LOOP UNTIL k$ <> ""
SELECT CASE k$ CASE IS = "w" IF CHR$(SCREEN(player.r - 1, player.c)) <> wall THEN oldplayer.r = player.r oldplayer.c = player.c player.r = player.r - 1 LOCATE oldplayer.r, oldplayer.c: PRINT " " END IF
CASE IS = "s" IF CHR$(SCREEN(player.r + 1, player.c)) <> wall THEN oldplayer.r = player.r oldplayer.c = player.c player.r = player.r + 1 LOCATE oldplayer.r, oldplayer.c: PRINT " "
END IF
CASE IS = "a" IF CHR$(SCREEN(player.r, player.c - 1)) <> wall THEN oldplayer.r = player.r oldplayer.c = player.c player.c = player.c - 1 LOCATE oldplayer.r, oldplayer.c: PRINT " "
END IF
CASE IS = "d" IF CHR$(SCREEN(player.r, player.c + 1)) <> wall THEN oldplayer.r = player.r oldplayer.c = player.c player.c = player.c + 1 LOCATE oldplayer.r, oldplayer.c: PRINT " "
END IF
CASE IS = "q" END
Title: Re: object detection in ascii based game
Post by: Raven_Singularity on April 10, 2019, 11:27:57 pm
Okay, you're not using POINT to get pixel colours. I'm not entirely sure what your issue is now, hmm.
What exactly goes wrong with your code in 32bit mode?
I'm not seeing any obvious bugs jump out at me on first look.
Title: Re: object detection in ascii based game
Post by: Pete on April 10, 2019, 11:36:20 pm
It looks like he is using SCREEN to determine placement. I don't work with color values, but I am wondering if some resolution change is associated with switching to _RGB value? If so, I suspect that would throw off the SCREEN locations. Anyway, just a wild ascii guess on my part. I can't run your code as is, so I really can't experiment with my theory or check for other things. It's always best to post either working code or the entire program for debugging help.
Pete
Title: Re: object detection in ascii based game
Post by: Raven_Singularity on April 10, 2019, 11:37:34 pm
- row and column are the INTEGER text coordinates of the SCREEN mode used.
- Optional colorflag INTEGER value can be omitted or0for ASCII code values or1forcolor attributes.
In 32bit mode, there is no palette, so that won't work. I'm checking to see if QB64 has a way to do that. Otherwise, stick to 256 colour mode.
Or you could redesign what you're doing and avoid the issue altogether. :-) There's no need to be checking the screen for ASCII characters and colour palette values. You can just keep track of the coordinates for your player, and when a move is requested you would check your mase data to see if the player is able to move or not. For drawing the screen, draw the map, then draw the player. You can use CLS and _DISPLAY for smooth animation.
Edit 1:
I also note that you're using SCREEN() with two parameters, but are not providing the extra 1 parameter to specify you want the colour value. This means you should be receiving the ASCII CHR$() number for that coordinate on the screen, not the colour.
Edit 2:
I just experimented with the SCREEN function, and it works fine in QB64 for returning either colour or ASCII values.
The first one in 8bit mode returns the colour palette value of "4" (this can be from 0 to 255).
The second one in 32bit mode returns the colour value as an _RGBA value.
But again, your code is NOT checking the colour of a character on the screen, it is checking which ASCII character it is.
I'm not sure how to make it work for ASCII characters, hmm. If I change the ", 1" to a ", 0" at the end, it returns 219 for the character at 1, 1, which is not correct. ASCII 219 is a box, not the letter "H".
Edit 3:
So I have confirmed that "SCREEN(1, 1, 0)" returns the "H" character in 8bit modes, but is broken in 32bit modes. This looks like an actual bug in QB64! :-P
Title: Re: object detection in ascii based game
Post by: ironwolfe on April 11, 2019, 12:09:50 am
here is a working code of my map in 32 bit .
i have attached file
Title: Re: object detection in ascii based game
Post by: Pete on April 11, 2019, 12:12:39 am
We can't convert an exe back to source. You need to post the source code, the basic file.
Also, I was trying to remember the one graphics program I built, a gui about 5 years back. I ran into a problem with chr$(219) showing up, because unlike SCREEN 0, which I normally program in, background color is treated differently. Actually, in QBasic, you couldn't use SCREEN in graphics mode. You can in QB64, but there are some restrictions. Some colors are accepted, and some are not in SCREEN 1-13, too. So with 32 color, that's the problem. Setting the background to black might help, and for more on that, see this thread... https://www.qb64.org/forum/index.php?topic=1248.0
Pete
Title: Re: object detection in ascii based game
Post by: ironwolfe on April 11, 2019, 12:32:26 am
sorry i posted wrong file, here is proper one.
Title: Re: object detection in ascii based game
Post by: ironwolfe on April 11, 2019, 01:18:17 am
changing background color to black seems to have corrected issue, i don't think this should affect my program as i only want to load images and text mostly, thanks for the help you have been very helpful.