Weekly Qbasic and Qb64 Lesson Topics
April 26, 2025, 12:29:56 am
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Want to see a specific Tutorial? ASK!
 
  Home Help Search Arcade Links Staff List Login Register  

PacMan2f This one moves with arrow keys

Pages: 1 [2] 3 4
  Print  
Author Topic: PacMan2f This one moves with arrow keys  (Read 4363 times)
guest
Guest
« Reply #15 on: March 10, 2011, 04:15:36 pm »


    Here is an update that alows movement off the arrow keys. This is more a demonstration or proof of concept. This wont be the final version.
Code:
REM Demo of Pac Map.
DEFLNG A-Z

SCREEN _NEWIMAGE(800, 600, 32) 'what we see

DIM SHARED mx, my, mbl, mbr
DIM SHARED PacMap(19, 25)
DIM SHARED Pacrow, Paccol, Pacsym, N, S, E, W, NN, SS, EE, WW

Pacsym = 10: Pacrow = 1: Paccol = 7
GOSUB Filldim
GOSUB Placepac
'NOTE row and column start at 0


DO
  _LIMIT 15
  CLS
  GOSUB Showmap
  GOSUB Movpac
  LOCATE 33, 1: PRINT Pacrow, Paccol, N, E, S, W
  LOCATE 34, 1: PRINT NN, EE, SS, WW
  _DISPLAY
LOOP UNTIL _KEYDOWN(27)
SLEEP
SCREEN 0
SYSTEM

Movpac:
'make a backup of PAC row and column
OlDPacrow = Pacrow: OldPaccol = Paccol

'we need to know what is above,below,to right and left for possible unblocked movement
'if any of NSEW is a limit on the map make it invalid as -1
N = Pacrow - 1
IF N < 0 THEN N = -1
S = Pacrow + 1
IF S > 18 THEN S = -1
E = Paccol + 1
IF E > 24 THEN E = -1
W = Paccol - 1
IF W < 0 THEN W = -1

'now if NSEW are valid see whats in those "cells"
IF N <> -1 THEN NN = PacMap(N, Paccol)
IF S <> -1 THEN SS = PacMap(S, Paccol)
IF E <> -1 THEN EE = PacMap(Pacrow, E)
IF W <> -1 THEN WW = PacMap(Pacrow, W)

IF _KEYDOWN(20480) THEN 'down arrow key
  IF SS <> 176 THEN 'test for wall
    IF S <> -1 THEN 'test for map limit
      Pacrow = Pacrow + 1
    END IF
  END IF
END IF

IF _KEYDOWN(18432) THEN 'up arrow key
  IF NN <> 176 THEN
    IF N <> -1 THEN
      Pacrow = Pacrow - 1
    END IF
  END IF
END IF

IF _KEYDOWN(19200) THEN 'left arrow key
  IF WW <> 176 THEN
    IF W <> -1 THEN
      Paccol = Paccol - 1
    END IF
  END IF
END IF

IF _KEYDOWN(19712) THEN 'right arrow key
  IF EE <> 176 THEN
    IF E <> -1 THEN
      Paccol = Paccol + 1
    END IF
  END IF
END IF
IF Pacrow <> OlDPacrow OR Paccol <> OldPaccol THEN
  'remove pac man from old position
  z = PacMap(OlDPacrow, OldPaccol) ''extract old pac man
  z = z - Pacsym ''suntract pacman symbol from it (42 -  10 = 32)
  PacMap(OlDPacrow, OldPaccol) = z ''place z  back inside map

  'add new pac to new position
  z = PacMap(Pacrow, Paccol) ''extract whats at this new row and column (should be 32)
  z = z + Pacsym ''add pacman symbol to it (32 +10 = 42)
  PacMap(Pacrow, Paccol) = z ''place in back inside map
END IF
RETURN

Showmap:
FOR c = 0 TO 18
  FOR R = 0 TO 24
    z = PacMap(c, R)
    SELECT CASE z
      CASE 32

      CASE 42
        LINE (R * 30, c * 30)-((R * 30) + 29, (c * 30) + 29), _RGB32(255, 255, 0), BF
      CASE 176
        LINE (R * 30, c * 30)-((R * 30) + 29, (c * 30) + 29), _RGB32(0, 0, 255), BF
    END SELECT
  NEXT R
NEXT c

RETURN

Filldim:
FOR c = 0 TO 18
  FOR R = 0 TO 24
    READ z
    PacMap(c, R) = z
    'PacMap(r, c) = Z
    IF z = 176 THEN
      LINE (R * 30, c * 30)-((R * 30) + 29, (c * 30) + 29), _RGB32(0, 0, 255), BF
    END IF
  NEXT R
NEXT c
RETURN

Placepac:
'extract whats at this row and column (should be 32)
z = PacMap(Pacrow, Paccol)
'add pacman symbol to it (32 +10 = 42)
z = z + Pacsym
'place in back inside map
PacMap(Pacrow, Paccol) = z
RETURN



'-------------------------- MAP --------------------------------------
DATA 176,176,176,176,176,176,176,176,176,176,176,176,32,176,176,176,176,176,176,176,176,176,176,176,176
DATA 176,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,176
DATA 176,32,176,176,176,176,176,176,176,176,176,32,176,32,176,176,176,176,176,176,176,176,176,32,176
DATA 176,32,176,32,32,32,32,32,32,32,32,32,176,32,176,32,32,32,32,32,32,32,176,32,176
DATA 176,32,176,32,176,176,176,176,32,176,176,32,176,32,176,32,176,176,176,176,176,32,176,32,176
DATA 176,32,176,32,176,32,32,32,32,32,176,32,176,32,176,32,32,32,32,32,32,32,176,32,176
DATA 176,32,176,32,176,32,176,176,32,176,176,32,176,32,176,32,176,32,176,32,176,32,32,32,176
DATA 176,32,32,32,176,32,32,32,32,32,32,32,32,32,32,32,176,32,176,32,176,32,176,32,176
DATA 176,32,176,32,176,32,176,176,176,32,176,176,32,176,176,32,32,32,176,32,32,32,176,32,176
DATA 32,32,176,32,32,32,32,32,32,32,176,32,32,32,176,32,176,176,176,176,176,32,176,32,32
DATA 176,32,176,32,176,32,176,176,176,32,176,176,176,176,176,32,32,32,176,32,32,32,176,32,176
DATA 176,32,32,32,176,32,32,32,32,32,32,32,32,32,32,32,176,32,176,32,176,32,176,32,176
DATA 176,32,176,32,176,32,176,176,32,176,176,32,176,32,176,32,176,32,176,32,176,32,32,32,176
DATA 176,32,176,32,176,32,32,32,32,32,176,32,176,32,176,32,32,32,32,32,32,32,176,32,176
DATA 176,32,176,32,176,176,176,176,32,176,176,32,176,32,176,32,176,176,176,176,176,32,176,32,176
DATA 176,32,176,32,32,32,32,32,32,32,32,32,176,32,176,32,32,32,32,32,32,32,176,32,176
DATA 176,32,176,176,176,176,176,176,176,176,176,32,176,32,176,176,176,176,176,176,176,176,176,32,176
DATA 176,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,176
DATA 176,176,176,176,176,176,176,176,176,176,176,176,32,176,176,176,176,176,176,176,176,176,176,176,176

« Last Edit: September 17, 2011, 09:48:09 am by GarrisonRicketson » Report Spam   Logged

Pages: 1 [2] 3 4
  Print  
 
Jump to:  

Powered by EzPortal
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum


Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy