Qbasicnews.com

Full Version: Pac Man game..help please..
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Im in the process of making a Pac Man game and I need some help. I finally got the Pac Man to move but I have a couple problems...

- I cant keep the Pac Man from going through walls
- I cant make the Pac Man eat the dots(it goes through it)

Here is my program so far(Keep in mind I have very very very basic Qbasic knowledge):
Quote:CLS
LOCATE 15, 35
COLOR 4
PRINT "Stage 1"
SLEEP 2
CLS

'PAC MAN GAME
SCREEN 7, 0, 2, 2
DIM pac(90)

REM pacman
CIRCLE (20, 20), 5, 6
PAINT (20, 20), 9, 6
GET (10, 10)-(30, 30), pac(10)

CLS
SCREEN 7, 0, 1, 2
x = 10
y = 10

DO
CLS
REM borders
LINE (20, 30)-(30, 170), 13, BF
LINE (50, 30)-(60, 220), 13, BF
LINE (80, 20)-(220, 30), 13, BF
LINE (80, 50)-(130, 60), 13, BF
LINE (80, 110)-(90, 140), 13, BF
LINE (80, 180)-(90, 220), 13, BF
LINE (170, 50)-(300, 60), 13, BF
LINE (110, 180)-(190, 190), 13, BF
LINE (110, 210)-(190, 220), 13, BF
LINE (230, 80)-(240, 220), 13, BF
LINE (260, 80)-(300, 90), 13, BF
LINE (260, 110)-(270, 170), 13, BF
LINE (290, 110)-(300, 170), 13, BF
LINE (260, 190)-(300, 200), 13, BF
LINE (110, 80)-(120, 160), 13, BF
LINE (110, 80)-(140, 100), 13, BF
LINE (110, 150)-(210, 160), 13, BF
LINE (200, 80)-(210, 160), 13, BF
LINE (180, 80)-(210, 100), 13, BF

'dots
FOR z = 20 TO 185 STEP 7
PSET (40, z), 7
NEXT z
FOR q = 20 TO 185 STEP 7
PSET (70, q), 7
NEXT q
FOR e = 80 TO 300 STEP 7
PSET (e, 40), 7
NEXT e
FOR r = 80 TO 300 STEP 7
PSET (r, 70), 7
NEXT r
FOR u = 80 TO 220 STEP 7
PSET (u, 170), 7
NEXT u



REM direction controller
k$ = INKEY$
IF k$ = CHR$(0) + CHR$(72) AND y > 10 THEN y = y - 5
IF k$ = CHR$(0) + CHR$(80) AND y <= 165 THEN y = y + 5
IF k$ = CHR$(0) + CHR$(77) AND x <= 280 THEN x = x + 5
IF k$ = CHR$(0) + CHR$(75) AND x > 10 THEN x = x - 5
PUT (x, y), pac(10)
PCOPY 1, 2
LOOP UNTIL k$ = "q" OR k$ = "Q"
CLS


I tried to make it so that Pac Man couldnt move if it was in a certain color but that idea went down the drain because i didnt know how to set it. As for the dot eating problem..i have no clue on how to go about it...I thought the circles were supposed to automatically disappear if the bigger circle went over it...
Any help would be appreciated..


-edit- sorry if this is in the wrong section
This is the right section...
first. use

'

instead of

REM


ok... how about you use an array map, data statements, and sprites for everything?

it would make collision detection A LOT easier
Once again...I have very very very basic knowledge of this program. Mind explaining what those things you listed are? Or maybe a different method that I can relate to?
Quote:Once again...I have very very very basic knowledge of this program. Mind explaining what those things you listed are? Or maybe a different method that I can relate to?
yea sure ill tell you in a bit im working on it
I don't really want to give you the whole code but it's the best was of explaining

[syntax="qbasic"]CLS
LOCATE 15, 35
COLOR 4
PRINT "Stage 1"
PCOPY 1, 2
SLEEP 2
CLS
'PAC MAN GAME
SCREEN 7, 0, 2, 2
'DIM the sprites
DIM pac(100)
DIM block(100)
DIM dot(100)
DIM map(10, 10)

'get the sprites from data statements
FOR y = 1 TO 10
FOR x = 1 TO 10
READ a
PSET (x, y), a
NEXT x, y
GET (1, 1)-(10, 10), pac(10)

FOR y = 1 TO 10
FOR x = 1 TO 10
READ a
PSET (x, y), a
NEXT x, y
GET (1, 1)-(10, 10), block(10)

FOR y = 1 TO 10
FOR x = 1 TO 10
READ a
PSET (x, y), a
NEXT x, y
GET (1, 1)-(10, 10), dot(10)
'stop getting sprites and get map
FOR y = 1 TO 10
FOR x = 1 TO 10
READ map(x, y)
NEXT x, y
READ xpos, ypos
SCREEN 7, 0, 1, 2
DO
CLS
'Plot map
FOR y = 1 TO 10
FOR x = 1 TO 10
IF map(x, y) = 1 THEN PUT (x * 10, y * 10), block(10), PSET
IF map(x, y) = 2 THEN PUT (x * 10, y * 10), dot(10), PSET
NEXT x
NEXT y

k$ = INKEY$
oldxpos = xpos
oldypos = ypos
'key detection
IF k$ = CHR$(0) + CHR$(72) THEN ypos = ypos - 1
IF k$ = CHR$(0) + CHR$(80) THEN ypos = ypos + 1
IF k$ = CHR$(0) + CHR$(77) THEN xpos = xpos + 1
IF k$ = CHR$(0) + CHR$(75) THEN xpos = xpos - 1
IF xpos < 1 THEN xpos = 1
IF xpos > 10 THEN xpos = 10
IF ypos < 1 THEN ypos = 1
IF ypos > 10 THEN ypos = 10

'collision detection
'--
'this checks with the current x,y value with the array and
'does something dependiong on whats there
SELECT CASE map(xpos, ypos)
CASE 1
xpos = oldxpos: ypos = oldypos
CASE 2
map(xpos, ypos) = 0
points = points + 1
END SELECT

'put pacman down
PUT (xpos * 10, ypos * 10), pac(10)
LOCATE 1, 1: PRINT "Points:"; points
PCOPY 1, 2
LOOP UNTIL LCASE$(k$) = "q"


'pacman
DATA 0,0,0,2,2,2,2,0,0,0
DATA 0,2,2,3,3,3,3,2,2,0
DATA 0,2,3,3,3,3,3,3,2,0
DATA 2,3,3,3,3,3,3,3,3,2
DATA 2,3,3,3,3,3,3,3,3,2
DATA 2,3,3,3,3,3,3,3,3,2
DATA 2,3,3,3,3,3,3,3,3,2
DATA 0,2,3,3,3,3,3,3,2,0
DATA 0,2,2,3,3,3,3,2,2,0
DATA 0,0,0,2,2,2,2,0,0,0

'wall
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,1,1,1,1,1,1
'dot
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,1,1,0,0,0,0
DATA 0,0,0,0,1,1,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
'map
'0 = empty
'1 = block
'2 = dot
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,2,2,2,2,2,2,2,2,1
DATA 1,2,1,1,1,0,1,1,2,1
DATA 1,2,1,2,2,2,2,1,2,1
DATA 1,2,1,2,1,1,2,1,2,1
DATA 1,2,1,2,2,1,2,2,2,1
DATA 1,2,1,1,2,1,2,1,2,1
DATA 1,2,1,2,2,1,2,1,2,1
DATA 1,2,2,2,2,2,2,2,2,1
DATA 1,1,1,1,1,1,1,1,1,1
DATA 2,2[/syntax]

@oracle: the syntax highlighter makes DATA statments look funny... is that normal?
It's the retarded regex for handling numbers... I've got it fixed somewhere else, but I haven't worked on it for some time. But soon that will be solved.
You might want to look into learning the POINT function

it will give you the color at any x,y point
If the number it gives you is the color fo the wall, then you will know not to move there, or if it is the color of a dot, you can go to a routine that eats the dot.

You have to look at the point (or better yet, several points) that you will be moving to BEFORE you move there. Find out what is there first, then determine what you can do.

use it like this if color 5 is the wall color for example:

IF POINT (x,y) = 5 THEN GOSUB dontmovepacman
Thanks a lot whitetiger..i actually wasnt expecting that much help..haha..im not familiar with a lot of the things you put...jeez i have a long ways to go.

Just ran the program and wow...waaay more advanced...and u have the score too!
Quote:Thanks a lot whitetiger..i actually wasnt expecting that much help..haha..im not familiar with a lot of the things you put...jeez i have a long ways to go.

Just ran the program and wow...waaay more advanced...and u have the score too!
Hehe no problem You'll learn if your heart truly desires *messed up music plays in background*
If I were you, I would not use POINT and rely on colour-collision-detection. I would use some sort of 2-dimension array that stores 0s and 1s (and possibly more) for a map. It would not be smooth looking when you move pacman though, unless you use some sort of mini-animation for moving from square to square. Are you following me on this? Also, use a STRING * 1 array for smaller, faster storage of numbers. Then you can still have 128 numbers in each cell, but you need to use it like CHR$(1) or CHR$(0). Fun to do, I think. And it makes you look like a smart coder Big Grin!!!!!!!!!! I LOVE JESUS SMITH!
Pages: 1 2 3