// Project: Waves
// Created: 2020-04-09
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Waves" )
SetWindowSize( 1080, 720, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1080, 720 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate(0, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
//physics stuff
SetPhysicsMaxPolygonPoints(12) `max 12
SurfCat = 1
WaveCat = 2
DiveCat = 3
WallCat = 4
SwellCat = 5
Surface = CreateSprite(0) : SetSpriteSize(Surface,1100,20) : SetSpritePosition(Surface,0,300) : SetSpriteVisible(Surface,0)
SetSpritePhysicsOn(Surface,1) : SetBit(Surface,Surfcat,0) : SetBit(Surface,WaveCat,0) : SetBit(Surface,DiveCat,0)
For x = 0 to 108
ThisPoint = CreateSprite(0) : SetSpriteSize(ThisPoint,10,300): SetSpritePosition(ThisPoint,x*11,310)
SetSpriteColor(ThisPoint,0,128,255,255)
SetSpritePhysicsOn(ThisPoint,2) : SetSpritePhysicsMass(ThisPoint,50)
CreateLineJoint( Surface,ThisPoint, (x*11),300, 0,1, 0 )
ThisPrism = CreatePrismaticJoint(Surface,ThisPoint,x*11,300,0,1,0)
SetJointLimitOn(ThisPrism,-50,50)
SetBit(ThisPoint,WaveCat,1) : SetBit(ThisPoint,SurfCat,0) : SetBit(ThisPoint,DiveCat,1)
Next x
`GLOBAL Waves as Integer
Waves as Integer []
Wall = CreateSprite(0) : SetSpriteSize(Wall,10,700) : SetSpritePosition(Wall,1070,10)
Type DiveData
ID as Integer
MaxDepth as Float
EndType
Divers as DiveData []
Do
mx = GetPointerX() : my = GetPointerY()
If GetPointerPressed() = 1
Drop = CreateSprite(0) : SetSpritePosition(Drop,MX,MY) : SetSpriteSize(Drop,48,48)
SetSpritePhysicsOn(Drop,2) : SetSpriteShapeCircle(Drop,0,0,24) : SetSpritePhysicsDamping(Drop,0.7)
SetSpritePhysicsCanRotate(Drop,0) : SetSpritePhysicsMass(Drop,300)
R = Random(0,255) : G = Random(0,255) : B = Random(0,255) : SetSpriteColor(Drop,R,G,B,255)
SetBit(Drop,SurfCat,0) : SetBit(Drop,WaveCat,0) : SetBit(Drop,DiveCat,1)
ThisDiver as DiveData : ThisDiver.ID = Drop : ThisDiver.MaxDepth = my
Divers.Insert(ThisDiver)
Endif
If NextWave# < Timer()
WaveSize# = Random(90,120)
Wave = CreateSprite(0) : SetSpriteSize(Wave,WaveSize#,WaveSize#) : SetSpritePosition(Wave,0,600) : SetSpriteGroup(Wave,-5) : SetSpriteVisible(Wave,0)
SetSpritePhysicsOn(Wave,2) : SetSpriteShapeCircle(Wave,0,0,WaveSize#/2) : SetSpritePhysicsFriction(Wave,1)
NextWave# = Timer() + 5
Waves.Insert(Wave)
Endif
If Waves.Length > -1
For x = Waves.Length to 0 step -1
ThisWave = Waves[x]
If GetSpriteCollision(ThisWave,Wall) = 1
DeleteSprite(ThisWave)
Waves.Remove(x)
Else
SetSpritePhysicsVelocity(ThisWave,150,0)
Endif
Next x
Endif
If Divers.Length > -1
For x = Divers.Length to 0 step -1
Diver = Divers[x].ID
MaxDepth = Divers[x].MaxDepth
ThisDepth = GetSpriteY(Diver)
Print(STR(MaxDepth) + "|" + STR(ThisDepth))
If GetSpriteCollision(Diver,Wall) = 1 or ThisDepth > 700
DeleteSprite(Diver)
Divers.Remove(x)
Else
If ThisDepth < MaxDepth
SetBit(Diver,WaveCat,0)
SetBit(Diver,DiveCat,0)
SetSpriteColorAlpha(Diver,96)
Else
Divers[x].MaxDepth = ThisDepth
Endif
Endif
Next x
Endif
Sync()
Loop
Function SetBit(Sprite,Cat,Flag)
SetSpriteCategoryBit(Sprite,Cat,Flag)
EndFunction
getting closer? (my first time playing with
category bits)