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 / 2d Map help please

Author
Message
KTCO_Tonesy
13
Years of Service
User Offline
Joined: 6th Mar 2011
Location: dark_basic
Posted: 6th Mar 2011 14:57 Edited at: 6th Mar 2011 18:42
Hey guys, making a 2d platformer game for my coll project and ive hit a snag!
I can make my sprite move and a backdrop appear (this took some time!)
Now my problem is that i cant make him collide with the ledge hes on, otherwise you can just go straight through the ledges to the objective!

Heres what I got so far!


level1_main:

load image ".\Media\man1.png",4
load image ".\Media\map1.png",5
load image ".\Media\damsel.png",6


DO

draw to back : paste image 5,0,0,1
draw to front : sprite 2,5,64,4 : sprite 3,870,527,6
center text 500,500,"you have 30 secs to save the civilian! GO,GO,GO"
IF spacekey()=1
set text transparent
text 500,500," "
gosub time
ENDIF

LOOP
return


time:

time#=30.00
x#= 5
y# = 64


DO

set text to normal
draw to front : sprite 2,5,64,4 : sprite 3,870,527,6
draw to back : paste image 5,0,0,1
if x# <1 then x# = 0
if x# >810 then x# = 810
if y# < 1 then y# = 0
if y# > 624 then y# = 624
if upkey()=1 then y#=y#-2
if downkey()=1 theny#=y#+1
if rightkey()=1 then x#=x#+1
if leftkey()=1 then x#=x#-1
sprite 2,x#,y#,4
if sprite hit (2,3) = 1 then gosub hooray
print time#
dec time#,0.01
IF time# <= 10.00
Center text 500,500 , "HURRY ONLY 10 secs to GO!!"
IF time# <= 0.0 THEN GOSUB restart_game:
ENDIF
LOOP
RETURN


`levels :




hooray:

DO
cls rgb (100,205,100)
`hide sprite 2 : hide sprite 3
text 500,500, "YOU SAVED THE CIVILIAN,CONGRATULATIONS!! Hit space to continue"
if spacekey() = 1 then gosub level1_main
LOOP
RETURN

restart_game:

DO

Center Text 500,500 , "YOU FAILED THE CIVILIAN! HIT SPACE TO RETRY!"
if spacekey() = 1
wait 30
GOSUB level1_main
ENDIF
LOOP
RETURN
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 7th Mar 2011 05:39 Edited at: 7th Mar 2011 05:42
The text and the damsel sprites were not placed within the screen boundaries. The game logic was a little hard for me to follow, so I took the liberty of reorganizing the code. Take a look at this to see if it makes sense to you:


As to the collision with the ledge issue, I didn't see where you were checking for a ledge in your code. There are at least a few ways you could do it. Some ideas:
1. You could create a series of tiles, say 32 X 32 pixels, to make a map. You could easily calculate where the player is in relationship to the tiles. You could either hard-code the tile image numbers yourself (in the code itself) or you could create an editor to place them on-screen and save the array to a file.
2. You could use sprites to place the ledge graphics on the screen and check against them.
3. You could use memblocks to check what is below the player's feet or in front of the player. Memblocks are an advanced programming topic and I would suggest you consider them when you are further along.
4. You could map out the collision areas within the map manually and check to see if the player's movement would place them within one of these boundaries.

I would recommend choice #1. If you do a forum search for 2D tile, you should be able to find something to help you with creating a tile map.

Hope this helps,

LB

KTCO_Tonesy
13
Years of Service
User Offline
Joined: 6th Mar 2011
Location: dark_basic
Posted: 10th Mar 2011 15:37
Appreciate the tidying up job you did for me there thanks!!

I'm not being lazy when i say this, but this is just not goin well for me... Looking through the tuts on 2d tile maps on this forum has made me mor confused!
I know i make data statements n then dim the array etc... but when i try this it erased my backdrop to the original blue and more often than not it doesnt work altogether!
Im not asking for code snippets here folks just wondering if anyone has advice on where i should go next with this!
This is what ive been attempting... creating a load o sprites and colliding off of them, but to no avail!
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 10th Mar 2011 17:25
You're welcome.

Using sprites, I would suggest the following:
1. Create the sprite graphics for the map(it would be more efficient to store the images on one sprite sheet and pull the individual images off of it in the code, but you could load individual images if you want).
2. Create an array to hold where the sprites are to be placed for a particular map and write a function / subroutine to place the sprite graphics on the screen.
3. In your MovePlayer subroutine, store the player's x/y coordinates first thing. Then check to see if the player sprite has collided with one of the map sprites. If so, put the sprite back at the old Y coordinate (allow the x coordinate to change if your graphics are all flat).
4. You should check to see if the player's Y coordinate is below a certain point on the screen (say 550, for example). If the player reaches this point, they die.
5. Suggest you check for collision with sprite collision(4,0) instead of sprite hit. Using 0 returns the sprite # that you collided with.

Login to post a reply

Server time is: 2024-11-24 06:19:49
Your offset time is: 2024-11-24 06:19:49