Main Menu

yet another collision question

Started by skull, January 26, 2006, 06:37:40 PM

Previous topic - Next topic

skull

hi, i am not sure if i am still in the dark here but........


this is how my project kind of runs :

<start>
.....
load in images
convert images to sprites
read map data
convert data in to sprites for screen
<do>
set up and display player on screen
display the playing field
check for key press - move up, down, left, right

check to see if player man is trying to walk through a wall < argggghhhhhh !!!!

<end do>
end

=================

so in simple terms ( i bet answer wont be quite so), how do i make a sprite
act like a wall and prevent another sprite from passing through it while letting
is pass over those surrounding it.

===================
(map is 8*8) <this is just a test map>
wall images run from 1 to 16      
floor image is 17
man image is 65

sprites 1 to 64 = map tiles
sprite 65 = player


===================

is there no way i can just ask this in code like :--

see if mansprite hits spriteimage number range 1 to 16

or

for x=1 to 16
if man hits sprite(x) and sprite(x) image is < 16 then "OUCH"
next                 < looks like it should work, but alas no>

have looked at :-
spritesoverlap, spritehit, and the stuff about collision modes

but i am lost, i could be going about this all wrong, but lets just hope that you can help and do so in a way that a novice like me can understand.
http://www.dragonglow.co.uk/
PUNIKS aka Piglet aka Skull
i'm mad, i'm bad and i'm here to play!!!

Ian Price

There are several ways to implement the type of collision detection you are after -

1. Create a map using arrays, then get the player position and use the array data to tell you where the walls are.

2. Using PBs map commands - see the scrolling map game example

3. Create your map, then use the data to create a solid walls only "hardness" map on a newly created image, then use -

Pseudocode

RenderToImage hard

rightpixel=Point(x+8,y)
leftpixel=Point(x-8,y)

RenderToScreen

If rightpixel>0 Then prevent moving right

If leftpixel>0 Then prevent moving left


What this does is test for individual points of colour on a map and if it detects a colour (that's not black (00,00,00) then it prevents further movement in that direction.
I came. I saw. I played some Nintendo.

skull

hi ian, thanks for the reply


for the mo, i have solved the problem

i have 3 arrays for each playscreen

array 1 = fakemap (this is a map in memory much like the hardness maps in div)
array 2 = display graphics on screen
array 3 = display pickups


array 2 and 3 are displayed.

so i reference the fakemap for a valid move

this works fine at the mo.

thanks
http://www.dragonglow.co.uk/
PUNIKS aka Piglet aka Skull
i'm mad, i'm bad and i'm here to play!!!

Ian Price

I've just noticed your sig - another ex-Div user! Yay!

I'm still waiting for you to complete Palacurious :P

Glad you got it working :)
I came. I saw. I played some Nintendo.

skull

#4
Palacurious, yes i should re-code it and finish it, maybe after this project is done i will reserect it.

as least i am no longer reduced to a 256 colour pallet.

was looking at you Jetpak re-make, looking good as always ian

ian have you looked at    http://www.booleansoup.com
http://www.dragonglow.co.uk/
PUNIKS aka Piglet aka Skull
i'm mad, i'm bad and i'm here to play!!!

Ian Price

I have, and unfortunately it appears to be the playground that Div-Arena turned into, one of the reasons I rarely visited/posted towards the end :(

Don't get me wrong, I like the people, but half the time, they were just talking crap and mucking around (no surprise really, as Div had already died, but nobody had told it).

Still, I was aware of it's imminent death and moved on to other languages - Blitz3D especially and more recently PlayBASIC.

Anyway, good to hear from you again :)
I came. I saw. I played some Nintendo.