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 / sprite collision, need a quick answer!

Author
Message
DJm
16
Years of Service
User Offline
Joined: 14th Feb 2010
Location: Portugal
Posted: 22nd Mar 2010 11:24
I have never used sprite collision before.

I am trying to shoot an alien, but my rocket seems to stick to the alien.

I've tried moving the rocket away upon impact. I've tried moving the alien away but the point of impact seems to stay where it is and when I shoot the rocket at the same place a collision is detected even though the alien isn't at that position anymore.

I'm using two sprites.

repeat

if rocket=0 then sprite 500,x#,386,149
if rocket=2 then sprite 501,x#,386,150

if rightkey()=1 and x#<200 then inc x#,0.1
if leftkey()=1 and x#>27 then dec x#,0.1
if spacekey()=1 and rocket=0 then rocket=1

if rocket=1 or rocket=2 then gosub rock:

if aexist=1 then gosub movealiens

if SPRITE COLLISION(502,503)=1 then gosub splat

sync

until lives=0

return

movealiens:
inc count
if count=400 then count=0

if aexist=1 and count<201 then sprite 503,ax#,ay#,153
if aexist=1 and count>200 then sprite 503,ax#,ay#,152

if dire=1 then inc ax#,0.1
if dire=1 and int(ax#)=200 then dire=2 : oldy#=ay#
if dire=2 and ay#<oldy#+20 then inc ay#,0.1
if dire=2 and int(ay#)>oldy#+19 then dire=3
if dire=3 then dec ax#,0.1
if dire=3 and int(ax#)<27 then dire=4 : oldy#=ay#
if dire=4 and ay#<oldy#+20 then inc ay#,0.1
if dire=4 and int(ay#)>oldy#+19 then dire=1

return

rock:

if rocket=1 then rx#=x#+12 : ry#=373 : inc rocket : show sprite 502 : hide sprite 500 : show sprite 501
if rocket=2 then sprite 502,rx#,ry#,151
if rocket=2 and ry#>220 then dec ry#,0.2
if rocket=2 and ry#<221 then hide sprite 502 : rocket=0 : hide sprite 501 : show sprite 500

return

splat:

No good deed goes unpunished!
luskos
19
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 22nd Mar 2010 12:37
First of all edit your post before the moderator.Use CODE function!Select your code and click at code button at the Post Forum Message window.

Where there is a will, there is a way.
I often edit my posts, that`s who i am
DJm
16
Years of Service
User Offline
Joined: 14th Feb 2010
Location: Portugal
Posted: 22nd Mar 2010 12:41
I did!

No good deed goes unpunished!

Login to post a reply

Server time is: 2026-07-26 23:40:42
Your offset time is: 2026-07-26 23:40:42