Weekly Qbasic and Qb64 Lesson Topics
October 12, 2024, 05:58:48 pm
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 4025 times)
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« on: February 22, 2011, 10:51:20 pm »

Ok, well I got this one working ok,...it is not much,
the Pac Man just moves up and down, side to side, with arrow keys.
 I would like to figure out how to make hime face down, or up, when he is moved up or down, I may need to add these to the sprite sheet,.Or Can he be rotated useing _putimage ?

sprite at http://dl.dropbox.com/u/15387474/SprtSheet2F.PNG
Code:
   
REM Get sprite at http://dl.dropbox.com/u/15387474/SprtSheet2F.PNG
DEFLNG A-Z


SCREEN 12
WorkPage& = _LOADIMAGE("Sprtsheet2f.png") 'create the sprite sheet page
_COPYPALETTE WorkPage&, 0
FrameNum& = 0: x1 = 100: y1 = 100: direction = 1: flap = 0: Active = 0:
PRINT " use arrow keys, to move side,to side, up down. Esacpekey exits"
SLEEP 2
DO
    _DISPLAY
    _LIMIT 20
    GOSUB Getkey
    CLS 'need to clear the page ready for new image
    GOSUB Showframe
    COLOR 14
    LOCATE 20, 1: PRINT " Hello World, now just give me some dots to eat"
    '// I would like to see how to make him eat the above text.
    PLAY "MB <a15c20e15>" '//you can remark this out if it annoys you
LOOP UNTIL INP(&H60) = 1
SLEEP
SYSTEM

Getkey:
IF _KEYDOWN(20480) THEN y1 = y1 + 4
IF _KEYDOWN(18432) THEN y1 = y1 - 4
IF _KEYDOWN(19200) THEN
    x1 = x1 - 4: direction = 2
END IF
IF _KEYDOWN(19712) THEN
    x1 = x1 + 4: direction = 1

END IF
_DELAY .05

RETURN

Showframe:
SELECT CASE FrameNum&
    CASE 0
        IF direction = 1 THEN
            _PUTIMAGE (x1, y1)-(x1 + 94, y1 + 94), WorkPage&, 0, (1, 1)-(94, 94)
        ELSE
            _PUTIMAGE (x1, y1)-(x1 + 94, y1 + 94), WorkPage&, 0, (94, 1)-(1, 94)
        END IF
    CASE 1
        IF direction = 1 THEN
            _PUTIMAGE (x1, y1)-(x1 + 94, y1 + 94), WorkPage&, 0, (91, 0)-(188, 94)
        ELSE
            _PUTIMAGE (x1, y1)-(x1 + 94, y1 + 94), WorkPage&, 0, (188, 0)-(94, 94)
        END IF
END SELECT
blink = blink + 1
IF blink = 3 THEN
    blink = 0
    FrameNum& = FrameNum& + 1
END IF
IF FrameNum& = 2 THEN FrameNum& = 0
RETURN
 
from Garry
« Last Edit: September 09, 2011, 12:50:35 am by GarrisonRicketson » Report Spam   Logged

Share on Facebook Share on Twitter

guest
Guest
« Reply #1 on: February 23, 2011, 09:25:16 am »


Code:
REM Get sprite at http://dl.dropbox.com/u/15387474/SprtSheet2F.PNG
DEFLNG A-Z


Video& = _NEWIMAGE(640, 480, 32)
WorkPage& = _LOADIMAGE("Sprtsheet.png", 32) 'create the sprite sheet page
SCREEN Video&

FrameNum& = 0: x1 = 100: y1 = 100: direction = 1: flap = 0: Active = 0:
PRINT " use arrow keys, to move side,to side, up down. Esacpekey exits"
SLEEP 2
DO
  _DISPLAY
  _LIMIT 20
  GOSUB Getkey
  CLS 'need to clear the page ready for new image
  GOSUB Showframe
  COLOR 14
  LOCATE 20, 1: PRINT " Hello World, now just give me some dots to eat"
  '// I would like to see how to make him eat the above text.
  'PLAY "MB <a15c20e15>" '//you can remark this out if it annoys you
LOOP UNTIL INP(&H60) = 1
SLEEP
SYSTEM
Getkey:
IF _KEYDOWN(20480) THEN y1 = y1 + 4
IF _KEYDOWN(18432) THEN y1 = y1 - 4
IF _KEYDOWN(19200) THEN
  x1 = x1 - 4: direction = 2
END IF
IF _KEYDOWN(19712) THEN
  x1 = x1 + 4: direction = 1
END IF
_DELAY .05
RETURN
Showframe:
SELECT CASE FrameNum&
  CASE 0
    IF direction = 1 THEN
      _PUTIMAGE (x1, y1)-(x1 + 94, y1 + 94), WorkPage&, 0, (1, 1)-(94, 94)
    ELSE
      _PUTIMAGE (x1, y1)-(x1 + 94, y1 + 94), WorkPage&, 0, (94, 1)-(1, 94)
    END IF
  CASE 1
    IF direction = 1 THEN
      _PUTIMAGE (x1, y1)-(x1 + 94, y1 + 94), WorkPage&, 0, (91, 0)-(188, 94)
    ELSE
      _PUTIMAGE (x1, y1)-(x1 + 94, y1 + 94), WorkPage&, 0, (188, 0)-(94, 94)
    END IF
END SELECT
blink = blink + 1
IF blink = 3 THEN
  blink = 0
  FrameNum& = FrameNum& + 1
END IF
IF FrameNum& = 2 THEN FrameNum& = 0
RETURN

Note the removal of screen 12 and creation of a 32bit window the size of screen 12. Keep in mind if we make new graphics to show pac man upward and downward make them to the existing size of the current pics and they will slot into the code very easy. The current pics are wider than they are high
« Last Edit: September 17, 2011, 09:26:21 am by GarrisonRicketson » Report Spam   Logged
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #2 on: February 23, 2011, 09:08:56 pm »

Hi all,
    I couldn't get that one to work Garry. Here's my modded one that does work.
Note the removal of screen 12 and creation of a 32bit window the size of screen 12. Keep in mind if we make new graphics to show pac man upward and downward make them to the existing size of the current pics and they will slot into the code very easy. The current pics are wider than they are high.
OlDosLover.
Ok, I cut the code, since it is in the previous post, ok this is a little odd, as it did work on my computer,.(mine), I tested it agian, and what I posted dose work,...Also your version, works,...So I wonder why, it would work on my computer but not yours ?,..if you have any ideas, let me know...However, since both work on my computer, and yours is ready for a new spritesheet, Which also based on your statement, apparently there is a mistake in my images, because they are supposed to be 94 x 94, I bet I made a mistake, when I edited my sprite sheet, because I took the 2 out of a 4 frame sheet, I must have cut them a little short,..
Anyway thanks for the new code, and I agree, the best thing to do is make a new sprite sheet, but useing the existing sizes,...I also have the one, you e-mailed me,.. for now thats about it
from Garry
Report Spam   Logged

GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #3 on: February 25, 2011, 01:58:11 pm »


 I tried a little bit, to fit the 6 image sprite, into the code,you posted, but am
not able to get the 2 frames faceing up and down, to show, Don't know if you can understand, and thinking about it now, it seems I will actually need 8 fromes, and 2 more CASES, similar, to the original, from the way I understand
this, one CASE, is for it moveing right, the other moveing left,  the same, it seems would hold true for the up and the down, like wise, 4 more _putimage lines,..Also the _keydown, will need to be changed, on the 2 lines that are related to the up and the down. I am wondering, if I make sense to you, Am I on the right track ? Later, I still am going to make another sprite sheet,....
If I am on the right track, I may get it worked out. I did not have time to try
what I was thinking yet.Guess thats about it for now. from Garry
« Last Edit: September 17, 2011, 09:26:57 am by GarrisonRicketson » Report Spam   Logged

guest
Guest
« Reply #4 on: February 26, 2011, 09:48:09 am »

Quote

create a screen for all output graphics
load the pacman graphics
point the video screen to the monitor

top of loop
  gosub getkey
  gosub showframe
bottom of loop

system or program end

getkey
  if down key pressed then
    y = y + 4
    direction = 4
  if up key pressed then
    y =y - 4
    direction = 3
  if left key pressed then
    x = x - 4
    direction = 2
  if right key pressed then
    x = x + 4
    direction = 1

showframe
select case direction
   case =1
     put right facing pac man to video screen
   case =2
     put left facing pac man to video screen
   case =3
     put up facing pac man to video screen
   case =4
     put down facing pac man to video screen

    The only thing not accounted for in this "skeleton code" is the frame of animation with pac mans mouth open or closed. Thats easy to accommodate as he always goes from closed to open ( that variable is 1 o r 2 only) so inside of the select case and inside the case = we need an IF ... THEN test to point to correct graphic frame of animation. eg
Quote
   case =4
          if pac open then
       put down open facing pac man to video screen
          else
       put down closed facing pac man to video screen

« Last Edit: September 17, 2011, 09:28:10 am by GarrisonRicketson » Report Spam   Logged
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #5 on: February 27, 2011, 12:14:43 pm »

Thanks Oldoslover,
Quote
  Posted by: OlDosLover
Insert Quote
Hi all,
    Send me the new sprite sheet and ill set it up for you. We will need to add two new values to direction variable. Namely 3=up , 4 = down and the code will have to be adjusted to accomodate this. For example the select case will need addition to draw the correct up and down graphic.
OlDosLover.
I may be able to figure this out, now. I don't have my "tablet",here, and do not like useing the mouse to draw, much, they come out alot nicer useing the tablet and "pen". So more in the week, I can try this code. Sometimes that helps me
alot, if I see more or less how the code is written,  when I make the sprites,...
Any way just to let you know I have seen this, but it may be a few days, before
I respond with the sprite sheet, and any question, if I can't get to work.
Apart from being a little wider, on the sprite sheet I have, I noticed I had forgotten, to put in the image with the mouth closed, in the faceing down images, they are all with the mouth open!..so guess thats about it.
from Garry

Report Spam   Logged

GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #6 on: February 28, 2011, 07:50:37 am »

http://dl.dropbox.com/u/15387474/OldDosLoverSprtSheet1.PNG
Above is the new sprite, I almost had it, but when I got up to Case 3 and 4
I started getting errors, at one point I had some interesting effects,...
 But still did not get it right. I decided not to post the code I made, so as not to creat confusion, as it still dose not work.
 The sprite sheet is a little rough still, but should work for a code sample,
94 x 94 each frame.
  If you have time, it would be nice to see a good sample, if not I will keep trying, as I did get close,...
thanks from Garry
Report Spam   Logged

guest
Guest
« Reply #7 on: February 28, 2011, 06:43:20 pm »


    Here's a PacMan MAP maker that creates a graphical map 800 x 600. The size of the corridor is 30 pixels. Pacman is 28 pixels leaving 1 pixel either side of pacman for collision detection with point. Currently saves the map to PacMap0.bmp. The grid is NOT copied to the saved file!. Map is 25 cells wide by 19 cells deep. To draw more maps rename the original before creating another new map.

Code:
REM Best version yet.
DEFLNG A-Z

DIM SHARED mx, my, mbl, mbr

Video& = _NEWIMAGE(800, 600, 32) 'page we actually draw on
Grid& = _NEWIMAGE(800, 600, 32) 'grid to place over monitor

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

Yellow& = _RGB32(255, 255, 0)
MSBlue& = _RGB32(123, 104, 238)
Black& = _RGB32(0, 0, 0)

GOSUB Makemap

DO
  _CLEARCOLOR Black&, Grid&
  _PUTIMAGE , Grid&, 0 'copy yellow lines of grid only
  _PUTIMAGE , Video&, 0
  MousePoll
  r = INT(mx \ 30) 'row
  r1 = r * 30 'x1
  r2 = r1 + 30 'x2
  c = INT(my \ 30) 'column
  c1 = c * 30 'y1
  c2 = c1 + 30 'y2

  IF mbl = -1 THEN GOSUB LFillbox
  IF mbr = -1 THEN GOSUB RFillbox

  _DEST 0
  LOCATE 1, 95: PRINT mx
  LOCATE 2, 95: PRINT my
  LOCATE 4, 95: PRINT r + 1
  LOCATE 5, 95: PRINT c + 1

LOOP UNTIL _KEYDOWN(27)

SaveImage Video&, "PacMap0.bmp"
_DEST 0
LOCATE 10, 37: PRINT "FILE SAVED AS PacMap0.bmp"
SOUND 1500, 1: SOUND 2000, 1
SLEEP
SCREEN 0
_FREEIMAGE Video&
_FREEIMAGE Grid&
SYSTEM
'------------------------------ SUBS -------------------

RFillbox:
IF mx < 748 THEN
  IF my < 566 THEN
    _DEST Video&
    LINE (r1, c1)-(r2, c2), Black&, BF 'erase box
  END IF
END IF
RETURN

LFillbox:
IF mx < 748 THEN
  IF my < 566 THEN
    _DEST Video&
    LINE (r1, c1)-(r2, c2), MSBlue&, BF 'fill box
  END IF
END IF
RETURN

Makemap:
_DEST Grid&
FOR x = 0 TO 740 STEP 30
  FOR y = 0 TO 560 STEP 30
    LINE (x, y)-(x + 30, y + 30), Yellow&, B
  NEXT y
NEXT x
RETURN

SUB SaveImage (image AS LONG, filename AS STRING)
bytesperpixel& = _PIXELSIZE(image&)
IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
x& = _WIDTH(image&)
y& = _HEIGHT(image&)
b$ = "BM????QB64????" + MKL$(40) + MKL$(x&) + MKL$(y&) + MKI$(1) + MKI$(bpp&) + MKL$(0) + "????" + MKL$(0) + MKL$(0) + MKL$(0) + MKL$(0) 'partial BMP header info(???? to be filled later)
IF bytesperpixel& = 1 THEN
  FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
    cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
    b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  NEXT
END IF
MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
lastsource& = _SOURCE
_SOURCE image&
IF (x& AND 3) THEN padder$ = SPACE$(4 - (x& AND 3))
FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  r$ = ""
  FOR px& = 0 TO x& - 1
    c& = POINT(px&, py&)
    IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  NEXT px&
  d$ = d$ + r$ + padder$
NEXT py&
_SOURCE lastsource&
MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
b$ = b$ + d$ ' total file data bytes to create file
MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
f& = FREEFILE
OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
OPEN filename$ + ext$ FOR BINARY AS #f&
PUT #f&, , b$
CLOSE #f&
END SUB

SUB MousePoll ()
DO WHILE _MOUSEINPUT
  mx = _MOUSEX: my = _MOUSEY: mbl = _MOUSEBUTTON(1): mbr = _MOUSEBUTTON(2)
LOOP
END SUB

SUB ButtonRelease ()
IF mbl = 0 AND mbr = 0 THEN EXIT SUB
WHILE mbl = -1
  MousePoll
WEND
WHILE mbr = -1
  MousePoll
WEND
END SUB



« Last Edit: September 17, 2011, 09:29:28 am by GarrisonRicketson » Report Spam   Logged
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #8 on: February 28, 2011, 07:20:51 pm »

I was just fooling around with the code, and Pacy001.bmp, that you posted,
when you posted the map maker, which I have not tried yet.
 This is great!, all though it looks easy enough to follow, it is quite a bit different, then what I imagined,....Sorry about the image I posted not working,...Guess I need to work on that, too. I think, maybe I need a new mouse, when I am trying to paste something, it is really hard to get it on the exact pixel number I want,.
or practice,..!
 I need to lie down a while, as I just got home, hopefully later tonight I can look at the map too,...
thanks a bunch, from Garry
Report Spam   Logged

GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #9 on: February 28, 2011, 10:59:58 pm »

 OK, thats, fine with me,...I was just now, "fooling around" with, the
sample you wrote,....I had some code CG gave me, that helped me ,eat some text I put in,...also I had been trying to do some thing with PLAY, but not very good results, the eating some text, yes I got good results, but useing play no,.
...I like the idea of useing midi, I'll see what I can do there,...I was just thinking,  if you want to see what I did,..? But I would post it separate, so we can continue with this thread, as the Game thread,...I don't want to post my "expeiments", as it could really confuse things,...
Do you have the DOS version of PAC MAN ? I have one if you want to see it,
but I would like to try to something different, so as not to be "copying" his (the author), He did do a excelent job,I don't hae his name handy.
But yea, I like the idea, of continueing with this...
from Garry
P.S. I posted links to the Dos version, MsPack, and PacMan here:
http://weeklyqbasicandqb64lesson.smfforfree.com/index.php/topic,51.0.html
« Last Edit: September 17, 2011, 09:32:57 am by GarrisonRicketson » Report Spam   Logged

guest
Guest
« Reply #10 on: March 01, 2011, 12:48:23 pm »


    Heres an update to the editor. I decided to make a ascii data saving routine to a file. This is so the level can be imbedded into the program , saving loading and finding the individual level files. Also there are 2 ways to do this game
1] Pixel collision
2] Array as map collision
    The first evolution will be Array as map. The idea is the map is read into an array. To plot movement if you moving right, you simply check the next cell for wall,enemy,or prize etc. Makes it easier to determine all valid directions as you plot all 4 possible directions the hero is able to travel. They are blocked or open. Blocked is a wall open is free or emeny or prize etc. Hope you understand. Will finish the convert to string and actual write to file tomorrow.
Code:
REM Best version yet.
DEFLNG A-Z

DIM SHARED mx, my, mbl, mbr
DIM SHARED PacMap(19, 25)

Video& = _NEWIMAGE(800, 600, 32) 'page we actually draw on
Grid& = _NEWIMAGE(800, 600, 32) 'grid to place over monitor
Text& = _NEWIMAGE(800, 600, 32)

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

Yellow& = _RGB32(255, 255, 0)
MSBlue& = _RGB32(123, 104, 238)
Black& = _RGB32(0, 0, 0)
Blok$ = CHR$(176): Blank$ = CHR$(32)

GOSUB Makemap

DO
  _CLEARCOLOR Black&, Grid&
  _PUTIMAGE , Grid&, 0 'copy yellow lines of grid only
  _PUTIMAGE , Video&, 0
  MousePoll
  r = INT(mx \ 30) 'row
  r1 = r * 30 'x1
  r2 = r1 + 30 'x2
  c = INT(my \ 30) 'column
  c1 = c * 30 'y1
  c2 = c1 + 30 'y2

  IF mbl = -1 THEN GOSUB LFillbox
  IF mbr = -1 THEN GOSUB RFillbox
  IF _KEYDOWN(32) THEN
    _PUTIMAGE , Text&, 0
  END IF
  _DEST 0
  LOCATE 1, 95: PRINT mx
  LOCATE 2, 95: PRINT my
  LOCATE 4, 95: PRINT r + 1
  LOCATE 5, 95: PRINT c + 1

LOOP UNTIL _KEYDOWN(27)

SaveImage Video&, "PacMap0.bmp"
_DEST 0
LOCATE 10, 37: PRINT "FILE SAVED AS PacMap0.bmp"
SOUND 1500, 1: SOUND 2000, 1
SLEEP 1
SCREEN 0
cycle = 0
FOR c = 0 TO 18
  FOR r = 0 TO 24
    LOCATE c + 1, r + 1
    'z = PacMap(c, r)
    z = PacMap(c, r)
    IF z = 0 THEN PRINT CHR$(32) ELSE PRINT CHR$(z)
    _DELAY .1
    cycle = cycle + 1
    LOCATE 1, 40: PRINT cycle
  NEXT r
NEXT c
SLEEP
_FREEIMAGE Video&
_FREEIMAGE Grid&
_FREEIMAGE Text&
SYSTEM
'------------------------------ SUBS -------------------

RFillbox:
IF mx < 748 THEN
  IF my < 566 THEN
    _DEST Video&
    LINE (r1, c1)-(r2, c2), Black&, BF 'erase box
    _DEST Text&
    LOCATE c + 1, r + 1: PRINT Blank$
    PacMap(c, r) = 32
  END IF
END IF
RETURN

LFillbox:
IF mx < 748 THEN
  IF my < 566 THEN
    _DEST Video&
    LINE (r1, c1)-(r2, c2), MSBlue&, BF 'fill box
    _DEST Text&
    LOCATE c + 1, r + 1: PRINT Blok$
    PacMap(c, r) = 176
  END IF
END IF
RETURN

Makemap:
_DEST Grid&
FOR x = 0 TO 740 STEP 30
  FOR y = 0 TO 560 STEP 30
    LINE (x, y)-(x + 30, y + 30), Yellow&, B
  NEXT y
NEXT x
RETURN

SUB SaveImage (image AS LONG, filename AS STRING)
bytesperpixel& = _PIXELSIZE(image&)
IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
x& = _WIDTH(image&)
y& = _HEIGHT(image&)
b$ = "BM????QB64????" + MKL$(40) + MKL$(x&) + MKL$(y&) + MKI$(1) + MKI$(bpp&) + MKL$(0) + "????" + MKL$(0) + MKL$(0) + MKL$(0) + MKL$(0) 'partial BMP header info(???? to be filled later)
IF bytesperpixel& = 1 THEN
  FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
    cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
    b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  NEXT
END IF
MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
lastsource& = _SOURCE
_SOURCE image&
IF (x& AND 3) THEN padder$ = SPACE$(4 - (x& AND 3))
FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  r$ = ""
  FOR px& = 0 TO x& - 1
    c& = POINT(px&, py&)
    IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  NEXT px&
  d$ = d$ + r$ + padder$
NEXT py&
_SOURCE lastsource&
MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
b$ = b$ + d$ ' total file data bytes to create file
MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
f& = FREEFILE
OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
OPEN filename$ + ext$ FOR BINARY AS #f&
PUT #f&, , b$
CLOSE #f&
END SUB

SUB MousePoll ()
DO WHILE _MOUSEINPUT
  mx = _MOUSEX: my = _MOUSEY: mbl = _MOUSEBUTTON(1): mbr = _MOUSEBUTTON(2)
LOOP
END SUB

SUB ButtonRelease ()
IF mbl = 0 AND mbr = 0 THEN EXIT SUB
WHILE mbl = -1
  MousePoll
WEND
WHILE mbr = -1
  MousePoll
WEND
END SUB


« Last Edit: September 17, 2011, 09:31:22 am by GarrisonRicketson » Report Spam   Logged
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #11 on: March 01, 2011, 09:02:28 pm »

.
Quote
  you simply check the next cell for wall,enemy,or prize etc. Makes it easier to determine all valid 
Not sure I understand all of this,..I just got home, kind of late. What I don't understand, the "checking", (do you mean "clicking" with the mouse, it then fills the box ,at this point with  the wall),? But if you want concentrate on
Quote
Will finish the convert to string and actual write to file tomorrow.
Then it may be self explaining, or you can give more detailed explanation...But what you have so far looks good, and as a .bmp it can also be edited useing paint.  We will need enemys(ghosts), and like you say prizes, also, I need to look for some midi, stuff, or can also wav be used ?
 So this is more of a comment right now, you don't need to take the time to do a long detailed explanation, at this point,..I am going to start a new instance of qb64, Down load a new one,  so I have a qb64 folder dedicated to this,...My current  folder has so much in it , it is takeing me forever to find things, and I all ready have a bunch of Pacmans(previous).
 Guess thats about it for now.
from Garry
« Last Edit: September 17, 2011, 09:32:14 am by GarrisonRicketson » Report Spam   Logged

guest
Guest
« Reply #12 on: March 02, 2011, 07:09:25 am »


    Ok Garry heres an in depth explanation of how this works.
Quote
         Pac Man Map
   How does the map , Array and the image onscreen all relate to each other?
This is the cruz of the problem of getting everything to work in co-ordination.
Imagine a page of text. We divide this page (as programmers) into rows and columns.
Each individual letter exists in a "cell" on a particular line on the page. We can
know its address by its row and column.
   If we set the graphical map up as the page of text then they replicate each
other. Instead of row and column we use pixel in x axis and pixel in y axis. And to
represent a "cell" thats just a collection of pixels wide(x axis) by pixels deep
(y axis).
   Now if we set the Array up as like the text page thats rows and columns then
thats a two dimention Array. This means the individual "cells" are represented like
row and column idea. Inside each "cell" is the number to represent what exists as a
symbol at that address onscreen.
   The editor's grid is based on "cells" in row and column form.
A row is a collection of columns. So thats 19 rows of 25 columns. Thats 475 individual
"cells". In the editor you fill a cell with color blue to indicate a wall. In the
actual text page that wall is converted into character 176. In the Array that address
holds the number 176. And so you build your map being careful to make each corridor
only one cell wide. In fact the entire map MUST have no double empty cell spaces.
   The symbols that represent the objects in our game are
1] Wall          = Ascii Characters 176
2] PacMan      =
3] Red ghost   =
4] Blue ghost   =
5] White ghost   =
6] Yellow ghost   =
7] Fruit      =
8] Empty      =Ascii characters 32

   So in the Array the number 176 is converted into the ASCII character code by
the text page which is the equivalent of the graphic. So the 3 pages all represent
the contents of each "cell" with data that is native to their style.
Array is numbers
Graphic is pixels
Text is characters

   Now to complicate this even more the fact is once you can convert from one
page to another then you can edit in any of the 3 pages and update the other two pages
with the correct form of data that that page needs. One only has to write the code that
does the conversion. In this editor i decided that the map would be composed with the
graphic page. Each entry on this page is updated to the Array and the Text. Only the
Graphic and Text is saved by the program. At run time the array can be created and filled
by reading the Text page. Also the graphic can be recreated by the same method at run time.

   Ok so you have your Array filled with the data off the Text page. Inside the Array
somewhere is the symbol to represent pac man. We find it by scanning the rows and columns
of the array. Once found that address is the key to how we move him. For arguements sake we
say he is at row10 and column10.
If we want him to move east then we scan address row10,column11.
If we want to move north we scan address row9,column10
If we want to move south we scan address row11,column10
If we want to move west we scan address row10,column9

   So based off what each directions neighbouring "cell" has as its contents we can
create in game logic to decide what should and does happen. This idea is alos used to
replicate random movement by the ghosts. When a ghost comes to an intersection we use a
random choice to decide new direction. With pac man its not random. While a corridor is
empty he continually moves until he hits a wall or the user enters a key to ask to change
direction.

  Next step is to get the map saved as data statements that can be imbedded in the code as a level
  After this we need to create some random direction generator
  After this we need to create a find path to pac man function

« Last Edit: September 17, 2011, 09:35:30 am by GarrisonRicketson » Report Spam   Logged
guest
Guest
« Reply #13 on: March 02, 2011, 02:08:11 pm »


    Heres an update that has instructions and saves map as both BMP and TXT data statements ready to cut and paste into a program. Remember the BMP file is overwritten and the TXT file gets added to. Best bet is to rename both files before you draw another map.
Code:
REM Best version yet.
DEFLNG A-Z

DIM SHARED mx, my, mbl, mbr
DIM SHARED PacMap(19, 25)

Video& = _NEWIMAGE(800, 600, 32) 'page we actually draw on
Grid& = _NEWIMAGE(800, 600, 32) 'grid to place over monitor
Text& = _NEWIMAGE(800, 600, 32)

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

Yellow& = _RGB32(255, 255, 0)
MSBlue& = _RGB32(123, 104, 238)
Black& = _RGB32(0, 0, 0)
Blok$ = CHR$(176): Blank$ = CHR$(32)

GOSUB Makemap
_MOUSESHOW
DO
  _CLEARCOLOR Black&, Grid&
  _PUTIMAGE , Grid&, 0 'copy yellow lines of grid only
  _PUTIMAGE , Video&, 0
  MousePoll
  r = INT(mx \ 30) 'row
  r1 = r * 30 'x1
  r2 = r1 + 30 'x2
  c = INT(my \ 30) 'column
  c1 = c * 30 'y1
  c2 = c1 + 30 'y2

  IF mbl = -1 THEN GOSUB LFillbox
  IF mbr = -1 THEN GOSUB RFillbox
  IF _KEYDOWN(32) THEN
    _PUTIMAGE , Text&, 0
  END IF
  _DEST 0
  LOCATE 1, 95: PRINT mx
  LOCATE 2, 95: PRINT my
  LOCATE 4, 95: PRINT r + 1
  LOCATE 5, 95: PRINT c + 1

LOOP UNTIL _KEYDOWN(27)

GOSUB Savgrapmap 'save a bmp of it
_DEST 0
LOCATE 10, 37: PRINT "FILE SAVED AS PacMap0.BMP"
LOCATE 13, 37: PRINT "FILE SAVED AS PacMap0.TXT"
SOUND 1500, 1: SOUND 2000, 1
SLEEP 1
GOSUB Savdatamap 'save as data statements in text
SLEEP

_FREEIMAGE Video&
_FREEIMAGE Grid&
_FREEIMAGE Text&
SYSTEM
'------------------------------ SUBS -------------------
Init:
PRINT "Use left mice button to color cell blue"
PRINT "Use right mice button to erase cell color to black"
PRINT "When finished drawing press ESCAPE"
PRINT "Program will save a copy as BMP named PacMap0.BMP"
PRINT "Program will save a copy as DATA statements in text form named PacMap0.TXT"
PRINT "Press any key"
dummy$ = INPUT$(1)
CLS
RETURN

Savgrapmap:
SaveImage Video&, "PacMap0.bmp"
RETURN

Savdatamap:
SCREEN 0

Temp$ = "": Comma$ = ",": Savfilename$ = "PacMap0.txt"
cycle = 0
FOR c = 0 TO 18
  FOR r = 0 TO 24
    LOCATE c + 1, r + 1
    z = PacMap(c, r)
    IF z = 0 THEN
      z = 32
      PRINT CHR$(32)
    ELSE
      PRINT CHR$(z)
    END IF
    temp1$ = LTRIM$(STR$(z))
    Temp$ = Temp$ + temp1$ + Comma$
  NEXT r
  GOSUB Txtsaver
  Temp$ = ""
NEXT c
Temp$ = ""
RETURN

Txtsaver:
z = LEN(Temp$)
Temp$ = LEFT$(Temp$, z - 1)
Temp$ = "DATA " + Temp$
OPEN Savfilename$ FOR APPEND AS #1
PRINT #1, Temp$
CLOSE #1
RETURN

RFillbox:
IF mx < 748 THEN
  IF my < 566 THEN
    _DEST Video&
    LINE (r1, c1)-(r2, c2), Black&, BF 'erase box
    _DEST Text&
    LOCATE c + 1, r + 1: PRINT Blank$
    PacMap(c, r) = 32
  END IF
END IF
RETURN

LFillbox:
IF mx < 748 THEN
  IF my < 566 THEN
    _DEST Video&
    LINE (r1, c1)-(r2, c2), MSBlue&, BF 'fill box
    _DEST Text&
    LOCATE c + 1, r + 1: PRINT Blok$
    PacMap(c, r) = 176
  END IF
END IF
RETURN

Makemap:
_DEST Grid&
FOR x = 0 TO 740 STEP 30
  FOR y = 0 TO 560 STEP 30
    LINE (x, y)-(x + 30, y + 30), Yellow&, B
  NEXT y
NEXT x
RETURN

SUB SaveImage (image AS LONG, filename AS STRING)
bytesperpixel& = _PIXELSIZE(image&)
IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
x& = _WIDTH(image&)
y& = _HEIGHT(image&)
b$ = "BM????QB64????" + MKL$(40) + MKL$(x&) + MKL$(y&) + MKI$(1) + MKI$(bpp&) + MKL$(0) + "????" + MKL$(0) + MKL$(0) + MKL$(0) + MKL$(0) 'partial BMP header info(???? to be filled later)
IF bytesperpixel& = 1 THEN
  FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
    cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
    b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  NEXT
END IF
MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
lastsource& = _SOURCE
_SOURCE image&
IF (x& AND 3) THEN padder$ = SPACE$(4 - (x& AND 3))
FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  r$ = ""
  FOR px& = 0 TO x& - 1
    c& = POINT(px&, py&)
    IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  NEXT px&
  d$ = d$ + r$ + padder$
NEXT py&
_SOURCE lastsource&
MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
b$ = b$ + d$ ' total file data bytes to create file
MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
f& = FREEFILE
OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
OPEN filename$ + ext$ FOR BINARY AS #f&
PUT #f&, , b$
CLOSE #f&
END SUB

SUB MousePoll ()
DO WHILE _MOUSEINPUT
  mx = _MOUSEX: my = _MOUSEY: mbl = _MOUSEBUTTON(1): mbr = _MOUSEBUTTON(2)
LOOP
END SUB

SUB ButtonRelease ()
IF mbl = 0 AND mbr = 0 THEN EXIT SUB
WHILE mbl = -1
  MousePoll
WEND
WHILE mbr = -1
  MousePoll
WEND
END SUB

Next comes the TXT file loader that creates the map graphically.


« Last Edit: September 17, 2011, 09:38:25 am by GarrisonRicketson » Report Spam   Logged
guest
Guest
« Reply #14 on: March 02, 2011, 02:52:57 pm »


    Heres an example map and code to display it. Note the "cell" created is just a block as yet. Graphic pics could be loaded and placed at same places.
Code:
REM Demo of Pac Map.
DEFLNG A-Z

DIM SHARED mx, my, mbl, mbr
DIM SHARED PacMap(19, 25)


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

LOOP UNTIL _KEYDOWN(27)
SLEEP
SCREEN 0
SYSTEM

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(255, 255, 0), BF
    END IF
  NEXT r
NEXT c
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

Next comes an example map with a moveable PacMan.
« Last Edit: September 17, 2011, 09:39:20 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