News:

Function Finder  Find all the functions within source code files

Main Menu

PlayBasic V1.64M (Work In Progress) Gallery

Started by kevin, May 25, 2010, 01:37:57 AM

Previous topic - Next topic

kevin

#30
   PlayBASIC V1.64M  Beta #21 - Ray Hit Map Pixels (again)

    Back working on the V1.64M upgrade again, this afternoons focus has been on mapping, most notably implementing support for the ray to map functions to support both Video and FX maps.   Was trying for a generic solution originally, but things don't always work the way i'd like, namely it's not really fast enough for the type of abuse such a function is bound to receive.    So after a bit of tinkering and another reshuffle of the algorithm,  I think i've hit upon a solution I can live with in terms of code length and it's performance should be pretty good once implemented.  Currently i'm just testing the theory in PB first.  The main change is that routine now has modes for scanning the various internal map zones, which should be a faster in the real world.



kevin

#31
 PlayBASIC V1.64M  Beta #21 - Ray Hit Map Pixels (continued)

   Yesterday I was testing out another ray to map pixels method, today that theory has been implemented into PB.  The change is about twice as fast as the fastest version of older implementation.  Given the circumstances of the demo (It's virtually an array of unique and entirely transparent blocks)  that's about limit of where we can go with this, given it's a brute force test after all.   Normally we've use Ray intersection for this stuff. Which by the way, is why we have worlds :)

    In the demo the map is made up (in code) of 4096 unique 100*100 (32bit) blocks.   In the whole level there's only 1 tile that's known to be fully transparent.  In a real map though there's going to be load of them. The updated scanner is opt'd with this situation in mind.   It's doesn't support animated maps though.  

PlayBASIC Code: [Select]
 screen=newfximage(6400,6400)
rendertoimage screen
cls $ff0000
circlec 400,400,400,true,$ffffff
circlec 1300,400,400,true,$0fffaf


BlockWidth=100
BlockHeight=100

Map=Newmap(50)
createmapgfx Map,BlockWidth,BlockHeight,4096,$00ff0000,2 ; CREATE 4096 FX BLOCKS

Level=NewLevel(Map,GetSurfaceWidth()/BlockWidth,GetSurfaceHeight()/BlockHeight)
leveltransparent Map,Level,200

For ylp=0 to GetLevelHeight(map,level)-1
Ypos=ylp*BlockHeight
if Ypos+BlockHeight<=GetSurfaceHeight()
For xlp=0 to GetLevelWidth(map,level)-1
Xpos=xlp*BlockWidth
ink $ffff00ff
text Xpos,ypos,Tile
ink $ffffffff
GetMapBlk Map,Tile,Xpos,ypos
PokeLevelTile Map,Level,xlp,ylp,tile
#print GetMapBlockTransparent(Map,Tile)
tile++
if Tile=>GetMapBlocks(Map) then exitfor ylp
next
endif
next

;GetMapBlockTransparent

rendertoscreen

cam=newcamera()
cameracls cam,off

c1=rndrgb()
c2=rndrgb()

Do

shadebox 0,0,getsurfacewidth(),GetsurfaceHeight(),c1,c1,c2,c2

MouseWorldXpos=MouseX()-1+GetCameraX(Cam)
MouseWorldYpos=MouseY()-1+GetCameraY(Cam)

capturetoscene
clsscene

capturedepth 100

; draw the map level
drawmap map,Level,0,0

; DRaw the the Mouse pointer within the world space
capturedepth 10
; dotc MouseWorldXpos,MouseWorldYpos,RndRGB()


RayStart=Timer()
CheckRays(Map,Level,MouseWorldXpos,MouseWorldYpos,300,128)
; CheckRays(Map,Level,MouseWorldXpos,MouseWorldYpos,300,64)
RayTime=Timer()-RayStart

; draw whatever the camera can see
drawcamera cam

setcursor 0,0

ink $ff0000ff

print "Ray Timer:"+STR$(RAYTIME)


speed=2
if leftkey() then movecamera cam,-Speed,0
if rightkey() then movecamera cam,Speed,0
if upkey() then movecamera cam,0,-Speed
if downkey() then movecamera cam,0,Speed

Sync
loop




Function CheckRays(Map,Level,Xpos,Ypos,RAdius,Rays)
AngleStep#=360.0/Rays

For lp=0 to rays-1
angle#=lp*AngleStep#
x2#=cosnewvalue(xpos,Angle#,radius)
y2#=sinnewvalue(ypos,Angle#,radius)
Collision=RayHitMapPixels(Map,Level,xpos,ypos,x2#,y2#)
if Collision
hitx#=getINtersectx#(0)
hity#=getINtersecty#(0)
line xpos,ypos,hitx#,hity#
circlec hitx#,hity#,5,true,$00ff0000
else
line xpos,ypos,x2#,y2#
endif
next


EndFunction







kevin

#32
 PlayBASIC V1.64M  Beta #22 - Ray Hit Map Pixels Video Maps

  Finally got this working on maps with graphic blocks in Video memory.   On the surface it's one of those simple little additions that's easily glossed over, then you run into the reality of doing it.    The goal with the updated implementation has been to avoid fetching video memory, which you should know (by now) is slow, so the routine tries to avoid this as much of possible.  But you know at the end of the day it has to do this.  So running lots of ray intersections on  video blocks is going to eat up lots of time, but you should be able to get away doing a little bit of it.  

  Another change that's come as a by product of recent mapping additions, is that map engine now keeps better track of each graphic blocks tranparency status.  Previously you could query if  block was Solid (0) or Transparent (1) (GetMapBlockTransparent), but now another state has been added,  this state lets us know that this graphic block is completely transparent (-1).  This new state allows the ray scanner and map drawing routines some more early rejection options.
   

kevin

 PlayBASIC V1.64M  Beta #23 - Auto Block Reductions

   Today i've working away on the mapping.  So far I've shrunk much of the map drawing routines down into a much simpler set of routines.  This seems to have given us a bit of a free speed up, although that's most likely from the block transparency additions a few days ago.   Another addition that's been made to the library, is the import routines now attempt to reduce the drawing surface of each block as much as possible.   To demostrate this, i'm using the previous demo code (posted a above), but this time it's drawing  a grid over the level   and drawing blocks that are meant to be transparent using the solid filler just to show the area that's actually being drawn.   If you look closely you'll see the reductions.     


kevin

#34
 PlayBASIC V1.64M  Beta #24 - Testing Holly

   The screen shot bellow is from Steve's platform game Holly,  I'm using this as real world test of the map block reduction routines, which seem to be working fairly well.    If you look at the shot, the Green Grid is the Maps Debug mode, the overlaid red bounding boxes show the smallest possible rect that this block covers.  Performance wise it's hard to tell really (as i've no bench mark for Holly), but  we've certainly saving a few % off the top of the rendering time.    Every little bit helps !

   


kevin

#35
 PlayBasic V1.64 Beta #24 Released

  The latest beta is available for download the registered users.  

  Download PlayBasic V1.64 Beta #24 (login required)

kevin

#36
  PlayBASIC V1.64M  Beta #25 - Rect Hit Map (Collision)

    Now that the Ray & Pixel Methods are implemented, focus has turned to the adding some more methods, starting with RectHitMap function.  This function does exactly what the name suggests, it detects if a rectangle (none rotated) hits on a solid region of the map.  This is not Pixel level impact it's a region impact.  The pixel version will follow.  Had a few drama's getting this work, which turned out to be some misaligned reads from the level..
 
   In the shot  bellow we see the running example (code bellow) which creates a map out of some circles and then runs collision upon them.  The collision not at pixel level  but region level, so the impacts occur when the rectangle overlaps a solid tile or a transparent tiles smallest rect.  


PlayBASIC Code: [Select]
  BackdropColour=$ff0000

screen=newfximage(6400,6400)
rendertoimage screen
cls BackdropColour
circlec 400,400,400,true,$ffffff
circlec 1300,400,400,true,$0fffaf

for lp=0 to 150
ellipsec rnd(2400),rnd(800),rndrange(50,150),rndrange(10,50),true, BackdropColour
next

BlockWidth =100
BlockHeight=100

Map=Newmap(50)
createmapgfx Map,BlockWidth,BlockHeight,4096,$00ff0000,2; CREATE 4096 FX BLOCKS

Level=NewLevel(Map,GetSurfaceWidth()/BlockWidth,GetSurfaceHeight()/BlockHeight)
leveltransparent Map,Level,0

For ylp=0 to GetLevelHeight(map,level)-1
Ypos=ylp*BlockHeight
if Ypos+BlockHeight<=GetSurfaceHeight()
For xlp=0 to GetLevelWidth(map,level)-1
Xpos=xlp*BlockWidth
ink $ffff00ff
; text Xpos,ypos,Tile
ink $ffffffff
GetMapBlk Map,Tile,Xpos,ypos
; text Xpos,ypos,GetMapBlockTransparent(Map,Tile)
; GetMapBlk Map,Tile,Xpos,ypos
#print GetMapBlockTransparent(Map,Tile)

PokeLevelTile Map,Level,xlp,ylp,tile
tile++
if Tile=>GetMapBlocks(Map) then exitfor ylp
next
endif
next

;GetMapBlockTransparent

rendertoscreen

cam=newcamera()
cameracls cam,off

c1=rndrgb()
c2=rndrgb()


Screen=NEwIMage(800,600)
rendertoimage screen
shadebox 0,0,getsurfacewidth(),GetsurfaceHeight(),c1,c1,c2,c2
rendertoscreen

Do

drawimage screen,0,0,false

MouseWorldXpos=MouseX()-1+GetCameraX(Cam)
MouseWorldYpos=MouseY()-1+GetCameraY(Cam)

capturetoscene
clsscene

capturedepth 100

; draw the map level

drawmap map,Level,0,0
; DRaw the the Mouse pointer within the world space
capturedepth 10

RayStart=Timer()
; CheckRays(Map,Level,MouseWorldXpos,MouseWorldYpos,300,128)
;
; MouseWorldXpos,MouseWorldYpos,300,128
x2=MouseWorldXpos+20
y2=MouseWorldYpos+20

Collision=RectHitMap(Map,Level,MouseWorldXpos,MouseWorldYpos,x2,y2)

if Collision
Colour=$ff0000
Print "Rect Hit"
else
Colour=$0000ff
Print "Rect Missed"
endif
boxc MouseWorldXpos,MouseWorldYpos,x2,y2,true,colour

RayTime=Timer()-RayStart

; draw whatever the camera can see
drawcamera cam

setcursor 0,0

ink $ff0000ff

print "Ray Timer:"+STR$(RAYTIME)

speed=2
if leftkey() then movecamera cam,-Speed,0
if rightkey() then movecamera cam,Speed,0
if upkey() then movecamera cam,0,-Speed
if downkey() then movecamera cam,0,Speed



if EnterKey()
MapDebug Map,1-GetMapDebug(Map)
flushkeys
endif

Sync
loop





PlayBASIC V1.64M  Beta #25 - Rect Hit Map Pixels (Collision)

   The second shot is showing the RectHitMapPixels version of the function.  

PlayBASIC Code: [Select]
  BackdropColour=$ff0000

screen=newfximage(6400,6400)
rendertoimage screen
cls BackdropColour
circlec 400,400,400,true,$ffffff
circlec 1300,400,400,true,$0fffaf

for lp=0 to 150
ellipsec rnd(2400),rnd(800),rndrange(50,150),rndrange(10,50),true, BackdropColour
next

BlockWidth =100
BlockHeight=100

Map=Newmap(50)
createmapgfx Map,BlockWidth,BlockHeight,4096,$00ff0000,2; CREATE 4096 FX BLOCKS

Level=NewLevel(Map,GetSurfaceWidth()/BlockWidth,GetSurfaceHeight()/BlockHeight)
leveltransparent Map,Level,0

For ylp=0 to GetLevelHeight(map,level)-1
Ypos=ylp*BlockHeight
if Ypos+BlockHeight<=GetSurfaceHeight()
For xlp=0 to GetLevelWidth(map,level)-1
Xpos=xlp*BlockWidth
ink $ffff00ff
; text Xpos,ypos,Tile
ink $ffffffff
GetMapBlk Map,Tile,Xpos,ypos
; text Xpos,ypos,GetMapBlockTransparent(Map,Tile)
; GetMapBlk Map,Tile,Xpos,ypos
#print GetMapBlockTransparent(Map,Tile)

PokeLevelTile Map,Level,xlp,ylp,tile
tile++
if Tile=>GetMapBlocks(Map) then exitfor ylp
next
endif
next

;GetMapBlockTransparent

rendertoscreen

cam=newcamera()
cameracls cam,off

c1=rndrgb()
c2=rndrgb()


Screen=NEwIMage(800,600)
rendertoimage screen
shadebox 0,0,getsurfacewidth(),GetsurfaceHeight(),c1,c1,c2,c2
rendertoscreen

Do

drawimage screen,0,0,false

MouseWorldXpos=MouseX()-1+GetCameraX(Cam)
MouseWorldYpos=MouseY()-1+GetCameraY(Cam)

capturetoscene
clsscene

capturedepth 100

; draw the map level

drawmap map,Level,0,0
; DRaw the the Mouse pointer within the world space
capturedepth 10

RayStart=Timer()
; CheckRays(Map,Level,MouseWorldXpos,MouseWorldYpos,300,128)
;
MouseWorldXpos-=30

; MouseWorldXpos,MouseWorldYpos,300,128
x2=MouseWorldXpos+20
y2=MouseWorldYpos+20

Collision=RectHitMapPixels(Map,Level,MouseWorldXpos,MouseWorldYpos,x2,y2)


; capturedepth 200
if Collision
Colour=$ff0000
Print "Rect Hit"
else
Colour=$ffff00
Print "Rect Missed"
endif
boxc MouseWorldXpos,MouseWorldYpos,x2,y2,Collision,colour

RayTime=Timer()-RayStart

; draw whatever the camera can see
drawcamera cam

setcursor 0,0

ink $ff0000ff

print "Ray Timer:"+STR$(RAYTIME)

speed=2
if leftkey() then movecamera cam,-Speed,0
if rightkey() then movecamera cam,Speed,0
if upkey() then movecamera cam,0,-Speed
if downkey() then movecamera cam,0,Speed

if EnterKey()
MapDebug Map,1-GetMapDebug(Map)
flushkeys
endif

Sync
loop






kevin

#37
  PlayBASIC V1.64M  Beta #25 - Circle /Ellipse Hit Map (Testing)

  Just testing some new improved methods for detecting if a circle hits a map.  The first pic shows the map grid, the circle and the zones within the circle and type of collision the zones need.   The second picture is the ellipse version, this time it's showing the zones it passes through.  Inner zones are solid and outer zones are possible transparent zones.
 



kevin

#38
  PlayBASIC V1.64M  Beta #25 - Polygon (Quad) Hit Map (Testing)

   Today i've working towards a set of generic polygon to map collision functions. Ideally these functions will detect impacts between a map an a polygon of 3, 4 or user defined sides.  Atm the i'm testing a 4 sided polygon.  The routines (as per the rect and circle and ellipse routines) break down the shape into a grid so the area can be checked against the map.  This allows for early rejection when performing tests against the map and a few other tidbits.. :)

 
   Update: The third shot is showing a 5 sided polygon.  While the routine is running there's still a few teething problems to iron out with method though. 

kevin


  PlayBASIC V1.64M  Beta #25 - Polygon (Quad) Hit Map (Continued)

     The polygon to map routines are proving to be a bit of a sticking point.  Those will long memories might remember that FX prototypes have some of this functionality built into them.  This thing is, while writing those implementations (which are bit heavy in terms of work load) I'd always wanted to try adding a prescreening ability to reduce the work load where possible.  Which is the main idea behind the current tests.  That being the routine works out what blocks the polygon is going to impact with, then we can do a quick trivial reject/inclusion at this point, rather than needing to jump straight into the pixel to pixel level impacts.

     It's in this speed up thats causing the issues,  the first past has to be fast and accurate.  Which is something of an oxymoron, normally when you optimize for speed,  accuracy is compromised.   In this case when it's not 100% accurate it can return false positives or miss obvious (to the naked eye) intersections.   Which just means that i've been tinkering with a number of different methods of doing the initial classification pass, but without much luck at this point.   The most accurate method so far is also super slow, defeating the purpose of the pass completely. 

     Ideally,  If i can resolve the accuracy issues, such a routine would be handy for scene occlusion purposes.   



kevin


  PlayBASIC V1.64M  Beta #25 - Polygon (Quad) Hit Map (Continued)
   
    It's been a busy week (life wise), but even so i've been tinkering with these intersection routines.  Settling on a  hybrid solution that's fairly fast while retaining the accuracy.   The current tech demos are all written in PB (as always) when testing the theory, the next challenge  will be to be build an implementation of them into PB.   So things should progress a little faster now in this regard.  Frankly i'm sick of looking at it.   

   Anyway, here's a look see at the updated method.  In it you can see the quad and the blocks regions masked over the top. The different colours represent the different types of zones.
     

kevin

#41
  PlayBASIC V1.64M  Beta #25b - Ellipse & Rect/Polygon Hit Grid

   Yep, it's come full circle and we're back to looking at ellipses with some grid masked over the top.    The only difference is, this one's built into PB and no longer a running theory.   Speed wise it's OK, the routine is certainly quick enough to be more than useful, but it's a little slower than I'd like.  But i'd much rather get it working, than tinker with the method anymore.  


   Edit: Testing the grid conversion with polygon mapper, seems to be works fine.

kevin

#42
  PlayBASIC V1.64M  Beta #26 - Ellipse/Circle to Map

   Been working my way through the actual implementation of the Ellipse/Circle Hit Map function.  The pre-scanning part of the method is in and working well.   So when the interior solid part of the circle/ellipse covers the map, we can get an impacts.    The beauty of this we don't actually need to read the maps pixel data.

  All that's left for this version of the function is to add checks for those regions that circle/ellipse partly covers (those on the boundary).  For this we need another collision method to quickly detect when Ellipse/Circle & Rect regions overlap.

    Bellow i've been tinkering (in PlayBasic) with a few ways to detecting intersections between the two shapes (Since there's no built in method already, or at least I can't find it :) ).  The first demo picture bellow is comparing the screen full of the square tiles to the ellipse.  Those that intersect are highlighted in red.  Giving much the same effect as some of the previous shots in this thread, but achieving it a completely different way.    All that's left to do is port this into the maths library and we should finally be able to tick the CircleHitMap / EllipseHitMap functions off the the To DO List.   Of course, then we need Pixel To Pixel level intersections.  

   The second shot shows the CircleToMap test, you can see it's highlighting the interior tiles of the circle, so if any of this map tiles have pixels in them, then there must and collision.

   Edit:  The third shot is showing the collision test up and running.  In this shot, when the circle edges can now be compard against the maps blocks rects.   So we can get a pretty good indication of what we've hitting.   


kevin

#43
  PlayBASIC V1.64M  Beta #26 - Ellipse/Circle to Map (cont)

   The CircleHitMap function is up and running.  Before we proceed, I just wanted to really raise the awareness about how intensive these types of collision methods can be.  In the first picture / example bellow we're testing a circle of radius 300 to the map,  not once though but 1000 times.    While really excessive the process eats around 28 to 32 milliseconds at this size.    The size matters since we're translating the shape back to a the map, then comparing them.  The larger the shape the larger the potential work load for the collision engine.  By comparison, if the set the Radius to 30 and run it 1000 times,  it eats about 4 to 6 milliseconds.   So, like everything think carefully about what you're doing when implementing your collisions.

 
PlayBASIC Code: [Select]
  BackdropColour=$008f00

screen=newfximage(6400,6400)
rendertoimage screen
cls BackdropColour
circlec 800,400,400,true,$8f8f8f
circlec 1700,400,400,true,$0f8faf

for lp=0 to 150
ellipsec rnd(2400),rnd(800),rndrange(50,150),rndrange(10,50),true, BackdropColour
next

BlockWidth =32
BlockHeight=32

Map=Newmap(50)
createmapgfx Map,BlockWidth,BlockHeight,4096,BackdropColour,2; CREATE 4096 FX BLOCKS

Level=NewLevel(Map,GetSurfaceWidth()/BlockWidth,GetSurfaceHeight()/BlockHeight)
leveltransparent Map,Level,0
Tile=1
For ylp=0 to GetLevelHeight(map,level)-1
Ypos=ylp*BlockHeight
if Ypos+BlockHeight<=GetSurfaceHeight()
For xlp=0 to GetLevelWidth(map,level)-1
Xpos=xlp*BlockWidth
ink $ffffffff
GetMapBlk Map,Tile,Xpos,ypos
PokeLevelTile Map,Level,xlp,ylp,tile
tile++
if Tile=>GetMapBlocks(Map) then exitfor ylp
next
endif
next

rendertoscreen


c1=rndrgb()
c2=rndrgb()



Screen=NEwfxIMage(800,600)

BackDrop=NEwfxIMage(800,600)
rendertoimage Backdrop
shadebox 0,0,getsurfacewidth(),GetsurfaceHeight(),c1,c1,c2,c2
rendertoscreen

RadiusX=200
RadiusY=200


Do
rendertoimage Screen

drawimage BackDrop,0,0,false

MouseWorldXpos=MouseX()
MouseWorldYpos=MouseY()

; draw the map level

drawmap map,Level,0,0


lockbuffer
radius=300
t=timer()
for lp=0 to 1000
Collision=CircleHitMap(Map,Level,MouseWorldXpos,MouseWorldYpos,RAdius)
next
te=timer()-t
unlockbuffer

Print "testing "+Str$(lp)+" times"

if Collision
Colour=$ff0000
Print "Hit"
else
Colour=$0000ff
Print "Missed"
endif
inkmode 1+32
Circlec MouseWorldXpos,MouseWorldYpos,Radius,true,colour
inkmode 1

print te

setcursor 0,0
ink $ff0000ff

if EnterKey()
MapDebug Map,1-GetMapDebug(Map)
flushkeys
endif

rendertoscreen
drawimage screen,0,0,false

Sync
loop





   



kevin

#44
  PlayBASIC V1.64M  Beta #26 - Ellipse/Circle to Map Video

   Finally the Pixel collision version of these functions working very early this morning.   Rather than post another screen shot,  decided to make a little video.

   You can  watch  CircleHitMapPixels video on our PlayBasic channel  on YouTube


   





 EllipseHitMapPixels Test Source
 
  Here's the test code for the Circle/Ellipse Hit Map demos. (picture attached)

 
PlayBASIC Code: [Select]
  BackdropColour=$ff0000

screen=newfximage(6400,6400)
rendertoimage screen
cls BackdropColour
circlec 800,400,400,true,$8f8f8f
circlec 1700,400,400,true,$0f8faf

for lp=0 to 150
ellipsec rnd(2400),rnd(800),rndrange(50,150),rndrange(10,50),true, BackdropColour
next

BlockWidth =32
BlockHeight=16

Map=Newmap(50)
createmapgfx Map,BlockWidth,BlockHeight,4096,BackdropColour,2; CREATE 4096 FX BLOCKS

Level=NewLevel(Map,GetSurfaceWidth()/BlockWidth,GetSurfaceHeight()/BlockHeight)
leveltransparent Map,Level,0

GetMapBlk Map,0,0,0
Tile=1

For ylp=0 to GetLevelHeight(map,level)-1
Ypos=ylp*BlockHeight
if Ypos+BlockHeight<=GetSurfaceHeight()
For xlp=0 to GetLevelWidth(map,level)-1
Xpos=xlp*BlockWidth
ink $ffff00ff
; text Xpos,ypos,Tile
ink $ffffffff
GetMapBlk Map,Tile,Xpos,ypos
; text Xpos,ypos,GetMapBlockTransparent(Map,Tile)
; GetMapBlk Map,Tile,Xpos,ypos
if GetMapBlockTransparent(Map,Tile)>-1
PokeLevelTile Map,Level,xlp,ylp,tile
tile++
else
PokeLevelTile Map,Level,xlp,ylp,0
endif

if Tile=>GetMapBlocks(Map) then exitfor ylp
next
endif
next


Screen=NEwfxIMage(800,600)

rendertoimage Screen

cam=newcamera()
cameracls cam,off

c1=rndrgb()
c2=rndrgb()




BackDrop=NEwfxIMage(800,600)
rendertoimage Backdrop
shadebox 0,0,getsurfacewidth(),GetsurfaceHeight(),c1,c1,c2,c2
rendertoscreen

RadiusX=100
RadiusY=200


Do

MouseWorldXpos=MouseX()-1+GetCameraX(Cam)
MouseWorldYpos=MouseY()-1+GetCameraY(Cam)

capturetoscene
clsscene

capturedepth 200

drawimage BackDrop,GetCameraX(Cam),GetCameraY(Cam),false

capturedepth 100

; draw the map level

drawmap map,Level,0,0
; DRaw the the Mouse pointer within the world space
capturedepth 10

Collision=EllipseHitMapPixels(Map,Level,MouseWorldXpos,MouseWorldYpos,RAdiusX,RadiusY)


if Collision
Colour=$ff0000
Message$="Hit"
else
Colour=$0000ff
Message$="Missed"
endif
inkmode 1+32
Ellipsec MouseWorldXpos,MouseWorldYpos,RadiusX,RadiusY,true,colour

inkmode 1



; draw whatever the camera can see
drawcamera cam

drawimage screen,0,0,false



setcursor 0,0
ink $ffffffff
print "Ellipse Hit Map Pixels"
Print "testing "+Str$(lp)+" times"
print Message$


if LeftMouseBUtton()
RAdiusX+=1
If RadiusX>300 then RadiusX=1
endif

if RightMouseBUtton()
RAdiusY+=1
If RadiusY>300 then RadiusY=1
endif


speed=2
if leftkey() then movecamera cam,-Speed,0
if rightkey() then movecamera cam,Speed,0
if upkey() then movecamera cam,0,-Speed
if downkey() then movecamera cam,0,Speed



if EnterKey()
MapDebug Map,1-GetMapDebug(Map)
flushkeys
endif


Sync
Login required to view complete source code





 PlayBASIC V1.64M  Beta #27 - Quad to Map Collision

  Tonight's little task has been to build the Polygon to map collision routines,  this is relatively simple as the process is much the same as the Circle/Ellipse version except we're feeding it a convex polygon to start with.  It'll actually actually work for the polygons with more than 3 or 4 vertex, but that's something for the future.  

  Anyway, the second shot is showing this QuadHitMap function up and running in Beta 27...   It's a bit quicker than the circle/ellipse version, as calling the routine 1000 times is about 50% faster.   And there's a bit of room to move in terms of further optimizations, but for now i'm just trying to keep the implementation as short as possible.