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.

Newcomers DBPro Corner / need help with my 2d game am making please help

Author
Message
Brock
20
Years of Service
User Offline
Joined: 10th Oct 2004
Location: USA,MI,Detroit,
Posted: 30th Oct 2004 10:08 Edited at: 30th Oct 2004 10:13
need help with my 2d game am making please help am stuck
i making my first game a 2d pacman game the enemy movement dont work


sync on : sync rate 60

rem randomize timer
Randomize timer()



dim maze#(20,16)

rem ghost array
dim ghosts#(4,11)

remstart
1 = x co-ordinate
2 = y co-ordinate
3 = going up?
4 = going down?
5 = going left?
6 = going right?
7 = can go up?
8 = can go down?
9 = can go left?
10 = can go right?
11 = state (alive,eaten,under influenece of pills, in pen etc)
remend

rem load all media for the game
loadmedia()

rem load the maze
loadmaze()

rem setup the variables
startlevel()

do

rem check if player is in the centre of a cell
centrex# = (playerx# - 174) / 16
centrey# = (playery# - 59) / 16
centrex = Int(centrex#)
centrey = Int(centrey#)

centre = 0

if centrex# = centrex and centrey# = centrey
centre = 1
endif

rem if the player is in the centre
if centre = 1

rem initilaise all possible directions
playercangoup = 0
playercangodown = 0
playercangoleft = 0
playercangoright = 0

rem check what is imediately up,down,left and right
mazeup = maze#(centrey - 1, centrex)
mazedown = maze#(centrey + 1, centrex)
mazeleft = maze#(centrey, centrex - 1)
mazeright = maze#(centrey, centrex + 1)
endif






showplayer()
eatpills()
showghost()
ghostmove()
checkghost()
sync
loop

remstart
1 is wall
2 is gate
3 is pill
4 is power pill
0 is gap
remend

Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Data 1,4,3,3,3,3,3,3,3,3,3,3,3,3,4,1
Data 1,3,1,1,1,1,1,3,3,1,1,1,1,1,3,1
Data 1,3,1,3,3,3,3,3,3,3,3,3,3,1,3,1
Data 1,3,1,3,1,3,1,0,0,1,3,1,3,1,3,1
Data 1,3,1,3,1,3,1,2,2,1,3,1,3,1,3,1
Data 1,3,1,3,1,3,1,0,0,1,3,1,3,1,3,1
Data 1,3,1,3,1,3,1,1,1,1,3,1,3,1,3,1
Data 0,3,1,3,1,3,3,3,3,3,3,1,3,1,3,0
Data 1,3,1,3,1,1,1,1,1,1,1,1,3,1,3,1
Data 1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1
Data 1,3,1,1,1,1,1,1,1,1,1,1,1,1,3,1
Data 1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1
Data 1,3,1,3,1,3,1,1,1,1,3,1,3,1,3,1
Data 1,3,1,3,1,3,3,3,3,3,3,1,3,1,3,1
Data 1,3,1,3,1,1,1,1,1,1,1,1,3,1,3,1
Data 1,3,1,3,3,3,3,3,0,3,3,3,3,1,3,1
Data 1,3,1,1,1,3,1,1,1,1,3,1,1,1,3,1
Data 1,4,3,3,3,3,3,3,3,3,3,3,3,3,4,1
Data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1


function loadmedia
rem Load character into hidden bitmap
LOAD BITMAP "sprites/runner.bmp",1

rem Grab images for character animation
FOR y=0 to 1
FOR x=0 TO 6
GET IMAGE 1+x+(y*7),(x*89),(y*120),(x*89)+89,(y*120)+120
NEXT x
NEXT y

rem Set player variables
xpos=255
ypos=255
image=1

rem Delete character bitmap
DELETE BITMAP 1
sync on
load image "sprites\wall.bmp",1
load image "sprites\gate.bmp",2
load image "sprites\pill.bmp",3
load image "sprites\power.bmp",4
load image "sprites\blank.bmp",5
load image "sprites\pacman.bmp",6
load image "sprites\pacplace.bmp",7
load image "sprites\redghost.bmp",8
load image "sprites\blueghost.bmp",9
load image "sprites\pinkghost.bmp",10
load image "sprites\greenghost.bmp",11
load image "sprites/Background.bmp",12
paste image 12, 60,00

endfunction

function showplayer
rem Run right and wrap
if rightkey() THEN xpos=xpos+6 :IF xpos>640 THEN xpos=-64

Rem Animate runner and wrap
if rightkey() Then image=image+1 : IF image>12 THEN image=2
if leftkey() Then image=image+1 : IF image>12 THEN image=2
if upkey() Then image=image+1 : IF image>12 THEN image=2
if downkey() Then image=image+1 : IF image>12 THEN image=2

rem Update sprite
sprite 1,xpos,ypos,image



if sprite collision(1,0)>0
xpos=oldx
ypos=oldy
endif

rem Update screen
sync

`The following lines below implement the Controls stated on the

rem Record old position
oldx=sprite x(1)
oldy=sprite y(1)


rem Refresh screen now
SYNC

endfunction

function loadmaze

sprite 1,190,75,5

mazewall = 10
mazepill = 200
mazepower = 500

For Y = 0 to 19
For X = 0 to 15


Read maze

Maze#(Y+1,X+1) = Maze

if maze = 1

inc mazewall
endif

if maze = 2
sprite mazewall,190+x*16,75+y*16,2
inc mazewall
endif

if maze = 3

inc mazepill
endif

if maze = 4
sprite mazepower,190+x*16,75+y*16,4
inc mazepower
endif

Next X
Next Y

endfunction

function startlevel


playerx# = 318
playery# = 331
playerup = 0
playerdown = 0
playerleft = 0
playeright = 0

resetghosts()

endfunction

function eatpills

for pillstate = 200 to 343

next pillstate

set cursor 310,400
print score


endfunction

function resetghosts

rem reset ghost directions

for ghost = 1 to 4
ghosts#(ghost,3) = 0
ghosts#(ghost,4) = 0
ghosts#(ghost,5) = 0
ghosts#(ghost,6) = 0
ghosts#(ghost,7) = 0
ghosts#(ghost,8) = 0
ghosts#(ghost,9) = 0
ghosts#(ghost,10) = 0
next ghost

rem red ghost starts at top of pen

ghosts#(1,1) = 286
ghosts#(1,2) = 123
ghosts#(1,11) = 0

rem blue ghost starts in pen
ghosts#(2,1) = 302
ghosts#(2,2) = 171
ghosts#(2,11) = 1

rem pink ghost starts in pen
ghosts#(3,1) = 318
ghosts#(3,2) = 171
ghosts#(3,11) = 1

rem green ghost starts at top of pen
ghosts#(4,1) = 334
ghosts#(4,2) = 123
ghosts#(4,11) = 0

rem give each ghost a starting direction
Ghosts#(1,5) = 1
Ghosts#(2,3) = 1
Ghosts#(3,3) = 1
Ghosts#(4,6) = 1

endfunction

function showghost

for ghost = 1 to 4
ghostsprite = 1000 + ghost
ghostx# = ghosts#(ghost,1)
ghosty# = ghosts#(ghost,2)
ghostimage = ghost + 7

sprite ghostsprite,ghostx#,ghosty#,ghostimage

next ghost

endfunction

function ghostmove

for ghost = 1 to 4

ghostx# = ghosts#(ghost,1)
ghosty# = ghosts#(ghost,2)
ghostup = ghosts#(ghost,3)
ghostdown = ghosts#(ghost,4)
ghostleft = ghosts#(ghost,5)
ghostright = ghosts#(ghost,6)

rem check to see if the ghost is at the edge of the maze

if ghostx# < 190
ghostx# = 428
endif

if ghostx# > 428
ghostx# = 190
endif

if ghostup = 1 then ghosty# = ghosty# - 1
if ghostdown = 1 then ghosty# = ghosty# + 1
if ghostleft = 1 then ghostx# = ghostx# - 1
if ghostright = 1 then ghostx# = ghostx# + 1

ghosts#(ghost,1) = ghostx#
ghosts#(ghost,2) = ghosty#

next ghost

endfunction

function checkghost

for ghost = 1 to 4

ghostx# = ghosts#(ghost,1)
ghosty# = ghosts#(ghost,2)
ghostup = ghosts#(ghost,3)
ghostdown = ghosts#(ghost,4)
ghostleft = ghosts#(ghost,5)
ghostright = ghosts#(ghost,6)

rem check if the ghost is in the centre of a cell
centrex# = (ghostx# - 174) / 16
centrey# = (ghosty# - 59) / 16
centrex = Int(centrex#)
centrey = Int(centrey#)

centre = 0

if centrex# = centrex and centrey# = centrey
centre = 1
endif

rem if ghost is in centre of cell
if centre = 1

rem initialise all possible directions

ghostcangoup = 0
ghostcangodown = 0
ghostcangoleft = 0
ghostcangoright = 0

rem check what is imediately up,down,left and right
mazeup = maze#(centrey - 1, centrex)
mazedown = maze#(centrey + 1, centrex)
mazeleft = maze#(centrey, centrex - 1)
mazeright = maze#(centrey, centrex + 1)

rem store current directions

ghostwasup = ghostup
ghostwasdown = ghostdown
ghostwasleft = ghostleft
ghostwasright = ghostright

rem determine whether it is possible for the player tomake a move
If mazeup = 0 or mazeup >= 3
ghostcangoup = 1
else
ghostup = 0
endif

if mazedown = 0 or mazedown >= 3
ghostcangodown = 1
else
ghostdown = 0
endif

if mazeleft = 0 or mazeleft >= 3
ghostcangoleft = 1
else
ghostleft = 0
endif

if mazeright = 0 or mazeright >= 3
ghostcangoright = 1
else
ghostright = 0
endif

ghosts#(ghost,3) = ghostup
ghosts#(ghost,4) = ghostdown
ghosts#(ghost,5) = ghostleft
ghosts#(ghost,6) = ghostright
ghosts#(ghost,7) = ghostcangoup
ghosts#(ghost,8) = ghostcangodown
ghosts#(ghost,9) = ghostcangoleft
ghosts#(ghost,10) = ghostcangoright

rem if ghost isn't moving

if ghostup + ghostdown + ghostright + ghostleft = 0
turnghost(ghost)
endif

endif

if ghostwasup = 1
if ghostcangoleft = 1 or ghostcangoright = 1
ghostcangodown = 0
ghostup = 0
endif
endif

if ghostwasdown = 1
if ghostcangoleft = 1 or ghostcangoright = 1
ghostcangoup = 0
ghostdown = 0
endif
endif

if ghostwasleft = 1
if ghostcangoup = 1 or ghostcangodown = 1
ghostcangoright = 0
ghostleft = 0
endif
endif

if ghostwasright = 1
if ghostcangoup = 1 or ghostcangodown = 1
ghostcangoleft = 0
ghostright = 0
endif
endif

next ghost

endfunction

function turnghost(ghost)

dim Turn$(4)

Turn = 0
ghostcangoup = ghosts#(ghost,7)
ghostcangodown = ghosts#(ghost,8)
ghostcangoleft = ghosts#(ghost,9)
ghostcangoright = ghosts#(ghost,10)

if ghostup + ghostdown + ghostleft + ghostright = 0

if ghostcangoup = 1
inc turn
Turn$(turn) = "U"
endif

if ghostcangodown = 1
inc turn
Turn$(turn) = "D"
endif

if ghostcangoleft = 1
inc turn
Turn$(turn) = "L"
endif

if ghostcangoright = 1
inc turn
Turn$(turn) = "R"
endif

Direction$ = Turn$(Rnd(Turn) + 1)
if Direction$ = "U" then ghostup = 1
if Direction$ = "D" then ghostdown = 1
if Direction$ = "L" then ghostleft = 1
if Direction$ = "R" then ghostright = 1

endif

rem see where the player is in relation to the ghost
playerxdiff# = playerx# - ghosts#(ghost,1)
playerydiff# = playery - ghosts#(ghost,2)

rem see whether the ghost should be goin horizontally or vertically
if abs(playerxdiff#) > abs(playerydiff#)
xbias = 1
ybias = 0
else
xbias = 0
ybias = 1
endif

if xbias = 1
if playerxdiff# > 0
if ghostcangoleft = 1
ghostleft = 1
endif
else
if ghostcangoright = 1
ghostright = 1
endif
endif
endif

if ybias = 1
if playerydiff# > 0
if ghostcangodown = 1
ghostdown = 1
endif
else
if ghostcangoup = 1
ghostup = 1
endif
endif
endif

ghosts#(ghost,3) = ghostup
ghosts#(ghost,4) = ghostdown
ghosts#(ghost,5) = ghostleft
ghosts#(ghost,6) = ghostright

endfunction


rem pixel perfect collision code taken from the codebase
















XPos1=sprite x(sprite1)-sprite offset x(sprite1)
YPos1=sprite y(sprite1)-sprite offset y(sprite2)

inc Sprite1Base, 4

inc Sprite1Base, 11

XPos2=sprite x(sprite2)-sprite offset x(sprite2)
YPos2=sprite y(sprite2)-sprite offset y(sprite2)

inc Sprite2Base, 4

inc Sprite2Base, 11

if XPos2 > XPos1
XStart1=XPos2-XPos1
XStart2=0
XOverlapSize=(Width1-XStart1)-1
if XOverlapSize >= Width2 then XOverlapSize=Width2-1
else
XStart2=XPos1-XPos2
XStart1=0
XOverlapSize=(Width2-XStart2)-1
if XOverlapSize >= Width1 then XOverlapSize=Width1-1
endif

if YPos2 > YPos1
YStart1=YPos2-YPos1
YStart2=0
YOverlapSize=(Height1-YStart1)-1
if YOverlapSize >= Height2 then YOverlapSize=Height2-1
else
YStart2=YPos1-YPos2
YStart1=0
YOverlapSize=(Height2-YStart2)-1
if YOverlapSize >= Height1 then YOperlapSize=Height1-1
endif

XStart1=XStart1*4
XStart2=XStart2*4
Width1=Width1*4
Width2=Width2*4
for YOffset=YOverlapSize to 0 step -1
Sprite1Addr=Sprite1Base + ((YOffset+YStart1)*Width1) + XStart1
Sprite2Addr=Sprite2Base + ((YOffset+YStart2)*Width2) + XStart2
for XOffset=XOverlapSize to 0 step -1






exitfunction 1


inc Sprite1Addr, 4
inc Sprite2Addr, 4
next XOffset
next YOffset

Chima-Duru
Brock
20
Years of Service
User Offline
Joined: 10th Oct 2004
Location: USA,MI,Detroit,
Posted: 30th Oct 2004 10:13
can some one tell me why it dont work

Chima-Duru
Brock
20
Years of Service
User Offline
Joined: 10th Oct 2004
Location: USA,MI,Detroit,
Posted: 30th Oct 2004 10:16
what is wrong why dont i see the player and why dont the enemy follow the player and bounce back and fourth
and i need a code for the animation collision cus mine dont work it dont work

Chima-Duru

Login to post a reply

Server time is: 2024-11-27 15:54:27
Your offset time is: 2024-11-27 15:54:27