Author Topic: object detection in ascii based game  (Read 2979 times)

0 Members and 1 Guest are viewing this topic.

Offline ironwolfe

  • Newbie
  • Posts: 9
    • View Profile
object detection in ascii based game
« 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.

Offline Raven_Singularity

  • Forum Regular
  • Posts: 158
    • View Profile
Re: object detection in ascii based game
« Reply #1 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.
« Last Edit: April 10, 2019, 10:17:59 pm by Raven_Singularity »

Offline ironwolfe

  • Newbie
  • Posts: 9
    • View Profile
Re: object detection in ascii based game
« Reply #2 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.

Offline ironwolfe

  • Newbie
  • Posts: 9
    • View Profile
Re: object detection in ascii based game
« Reply #3 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.

Offline Raven_Singularity

  • Forum Regular
  • Posts: 158
    • View Profile
Re: object detection in ascii based game
« Reply #4 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:
Quote
The return value is an INTEGER palette attribute value or an _UNSIGNED LONG _RGBA 32 bit value in QB64.


Your old code was returning an INTEGER palette value.  Your new code is returning an _RGBA 32 bit value.

Your new IF statement should look something like this (untested):

Code: QB64: [Select]
  1. IF POINT(X, Y) = _RGB(255, 255, 0) THEN
  2.    ' Colour at pixel is bright yellow

Offline ironwolfe

  • Newbie
  • Posts: 9
    • View Profile
Re: object detection in ascii based game
« Reply #5 on: April 10, 2019, 11:09:56 pm »
im just printing test strings using mid$  here is a sample of my code  im very new to this so i appreiciate the patience.

    mase(2, 1) = "###############################################################################################"
    mase(3, 1) = "#xxxxxx###       ########                                                                D    #"
    mase(4, 1) = "#xxxx   ###      ########    ######  #######################     ########  #########  #####   #"



i'm using this code to print out mase(43,1)  string array and change color of map character.

    shop = "V": shopcolor = _RGB(83, 105, 0)
    wall = "#": wallcolor = _RGB(133, 122, 0)
    home = "H": homecolor = _RGB(244, 89, 0)
    door = "D": doorcolor = _RGB(89, 61, 0)
    tree = "x": treecolor = _RGB(17, 177, 0)
    player = "P": playercolor = _RGB(216, 161, 0)

    DO

        FOR y = 2 TO 43
            FOR x = 1 TO 95

                'FOR i = 42 TO 95

                SELECT CASE MID$(mase(y, level), x, 1)

                    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






Offline ironwolfe

  • Newbie
  • Posts: 9
    • View Profile
Re: object detection in ascii based game
« Reply #6 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



Offline Raven_Singularity

  • Forum Regular
  • Posts: 158
    • View Profile
Re: object detection in ascii based game
« Reply #7 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.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: object detection in ascii based game
« Reply #8 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Raven_Singularity

  • Forum Regular
  • Posts: 158
    • View Profile
Re: object detection in ascii based game
« Reply #9 on: April 10, 2019, 11:37:34 pm »
Okay, I see you're using the SCREEN function:

Code: QB64: [Select]
  1. The SCREEN function returns the ASCII code of a text character or the color attribute at a set text location on the screen.
  2.  
  3. Syntax:
  4.          codeorcolor% = SCREEN (row%, column% [, colorflag%])
  5.  
  6.  - row and column are the INTEGER text coordinates of the SCREEN mode used.
  7.  - Optional colorflag INTEGER value can be omitted or 0 for ASCII code values or 1 for color 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.


Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1920, 1080, 256)
  2. PRINT "Hello"
  3. PRINT "Colour Value ="; SCREEN(1, 1, 1)
  4.  
  5. SCREEN _NEWIMAGE(1920, 1080, 32)
  6. COLOR _RGB(222, 244, 155)
  7. PRINT "Hello"
  8. PRINT "Colour Value ="; SCREEN(1, 1, 1)

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
« Last Edit: April 10, 2019, 11:53:14 pm by Raven_Singularity »

Offline ironwolfe

  • Newbie
  • Posts: 9
    • View Profile
Re: object detection in ascii based game
« Reply #10 on: April 11, 2019, 12:09:50 am »
here is a working code of my map in 32 bit .

i have attached file

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: object detection in ascii based game
« Reply #11 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
« Last Edit: April 11, 2019, 12:29:06 am by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline ironwolfe

  • Newbie
  • Posts: 9
    • View Profile
Re: object detection in ascii based game
« Reply #12 on: April 11, 2019, 12:32:26 am »
sorry i posted wrong file, here is proper one.


Offline ironwolfe

  • Newbie
  • Posts: 9
    • View Profile
Re: object detection in ascii based game
« Reply #13 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.