Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A Newbie Programs pacman... Round One...
#11
Ok...

Redid a lot of little things.

I have some serious revamping to do before I repost the code. I'm getting ready to mess with the bsave and bload. Before I do that though, I'd like to get the AI going.

Now, I have a question. How would you suggest doing AI? The way I'm going about it is kind of slow and buggy. (Basically, I have two random numbers, and whenever they match, the ghost searches for pacman by doing a bunch of "If pacmanx < ghostx then whatever...". When the ghost moves, though, there is a ghost trail that SLOWLY catches up to the ghost. (So it's drawing new ghosts faster than it's redrawing the old)

The A* algo was pretty complex. I may one day incorporate it, but for now, I just want to complete a game that is functional. (It doesn't have to be pretty, it doesn't have to be outsandingly fun or creative. It just needs to be complete! This way I can say I completed a game!)
hrono Trigger Fanboy Forever
Reply
#12
Code:
DECLARE FUNCTION Collision%(posx AS INTEGER, posy AS INTEGER)

DIM Map(63, 63) AS INTEGER


FUNCTION Collision%(posx AS INTEGER, posy AS INTEGER)

IF posx > UBOUND(MAP, 1)  or posx < LBOUND(MAP, 1) THEN
error$ = "FUNCTION Collision() has incountered a subscript out of range..."
ELSEIF posy > UBOUND(MAP, 2)  or posy < LBOUND(MAP, 2) THEN
error$ = "FUNCTION Collision() has incountered a subscript out of range..."
END IF

IF MAP(posx, posy) = 0 THEN
Collision=0
ELSE
Collision = MAP(posx, posy)
END IF

END FUNCTION

This checks a tile on a map.....if there is no tile, then it returns '0', otherwise, it returns the tile number....

Oz~
Reply
#13
I'm not quite to collision just yet. I'm trying to figure out the seeking algo to make the ghost search for pacman. Right now, he moves around following pacman for a little bit, but in the end, he gets stuck in the corner. I reduced my sprites from 10x10 to 9x9. My maze is the same as the traditional pacman maze, but sideways. I haven't yet programmed in the "escape tunnels" but that will come with time. Here is some updated code.

Critique your little hearts out. Smile
Code:
DECLARE SUB movement (x%, y%)
DECLARE SUB redrawmap (checkformovex%, checkformovey%, x%, y%)
DECLARE SUB pelletcount (x%, y%)
DECLARE SUB ghostmove (x%, y%, ghostx%, ghosty%, matchcount%)

DIM SHARED map(32, 21)
DIM SHARED blank(9, 9)
DIM SHARED pacman(9, 9)
DIM SHARED charmask(9, 9)
DIM SHARED ghost1(9, 9)
DIM SHARED pellet(9, 9)
DIM SHARED WallLR(9, 9)
DIM SHARED wallUD(9, 9)
DIM SHARED cornerUL(9, 9)
DIM SHARED cornerUR(9, 9)
DIM SHARED cornerDL(9, 9)
DIM SHARED cornerDR(9, 9)
DIM SHARED endpeiceLRleft(9, 9)
DIM SHARED endpeiceLRright(9, 9)
DIM SHARED endpeiceUDtop(9, 9)
DIM SHARED endpeiceUDbottom(9, 9)
DIM SHARED TacrossLeft(9, 9)
DIM SHARED TacrossRight(9, 9)
DIM SHARED TupdownUP(9, 9)
DIM SHARED TupdownDOWN(9, 9)

DIM SHARED x AS INTEGER
DIM SHARED y AS INTEGER
DIM SHARED checkformovex AS INTEGER
DIM SHARED checkformovey AS INTEGER
DIM SHARED ghostx AS INTEGER
DIM SHARED ghosty AS INTEGER
DIM SHARED matchcount AS INTEGER

SCREEN 13
matchcount = 0
GOSUB makegraphics
ghostx% = 45
ghosty% = 45
x = 1
y = 1
CLS

top:

WAIT &H3DA, 8



movement x%, y%
redrawmap checkformovex%, checkformovey%, x%, y%
pelletcount x%, y%
ghostmove x%, y%, ghostx%, ghosty%, matchcount%
GOTO top

'=========================================================================
makegraphics:

'create Blank tile
FOR y = 1 TO 9
FOR x = 1 TO 9
READ colr
PSET (x, y), colr
NEXT x
NEXT y
GET (1, 1)-(9, 9), blank


'create pellet tile
FOR y = 1 TO 9
FOR x = 1 TO 9
READ colr
PSET (x, y), colr
NEXT x
NEXT y
GET (1, 1)-(9, 9), pellet

'create Left2Right Bar tile
FOR y = 1 TO 9
FOR x = 1 TO 9
READ colr
PSET (x, y), colr
NEXT x
NEXT y
GET (1, 1)-(9, 9), WallLR

'create T up
FOR y = 1 TO 9
FOR x = 1 TO 9
READ colr
PSET (x, y), colr
NEXT x
NEXT y
GET (1, 1)-(9, 9), TupdownUP

'create T down
FOR y = 1 TO 9
FOR x = 1 TO 9
READ colr
PSET (x, y), colr
NEXT x
NEXT y
GET (1, 1)-(9, 9), TupdownDOWN



'create LR endpeice left
FOR y = 1 TO 9
FOR x = 1 TO 9
READ colr
PSET (x, y), colr
NEXT x
NEXT y
GET (1, 1)-(9, 9), endpeiceLRleft

'create endpeice right
FOR y = 1 TO 9
FOR x = 1 TO 9
READ colr
PSET (x, y), colr
NEXT x
NEXT y
GET (1, 1)-(9, 9), endpeiceLRright


'create Top2Bottom Bar tile
FOR y = 1 TO 9
FOR x = 1 TO 9
READ colr
PSET (x, y), colr
NEXT x
NEXT y
GET (1, 1)-(9, 9), wallUD

'create T left
FOR y = 1 TO 9
FOR x = 1 TO 9
READ colr
PSET (x, y), colr
NEXT x
NEXT y
GET (1, 1)-(9, 9), TacrossLeft

'create T right
FOR y = 1 TO 9
FOR x = 1 TO 9
READ colr
PSET (x, y), colr
NEXT x
NEXT y
GET (1, 1)-(9, 9), TacrossRight


'create endpeice top
FOR y = 1 TO 9
FOR x = 1 TO 9
READ colr
PSET (x, y), colr
NEXT x
NEXT y
GET (1, 1)-(9, 9), endpeiceUDtop

'create endpeice bottom
FOR y = 1 TO 9
FOR x = 1 TO 9
READ colr
PSET (x, y), colr
NEXT x
NEXT y
GET (1, 1)-(9, 9), endpeiceUDbottom


'create Corner Upper Left
FOR y = 1 TO 9
FOR x = 1 TO 9
READ colr
PSET (x, y), colr
NEXT x
NEXT y
GET (1, 1)-(9, 9), cornerUL

'create Corner Upper Right
FOR y = 1 TO 9
FOR x = 1 TO 9
READ colr
PSET (x, y), colr
NEXT x
NEXT y
GET (1, 1)-(9, 9), cornerUR

'create Corner Lower Left
FOR y = 1 TO 9
FOR x = 1 TO 9
READ colr
PSET (x, y), colr
NEXT x
NEXT y
GET (1, 1)-(9, 9), cornerDL

'create Corner Lower Right
FOR y = 1 TO 9
FOR x = 1 TO 9
READ colr
PSET (x, y), colr
NEXT x
NEXT y
GET (1, 1)-(9, 9), cornerDR


'create face
FOR y = 1 TO 9
FOR x = 1 TO 9
READ colr
PSET (x, y), colr
NEXT x
NEXT y
GET (1, 1)-(9, 9), pacman

'create mask
FOR y = 1 TO 9
FOR x = 1 TO 9
READ colr
PSET (x, y), colr
NEXT x
NEXT y
GET (1, 1)-(9, 9), charmask

'create ghost1
FOR y = 1 TO 9
FOR x = 1 TO 9
READ colr
PSET (x, y), colr
NEXT x
NEXT y
GET (1, 1)-(9, 9), ghost1

CLS

FOR y = 0 TO 20
  FOR x = 0 TO 26
    READ map
  map(x, y) = map
    NEXT: NEXT


CLS
RETURN





'===========================================================================
'blank
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00



'pellet
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,15,00,00,00,00
DATA 00,00,00,15,15,15,00,00,00
DATA 00,00,00,00,15,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00


'wall Left2Right(along the top and bottom)
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 01,01,01,01,01,01,01,01,01
DATA 00,00,00,00,00,00,00,00,00
DATA 01,01,01,01,01,01,01,01,01
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00

'up T
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 01,01,01,00,00,00,01,01,01
DATA 00,00,00,00,00,00,00,00,00
DATA 01,01,01,01,01,01,01,01,01
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00

'down T
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 01,01,01,01,01,01,01,01,01
DATA 00,00,00,00,00,00,00,00,00
DATA 01,01,01,00,00,00,01,01,01
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00


'wall Left to Right Endpeice left
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,01,01,01
DATA 00,00,00,00,00,01,00,00,00
DATA 00,00,00,00,00,00,01,01,01
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00


'wall Left to Right Endpeice right
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 01,01,01,00,00,00,00,00,00
DATA 00,00,00,01,00,00,00,00,00
DATA 01,01,01,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00

'wall Top2bottom(along left and right sides)
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00

'T left
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 01,01,01,00,00,01,00,00,00
DATA 00,00,00,00,00,01,00,00,00
DATA 01,01,01,00,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00

'T right
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,00,01,01,01
DATA 00,00,00,01,00,00,00,00,00
DATA 00,00,00,01,00,00,01,01,01
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00


'top endpeice
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,01,00,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00


'bottom endpeice
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,00,01,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00


'corner Upper Left
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,01,01,01,01,01
DATA 00,00,00,01,00,00,00,00,00
DATA 00,00,00,01,00,00,01,01,01
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00



'Corner Upper Right
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 01,01,01,01,01,00,00,00,00
DATA 00,00,00,00,00,01,00,00,00
DATA 01,01,01,00,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00


'corner Lower Left
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,00,01,01,01
DATA 00,00,00,01,00,00,00,00,00
DATA 00,00,00,00,01,01,01,01,01
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00



'Corner Lower Right
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 00,00,00,01,00,01,00,00,00
DATA 01,01,01,00,00,01,00,00,00
DATA 00,00,00,00,00,01,00,00,00
DATA 01,01,01,01,01,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00



'pacman
DATA 00,00,00,14,14,14,14,00,00
DATA 00,00,14,14,14,14,14,14,00
DATA 00,14,14,14,14,14,14,00,00
DATA 00,14,14,14,14,00,00,00,00
DATA 14,14,14,14,00,00,00,00,00
DATA 14,14,14,14,14,00,00,00,00
DATA 00,14,14,14,14,14,14,00,00
DATA 00,14,14,14,14,14,14,14,00
DATA 00,00,14,14,14,14,14,14,00


'mask
DATA 255,255,255,000,000,000,000,255,255
DATA 255,255,000,000,000,000,000,000,255
DATA 255,000,000,000,000,000,000,000,000
DATA 255,000,000,000,000,000,000,000,000
DATA 000,000,000,000,000,000,000,000,000
DATA 000,000,000,000,000,000,000,000,000
DATA 255,000,000,000,000,000,000,000,000
DATA 255,000,000,000,000,000,000,000,000
DATA 255,255,000,000,000,000,000,000,255


'ghost1
DATA 00,00,00,00,00,00,00,00,00
DATA 00,00,15,15,15,04,15,15,15
DATA 00,04,15,00,15,04,15,00,15
DATA 04,04,00,00,00,04,00,00,00
DATA 04,04,04,04,04,04,04,04,04
DATA 04,04,04,04,04,04,04,04,04
DATA 04,04,04,04,04,04,04,04,04
DATA 04,04,04,04,04,04,04,04,04
DATA 04,04,00,04,04,04,00,04,04



'==================================================================
DATA 03,01,01,01,01,01,01,01,01,04,00,00,03,01,04,00,00,03,01,01,01,15,15,01,01,01,04
DATA 02,07,07,07,07,07,07,07,07,02,00,00,02,00,02,00,00,02,07,07,07,02,02,07,07,07,02
DATA 02,07,03,01,04,07,03,04,07,02,00,00,02,00,02,00,00,02,07,10,07,05,06,07,10,07,02
DATA 02,07,02,00,02,07,02,02,07,02,00,00,02,00,02,00,00,02,07,02,07,07,07,07,02,07,02
DATA 02,07,05,01,06,07,05,06,07,05,01,01,06,00,05,01,01,06,07,05,01,01,09,07,02,07,02
DATA 02,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,02,07,02
DATA 02,07,03,01,04,07,08,01,01,15,01,01,09,00,08,01,01,09,07,10,07,08,01,01,12,07,02
DATA 02,07,02,00,02,07,07,07,07,02,00,00,00,00,00,00,00,00,07,02,07,07,07,07,02,07,02
DATA 02,07,05,01,06,07,03,04,07,11,00,03,01,01,04,00,03,04,07,11,07,03,04,07,11,07,02
DATA 02,07,07,07,07,07,02,02,07,00,00,02,00,00,02,00,02,02,07,07,07,02,02,07,07,07,02
DATA 13,01,01,01,09,07,02,13,01,09,00,02,00,00,02,00,02,13,01,09,07,02,13,01,09,07,02
DATA 02,07,07,07,07,07,02,02,07,00,00,02,00,00,02,00,02,02,07,07,07,02,02,07,07,07,02
DATA 02,07,03,01,04,07,05,06,07,10,00,05,01,01,06,00,05,06,07,10,07,05,06,07,10,07,02
DATA 02,07,02,00,02,07,07,07,07,02,00,00,00,00,00,00,00,00,07,02,07,07,07,07,02,07,02
DATA 02,07,05,01,06,07,08,01,01,14,01,01,09,00,08,01,01,09,07,11,07,08,01,01,12,07,02
DATA 02,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,07,02,07,02
DATA 02,07,03,01,04,07,03,04,07,03,01,01,04,00,03,01,01,04,07,03,01,01,09,07,02,07,02
DATA 02,07,02,00,02,07,02,02,07,02,00,00,02,00,02,00,00,02,07,02,07,07,07,07,02,07,02
DATA 02,07,05,01,06,07,05,06,07,02,00,00,02,00,02,00,00,02,07,11,07,03,04,07,11,07,02
DATA 02,07,07,07,07,07,07,07,07,02,00,00,02,00,02,00,00,02,07,07,07,02,02,07,07,07,02
DATA 05,01,01,01,01,01,01,01,01,06,00,00,05,01,06,00,00,05,01,01,01,14,14,01,01,01,06

SUB ghostmove (x%, y%, ghostx%, ghosty%, matchcount%)
RANDOMIZE TIMER
stupidize1 = INT(RND * 10) + 1
stupidize2 = INT(RND * 10) + 1

IF stupidize1 = stupidize2 THEN
matchcount = matchcount + 1

IF x% < ghostx% AND ghostx% > 8 THEN
  IF map((ghostx% - 9) / 9, ghosty% / 9) = 0 OR map((ghostx% - 9) / 9, ghosty% / 9) = 7 THEN

ghostx% = ghostx% - 9
END IF

IF x% > ghostx% AND ghostx% < 270 THEN
  IF map((ghostx% + 9) / 9, ghosty% / 9) = 0 OR map((ghostx% + 9) / 9, ghosty% / 9) = 7 THEN

ghostx% = ghostx% + 9
END IF

IF y% < ghosty% AND ghosty% > 8 THEN
  IF map(ghostx% / 9, (ghosty% - 9) / 9) = 0 OR map(ghostx% / 9, (ghosty% - 9) / 9) = 7 AND

ghosty% > 9 THEN ghosty% = ghosty% - 9
END IF

IF y% > ghosty% AND ghosty% < 170 THEN
  IF map(ghostx% / 9, (ghosty% + 9) / 9) = 0 OR map(ghostx% / 9, (ghosty% + 9) / 9) = 7 AND

ghosty% < 171 THEN ghosty% = ghosty% + 9
END IF

END IF

PUT (ghostx%, ghosty%), ghost1, PSET
LOCATE 7, 32: PRINT "Ghost"
LOCATE 8, 32: PRINT "x: "; ghostx%
LOCATE 10, 32: PRINT "Ghost"
LOCATE 11, 32: PRINT "y: "; ghosty%
LOCATE 13, 32: PRINT "matchs "
LOCATE 14, 32: PRINT "hit: "; matchcount
END SUB

SUB movement (x%, y%)
'lOCATE 1, 1: PRINT "x%: "; x%; "y%: "; y%
SELECT CASE INKEY$

CASE CHR$(0) + "H"
'up
IF map(x%, y% - 1) = 0 OR map(x%, y% - 1) = 7 AND (y% * 9) - 9 > 1 THEN
y% = y% - 1
END IF

CASE CHR$(0) + "P"
'down
flag = 0
IF map(x%, y% + 1) = 0 OR map(x%, y% + 1) = 7 AND (y% * 9) + 9 < 190 THEN
y% = y% + 1
END IF

CASE CHR$(0) + "K"
'left
IF map(x% - 1, y%) = 0 OR map(x% - 1, y%) = 7 AND (x% * 9) - 9 > 1 THEN
x% = x% - 1
END IF

CASE CHR$(0) + "M"
'right
IF map(x% + 1, y%) = 0 OR map(x% + 1, y%) = 7 AND (x% * 9) + 9 < 310 THEN
x% = x% + 1
END IF

CASE CHR$(27)
END
END SELECT

END SUB

SUB pelletcount (x%, y%)

FOR mapx = 0 TO 31 - 1
  FOR mapy = 0 TO 19 - 1
   IF map(mapx, mapy) = 7 THEN pellet = pellet + 1
  NEXT mapy
NEXT mapx

IF map(x, y) = 7 THEN map(x, y) = 0
LOCATE 1, 32: PRINT "Pellets"
LOCATE 2, 32: PRINT "left: "
LOCATE 3, 32: PRINT pellet
IF pellet = 0 THEN LOCATE 10, 32: PRINT "YOU WIN!"
END SUB

SUB redrawmap (checkformovex%, checkformovey%, x%, y%)
IF checkformovex <> x OR checkformovey <> y THEN
checkformovex = x
checkformovey = y
'redraw screen
FOR mapx = 0 TO 27 - 1
FOR mapy = 0 TO 21 - 1
    SELECT CASE map(mapx, mapy)
    CASE 0
    PUT (mapx * 9, mapy * 9), blank, PSET
    CASE 1
    PUT (mapx * 9, mapy * 9), WallLR, PSET
    CASE 2
    PUT (mapx * 9, mapy * 9), wallUD, PSET
    CASE 3
    PUT (mapx * 9, mapy * 9), cornerUL, PSET
    CASE 4
    PUT (mapx * 9, mapy * 9), cornerUR, PSET
    CASE 5
    PUT (mapx * 9, mapy * 9), cornerDL, PSET
    CASE 6
    PUT (mapx * 9, mapy * 9), cornerDR, PSET
    CASE 7
    PUT (mapx * 9, mapy * 9), pellet, PSET
    CASE 8
    PUT (mapx * 9, mapy * 9), endpeiceLRleft, PSET
    CASE 9
    PUT (mapx * 9, mapy * 9), endpeiceLRright, PSET
    CASE 10
    PUT (mapx * 9, mapy * 9), endpeiceUDtop, PSET
    CASE 11
    PUT (mapx * 9, mapy * 9), endpeiceUDbottom, PSET
    CASE 12
    PUT (mapx * 9, mapy * 9), TacrossLeft, PSET
    CASE 13
    PUT (mapx * 9, mapy * 9), TacrossRight, PSET
    CASE 14
    PUT (mapx * 9, mapy * 9), TupdownUP, PSET
    CASE 15
    PUT (mapx * 9, mapy * 9), TupdownDOWN, PSET
  CASE ELSE
   END SELECT

NEXT: NEXT

'put character in new location
PUT (x * 9, y * 9), charmask, AND
PUT (x * 9, y * 9), pacman, OR
END IF
END SUB

Here is the code in it's fullness... I'll post in the following post the specific sub I'm having issues with.
hrono Trigger Fanboy Forever
Reply
#14
Code:
SUB ghostmove (x%, y%, ghostx%, ghosty%, matchcount%)
RANDOMIZE TIMER
stupidize1 = INT(RND * 10) + 1
stupidize2 = INT(RND * 10) + 1

IF stupidize1 = stupidize2 THEN
matchcount = matchcount + 1

IF x% < ghostx% AND ghostx% > 8 THEN
  IF map((ghostx% - 9) / 9, ghosty% / 9) = 0 OR map((ghostx% - 9) / 9, ghosty% / 9) = 7 THEN

ghostx% = ghostx% - 9
END IF

IF x% > ghostx% AND ghostx% < 270 THEN
  IF map((ghostx% + 9) / 9, ghosty% / 9) = 0 OR map((ghostx% + 9) / 9, ghosty% / 9) = 7 THEN

ghostx% = ghostx% + 9
END IF

IF y% < ghosty% AND ghosty% > 8 THEN
  IF map(ghostx% / 9, (ghosty% - 9) / 9) = 0 OR map(ghostx% / 9, (ghosty% - 9) / 9) = 7 AND

ghosty% > 9 THEN ghosty% = ghosty% - 9
END IF

IF y% > ghosty% AND ghosty% < 170 THEN
  IF map(ghostx% / 9, (ghosty% + 9) / 9) = 0 OR map(ghostx% / 9, (ghosty% + 9) / 9) = 7 AND

ghosty% < 171 THEN ghosty% = ghosty% + 9
END IF

END IF

PUT (ghostx%, ghosty%), ghost1, PSET
LOCATE 7, 32: PRINT "Ghost"
LOCATE 8, 32: PRINT "x: "; ghostx%
LOCATE 10, 32: PRINT "Ghost"
LOCATE 11, 32: PRINT "y: "; ghosty%
LOCATE 13, 32: PRINT "matchs "
LOCATE 14, 32: PRINT "hit: "; matchcount
END SUB
Ok, so here is the specific subroutine I'm having issues with. I used the two stupidize variables so that the ghost wouldn't move so fast you didn't stand a sporting chance. For some reason, though, when the ghost gets into the corner, he doesn't move but a few spaces left, right, down, and up.
hrono Trigger Fanboy Forever
Reply
#15
Man... I would post the way I did it in Pacenstein, but it uses scripting and stuff. That would probably just confuse you even more. So, I have a simple idea...

Each Ghost can have a variable for their *temper*... Normal, Scared, Angry, BackHome, etc...

I did it with CONSTants...

Normal=0
Scared=1
Angry=2
BackHome=3
etc...

Then, I just wrote some code, kinda' like this...

Code:
Select case Ghost(G).Temper
CASE Normal
  Ghost(G).TargX=Pac.X -SomeRNDInt+SomeRNDInt
  Ghost(G).TargY=Pac.Y-SomeRNDInt+SomeRNDInt
Case Scared  
  Ghost(G).TargX=-Pac.X-SomeRNDInt+SomeRNDInt
  Ghost(G).TargY=-Pac.Y-SomeRNDInt+SomeRNDInt
Case Angry
  Ghost(G).TargX=Pac.X
  Ghost(G).TargY=Pac.Y

Case Blah
  'Do Something else

End Select


Then, You can just make the ghost follow the target that you prescribed...

Code:
OGx=Ghost(G).XD
OGy=Ghost(G).YD

If Ghost(G).X<Ghost(G).TargX then
Ghost(G).XD=1
End if

If Ghost(G).X>Ghost(G).TargX then
Ghost(G).XD=-1
End if


Ghost(G).X=Ghost(G).X+Ghost(G).Xd

'Do the same with Ghost(G).Y , Ghost(G).YD

Let me know if you get the idea of that...
I'm not very good at teaching, I guess. :???:
Reply
#16
Ack... Looks like I'm gonna have to put this bad boy on hold for a few weeks. I'm getting married in a little more than a week. (October 9th to be exact.) In that time, I have to put in some extra hours at work to be able to afford my bills, get my car insurance and title switched to my name, get my mail switched to my new address, get all my stuff moved out of my room and into my apartment, get internet set up at my apartment (duh!), get married, go on my honeymoon, get settled in, and work a few extra hours... ay yi yi... it's gonna be a busy one. :o I'll post a message letting you all know when I have net back and try to get back on track with my pacman game...
hrono Trigger Fanboy Forever
Reply
#17
Hey!, Wheres my wedding invitation! Big Grin


Good luck =)
Don't faint on the altar =)

I wouldn't mind seeing some pictures of you and your bride =)
Reply
#18
Many happy returns! Have a great time at the Wedding and Honeymoon!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)