April 17, 2024, 07:50:17 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Sprite collision with ground

Started by barry, September 20, 2010, 07:40:39 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

barry

I'm thinking of doing something like a lunar lander game to learn to use the 2D directx stuff in IWBasic and I don't see any built-in way to detect a colision with the ground.  A few possibilities occur to me.  One is to make the ground a sprite but I don't know enough about directx to know if that's realistic.  Another is using ReadPixel but that might make things pretty slow since a number of reads will have to be made.  Or maybe not.  I don't know what to expect.

This will be very simple, done using the dx_windowed example as a base and modifying it. It's just a learning exercise.  Does anyone have any thoughts on the best way to detect ground collisions?

Thanks,
Barry

ZeroDog

Using a sprite for the ground is quite easy to do, and there is built in commands for collision detection with sprites, SpriteCollided and SpriteCollidedEx.  Check the 2D Programming guide in the users guide for the topic Collision Detecting, which shows how to use the functions.   If you get stuck, just let us know, and someone will be more than happy to help you out.  :)

barry

I did read that section in the help and I probably can find a way to use a sprite for ground.  I wasn't sure if it was practical or even possible to have that large a sprite.  However, the ground will be randomly generated.  I think I can find ways to do that with a sprite with scaling and showing portions of it if that's possible, but it seems less flexible.

Anyway I'll give that a try and see how it works out.  Thanks.

Barry

pistol350

Hello Barry!
I assume you're aming at something like that.
This code in "lunar lander" from Boris, coded for the 1K code contest a few years ago.
honestly, i do not advise you to try and study this code i guess you can easily guess why...
Just compile it and see the results.

createscreen 800,600,16:setcursor frontbuffer,2:h=0x999999:d="CAABBCDEEBAFFBABABCEEBBDDCD":pointer b:b=backbuffer:setlinestyle #b,0,5:t=millisecs():m=0f:a=0:x=400:k=-8f:y=20f:l=0f:q=0:r=22:f=x:v=180:z=45:do:if(millisecs()-t)*(q=0)>r:t=millisecs():fillscreen 0:a+=4*(keydown(44))-4*(keydown(z)):line#b,m,d[0]*8,m,(d[0]-59)*50,0:for n=1 to 9:lineto#b,n*100+m,(d[n]-59)*50,h-99*(d[n]+d[n-1]>139):next n:q=readpixel(s(z,r),c(z,r))+readpixel(s(-z,r),c(-z,r)):line#b,s(v,r),c(v,r),s(z,r),c(z,r),h:lineto#b,s(0,5),c(0,5),h:lineto#b,s(-z,r),c(-z,r),h:lineto#b,s(v,r),c(v,r),h:if keydown(53)*(f>0):line#b,s(0,r),c(0,r),s(0,30),c(0,30),h
k+=sind(a)/r:l-=cosd(a)/r:f=f-1:endif:m+=k:y+=l:l+=.01:if q>0 then g=" Crash":if m<-99:m+=99:d=mid$(d,2)+d[0]:else:if m>-1:m-=99:d=d[26]+left$(d,26):endif:endif:if (abs(k)<.2)*(l<.4)*(q=20000864) then g=" Landed":writetext 10,10,str$(f)+g:flip:endif:until asc(getkey)=27:closescreen:end
sub s(g:int,m:int),int
return x+sind(a+g)*m:endsub
sub c(g:int,m:int),int
return y+cosd(a+g)*m:endsub
Regards,

Peter B.