Quote: "I'm trying to figure out how to do collision detection in a 2D game I'm working on. "
Cool, I was looking for a challenge this morning. I've never done a Sierra On-line type game before but loved playing Space Quest. Your best bet is to use the POINT command using another graphic with set zones you want the character to be in. I have to go right now but I'll be back to throw together a code example for you.
Edit: Ok, I'm back and here's a code example:
` Make sure the screen size is 640x480
set display mode 640,480,32
` Set the sync rate to maximum speed
sync rate 0
` Turn on syncing
sync on
` Change backdrop color to black
color backdrop 0
` Load the viewing image
load image "starport.bmp",1,1
` Load the player area image
load image "starport2.png",2,1
` Make the player
ink rgb(255,255,255),0
box 0,0,13,22
get image 100,0,0,13,22,1
` Create the player area bitmap
create bitmap 1,640,480
` Paste the player area image
paste image 2,2,0,1
` Change to the main view screen
set current bitmap 0
` Set the starting players x and y coordinates
PlayerX=157
PlayerY=200
` Set a starting timer (to slow down player movement)
tim=timer()
do
` Show the background
paste image 1,2,0
` Show the player area image (unrem for testing)
`paste image 2,2,0,1
` Show the player
sprite 1,PlayerX,PlayerY,100
` Check the timer to make sure the player can move
if timer()>tim+10
` Up Arrow (Make sure player stays within the target area... not color zero)
if keystate(200) and CheckArea(PlayerX,PlayerY-1)>0
dec PlayerY
endif
` Down Arrow
if keystate(208) and CheckArea(PlayerX,PlayerY+1)>0
inc PlayerY
endif
` Left Arrow
if keystate(203) and CheckArea(PlayerX-1,PlayerY)>0
dec PlayerX
endif
` Right Arrow
if keystate(205) and CheckArea(PlayerX+1,PlayerY)>0
inc PlayerX
endif
` Reset timer
tim=timer()
endif
` Check the area color for events
Color=CheckArea(PlayerX,PlayerY)
` Check if the color is more than zero
if Color>0
` Select event based on color found under players feet
select Color
` Upper Left Door
case 11010048
text 0,420,"Event: Open Upper Left Door"
endcase
` Upper Middle Door
case 12818435
text 0,420,"Event: Open Upper Middle Door"
endcase
` Upper Right Door
case 2817748
text 0,420,"Event: Open Upper Right Door"
endcase
` Lower Left Door
case 16646395
text 0,420,"Event: Open Lower Left Door"
endcase
` Lower Middle Door
case 12797699
text 0,420,"Event: Open Lower Middle Door"
endcase
` Lower Right Door
case 6914553
text 0,420,"Event: Open Lower Right Door"
endcase
` Unseen Trap
case 1114836
text 0,420,"Event: Unseen trap triggered"
endcase
endselect
endif
` Update the screen
sync
loop
end
function CheckArea(x,y)
` Switch to player area bitmap
set current bitmap 1
` Check the color at the players feet
a=point(x+7,y+20)
` Switch back to main view screen
set current bitmap 0
` Show the current color
if a>0 then text 0,400,"Color = "+str$(a)
` End the function returning the color found
endfunction a
Since I've never done anything like that before it's a bit primitive but it works fine. What the code snip basically does is it loads your image and a new image that's attached and uses the new image as a color key to where the player is allowed to move and events that can be triggered. The player is only allowed to move in colored areas and not allowed to go anywhere that's black.
To make the new image I took the original image and filled in with a solid color the area that the player would be allowed to move in and filled in certain spots with different colors to trigger events in the code. I then removed all non-essential graphics.
When you use the arrow keys move the white box towards one of the doors and you'll see when you touch the area in front of the door it'll trigger the event of opening the door (just text right now shown at the bottom of the screen). The event is triggered by the specific areas color using the POINT command to retrieve the color. Move the player to the left side of middle barrier and it'll trigger an event that's not obvious because you don't see any telltale signs that moving to that spot will do anything. Doing each area like this will give you the ability to trigger any kind of event seen or otherwise.
I recommend changing that .bmp to a .png instead so it's easier to work with and will allow you to show transparencies (allowing your player to be seen behind windows and such).