Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Confused about mid() command
#4
(06-11-2024, 12:25 PM)johnno56 Wrote: Cool... Worked like a charm... Thank you!

The mid() function may be used as collision detection.
Let's try this one !

Code:
'=====================================================
'PACMAN in N7
'Control Key :
'- movement   WASD
'- exit       ESC
'
'Reference :
'Tutorial on QBasic Game Design by Andre van Wyk
'http://petesqbsite.com/sections/tutorials/tutorials/basicgd.htm
'
'Quick Tips on qbasic to N7
'-locate y,x                 - set caret x,y
'-print                      - write
'-mid$()                     - mid
'======================================================
#win32
set window "Pacman",80,60,false,10
set redraw off

'color definition
black  = [0,0,0]
white  = [255,255,255]
yellow = [255,255,0]

'initial Pacman's position
x = 40
y = 10

'maze
maze = []
maze[0] = "########"
maze[1] = "#    # #"
maze[2] = "#  #   #"
maze[3] = "# ## # #"
maze[4] = "#    # #"
maze[5] = "########"

do
    set color black ; cls
   
    'maze
    set color white
    for j=0 to 7
        for i = 0 to 5
            set caret j*10,i*10
            write mid(maze[i],j)
        next
    next
   
    'remember Pacman's position
    posX = x
    posY = y
       
    'control
    if keydown(KEY_W) and y>1   then y=y-10
    if keydown(KEY_S) and y<60  then y=y+10
    if keydown(KEY_A) and x>1   then x=x-10
    if keydown(KEY_D) and x<80  then x=x+10
   
    'collision detection Pacman and Maze
    if mid(maze[y/10],x/10)="#" then
        x = posX
        y = posY
    endif
   
    'Pacman
    set color yellow
    set caret x,y ; write "C"
   
    redraw
    fwait 10
until keydown(KEY_ESCAPE,true)
Reply


Messages In This Thread
Confused about mid() command - by johnno56 - 06-11-2024, 01:39 AM
RE: Confused about mid() command - by 1micha.elok - 06-11-2024, 10:27 AM
RE: Confused about mid() command - by johnno56 - 06-11-2024, 12:25 PM
RE: Confused about mid() command - by 1micha.elok - 06-12-2024, 09:46 AM
RE: Confused about mid() command - by johnno56 - 06-12-2024, 07:59 PM
RE: Confused about mid() command - by Marcus - 06-14-2024, 01:43 PM
RE: Confused about mid() command - by johnno56 - 06-14-2024, 08:34 PM
RE: Confused about mid() command - by Marcus - 06-15-2024, 08:23 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)