Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / pacman walls detections problems

Author
Message
henrikh2008
16
Years of Service
User Offline
Joined: 25th Apr 2010
Location: Denmark
Posted: 27th Apr 2010 18:17
hello, every one, i just downloadet the dark basic pro, and i`m enjoying alot.

i have been programming in c++, java, visual basic/net, machine code., but it has been a long time, since i have been programming, now i`m fairly begninning to get to know dark basic pro.

i did create a pacman clone, every things works ok, but i do have trouble with the pac walls, i`m trying to make an if -then statement, so pacman wont run through the walls, but this seems to more diffcult than i expected.
i want pacman to stand still when he hits the walls that suround him.

my a approach to detect when pacman hits the wall is (code below).

sprite (1)= is my pacman sprite.

if sprite y(1)<210 and sprite hit(1,3)=1 then y=y-1

rem if pacman hit the wall barrier that is less than 210 pixel and hits the wall (sprite 3) at same time then execute code.

or maybe is should use this statement.

if sprite y(1)>210 and sprite y(1)<240 and sprite x(1)>60 and sprite x(1)<120 then

nothing really seems to work problery, because i want to make a perfect collision detection that can detect the pacman wall from 4 side like: up down, left right , how can i achieve this ?.


allso is there is a way to make the pacwalls easier to make, for eks, using arryes for - next loop with spritea or ???.
is it possible to convert aschii symbol to graphics, so i can build up the levels / pac walls.

hope its not to diffcult to read my text.


male, live in denmark.
38 years old.
Teh Stone
16
Years of Service
User Offline
Joined: 12th Dec 2009
Location:
Posted: 28th Apr 2010 00:45
Post what you have for the making of the Walls and i'm sure someone will help to improve it
DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 28th Apr 2010 18:00
Hmmm, are you making this in 2d or 3d? Pacman is fairly straightforward when it comes to the wall detection. You only have to check the direction you are traveling for one. Not done one in years and years, but in 2D and I assume 3D will be the same, you need to use an array to create the maze. You can then use the array both for the look of your maze and the collision. Just have walls signified by 1 and corridors by 0, you may even want pills also, so you could use 2 to signify those etc. You can also assign an image to each number you use so you can use bitmaps for the walls,floors and pills.
For collision you would check the array to see what tile you are on and what tile is next.So, if it is a wall, stop, if its a floor continue, and if its a pill eat it and carry on etc.
Although if you have used as many languages as you say I am surprised this would be much trouble.

http://s6.bitefight.org/c.php?uid=103081
henrikh2008
16
Years of Service
User Offline
Joined: 25th Apr 2010
Location: Denmark
Posted: 28th Apr 2010 19:54
here i`m posting the whole pacman game, but its not finished yet.

its in 2d.


yes i have been programming in different languages, its not many, and i did not create games really mostly database program, some grahhics, long time ago, (when you take a break for a couple of years not programming at all, you allmost forget a lot of things) and i not a pro programmer.

but now i really hope i can catch up with every things.

i never did 3d programming, nor really use directx, but did played around with some api for graphics in visual basic 6.


now i really have to pull my self together, to better achieve better resultat, i admit i have some hols in my programming knowledge (arrgg).


rem initialise variables.


score=0
y=65


x=350


ghostmoveleft=0
ghostmoveright=1

pacmoveright=0
pacmoveleft=0
pacmovedown=0
pacmoveup=0





rem setting display 1024*768 32 bit color


set display mode 1024,768,32


rem clear screen

cls





















rem get pacman image.

get image 1,20,30,100,100,0

get image 2,20,30,100,100,0

rem get ghost image

get image 3,20,30,100,100,0

rem pac walls 1 image no 3



rem get image image no, left,top,right bottom.

get image 4,20,30,100,100,0

rem pac walls 1 image no 4

get image 5,20,30,100,100,0

rem pac walls 1 image no 4

get image 5,20,30,100,100,0

rem pac walls 1 image no 5

get image 6,20,30,100,100,0

rem pac walls 1 image no 6

get image 7,20,30,100,100,0

rem pac walls 1 image no 7

get image 8,20,30,100,100,0

get image 9,20,30,100,100,0

rem pac walls 1 image no 8


rem load coresponding image for each sprite.

rem load image "filename location.picture format",image no.

load image "c:\dark basic sprites\pacman left.bmp",1
load image "c:\dark basic sprites\ghost1.bmp",2
load image "c:\dark basic sprites\pacwall1.bmp",3
load image "c:\dark basic sprites\pacwall1.bmp",4
load image "c:\dark basic sprites\pacwall2.bmp",5
load image "c:\dark basic sprites\pacwall3.bmp",6
load image "c:\dark basic sprites\pacwall3.bmp",7
load image "c:\dark basic sprites\pacpillbig.bmp",8

rem setting each sprite no, backsave,transparacy ( 1= transparency, 0 = no transparaency, black color will treated as transparaency).


set sprite 1,0,0
set sprite 2,0,0
set sprite 3,0,0
set sprite 4,0,0
set sprite 5,0,0
set sprite 6,0,0
set sprite 7,0,0
set sprite 8,0,0


rem SPRITE Sprite Number, XPos, YPos, Image Number


rem show sprite no, x,y pos,image no.

sprite 3,200,160,3
sprite 4,200,540,4
sprite 5,360,360,5
sprite 6,200,320,6
sprite 7,780,320,7
sprite 8,40,80,8




rem game loop

do


for fff=1 to 90000
next


rem i am useing a for next loop to an delay in the game (its running to fast)




rem move pacman continuously in each direction when the coresponding key is pressed.

x=x+pacmoveright
x=x-pacmoveleft
y=y+pacmovedown
y=y-pacmoveup
ghostx=ghostx-ghostmoveleft
ghostx=ghostx+ghostmoveright

rem check if leftkey is pressed, pacman moves to the left.
rem if left key is pressed move pacman to left, but disable him to move in other direction simultaneously (he, he can could be nice).
if leftkey()=1 then pacmoveleft=1:pacmoveright=0:pacmoveup=0:pacmovedown=0
if rightkey()=1 then pacmoveright=1:pacmoveleft=0:pacmoveup=0:pacmovedown=0

if upkey()=1 then pacmoveup=1:pacmovedown=0:pacmoveleft=0:pacmoveright=0
if downkey()=1 then pacmoveup=0:pacmovedown=1:pacmoveright=0

rem check if pacman crossing the boundaries of the screen, so he wont disappear.

if x<25 then x=25

rem same her but to the right .

if x>900 then x=900



rem same her but check if pacman dosent dissapear from the screen view in y diection (up).

if y<65 then y=65

rem again same here, check for for bottom of the screen.

if y>600 then y=600



rem if ghost x possition is greater then 500 or move moe than 500 pixel then reverse direction to the left (the ghost movemnet).



if ghostx>500 then ghostmoveleft=1:ghostmoveright=0


rem if ghost has changed dirction to the lett and reached less than 90< Pixel then reverse the direction of the ghost movement,
rem so hes move to right (the ghost moves to right and left continuously in a loop.

if ghostx<90 and ghostmoveleft=1 then ghostmoveright=1:ghostmoveleft=0






rem check if pacman hit the sprite no 8 (the big pac pills, if so then hide the sprite and delete if from memory, so pacman will
rem only be able to¨eat the pill once. (i did only use one pill for this pacman game. (testing game).
rem increase the the score by 1.

if sprite hit(1,8)=1 then score=score+10:hide sprite 8:delete sprite 8


rem collesion of the first wall, does not work properly.

if sprite x(1)>220 and sprite y(1)>60 and sprite x(1)<700 and sprite y(1)<210 then pacmovedown=0
if sprite x(1)>220 and sprite y(1)>60 and sprite x(1)<700 and sprite y(1)<211 then pacmoveup=0














rem clear screen


cls


sprite 1,x,y,1

sprite 2,ghostx,230,2

rem set cursor position and print score, lives ....
SET CURSOR 350,20: print "SCORE: ",score, " LIVES: ",lives, " lEVEL: ",level








loop

rem end of the game loop





male, live in denmark.
38 years old.
Teh Stone
16
Years of Service
User Offline
Joined: 12th Dec 2009
Location:
Posted: 29th Apr 2010 00:29
I know I posted before but I don't know how to do pacman games :/ but I just want to point out a couple of commands that you will find useful

1) sync on
2) sync rate (desired rate)

Put these at the top and delete that for loop with nothin in, then play around with the sync rate until it suits your game
DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 29th Apr 2010 01:05
Here is something I have knocked up. probably not the best code as I have bodged here and there, but it works.


You will need 3 32x32 bitmaps, one for wall one for floor and one for pacman. You can add in more functionality by using more numbers in the array for pills, power pills and the ghost box.
I have included the mock up ones I made just for completeness .

http://s6.bitefight.org/c.php?uid=103081
henrikh2008
16
Years of Service
User Offline
Joined: 25th Apr 2010
Location: Denmark
Posted: 29th Apr 2010 01:16
thanks, i think i am beginning to understand how to make much better collision detection, it all about arrays, properly read data statement, strings with aschii symbol containing 1 and 0, 2.
the zero`s would mean patchway, 1 walls and 2 for the pills.
i will need a function and for next loop to detect, scan the whole aschii symbols for one, two, and zero`s and then somehow use the maze as as reference to the boundaries of the walls, if the walls is solid, pacman can`t go through them(1=solid,...). but to integrate this Methodology to my code, is somehow diffecult, but i
was reading a pacman tutorials in this forum, just need to figure it out, and need some more experince, codeing is hard, sometimes.
i do adsmit i get stuck to often, but not allways.
i hate when its like that.
so how can i convert and tranfer not only the string maze but allso the x,y position of the maze and its element to the pacman game and sprite relationchips ??, can i use boolean statement...
if i can figure it out, i can easyli make platform games and a lot more games without diffucult collision detection, that could be neat.
i allready made 1 platform game (not yet finished), and one pong game (finished), both games works ok.

male, live in denmark.
38 years old.
henrikh2008
16
Years of Service
User Offline
Joined: 25th Apr 2010
Location: Denmark
Posted: 29th Apr 2010 01:20
thansk, DVader

i did`nt use function or arrays yet, because i need to keep it simpel, but later on, i will.

male, live in denmark.
38 years old.
henrikh2008
16
Years of Service
User Offline
Joined: 25th Apr 2010
Location: Denmark
Posted: 9th May 2010 15:01
still problems with wall collision detection - pacman.

i tried every thing, and i figured out ,hopefully most of the code, how to paste sprite a in a maze using read data / arrays statements/codes.


every things works fine, but i still can´t figured a easy way to make a simpel wall collision detection in my pacman game.

what does the code line here, means below:

if maze(int((y-17)/32),int(x/32))=0

my guess if the maze array integer value, x-17 dividet with 32 ?, integer value y / 32 is zero (if the maze arrays plus minus y,x /32 etc,

contains a zero, well if pacman somehow meeets a wall containing a zero ??, then hes change direction x or y direction.

allso should i use a flag, to keep status of what pacman do in the game. (did he move x or y, is he not moveing, what direction did he go

(hopefully he did´nt choose to leave the game becuase of my poor coding ,ha,ha.

should i somehow, use a counter for messurement of the distant of the surrounding walls (counterstep=counterstep+1 ? ), so i know when he`s

interact or colide with a wall ?.

i have been told on internet that, pacman doesn't use collision detection, but instead use a trick to mesure the distant how far he is, from the

wall ??....

i really hoped i was going to finish up my pac game, but unfortunately that gonna take a while.

how can you check the maze/sprite, when the sprite is pasted over all the screen ? (i mean the sprite "wall" is the same sprite, only defined by

the data statement´s 1 for wall and 1 for floor),maze build up by the data codes / lines.


male, live in denmark.
38 years old.
henrikh2008
16
Years of Service
User Offline
Joined: 25th Apr 2010
Location: Denmark
Posted: 9th May 2010 16:40
i forgot to mentioned, that i did put a download atachement text file of my pacman source code in prevous post.

how i can i make a "code snippet" link ?.


any way here is my code.



rem set display mode to pixel 800x600 32 bit color

set display mode 800,600,32,1


rem initialize a array of 33 by 16 for the mazed
rem properly i should use 12*12 array, but for now i just using 33*16

dim maze(33,16)


rem ther´s no walls collision detections yet, i have`nt figured out a way, how to do it, in a easy way.


rem blok=24 expand the space between the sprite so it will fit a 800*600 resolution of the screen

blok=24

rem pacman x and y cordinate when the game starts

pacx=320
pacy=200


rem reset data statement pointer to the first element of data in a array.

restore mazedata

rem set the sprite with options sprite no, no backsave, transparency

set sprite 1,0,1

set sprite 2,0,1
set sprite 3,0,0


rem load image for sprite for walls, floor, pacman.

load image "c:\dark basic sprites\pacpills2.bmp",1
load image "c:\dark basic sprites\pacfloor.bmp",2
load image "c:\dark basic sprites\pacman.bmp",3


rem clear screen

cls

rem draw sprite no, x,y cordinate, image no.

sprite 1,x,y,1

sprite 2,x,y,2

rem for next loop, draw maz 16 row height and colum 32 width.


do

gosub maze

gosub control

sync




loop



maze:

for row=0 to 15
for colum=0 to 32
rem read maze array of row,colum (read entire maze)

read maze(colum,row)


rem if maze array contain/finds a 0 (zero digit) then paste the sprite with empty space (the sprite FLOOR is a small black square bitmap picture).

if maze(x,y)=0 then paste sprite 2,colum*blok,row*blok

rem if maze array contain/finds a 1 (one digit ) then paste the sprite with the pac walls sprite.
if maze(colum,row)=1 then paste sprite 1,colum*blok,row*blok



next row
next colum

return





rem pacman movement is zero at the beginning when the game starts.
rem pressing any key,pacman continuously move in that direction, until another key is pressed.

countxleft=0
countxright=0
countyleft=0
countyright=0


control:

pacx=pacx-countxleft
pacx=pacx+countxright
pacy=pacy+countyleft
pacy=pacy-countyright


rem if user pressed the left key, on the keyboard, then move pacman to left (pacx=pacx+1). instead of using pacx=pacx+1 i added PACX=PACX+COUNTERX.

if scancode()=203 then countxleft=1:countxright=0:countyleft=0:countyright=0

rem if user pressed the right on the keyboard, then move pacman to the right.


rem right

if scancode()=205 then countxright=1:countxleft=0:countxleft=0:countyleft=0:countyright=0


rem up


if scancode()=208 then countyleft=1:countyright=0:countxright=0:countxleft=0

rem down

if scancode()=200 then countyright=1:countyleft=0:countxright=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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1








male, live in denmark.
38 years old.

Login to post a reply

Server time is: 2026-07-26 06:17:39
Your offset time is: 2026-07-26 06:17:39