Main Menu

Particle Map Collision Demo

Started by kevin, October 28, 2021, 11:05:24 AM

Previous topic - Next topic

kevin

   Particle Map Collision Demo


   This example shows how we can use the CheckMapImpact function within even a particle routine.  



Video



   






PlayBASIC Code: [Select]
 openscreen 1280,720,32,1






; Create a map with provision for 5 levels
MyMap=NewMap(5)

; Create some blank blocks for this map
CreateMapGFX MyMap,64,64,2,RGB(0,0,0)
BoxC 0,0,128,128,1,RGB(255,0,200)
GetMapBlk MyMap,1,0,0


width=25
Height=20

; create the level
MyLevel=NewLevel(Mymap, Width,Height)


; Fill the Level edges with blocks
For Xlp=0 To Width
PokeLevelTile Mymap,MyLevel,xlp,0,1
PokeLevelTile Mymap,MyLevel,xlp,Height,1
Next

For Ylp=0 To Height
PokeLevelTile Mymap,MyLevel,0,ylp,1
PokeLevelTile Mymap,MyLevel,Width,ylp,1
Next

; Draw a strip of blocks across the middle
; of the page
For Xlp=3 To Width-3
PokeLevelTile Mymap,MyLevel,xlp,Height/2,1
Next


PokeLevelTile Mymap,MyLevel,5,5,1
PokeLevelTile Mymap,MyLevel,15,5,1

;
; Start a Do / Loop
Do
; Clear the screen
Cls RGB(0,0,0)

; Draw the map to the screen
DrawMap MyMap,MyLevel,0,0

Draw(MyMap,MyLevel)

mx=mousex()
my=mousey()
Spawn(mx,my,rndrange(5,15)) ;)basex#,basey#,Count)



; Display()
; Display the screen
Sync
; Loop back to the do statement
Loop spacekey()








; PROJECT : Map-Particle-Library-V0001
; EDITED : 29/10/2021
; ---------------------------------------------------------------------

/* ------------- [EXAMPLE #01 NOTES -----------------------------

Here's a tweaked revision of base particle example.

------------------------------------------------------------ */




Type tParticle
status#
x#,y#
vx#,vy#
angle#
speed#
framecount
Colour
EndType

dim Particles(100000) as tParticle


// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// ------------------------[ SPAWN PARTICLES ]--------------------------
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------

function Spawn(basex#,basey#,Count)

if mousebutton()
if range(BaseX#,0,getscreenwidth())
if range(BaseY#,0,getScreenheight())
dim me as tParticle pointer

if GetArrayStatus(Particles())=false
dim Particles(100000) as tParticle
endif


r=rndrange(41,80)
g=rndrange(21,70)
b=rndrange(11,50)
ThisRGB=rgb(R,g,b)
for lp=1 to count

index=getfreecell(Particles())
if Index
Particles(index) = new tparticle

me = Particles(index).TParticle
me.x= basex#
me.y= basey#
Angle#=rnd#(360)
me.Angle = Angle#
speed# = rndrange#(3,10)
me.vx= cosradius(angle#,Speed#)
me.vy= sinradius(angle#,Speed#)
me.framecount = 400
me.colour = ThisRGB
endif

next
endif
endif
endif
EndFunction


Login required to view complete source code





Download Source Code


    Source Code Attached bellow.