THIS MESSAGE IS FOR BIG JOHN PAC-MAN

DEAR BIG JOHN,
OK I STARTED THE PAC-MAN GAME AND RAN INTO A LITTLE ISSUE. OK SO I'M STARTING THAT PAC-MAN GAME AND AS YOU KNOW I'M NEW TO PROGRAMMING AND HAVE NEVER USED CALL SUB PROGRAMS CASE OR ANY OF THOSE BUT I'M SORT OF OFF TO A GOOD START. ANYWAY THIS IS MY PROBLEM. I MADE A TITLE PAGE AND A MENU ON MY MENU THERE IS TWO CHOICES 1 THE GAME AND 2 INSTRUCTIONS I'M WORKING ON THE INSTRUCTIONS, NOW MY INSTRUCTIONS PAGE IS AN IMAGE BUT AFTER THEY ARE DONE LOOKING AND READING I DONT KNOW HOW TO MAKE IT GO BACK TO THE MENU. THIS IS WHAT I HAVE SO FAR...

SUB explain_rules
CALL read_image ("JPEG",instructions$, "instructions.jpg")
BOX SHOW instructions$ at 0,0
PAUSE 2
GET KEY pse
END SUB

PRINT
PRINT
PRINT
PRINT
PRINT
PRINT
PRINT
PRINT
PRINT
PRINT
PRINT
PRINT
PRINT TAB(47); " PAC-MAN"
PRINT
PRINT
PRINT
PRINT TAB(47); " PROGRAMMED BY CHUNK"
PRINT TAB(47); " DAVID THOMPSON"
PAUSE 6
print
PRINT
PRINT
PRINT
PRINT " PRESS ANY KEY TO CONTINUE."
GET KEY PSE
CLEAR
PRINT TAB(50); " MAIN MENU"
PRINT
PRINT
PRINT TAB(50); "1. PLAY GAME"
PRINT
PRINT TAB(50); "2. INSTRUCTIONS"
PRINT
PRINT
INPUT PROMPT "PLEASE ENTER SELECTION. (1-2)":MAIN_MENU
IF MAIN_MENU = 2 THEN
clear
CALL explain_rules
end if

END

ALSO I WAS HOPING YOU COULD GIVE ME AN EXAMPLE OF HOW TO USE A CASE STATEMENT AND NEXT STATEMENT.

THANKS IN ADVANCE

Comments

Game code

Hi,

OK so far - at least you had the good sense to ask about the stuff you don't undertsand instead of trying to guess how to do it.

Lets look at what you have done, but simplified so it's easier to read. I ahve also moved the sub-routine to the end of the program to keep it out of the way. I have also put your intro page inside a loop because the user may want to read the rules first so you need to show the intro page again - hence the loop. Once the user has selected play the game then you just exit the loop and start your game code. Notice I have included REM statements to explain what is going on - you may need them to remind yourself why you have done things certain ways.

REM: Introductory page
DO
FOR n=1 to 12 ! print PRINT 12 times
PRINT
NEXT n
PRINT TAB(47); " PAC-MAN"
FOR n=1 to 3
PRINT
NEXT n
PRINT TAB(47); " PROGRAMMED BY CHUNK"
PRINT TAB(47); " DAVID THOMPSON"
PAUSE 6
FOR n=1 to 4
PRINT
NEXT n
PRINT " PRESS ANY KEY TO CONTINUE."
GET KEY PSE
CLEAR
REM: Menu page
PRINT TAB(50); " MAIN MENU"
PRINT
PRINT
PRINT TAB(50); "1. PLAY GAME"
PRINT
PRINT TAB(50); "2. INSTRUCTIONS"
PRINT
PRINT
INPUT PROMPT "PLEASE ENTER SELECTION. (1-2)":MAIN_MENU
REM: respond to menu choices
IF MAIN_MENU = 2 THEN
CLEAR
CALL explain_rules ! then loop back to intro page
ELSEIF MAIN_MENU=1 then ! exit loop and start game
EXIT DO
ELSE
! do nothing because the user typed a wrong number
END IF
LOOP
REM: game code goes here

SUB explain_rules
PRINT "Press any key when you have read the instructions"
CALL read_image ("JPEG",instructions$, "instructions.jpg")
BOX SHOW instructions$ at 0,0
! PAUSE 2 you don't need PAUSE here
GET KEY pse
CLEAR
END SUB

END

You asked about select case. You could have used select case to handle the variable main_menu e.g.
REM: respond to menu choices
SELECT CASE main_menu
CASE 1
EEXIT DO
CASE 2
CLEAR
CALL explain_rules ! then loop back to intro page
CASE ELSE
! do nothing because number is invalid
END SELECT

Big John

THANK YOU

THANK YOU FOR GETTING BACK TO ME SO QUICKLY. NOW I HAVE ANOTHER QUESTION. ORIGINALLY WHEN YOU GAVE ME A SUGGESTED PROGRAM SETUP THING THE FOLLOWING WAS IN IT...

REM: set up screen dimensions
CALL explain_rules
CALL draw_grid
RANDOMIZE
CALL draw_random_walls

NOW IT SAYS "CALL DRAW_GRID," DO I HAVE TO PLOT OUT MY MAP OR CAN I CALL READ_IMAGE?

ALSO YOU WROTE "CALL DRAW_RANDOM_WALLS," IS THERE A WAY THAT I CAN MAKE IT ACTUALLY MAKE IT'S OWN MAPS ACCORDING TO CERTAIN PARAMETERS THAT I CAN SET LIKE THE WIDTH OF THE PATHS.

Pac-man game

Hi,

There are several ways of going about the task of creating the Pac-man map or environment.
(1) You could use the same map all the time, in which case your easiest route is to create an image of the grid and the walls.
(2) You could have a series of images as in (1) and randomly select them for each game. This is a very simple approach.
(3) you could start with a grid image and then draw the walls on top using a vector table i.e. a table of values that determine the start and end co-ordinates of each section of wall.
(4) You could have several vector tables and randomly select one for each game.
(5) You could develop an equation that creates a vector table using random numbers. This is a difficult method because you need a complex set of rules to check that the walls are valid.

Personally I would start with option (1). Once you get it working you can proceed to option (2) knowing it will will work.

When you are moving Pac-man or the ghosts I would suggest you check the pixel colors just ahead of Pac-man or the ghosts to see if they are wall colors - if so you cannot move in that direction. Do this inside a DO...LOOP and randomly keep changing the direction until the pixel color is not the wall color, then EXIT DO.

Big John

ok

OK, I THINK THAT TO START I WILL GO WITH OPTION NUMBER 1. THAT WAY I CAN MAKE THE GAME WORK AND AFTER A WHILE I CAN ADD MORE LEVELS AS I GO. SO I WAS WONDERING HOW I WOULD GO ABOUT IT THOUGH COULD I JUST CALL READ_IMAGE OR WOULD I HAVE TO PLOT OUT MY MAP? THANKS IN ADVANCE.

Pac-man game

Hi,

Use MS Paint or similar drawing software to create an image of the grid and walls. Then use read_image followed by BOX SHOW.

One piece of advice. I would decide what sort of units to work in right at the beginning. My advice would be to work in pixels e.g.
ASK PIXELS xpix,ypix
SET WINDOW 0,xpix-1,ypix-1,0

Now you know how big to make your Paint image and where to put it so that it is central in the screen. Don't forget that the units above make the top left corner the origin (0,0).

If you want to know what color a particular pixel is then use CALL get_Cpixel(x,y,r,g,b)
Where x,y are the x axis and yaxis of the pixel point
Where r,g,b are the red,green,blue components of the color. If you are looking for RED then r=1,g=0,b=0

Regards
Big John

thanks

THANKS BIG JOHN. iM GOING TO GIVE IT A TRY AND REPLY AS TO WHAT HAPPENS.

Pac-man game

Hi,

When you are preparing your first map of the grid and walls using MS Paint use the FLIP option to flip the map horizontally to make a second map that is a mirror of the first - so you now have two maps. Then flip each vertically - so you now have 4 maps - all from just one drawing. If you want to go further then split the original image in half and only flip half of the image in each case making 8 maps and so on.

To make sure you do not bias the direction the ghosts take I would suggest you use a random number selection procedure linked to numeric directions, e.g
(1=up:2=right:3=down:4=left: ignore other numbers)
! assume center point of current grid square is x,y
! assume grid is 30x30 pixels each square
! assume Pac-man is say 20 pixels diameter

SUB move_any_ghost
DO ! random direction
LET direction=ROUND(RND*5) ! generates numbers 0 to 5
SELECT CASE direction
CASE 1 ! up
CALL readCpixel(x,y-15,r,g,b)
CASE 2 ! right
CALL readCpixel(x+15,y,r,g,b)
CASE 3 ! down
CALL readCpixel(x,y+15,r,g,b)
CASE 4 ! left
CALL readCpixel(x-15,y,r,g,b)
CASE ELSE
LET r=1 ! do nothing
END SELECT
IF r<.1 then
REM: we could use IF r=0 but this is more risky
REM: move ghost 1 square of the grid in 'direction'
EXIT DO ! job done
END IF
LOOP
END SUB

(By the way readCpixel is the correct CALL not get_Cpixel)

I am suggesting a grid pitch of 30 pixels which gives you plenty of space for Pac-man or the ghosts.

A similar routine can be used to move Pac-man, but instead of a random number we use the arrow keys to determine the direction. The routine just checks whether a wall is in the way or not.

Big John

pac-man

can you send me an e-mail so that i can send you the pictures that i'm using. my e-mail address is ebaychunk@gmail.com.