Box_Bash game - peadenaw@gmail.com - 01-12-2025
This is a game where you to try to use various tools to guide falling boxes to the escape door. A lemmings with falling boxes (instead of lemmings) if you will.
The game basically finished, and I find it enjoyable in short sessions. It's mostly finished, but like they say, the last 2% takes 90% of the effort.
(I also have some ideas to add new tools, and there are a few minor known issues I should iron out)
I also lack any sort of feedback on this project.
This game started out as an attempt to program my own 2D physics engine, which was a great learning experience. (I know there are already physics engines out there, but I wanted to see if I could figure this out on my own). Also, for anyone examining the code, although I have dabbled in programming throughout my life, I'm not a professional at this. I didn't discover that qb had a "define type" feature until I was nearly done with this, or I would have used that instead of a massive matrix for the physics objects.
Code: (Select All)
Screen _NewImage(640, 360, 32)
_FullScreen
_MouseHide
Rem $Dynamic 'Allows for resizeable arrays
Open "Errata.txt" For Output As #5
'Open "Errata2.txt" For Output As #6
Dim Shared write1%, write2%
write1% = 0
'write2% = 0
Const touchcondition% = 1 '1=ON 0=OFF
Const springconst# = 4000
Const framelimit = 60
Const physicslimit = 180
Const gravity# = 9.8
Const springboundary# = .1
Const velocityangletransition# = 10
Const rotationalangletransition# = 10
Const damptype% = 1 '1=unidirectional, 0=traditional
Const collisionperobjectlimit% = 31
Dim looptimer#
Dim Shared landscape(960, 720) As Integer 'value dictates which type each cell is
Dim Shared landscapehealth(960, 720) As Single
Dim Shared objects(90, 19) As Double 'Type Health Size Mass X Y Vx Vy Ax Ay Angle1 Open Friction I Angle W Alpha #ObjectsColliding DampingCoef (0 indexed)
Dim Shared forces(1) As Double
Dim Shared corners#(90, 7)
Dim Shared springcorners#(90, 7)
Dim Shared collisioncounter%
collisioncounter% = 0
Dim Shared soundtimer#, gametimer#
Dim physicstimer#, pausetimer#, scoretimer#, warningtimer#, healthreductiontimer#, lowfreqtimer#
Dim clickdown` 'a bit, either -1 or 0
clickdown` = 0
Dim Shared scale#
Dim oldscale#, scalefactor%
scale# = 3
scalefactor% = 1
Dim cursorstyle%
Dim mousewheelvalue%, mousexpos%, mouseypos%, mousexmatrix%, mouseymatrix%
mousexpos% = 160 'Integer
mouseypos% = 100
cursorstyle% = 2
Dim Shared screenx%, screeny%, scroolspeed%
Dim pwarning%
screenx% = 0 'These values go negative as you scroll down and accross
screeny% = 0 'They are the screen offset values
Dim Shared soundmode% '1=boxes 2=environment 3=all 0=off
soundmode% = 3
Randomize (Timer)
'Game specific variables
Type gameobject
otype As Integer
xpos As Double
ypos As Double
radius As Double
time As Double
angle As Double
End Type
Dim Shared gameobjectarray(100) As gameobject
Dim nextobject#, totalobjects%, objectcaptured%
totalobjects% = 50
Dim Shared money%
money% = 1000
Dim Shared boxsaved%, boxdestroyed%
Dim Shared costarray%(11)
Dim vectorx#, vectory#
costarray%(2) = 5 'DRAW SOFT
costarray%(3) = 8 'ERASE
costarray%(4) = 20 'AWAY MAGNET
costarray%(5) = 30 'PULL MAGNET
costarray%(6) = 25 'MAGNET BOMB
costarray%(7) = 10 'BUILD BOX
costarray%(8) = 40 'SMALL BOMB
costarray%(9) = 80 'LARGE BOMB
costarray%(10) = 5 'DRAW HARD
Dim drawpoints#(16, 2)
Dim xx%, xpos%, ypos%
Dim temp#
Makelandscape 'requires there to be money
'Title Screen
Cls
Color _RGB(44, 177, 227)
Locate 2, 36
Print "BOX BASH"
'80 Characters across
Locate 4, 1
Color _RGB(200, 200, 200)
Print ""
Print " Select a tool then use it to help guide the falling boxes out the door"
Print ""
Print "Controls: mouse pan and zoom"
Print " d/f switch tool"
Print " s save file"
Print " l load file"
Print " p short pause"
Locate 16, 28
Color _RGB(94, 205, 28)
Print "Press Any Key To Continue"
Dim inputchar$, inputchar1$
_Display
Sleep 10
Color _RGB(255, 255, 255)
'Time dependent variables
gametimer# = Timer(.0001)
physicstimer# = Timer(.0001)
nextobject# = gametimer# + 2
scoretimer# = gametimer# + 180
moneytimer# = gametimer# + 1
warningtimer# = gametimer#
soundtimer# = gametimer#
healthreductiontimer# = gametimer# + 6
lowfreqtimer# = gametimer# + 1 / 60
'Main loop exits on ESC or game end
While inputchar$ <> Chr$(27) And scoretimer# - gametimer# > 0
'Cls 'temporary clear screen to see troubleshooting input steps
inputchar$ = InKey$
oldscale# = scale#
If inputchar$ = "." Then scale# = scale# + 0.2
If inputchar$ = "," Then scale# = scale# - 0.2
If inputchar$ = "s" Then Savefile
If inputchar$ = "l" Then Loadfile
If inputchar$ = "/" Then scale# = 1
If inputchar$ = "o" Then outputobjects
If inputchar$ = "d" Then cursorstyle% = cursorstyle% + 1
If inputchar$ = "f" Then cursorstyle% = cursorstyle% - 1
If inputchar$ = "p" Then Sleep 10
If _KeyDown(20480) Then screeny% = screeny% - 1 'up arrow
If _KeyDown(18432) Then screeny% = screeny% + 1 'down arrow
If _KeyDown(19200) Then screenx% = screenx% + 1 'left arrow
If _KeyDown(19712) Then screenx% = screenx% - 1 'right arrow
If cursorstyle% > 10 Then cursorstyle% = 2
If cursorstyle% < 2 Then cursorstyle% = 10
If _MouseInput Then
mousewheelvalue% = _MouseWheel
If mousewheelvalue% Then
scale# = scale# - mousewheelvalue% * scale# * 0.2
End If
mousexpos% = mousexpos% + _MouseMovementX
mouseypos% = mouseypos% + _MouseMovementY
End If
If scale# < 0.25 Then scale# = 0.25
If scale# > 30 Then scale# = 30
If oldscale# <> scale# Then 'adjust screen offsets is scaling changes
screenx% = Int(-scale# * (mousexpos% - screenx%) / (oldscale#) + mousexpos%)
screeny% = Int(-scale# * (mouseypos% - screeny%) / (oldscale#) + mouseypos%)
End If
mousexmatrix% = Round((mousexpos% - screenx%) / scale#)
mouseymatrix% = Round((mouseypos% - screeny%) / scale#)
'Print mousexmatrix%
'Print mouseymatrix%
'If _MouseButton(1) And mousexmatrix% > 0 And mousexmatrix% <= 960 And mouseymatrix% > 0 And mouseymatrix% <= 720 Then
'landscape(mousexmatrix%, mouseymatrix%) = 1
'End If
If pwarning% <> 0 And gametimer# - warningtimer# > 0 Then pwarning% = 0 'warning code if trying to place block in illegal location
' 4 PLACES TO ADDRESS USER INTERACTIONS. HERE, BEFORE GRAPHICS, IN GRAPHICS & IN PHYSICS
If _MouseButton(1) And cursorstyle% = 1 And clickdown` = 0 And Inbounds(mousexmatrix%, mouseymatrix%) = 1 Then '-1=True
If landscape(mousexmatrix%, mouseymatrix%) < 2 Then
pausetimer# = Timer(.0001)
' with this method individual clicks are required for each action. No hold and drag.
clickdown` = -1 'clickdown`=-1 when mouse button is down
'NewObject 2, 10, 10, 10, 100, 70, Rnd * 300, Rnd * 10, 0, 0, 1.0, Rnd * _Pi, Rnd * 200 - 100,.1,.2 '(otype%, health#, size#, mass#, xpos#, ypos#, xvel#, yvel#, xacc#, yacc#, forcereturn#, angle#, anglevel#, friction, damping)
placeobject ((mousexpos% - screenx%) / scale#), ((mouseypos% - screeny%) / scale#)
nextobject# = nextobject# + Timer(.0001) - pausetimer#
physicstimer# = physicstimer# + Timer(.0001) - pausetimer#
scoretimer# = scoretimer# + Timer(.0001) - pausetimer#
Else
pwarning% = 1
warningtimer# = gametimer# + .5
End If
ElseIf _MouseButton(1) And cursorstyle% = 1 And clickdown` = 0 And Inbounds(mousexmatrix%, mouseymatrix%) = 0 Then
pwarning% = 2
warningtimer# = gametimer# + .5
End If
If _MouseButton(1) And cursorstyle% = 2 And Inbounds(mousexmatrix%, mouseymatrix%) = 1 And money% > costarray%(2) Then 'Paint Soft Surface
brushfillweapon mousexmatrix%, mouseymatrix%, 7, 2, costarray%(2)
End If
If _MouseButton(1) And cursorstyle% = 3 And Inbounds(mousexmatrix%, mouseymatrix%) = 1 And money% > costarray%(3) Then 'Erase
brushfillweapon mousexmatrix%, mouseymatrix%, 8, 0, costarray%(3)
End If
If _MouseButton(1) And cursorstyle% = 4 And Inbounds(mousexmatrix%, mouseymatrix%) = 1 And money% > costarray%(4) And clickdown` = 0 Then 'Magnet Away
NewGameObject 3, mousexmatrix%, mouseymatrix%, 1, 0, gametimer# + 1.5
If gametimer# - soundtimer# > 0 Then Play "mbL64o2bao3gfedcbao4gfedcbao5gfedcba"
soundtimer# = gametimer# + .1
money% = money% - costarray%(4)
clickdown` = -1
End If
If _MouseButton(1) And cursorstyle% = 5 And Inbounds(mousexmatrix%, mouseymatrix%) = 1 And money% > costarray%(5) And clickdown` = 0 Then 'Pull Magnet
NewGameObject 4, mousexmatrix%, mouseymatrix%, 1, 0, gametimer# + 2.0
If gametimer# - soundtimer# > 0 Then Play "mbL64o4abcdefgo3abcdefgo2abcdefg"
soundtimer# = gametimer# + .1
money% = money% - costarray%(5)
clickdown` = -1
End If
If _MouseButton(1) And cursorstyle% = 6 And Inbounds(mousexmatrix%, mouseymatrix%) = 1 And money% > costarray%(6) And clickdown` = 0 Then 'Magnet Bomb
NewGameObject 5, mousexmatrix%, mouseymatrix%, 1, 0, gametimer# + 1.5
If gametimer# - soundtimer# > 0 Then Play "mbL64@2o3bo1bo3co1co3bo1bo3do1do3go1go3eo1eo3fo1f"
soundtimer# = gametimer# + .1
money% = money% - costarray%(6)
clickdown` = -1
End If
If _MouseButton(1) And cursorstyle% = 7 And money% > costarray%(7) And clickdown` = 0 Then 'Build Box
If Inbounds(mousexmatrix%, mouseymatrix%) = 1 Then
If landscape(mousexmatrix%, mouseymatrix%) = 0 Or landscape(mousexmatrix%, mouseymatrix%) = 1 Then
NewGameObject 6, (mousexpos% - screenx%) / scale#, (mouseypos% - screeny%) / scale#, 1, 0, 0
money% = money% - costarray%(7)
clickdown` = -1
Else
pwarning% = 1
warningtimer# = gametimer# + .5
End If
Else
pwarning% = 2
warningtimer# = gametimer# + .5
End If
End If
If _MouseButton(1) And cursorstyle% = 8 And Inbounds(mousexmatrix%, mouseymatrix%) = 1 And money% > costarray%(8) And clickdown` = 0 Then 'Small Bomb
NewGameObject 7, mousexmatrix%, mouseymatrix%, 1, 0, gametimer# + 0.7
If gametimer# - soundtimer# > 0 Then Play "mbL64@1o0gfdecabdegfcabo1gfdecabdegfcab"
soundtimer# = gametimer# + .1
money% = money% - costarray%(8)
clickdown` = -1
End If
If _MouseButton(1) And cursorstyle% = 9 And Inbounds(mousexmatrix%, mouseymatrix%) = 1 And money% > costarray%(9) And clickdown` = 0 Then 'Large Bomb
NewGameObject 8, mousexmatrix%, mouseymatrix%, 1, 0, gametimer# + 1.2
If gametimer# - soundtimer# > 0 Then Play "Q0mbL64V75@1o0gfedcdbabedcabagefcbadgfabdefa@2o1bababa"
soundtimer# = gametimer# + .1
money% = money% - costarray%(9)
clickdown` = -1
End If
If _MouseButton(1) And cursorstyle% = 10 And Inbounds(mousexmatrix%, mouseymatrix%) = 1 And money% > costarray%(10) Then 'Paint Hard Surface
brushfillweapon mousexmatrix%, mouseymatrix%, 6, 3, costarray%(10)
End If
If mousexpos% < 1 Then mousexpos% = 1
If mousexpos% > 480 Then mousexpos% = 480
If mouseypos% < 1 Then mouseypos% = 1
If mouseypos% > 360 Then mouseypos% = 360
If mousexpos% = 1 Then screenx% = screenx% + scrollspeed%
If mousexpos% = 480 Then screenx% = screenx% - scrollspeed%
If mouseypos% = 1 Then screeny% = screeny% + scrollspeed%
If mouseypos% = 360 Then screeny% = screeny% - scrollspeed%
'LIMIT SCREEN OFFSETS
If -screenx% < -40 / scale# Then screenx% = 40 / scale#
If -screeny% < -30 / scale# Then screeny% = 30 / scale#
If -screenx% > 960 * scale# - 480 + 40 / scale# Then screenx% = -960 * scale# + 480 - 40 / scale#
If -screeny% > 720 * scale# - 320 + 20 / scale# Then screeny% = -720 * scale# + 320 - 20 / scale#
Do While _MouseInput 'Clear Mouse Buffer
Loop
scrollspeed% = Int(scale# / 10) + 3
'Game Logic
If gametimer# - moneytimer# > 0 Then
money% = money% + 4
moneytimer# = gametimer# + 0.5
End If
If gametimer# - healthreductiontimer# > 0 Then
For x = 0 To UBound(objects, 1)
If objects(x, 0) = 2 Then objects(x, 19) = objects(x, 19) - 2.5
Next x
healthreductiontimer# = gametimer# + 1
End If
'Game Objects
If nextobject# - gametimer# < 0 And totalobjects% > 0 Then
NewGameObject 1, 11 + Rnd * 949, 10, 1, 0, gametimer# + 2
nextobject# = gametimer# + 3.0
totalobjects% = totalobjects% - 1
End If
'Cycle Through Game Objects For Non-Graphical Effects
For x = 0 To UBound(gameobjectarray)
Select Case gameobjectarray(x).otype
Case -1 'Box Destruction
gameobjectarray(x).radius = 20 * (0.52 - (gameobjectarray(x).time - gametimer#)) + 5
If gameobjectarray(x).time - gametimer# <= 0 Then
gameobjectarray(x).otype = 0
End If
Case 1 'Appearing Box
If gameobjectarray(x).time - gametimer# <= 0 Then
NewObject 2, 100, 10, 10, gameobjectarray(x).xpos, gameobjectarray(x).ypos, 0, 0, 0, 0, 1, 0, 0, .1, 0.05 '(otype%, health#, size#, mass#, xpos#, ypos#, xvel#, yvel#, xacc#, yacc#, forcereturn#, angle#, anglevel#, friction, damping)
gameobjectarray(x).otype = 0
End If
Case 2 'Disappearing Box
If gameobjectarray(x).time - gametimer# <= 0 Then
gameobjectarray(x).otype = 0
End If
gameobjectarray(x).radius = 7.07 * ((gameobjectarray(x).time - gametimer#) / 0.6)
Case 3 'Outward magnet
gameobjectarray(x).radius = 60 + 10 * Sin(4 * _Pi * (gametimer# - Int(gametimer#)))
If gameobjectarray(x).time - gametimer# <= 0 Then
gameobjectarray(x).otype = 0
End If
Case 4 'Pull magnet
gameobjectarray(x).radius = 60 + 10 * Sin(4 * _Pi * (gametimer# - Int(gametimer#)))
If gameobjectarray(x).time - gametimer# <= 0 Then
gameobjectarray(x).otype = 0
End If
Case 5 'Magnet Bomb
gameobjectarray(x).radius = 50 * (1.52 - (gameobjectarray(x).time - gametimer#))
If gameobjectarray(x).time - gametimer# <= 0 Then
gameobjectarray(x).otype = 0
End If
Case 6 'Box Build
If _MouseButton(1) = -1 And clickdown` = -1 Then
gameobjectarray(x).radius = 1.4 * Sqr((((mousexpos% - screenx%) / scale#) - gameobjectarray(x).xpos) ^ 2 + (((mouseypos% - screeny%) / scale#) - gameobjectarray(x).ypos) ^ 2)
gameobjectarray(x).angle = _Atan2(((mouseypos% - screeny%) / scale#) - gameobjectarray(x).ypos, ((mousexpos% - screenx%) / scale#) - gameobjectarray(x).xpos)
If gameobjectarray(x).radius > 60 Then gameobjectarray(x).radius = 60
End If
If _MouseButton(1) = 0 And clickdown` = -1 Then
drawpoints#(1, 1) = gameobjectarray(x).xpos + .707 * gameobjectarray(x).radius * Cos(gameobjectarray(x).angle + _Pi / 4)
drawpoints#(1, 2) = gameobjectarray(x).ypos + .707 * gameobjectarray(x).radius * Sin(gameobjectarray(x).angle + _Pi / 4)
drawpoints#(2, 1) = gameobjectarray(x).xpos + .707 * gameobjectarray(x).radius * Cos(gameobjectarray(x).angle + 3 * _Pi / 4)
drawpoints#(2, 2) = gameobjectarray(x).ypos + .707 * gameobjectarray(x).radius * Sin(gameobjectarray(x).angle + 3 * _Pi / 4)
drawpoints#(3, 1) = gameobjectarray(x).xpos + .707 * gameobjectarray(x).radius * Cos(gameobjectarray(x).angle + 5 * _Pi / 4)
drawpoints#(3, 2) = gameobjectarray(x).ypos + .707 * gameobjectarray(x).radius * Sin(gameobjectarray(x).angle + 5 * _Pi / 4)
drawpoints#(4, 1) = gameobjectarray(x).xpos + .707 * gameobjectarray(x).radius * Cos(gameobjectarray(x).angle + 7 * _Pi / 4)
drawpoints#(4, 2) = gameobjectarray(x).ypos + .707 * gameobjectarray(x).radius * Sin(gameobjectarray(x).angle + 7 * _Pi / 4)
xx% = 0
While (objects(xx%, 0) <> 2 And xx% < UBound(objects, 1)) Or ((objects(xx%, 0) = 2 And In4Points(objects(xx%, 4), objects(xx%, 5), drawpoints#(1, 1), drawpoints#(1, 2), drawpoints#(2, 1), drawpoints#(2, 2), drawpoints#(3, 1), drawpoints#(3, 2), drawpoints#(4, 1), drawpoints#(4, 2)) = -1) And xx% < UBound(objects, 1))
xx% = xx% + 1
Wend
If xx% = UBound(objects, 1) Then
NewObject 1, 10, gameobjectarray(x).radius, 10, gameobjectarray(x).xpos, gameobjectarray(x).ypos, 0, 0, 0, 0, 1, gameobjectarray(x).angle, 0, .1, 0.05 '(otype%, health#, size#, mass#, xpos#, ypos#, xvel#, yvel#, xacc#, yacc#, forcereturn#, angle#, anglevel#, friction, damping)
Else
pwarning% = 1
money% = money% + costarray%(7)
warningtimer# = gametimer# + .5
End If
gameobjectarray(x).otype = 0
End If
Case 7 'Small Bomb
gameobjectarray(x).radius = 50 * (.72 - (gameobjectarray(x).time - gametimer#))
If gameobjectarray(x).time - gametimer# <= 0 Then
gameobjectarray(x).otype = 0
End If
Case 8 'Large Bomb
gameobjectarray(x).radius = 60 * (1.22 - (gameobjectarray(x).time - gametimer#))
If gameobjectarray(x).time - gametimer# <= 0 Then
gameobjectarray(x).otype = 0
End If
End Select
Next x
If _MouseButton(1) = 0 And clickdown` = -1 Then clickdown` = 0 'mouse button unclicked
gametimer# = Timer(.0001)
If gametimer# - physicstimer# > 2 Then physicstimer# = gametimer#
While physicstimer# < gametimer#
PhysicsCollisions 'loop this sub while Gametime-Physicstime > physicstimedelta. Increment physicstime each loop
physicstimer# = physicstimer# + 1 / physicslimit 'limit of 200 iterations a second
Wend
While lowfreqtimer# < gametimer#
'Do Explosion Math
For z = 0 To UBound(gameobjectarray)
Select Case gameobjectarray(z).otype
Case -1 'Self Explosion
xpos% = Int(gameobjectarray(z).xpos)
ypos% = Int(gameobjectarray(z).ypos)
For x% = xpos% - Int(gameobjectarray(z).radius) - 1 To xpos% + Int(gameobjectarray(z).radius) + 1 Step 1
For y% = ypos% - Int(gameobjectarray(z).radius) - 1 To ypos% + Int(gameobjectarray(z).radius) + 1 Step 1
If Sqr((x% - xpos%) ^ 2 + (y% - ypos%) ^ 2) < gameobjectarray(z).radius And x% > 0 And y% > 0 And x% < 960 And y% < 720 Then
If landscape(x%, y%) = 2 Then
landscapehealth(x%, y%) = landscapehealth(x%, y%) - 3
If landscapehealth(x%, y%) <= 0 Then
If Rnd < .005 Then
landscape(x%, y%) = 1
Else
landscape(x%, y%) = 0
End If
End If
End If
End If
Next y%
Next x%
Case 7 'Small Bomb
xpos% = Int(gameobjectarray(z).xpos)
ypos% = Int(gameobjectarray(z).ypos)
For x% = xpos% - Int(gameobjectarray(z).radius) - 1 To xpos% + Int(gameobjectarray(z).radius) + 1 Step 1
For y% = ypos% - Int(gameobjectarray(z).radius) - 1 To ypos% + Int(gameobjectarray(z).radius) + 1 Step 1
If Sqr((x% - xpos%) ^ 2 + (y% - ypos%) ^ 2) < gameobjectarray(z).radius And x% > 0 And y% > 0 And x% < 960 And y% < 720 Then
If landscape(x%, y%) = 2 Then
landscapehealth(x%, y%) = landscapehealth(x%, y%) - 4
If landscapehealth(x%, y%) <= 0 Then
If Rnd < .005 Then
landscape(x%, y%) = 1
Else
landscape(x%, y%) = 0
End If
End If
End If
End If
Next y%
Next x%
Case 8 'Large Bomb
xpos% = Int(gameobjectarray(z).xpos)
ypos% = Int(gameobjectarray(z).ypos)
For x% = xpos% - Int(gameobjectarray(z).radius) - 1 To xpos% + Int(gameobjectarray(z).radius) + 1 Step 1
For y% = ypos% - Int(gameobjectarray(z).radius) - 1 To ypos% + Int(gameobjectarray(z).radius) + 1 Step 1
If Sqr((x% - xpos%) ^ 2 + (y% - ypos%) ^ 2) < gameobjectarray(z).radius And x% > 0 And y% > 0 And x% < 960 And y% < 720 Then
If landscape(x%, y%) = 2 Then
landscapehealth(x%, y%) = landscapehealth(x%, y%) - 5
If landscapehealth(x%, y%) <= 0 Then
If Rnd < .005 Then
landscape(x%, y%) = 1
Else
landscape(x%, y%) = 0
End If
End If
End If
End If
Next y%
Next x%
End Select
Next z
lowfreqtimer# = lowfreqtimer# + 1 / 60
Wend
'DRAW EVERYTHING
Cls
'Draw visible portion of screen
DrawGrid screenx%, screeny%, scale#
DrawObjects screenx%, screeny%, scale#
'Cycle Through Game Objects for Graphical Effects
For x = 0 To UBound(gameobjectarray)
Select Case gameobjectarray(x).otype
Case -1 'BOX DESTRUCTION
drawpoints#(1, 1) = screenx% + (gameobjectarray(x).xpos + .707 * gameobjectarray(x).radius * Cos(gameobjectarray(x).angle) - 5 * Sin(gameobjectarray(x).angle)) * scale#
drawpoints#(1, 2) = screeny% + (gameobjectarray(x).ypos + .707 * gameobjectarray(x).radius * Sin(gameobjectarray(x).angle) + 5 * Cos(gameobjectarray(x).angle)) * scale#
drawpoints#(2, 1) = screenx% + (gameobjectarray(x).xpos + .707 * gameobjectarray(x).radius * Cos(gameobjectarray(x).angle) + 5 * Sin(gameobjectarray(x).angle)) * scale#
drawpoints#(2, 2) = screeny% + (gameobjectarray(x).ypos + .707 * gameobjectarray(x).radius * Sin(gameobjectarray(x).angle) - 5 * Cos(gameobjectarray(x).angle)) * scale#
drawpoints#(3, 1) = screenx% + (gameobjectarray(x).xpos + .707 * gameobjectarray(x).radius * Cos(gameobjectarray(x).angle + 2 * _Pi / 4) - 5 * Sin(gameobjectarray(x).angle + 2 * _Pi / 4)) * scale#
drawpoints#(3, 2) = screeny% + (gameobjectarray(x).ypos + .707 * gameobjectarray(x).radius * Sin(gameobjectarray(x).angle + 2 * _Pi / 4) + 5 * Cos(gameobjectarray(x).angle + 2 * _Pi / 4)) * scale#
drawpoints#(4, 1) = screenx% + (gameobjectarray(x).xpos + .707 * gameobjectarray(x).radius * Cos(gameobjectarray(x).angle + 2 * _Pi / 4) + 5 * Sin(gameobjectarray(x).angle + 2 * _Pi / 4)) * scale#
drawpoints#(4, 2) = screeny% + (gameobjectarray(x).ypos + .707 * gameobjectarray(x).radius * Sin(gameobjectarray(x).angle + 2 * _Pi / 4) - 5 * Cos(gameobjectarray(x).angle + 2 * _Pi / 4)) * scale#
drawpoints#(5, 1) = screenx% + (gameobjectarray(x).xpos + .707 * gameobjectarray(x).radius * Cos(gameobjectarray(x).angle + 4 * _Pi / 4) - 5 * Sin(gameobjectarray(x).angle + 4 * _Pi / 4)) * scale#
drawpoints#(5, 2) = screeny% + (gameobjectarray(x).ypos + .707 * gameobjectarray(x).radius * Sin(gameobjectarray(x).angle + 4 * _Pi / 4) + 5 * Cos(gameobjectarray(x).angle + 4 * _Pi / 4)) * scale#
drawpoints#(6, 1) = screenx% + (gameobjectarray(x).xpos + .707 * gameobjectarray(x).radius * Cos(gameobjectarray(x).angle + 4 * _Pi / 4) + 5 * Sin(gameobjectarray(x).angle + 4 * _Pi / 4)) * scale#
drawpoints#(6, 2) = screeny% + (gameobjectarray(x).ypos + .707 * gameobjectarray(x).radius * Sin(gameobjectarray(x).angle + 4 * _Pi / 4) - 5 * Cos(gameobjectarray(x).angle + 4 * _Pi / 4)) * scale#
drawpoints#(7, 1) = screenx% + (gameobjectarray(x).xpos + .707 * gameobjectarray(x).radius * Cos(gameobjectarray(x).angle + 6 * _Pi / 4) - 5 * Sin(gameobjectarray(x).angle + 6 * _Pi / 4)) * scale#
drawpoints#(7, 2) = screeny% + (gameobjectarray(x).ypos + .707 * gameobjectarray(x).radius * Sin(gameobjectarray(x).angle + 6 * _Pi / 4) + 5 * Cos(gameobjectarray(x).angle + 6 * _Pi / 4)) * scale#
drawpoints#(8, 1) = screenx% + (gameobjectarray(x).xpos + .707 * gameobjectarray(x).radius * Cos(gameobjectarray(x).angle + 6 * _Pi / 4) + 5 * Sin(gameobjectarray(x).angle + 6 * _Pi / 4)) * scale#
drawpoints#(8, 2) = screeny% + (gameobjectarray(x).ypos + .707 * gameobjectarray(x).radius * Sin(gameobjectarray(x).angle + 6 * _Pi / 4) - 5 * Cos(gameobjectarray(x).angle + 6 * _Pi / 4)) * scale#
Line (drawpoints#(1, 1), drawpoints#(1, 2))-(drawpoints#(2, 1), drawpoints#(2, 2)), _RGB(255, 0, 0)
Line (drawpoints#(3, 1), drawpoints#(3, 2))-(drawpoints#(4, 1), drawpoints#(4, 2)), _RGB(255, 0, 0)
Line (drawpoints#(5, 1), drawpoints#(5, 2))-(drawpoints#(6, 1), drawpoints#(6, 2)), _RGB(255, 0, 0)
Line (drawpoints#(7, 1), drawpoints#(7, 2))-(drawpoints#(8, 1), drawpoints#(8, 2)), _RGB(255, 0, 0)
Circle (screenx% + gameobjectarray(x).xpos * scale#, screeny% + gameobjectarray(x).ypos * scale#), gameobjectarray(x).radius * scale#, _RGB(255, 50, 12)
Case 1 'Appearing Box
Circle (screenx% + gameobjectarray(x).xpos * scale#, screeny% + gameobjectarray(x).ypos * scale#), scale# * (7 * (2 - (gameobjectarray(x).time - gametimer#))), _RGB(0, 39, 255)
Circle (screenx% + gameobjectarray(x).xpos * scale#, screeny% + gameobjectarray(x).ypos * scale#), scale# * (6 * (2 - (gameobjectarray(x).time - gametimer#))), _RGB(0, 122, 255)
Circle (screenx% + gameobjectarray(x).xpos * scale#, screeny% + gameobjectarray(x).ypos * scale#), scale# * (5 * (2 - (gameobjectarray(x).time - gametimer#))), _RGB(0, 168, 255)
Line (screenx% + (gameobjectarray(x).xpos - (3 * (2 - (gameobjectarray(x).time - gametimer#)))) * scale#, screeny% + (gameobjectarray(x).ypos - (3 * (2 - (gameobjectarray(x).time - gametimer#)))) * scale#)-(screenx% + (gameobjectarray(x).xpos + (3 * (2 - (gameobjectarray(x).time - gametimer#)))) * scale#, screeny% + (gameobjectarray(x).ypos + (3 * (2 - (gameobjectarray(x).time - gametimer#)))) * scale#), _RGB(255, 0, 0), B
Case 2 'Disappearing Box
'Line (screenx% + (gameobjectarray(x).xpos - (9 * ((gameobjectarray(x).time - gametimer#)))) * scale#, screeny% + (gameobjectarray(x).ypos - (9 * ((gameobjectarray(x).time - gametimer#)))) * scale#)-(screenx% + (gameobjectarray(x).xpos + (9 * ((gameobjectarray(x).time - gametimer#)))) * scale#, screeny% + (gameobjectarray(x).ypos + (9 * ((gameobjectarray(x).time - gametimer#)))) * scale#), _RGB(255, 0, 0), B
drawpoints#(1, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * Cos(gameobjectarray(x).angle + _Pi / 4)) * scale#
drawpoints#(1, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * Sin(gameobjectarray(x).angle + _Pi / 4)) * scale#
drawpoints#(2, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * Cos(gameobjectarray(x).angle + 3 * _Pi / 4)) * scale#
drawpoints#(2, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * Sin(gameobjectarray(x).angle + 3 * _Pi / 4)) * scale#
drawpoints#(3, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * Cos(gameobjectarray(x).angle + 5 * _Pi / 4)) * scale#
drawpoints#(3, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * Sin(gameobjectarray(x).angle + 5 * _Pi / 4)) * scale#
drawpoints#(4, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * Cos(gameobjectarray(x).angle + 7 * _Pi / 4)) * scale#
drawpoints#(4, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * Sin(gameobjectarray(x).angle + 7 * _Pi / 4)) * scale#
Line (drawpoints#(1, 1), drawpoints#(1, 2))-(drawpoints#(2, 1), drawpoints#(2, 2)), _RGB(255, 0, 0)
Line (drawpoints#(2, 1), drawpoints#(2, 2))-(drawpoints#(3, 1), drawpoints#(3, 2)), _RGB(255, 0, 0)
Line (drawpoints#(3, 1), drawpoints#(3, 2))-(drawpoints#(4, 1), drawpoints#(4, 2)), _RGB(255, 0, 0)
Line (drawpoints#(4, 1), drawpoints#(4, 2))-(drawpoints#(1, 1), drawpoints#(1, 2)), _RGB(255, 0, 0)
Case 3 'Away Magnet
Circle (screenx% + gameobjectarray(x).xpos * scale#, screeny% + gameobjectarray(x).ypos * scale#), gameobjectarray(x).radius * scale#, _RGB(0, 122, 255)
Circle (screenx% + gameobjectarray(x).xpos * scale#, screeny% + gameobjectarray(x).ypos * scale#), gameobjectarray(x).radius * scale# * .92, _RGB(0, 100, 255)
Circle (screenx% + gameobjectarray(x).xpos * scale#, screeny% + gameobjectarray(x).ypos * scale#), gameobjectarray(x).radius * scale# * (4 * (1.5 - (gameobjectarray(x).time - gametimer#) / 1.5) - Int(4 * (1.5 - (gameobjectarray(x).time - gametimer#) / 1.5))), _RGB(6, 205, 255)
Case 4 'Pull Magnet
Circle (screenx% + gameobjectarray(x).xpos * scale#, screeny% + gameobjectarray(x).ypos * scale#), gameobjectarray(x).radius * scale#, _RGB(122, 5, 255)
Circle (screenx% + gameobjectarray(x).xpos * scale#, screeny% + gameobjectarray(x).ypos * scale#), gameobjectarray(x).radius * scale# * .92, _RGB(105, 55, 161)
Circle (screenx% + gameobjectarray(x).xpos * scale#, screeny% + gameobjectarray(x).ypos * scale#), gameobjectarray(x).radius * scale# * (4 * ((gameobjectarray(x).time - gametimer#) / 2.0) - Int(4 * (gameobjectarray(x).time - gametimer#) / 2.0)), _RGB(172, 133, 216)
Case 5 'MAGNET BOMB
drawpoints#(1, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * Cos(2 * _Pi * (1.5 - (gameobjectarray(x).time - gametimer#) / 1.5) + _Pi / 4)) * scale#
drawpoints#(1, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * Sin(2 * _Pi * (1.5 - (gameobjectarray(x).time - gametimer#) / 1.5) + _Pi / 4)) * scale#
drawpoints#(2, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * Cos(2 * _Pi * (1.5 - (gameobjectarray(x).time - gametimer#) / 1.5) + 3 * _Pi / 4)) * scale#
drawpoints#(2, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * Sin(2 * _Pi * (1.5 - (gameobjectarray(x).time - gametimer#) / 1.5) + 3 * _Pi / 4)) * scale#
drawpoints#(3, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * Cos(2 * _Pi * (1.5 - (gameobjectarray(x).time - gametimer#) / 1.5) + 5 * _Pi / 4)) * scale#
drawpoints#(3, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * Sin(2 * _Pi * (1.5 - (gameobjectarray(x).time - gametimer#) / 1.5) + 5 * _Pi / 4)) * scale#
drawpoints#(4, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * Cos(2 * _Pi * (1.5 - (gameobjectarray(x).time - gametimer#) / 1.5) + 7 * _Pi / 4)) * scale#
drawpoints#(4, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * Sin(2 * _Pi * (1.5 - (gameobjectarray(x).time - gametimer#) / 1.5) + 7 * _Pi / 4)) * scale#
drawpoints#(5, 1) = screenx% + gameobjectarray(x).xpos * scale#
drawpoints#(5, 2) = screeny% + gameobjectarray(x).ypos * scale#
drawpoints#(6, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * Cos(2 * _Pi * ((gameobjectarray(x).time - gametimer#) / 1.5) + _Pi / 4)) * scale#
drawpoints#(6, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * Sin(2 * _Pi * ((gameobjectarray(x).time - gametimer#) / 1.5) + _Pi / 4)) * scale#
drawpoints#(7, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * Cos(2 * _Pi * ((gameobjectarray(x).time - gametimer#) / 1.5) + 3 * _Pi / 4)) * scale#
drawpoints#(7, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * Sin(2 * _Pi * ((gameobjectarray(x).time - gametimer#) / 1.5) + 3 * _Pi / 4)) * scale#
drawpoints#(8, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * Cos(2 * _Pi * ((gameobjectarray(x).time - gametimer#) / 1.5) + 5 * _Pi / 4)) * scale#
drawpoints#(8, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * Sin(2 * _Pi * ((gameobjectarray(x).time - gametimer#) / 1.5) + 5 * _Pi / 4)) * scale#
drawpoints#(9, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * Cos(2 * _Pi * ((gameobjectarray(x).time - gametimer#) / 1.5) + 7 * _Pi / 4)) * scale#
drawpoints#(9, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * Sin(2 * _Pi * ((gameobjectarray(x).time - gametimer#) / 1.5) + 7 * _Pi / 4)) * scale#
Line (drawpoints#(5, 1), drawpoints#(5, 2))-(drawpoints#(2, 1), drawpoints#(2, 2)), _RGB(255, 0, 0)
Line (drawpoints#(5, 1), drawpoints#(5, 2))-(drawpoints#(3, 1), drawpoints#(3, 2)), _RGB(255, 0, 0)
Line (drawpoints#(5, 1), drawpoints#(5, 2))-(drawpoints#(4, 1), drawpoints#(4, 2)), _RGB(255, 0, 0)
Line (drawpoints#(5, 1), drawpoints#(5, 2))-(drawpoints#(1, 1), drawpoints#(1, 2)), _RGB(255, 0, 0)
Line (drawpoints#(5, 1), drawpoints#(5, 2))-(drawpoints#(6, 1), drawpoints#(6, 2)), _RGB(255, 0, 0)
Line (drawpoints#(5, 1), drawpoints#(5, 2))-(drawpoints#(7, 1), drawpoints#(7, 2)), _RGB(255, 0, 0)
Line (drawpoints#(5, 1), drawpoints#(5, 2))-(drawpoints#(8, 1), drawpoints#(8, 2)), _RGB(255, 0, 0)
Line (drawpoints#(5, 1), drawpoints#(5, 2))-(drawpoints#(9, 1), drawpoints#(9, 2)), _RGB(255, 0, 0)
Circle (screenx% + gameobjectarray(x).xpos * scale#, screeny% + gameobjectarray(x).ypos * scale#), gameobjectarray(x).radius * scale#, _RGB(255, 11, 12)
Case 6 'BUILD BOX
drawpoints#(1, 1) = screenx% + (gameobjectarray(x).xpos + .707 * gameobjectarray(x).radius * Cos(gameobjectarray(x).angle + _Pi / 4)) * scale#
drawpoints#(1, 2) = screeny% + (gameobjectarray(x).ypos + .707 * gameobjectarray(x).radius * Sin(gameobjectarray(x).angle + _Pi / 4)) * scale#
drawpoints#(2, 1) = screenx% + (gameobjectarray(x).xpos + .707 * gameobjectarray(x).radius * Cos(gameobjectarray(x).angle + 3 * _Pi / 4)) * scale#
drawpoints#(2, 2) = screeny% + (gameobjectarray(x).ypos + .707 * gameobjectarray(x).radius * Sin(gameobjectarray(x).angle + 3 * _Pi / 4)) * scale#
drawpoints#(3, 1) = screenx% + (gameobjectarray(x).xpos + .707 * gameobjectarray(x).radius * Cos(gameobjectarray(x).angle + 5 * _Pi / 4)) * scale#
drawpoints#(3, 2) = screeny% + (gameobjectarray(x).ypos + .707 * gameobjectarray(x).radius * Sin(gameobjectarray(x).angle + 5 * _Pi / 4)) * scale#
drawpoints#(4, 1) = screenx% + (gameobjectarray(x).xpos + .707 * gameobjectarray(x).radius * Cos(gameobjectarray(x).angle + 7 * _Pi / 4)) * scale#
drawpoints#(4, 2) = screeny% + (gameobjectarray(x).ypos + .707 * gameobjectarray(x).radius * Sin(gameobjectarray(x).angle + 7 * _Pi / 4)) * scale#
Line (drawpoints#(1, 1), drawpoints#(1, 2))-(drawpoints#(2, 1), drawpoints#(2, 2)), _RGB(255, 255, 255)
Line (drawpoints#(2, 1), drawpoints#(2, 2))-(drawpoints#(3, 1), drawpoints#(3, 2)), _RGB(255, 255, 255)
Line (drawpoints#(3, 1), drawpoints#(3, 2))-(drawpoints#(4, 1), drawpoints#(4, 2)), _RGB(255, 255, 255)
Line (drawpoints#(4, 1), drawpoints#(4, 2))-(drawpoints#(1, 1), drawpoints#(1, 2)), _RGB(255, 255, 255)
Case 7 'SMALL BOMB
temp# = Rnd * .125
drawpoints#(1, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Cos(2 * _Pi * temp#)) * scale#
drawpoints#(1, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Sin(2 * _Pi * temp#)) * scale#
temp# = Rnd * .125 + .125
drawpoints#(2, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Cos(2 * _Pi * temp#)) * scale#
drawpoints#(2, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Sin(2 * _Pi * temp#)) * scale#
temp# = Rnd * .125 + .25
drawpoints#(3, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Cos(2 * _Pi * temp#)) * scale#
drawpoints#(3, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Sin(2 * _Pi * temp#)) * scale#
temp# = Rnd * .125 + .375
drawpoints#(4, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Cos(2 * _Pi * temp#)) * scale#
drawpoints#(4, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Sin(2 * _Pi * temp#)) * scale#
temp# = Rnd * .125 + 0.5
drawpoints#(5, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Cos(2 * _Pi * temp#)) * scale#
drawpoints#(5, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Sin(2 * _Pi * temp#)) * scale#
temp# = Rnd * .125 + .625
drawpoints#(6, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Cos(2 * _Pi * temp#)) * scale#
drawpoints#(6, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Sin(2 * _Pi * temp#)) * scale#
temp# = Rnd * .125 + .75
drawpoints#(7, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Cos(2 * _Pi * temp#)) * scale#
drawpoints#(7, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Sin(2 * _Pi * temp#)) * scale#
temp# = Rnd * .125 + .875
drawpoints#(8, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Cos(2 * _Pi * temp#)) * scale#
drawpoints#(8, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Sin(2 * _Pi * temp#)) * scale#
Line (drawpoints#(1, 1), drawpoints#(1, 2))-(drawpoints#(2, 1), drawpoints#(2, 2)), _RGB(255, Int(Rnd * 40), Int(Rnd * 40))
Line (drawpoints#(2, 1), drawpoints#(2, 2))-(drawpoints#(3, 1), drawpoints#(3, 2)), _RGB(255, Int(Rnd * 40), Int(Rnd * 40))
Line (drawpoints#(3, 1), drawpoints#(3, 2))-(drawpoints#(4, 1), drawpoints#(4, 2)), _RGB(255, Int(Rnd * 40), Int(Rnd * 40))
Line (drawpoints#(4, 1), drawpoints#(4, 2))-(drawpoints#(5, 1), drawpoints#(5, 2)), _RGB(255, Int(Rnd * 40), Int(Rnd * 40))
Line (drawpoints#(5, 1), drawpoints#(5, 2))-(drawpoints#(6, 1), drawpoints#(6, 2)), _RGB(255, Int(Rnd * 40), Int(Rnd * 40))
Line (drawpoints#(6, 1), drawpoints#(6, 2))-(drawpoints#(7, 1), drawpoints#(7, 2)), _RGB(255, Int(Rnd * 40), Int(Rnd * 40))
Line (drawpoints#(7, 1), drawpoints#(7, 2))-(drawpoints#(8, 1), drawpoints#(8, 2)), _RGB(255, Int(Rnd * 40), Int(Rnd * 40))
Line (drawpoints#(8, 1), drawpoints#(8, 2))-(drawpoints#(1, 1), drawpoints#(1, 2)), _RGB(255, Int(Rnd * 40), Int(Rnd * 40))
Circle (screenx% + gameobjectarray(x).xpos * scale#, screeny% + gameobjectarray(x).ypos * scale#), gameobjectarray(x).radius * scale#, _RGB(255, 50, 12)
Case 8 'LARGE BOMB
temp# = Rnd * .125
drawpoints#(1, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Cos(2 * _Pi * temp#)) * scale#
drawpoints#(1, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Sin(2 * _Pi * temp#)) * scale#
temp# = Rnd * .125 + .125
drawpoints#(2, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Cos(2 * _Pi * temp#)) * scale#
drawpoints#(2, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Sin(2 * _Pi * temp#)) * scale#
temp# = Rnd * .125 + .25
drawpoints#(3, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Cos(2 * _Pi * temp#)) * scale#
drawpoints#(3, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Sin(2 * _Pi * temp#)) * scale#
temp# = Rnd * .125 + .375
drawpoints#(4, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Cos(2 * _Pi * temp#)) * scale#
drawpoints#(4, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Sin(2 * _Pi * temp#)) * scale#
temp# = Rnd * .125 + 0.5
drawpoints#(5, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Cos(2 * _Pi * temp#)) * scale#
drawpoints#(5, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Sin(2 * _Pi * temp#)) * scale#
temp# = Rnd * .125 + .625
drawpoints#(6, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Cos(2 * _Pi * temp#)) * scale#
drawpoints#(6, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Sin(2 * _Pi * temp#)) * scale#
temp# = Rnd * .125 + .75
drawpoints#(7, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Cos(2 * _Pi * temp#)) * scale#
drawpoints#(7, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Sin(2 * _Pi * temp#)) * scale#
temp# = Rnd * .125 + .875
drawpoints#(8, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Cos(2 * _Pi * temp#)) * scale#
drawpoints#(8, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Sin(2 * _Pi * temp#)) * scale#
temp# = Rnd * .125
drawpoints#(9, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Cos(2 * _Pi * temp#)) * scale#
drawpoints#(9, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Sin(2 * _Pi * temp#)) * scale#
temp# = Rnd * .125 + .125
drawpoints#(10, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Cos(2 * _Pi * temp#)) * scale#
drawpoints#(10, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Sin(2 * _Pi * temp#)) * scale#
temp# = Rnd * .125 + .25
drawpoints#(11, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Cos(2 * _Pi * temp#)) * scale#
drawpoints#(11, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Sin(2 * _Pi * temp#)) * scale#
temp# = Rnd * .125 + .375
drawpoints#(12, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Cos(2 * _Pi * temp#)) * scale#
drawpoints#(12, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Sin(2 * _Pi * temp#)) * scale#
temp# = Rnd * .125 + 0.5
drawpoints#(13, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Cos(2 * _Pi * temp#)) * scale#
drawpoints#(13, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Sin(2 * _Pi * temp#)) * scale#
temp# = Rnd * .125 + .625
drawpoints#(14, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Cos(2 * _Pi * temp#)) * scale#
drawpoints#(14, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Sin(2 * _Pi * temp#)) * scale#
temp# = Rnd * .125 + .75
drawpoints#(15, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Cos(2 * _Pi * temp#)) * scale#
drawpoints#(15, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Sin(2 * _Pi * temp#)) * scale#
temp# = Rnd * .125 + .875
drawpoints#(16, 1) = screenx% + (gameobjectarray(x).xpos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Cos(2 * _Pi * temp#)) * scale#
drawpoints#(16, 2) = screeny% + (gameobjectarray(x).ypos + gameobjectarray(x).radius * (Rnd * .4 + 0.8) * Sin(2 * _Pi * temp#)) * scale#
Line (drawpoints#(1, 1), drawpoints#(1, 2))-(drawpoints#(2, 1), drawpoints#(2, 2)), _RGB(255, Int(Rnd * 40), Int(Rnd * 40))
Line (drawpoints#(2, 1), drawpoints#(2, 2))-(drawpoints#(3, 1), drawpoints#(3, 2)), _RGB(255, Int(Rnd * 40), Int(Rnd * 40))
Line (drawpoints#(3, 1), drawpoints#(3, 2))-(drawpoints#(4, 1), drawpoints#(4, 2)), _RGB(255, Int(Rnd * 40), Int(Rnd * 40))
Line (drawpoints#(4, 1), drawpoints#(4, 2))-(drawpoints#(5, 1), drawpoints#(5, 2)), _RGB(255, Int(Rnd * 40), Int(Rnd * 40))
Line (drawpoints#(5, 1), drawpoints#(5, 2))-(drawpoints#(6, 1), drawpoints#(6, 2)), _RGB(255, Int(Rnd * 40), Int(Rnd * 40))
Line (drawpoints#(6, 1), drawpoints#(6, 2))-(drawpoints#(7, 1), drawpoints#(7, 2)), _RGB(255, Int(Rnd * 40), Int(Rnd * 40))
Line (drawpoints#(7, 1), drawpoints#(7, 2))-(drawpoints#(8, 1), drawpoints#(8, 2)), _RGB(255, Int(Rnd * 40), Int(Rnd * 40))
Line (drawpoints#(8, 1), drawpoints#(8, 2))-(drawpoints#(1, 1), drawpoints#(1, 2)), _RGB(255, Int(Rnd * 40), Int(Rnd * 40))
Line (drawpoints#(9, 1), drawpoints#(9, 2))-(drawpoints#(10, 1), drawpoints#(10, 2)), _RGB(255, Int(Rnd * 40), Int(Rnd * 40))
Line (drawpoints#(10, 1), drawpoints#(10, 2))-(drawpoints#(11, 1), drawpoints#(11, 2)), _RGB(255, Int(Rnd * 40), Int(Rnd * 40))
Line (drawpoints#(11, 1), drawpoints#(11, 2))-(drawpoints#(12, 1), drawpoints#(12, 2)), _RGB(255, Int(Rnd * 40), Int(Rnd * 40))
Line (drawpoints#(12, 1), drawpoints#(12, 2))-(drawpoints#(13, 1), drawpoints#(13, 2)), _RGB(255, Int(Rnd * 40), Int(Rnd * 40))
Line (drawpoints#(13, 1), drawpoints#(13, 2))-(drawpoints#(14, 1), drawpoints#(14, 2)), _RGB(255, Int(Rnd * 40), Int(Rnd * 40))
Line (drawpoints#(14, 1), drawpoints#(14, 2))-(drawpoints#(15, 1), drawpoints#(15, 2)), _RGB(255, Int(Rnd * 40), Int(Rnd * 40))
Line (drawpoints#(15, 1), drawpoints#(15, 2))-(drawpoints#(16, 1), drawpoints#(16, 2)), _RGB(255, Int(Rnd * 40), Int(Rnd * 40))
Line (drawpoints#(16, 1), drawpoints#(16, 2))-(drawpoints#(9, 1), drawpoints#(9, 2)), _RGB(255, Int(Rnd * 40), Int(Rnd * 40))
Circle (screenx% + gameobjectarray(x).xpos * scale#, screeny% + gameobjectarray(x).ypos * scale#), gameobjectarray(x).radius * scale#, _RGB(233, 28, 0)
Circle (screenx% + gameobjectarray(x).xpos * scale#, screeny% + gameobjectarray(x).ypos * scale#), gameobjectarray(x).radius * scale#, _RGB(255, 50, 12)
End Select
Next x
'Print 1 / (Timer(.0001) - looptimer#) 'Prints Framrate
'Print collisioncounter%
'Print mouseymatrix%
'Draw Screen Features
Line (0, 0)-(479, 359), _RGB(0, 255, 0), B
Line (480, 0)-(719, 359), _RGB(0, 0, 0), BF 'blacks out part of screen on the right, because limits aren't perfect
'Draw Text/etc on right hand panel
'Print screenx%
'Print screeny%
Locate 2, 62
Color _RGB(0, 255, 72)
Select Case cursorstyle%
Case 1
Print "PLACE OBJECTS"
Case 2
Print "DRAW SOFT"
Case 3
Print "ERASE"
Case 4
Print "PUSH MAGNET"
Case 5
Print "PULL MAGNET"
Case 6
Print "MAGNET BOMB"
Case 7
Print "BUILD BOX"
Case 8
Print "SMALL BOMB"
Case 9
Print "LARGE BOMB"
Case 10
Print "DRAW HARD"
End Select
Locate 3, 62
Color _RGB(255, 255, 255)
Print "COST:"
Locate 3, 68
Print costarray%(cursorstyle%)
If cursorstyle% = 2 Or cursorstyle% = 3 Then
Locate 4, 62
Print "PER SPOT"
End If
Select Case pwarning%
Case 1
Locate 4, 62
Print "ILLEGAL LOCATION"
Case 2
Locate 4, 62
Print "OUT OF BOUNDS"
End Select
Locate 1, 62
Color _RGB(255, 255, 255)
Print "TIME:"
Locate 1, 68
Print Int(scoretimer# - gametimer#)
Locate 5, 62
Color _RGB(0, 139, 0)
Print "MONEY"
Locate 6, 63
Print money%
Locate 7, 62
Color _RGB(55, 78, 227)
Print "BOXES SAVED"
Locate 8, 63
Print boxsaved%
Locate 9, 62
Color _RGB(255, 55, 55)
Print "BOXES LOST"
Locate 10, 63
Print boxdestroyed%
'Draw Mouse Last
Line (mousexpos%, mouseypos%)-(mousexpos% + 3, mouseypos%), _RGB(255, 255, 255)
Line (mousexpos%, mouseypos%)-(mousexpos%, mouseypos% + 3), _RGB(255, 255, 255)
Line (mousexpos%, mouseypos%)-(mousexpos% + 4, mouseypos% + 4), _RGB(255, 255, 255)
_Display
looptimer# = Timer(.0001)
_Limit framelimit
Wend
Close #5
'Close #6
outputobjects
'End Screen
Cls
Color _RGB(44, 177, 227)
Locate 2, 36
Print "BOX BASH"
'80 Characters across
Locate 4, 34
Color _RGB(211, 72, 127)
Print "BOXES SAVED:"
Locate 6, 38
Print boxsaved%
Locate 8, 32
Color _RGB(39, 188, 133)
Print "BOXES DESTROYED:"
Locate 10, 38
Print boxdestroyed%
Locate 12, 34
Color _RGB(238, 83, 200)
Print "FINAL SCORE:"
Locate 14, 38
Print boxsaved% * 100 - boxdestroyed% * 10
Locate 18, 28
Color _RGB(94, 205, 28)
Print "Press Any Key To Continue"
_Display
Sleep 5
Sub PhysicsCollisions
Dim numobjects%, initialimpact%, initialimpactenvironment%
numobjects% = UBound(objects, 1)
ReDim corners#(numobjects%, 7) 'without _PRESERVE all values become 0
Dim forcelist#(collisionperobjectlimit%, 2)
Dim finalforcelist#(collisionperobjectlimit%, 2)
Dim normx#, normy#, tx#, ty#, ttorque#, sum#
Dim distance#, dot#, dist#, angle1#, angle2#, dist1#, dist2#, correction#, pangle#, vangle#, fangle#
Dim numadjacent% 'number of adjacent cubes
Dim playsound1%, playsound2%
Dim tvx#, tvy#, cpx#, cpy# 'Total Velocity & collision Point
Dim textstring$
playsound1% = 0
playsound2% = 0
'object type 1 is fixed, never moves ever
'If write1%=1 Then Print #5, "OBJECT 1 INFO FIRST UPDATE: ", objects(0, 4), objects(0, 5), objects(0, 6), objects(0, 7), objects(0, 14), objects(0, 15)
'Compute Physics
update_non_screen_corners
'Update accelerations based off of force in splots 8 and 9, and angular acceleration based off of Torque and I in 16
Dim totalforcecounter%, tcheck%
Dim rotperc#, transperc#
Dim xmincorner%, ymincorner%, xmaxcorner%, ymaxcorner%
For i% = 0 To numobjects%
'PHYSICS
'GRAVITY
If objects(i%, 0) > 1 Then
objects(i%, 8) = 0 'x accel
objects(i%, 16) = 0 'angular accel
If objects(i%, 0) = 2 Then
objects(i%, 9) = gravity#
Else
objects(i%, 9) = 0
End If
End If
initialimpact% = objects(i%, 17)
initialimpactenvironment% = objects(i%, 10)
tx# = 0
ty# = 0
ttorque# = 0
objects(i%, 17) = 0 'reset number of objects hitting each round
objects(i%, 10) = 0 'Same for environment boxes
totalforcecounter% = 0
ReDim forcelist#(collisionperobjectlimit%, 2) 'also clears all values
ReDim finalforcelist#(collisionperobjectlimit%, 2)
'FIND COLLISIONS
If objects(i%, 0) <> 1 And objects(i%, 0) <> 0 Then 'Force Calculations not needed for things that are fixed or don't exist
For j% = 0 To numobjects%
If j% <> i% And objects(j%, 0) <> 0 Then 'don't include self intersections or j items that don't exists
'Weed out things that are too far apart
distance# = Sqr((objects(i%, 4) - objects(j%, 4)) ^ 2 + (objects(i%, 5) - objects(j%, 5)) ^ 2)
If distance# < (1.42 * objects(i%, 2) + 1.42 * objects(j%, 2)) Then
If write1% = 1 Then Print #5, ""
If write1% = 1 Then Print #5, "CALCULATING OBJECT ", i%, " AGAINST OBJECT ", j%
'textstring$ = "Newobject 1, 10, " + Str$(objects(i%, 2)) + ", 10, " + Str$(objects(i%, 4)) + ", " + Str$(objects(i%, 5)) + ", 0, 0, 0, 0, 0, " + Str$(objects(i%, 14)) + ", 0, 0, 0"
'If write1% = 1 Then Print #5, textstring$ '(otype%, health#, size#, mass#, xpos#, ypos#, xvel#, yvel#, xacc#, yacc#, forcereturn#, angle#, anglevel#)"
'textstring$ = "Newobject 1, 10, " + Str$(objects(j%, 2)) + ", 10, " + Str$(objects(j%, 4)) + ", " + Str$(objects(j%, 5)) + ", 0, 0, 0, 0, 0, " + Str$(objects(j%, 14)) + ", 0, 0, 0"
'If write1% = 1 Then Print #5, textstring$ '(otype%, health#, size#, mass#, xpos#, ypos#, xvel#, yvel#, xacc#, yacc#, forcereturn#, angle#, anglevel#)"
'touching forces: the idea is each objects acts a little bit like a spring
tcheck% = totalforcecounter%
If touchcondition% = 1 Then
If In4Points%(springcorners#(i%, 0), springcorners#(i%, 1), springcorners#(j%, 0), springcorners#(j%, 1), springcorners#(j%, 2), springcorners#(j%, 3), springcorners#(j%, 4), springcorners#(j%, 5), springcorners#(j%, 6), springcorners#(j%, 7)) = 1 Then
'If write1%=1 Then Print #5, "TCORNER 1"
inner_collision springcorners#(i%, 0), springcorners#(i%, 1), i%, j%, totalforcecounter%, forcelist#() 'This sub updates forcelist# at index totalforcecounter%
End If
If In4Points%(springcorners#(i%, 2), springcorners#(i%, 3), springcorners#(j%, 0), springcorners#(j%, 1), springcorners#(j%, 2), springcorners#(j%, 3), springcorners#(j%, 4), springcorners#(j%, 5), springcorners#(j%, 6), springcorners#(j%, 7)) = 1 Then
'If write1%=1 Then Print #5, "TCORNER 2"
inner_collision springcorners#(i%, 2), springcorners#(i%, 3), i%, j%, totalforcecounter%, forcelist#() 'This sub updates forcelist# at index totalforcecounter%
End If
If In4Points%(springcorners#(i%, 4), springcorners#(i%, 5), springcorners#(j%, 0), springcorners#(j%, 1), springcorners#(j%, 2), springcorners#(j%, 3), springcorners#(j%, 4), springcorners#(j%, 5), springcorners#(j%, 6), springcorners#(j%, 7)) = 1 Then
'If write1%=1 Then Print #5, "TCORNER 3"
inner_collision springcorners#(i%, 4), springcorners#(i%, 5), i%, j%, totalforcecounter%, forcelist#() 'This sub updates forcelist# at index totalforcecounter%
End If
If In4Points%(springcorners#(i%, 6), springcorners#(i%, 7), springcorners#(j%, 0), springcorners#(j%, 1), springcorners#(j%, 2), springcorners#(j%, 3), springcorners#(j%, 4), springcorners#(j%, 5), springcorners#(j%, 6), springcorners#(j%, 7)) = 1 Then
'If write1%=1 Then Print #5, "TCORNER 4"
inner_collision springcorners#(i%, 6), springcorners#(i%, 7), i%, j%, totalforcecounter%, forcelist#() 'This sub updates forcelist# at index totalforcecounter%
End If
If In4Points%(springcorners#(j%, 0), springcorners#(j%, 1), springcorners#(i%, 0), springcorners#(i%, 1), springcorners#(i%, 2), springcorners#(i%, 3), springcorners#(i%, 4), springcorners#(i%, 5), springcorners#(i%, 6), springcorners#(i%, 7)) = 1 Then
'If write1%=1 Then Print #5, "TCORNER 5"
inner_collision springcorners#(j%, 0), springcorners#(j%, 1), i%, j%, totalforcecounter%, forcelist#() 'This sub updates forcelist# at index totalforcecounter%
End If
If In4Points%(springcorners#(j%, 2), springcorners#(j%, 3), springcorners#(i%, 0), springcorners#(i%, 1), springcorners#(i%, 2), springcorners#(i%, 3), springcorners#(i%, 4), springcorners#(i%, 5), springcorners#(i%, 6), springcorners#(i%, 7)) = 1 Then
'If write1%=1 Then Print #5, "TCORNER 6"
inner_collision springcorners#(j%, 2), springcorners#(j%, 3), i%, j%, totalforcecounter%, forcelist#() 'This sub updates forcelist# at index totalforcecounter%
End If
If In4Points%(springcorners#(j%, 4), springcorners#(j%, 5), springcorners#(i%, 0), springcorners#(i%, 1), springcorners#(i%, 2), springcorners#(i%, 3), springcorners#(i%, 4), springcorners#(i%, 5), springcorners#(i%, 6), springcorners#(i%, 7)) = 1 Then
'If write1%=1 Then Print #5, "TCORNER 7"
inner_collision springcorners#(j%, 4), springcorners#(j%, 5), i%, j%, totalforcecounter%, forcelist#() 'This sub updates forcelist# at index totalforcecounter%
End If
If In4Points%(springcorners#(j%, 6), springcorners#(j%, 7), springcorners#(i%, 0), springcorners#(i%, 1), springcorners#(i%, 2), springcorners#(i%, 3), springcorners#(i%, 4), springcorners#(i%, 5), springcorners#(i%, 6), springcorners#(i%, 7)) = 1 Then
'If write1%=1 Then Print #5, "TCORNER 8"
inner_collision springcorners#(j%, 6), springcorners#(j%, 7), i%, j%, totalforcecounter%, forcelist#() 'This sub updates forcelist# at index totalforcecounter%
End If
End If
'If write1%=1 Then Print #5, "DISTANCE: ", distance#
' objects(i%, 6) * objects(j%, 6) + objects(i%, 7) * objects(j%, 7) 'dot product of vel vectors. useful?
' Dynamic forces
If In4Points%(corners#(i%, 0), corners#(i%, 1), corners#(j%, 0), corners#(j%, 1), corners#(j%, 2), corners#(j%, 3), corners#(j%, 4), corners#(j%, 5), corners#(j%, 6), corners#(j%, 7)) = 1 Then
'If write1%=1 Then Print #5, "CORNER 1"
outer_collision corners#(i%, 0), corners#(i%, 1), i%, j%, totalforcecounter%, forcelist#() 'This sub updates forcelist# at index totalforcecounter%
End If
If In4Points%(corners#(i%, 2), corners#(i%, 3), corners#(j%, 0), corners#(j%, 1), corners#(j%, 2), corners#(j%, 3), corners#(j%, 4), corners#(j%, 5), corners#(j%, 6), corners#(j%, 7)) = 1 Then
'If write1%=1 Then Print #5, "CORNER 2"
outer_collision corners#(i%, 2), corners#(i%, 3), i%, j%, totalforcecounter%, forcelist#() 'This sub updates forcelist# at index totalforcecounter%
End If
If In4Points%(corners#(i%, 4), corners#(i%, 5), corners#(j%, 0), corners#(j%, 1), corners#(j%, 2), corners#(j%, 3), corners#(j%, 4), corners#(j%, 5), corners#(j%, 6), corners#(j%, 7)) = 1 Then
'If write1%=1 Then Print #5, "CORNER 3"
outer_collision corners#(i%, 4), corners#(i%, 5), i%, j%, totalforcecounter%, forcelist#() 'This sub updates forcelist# at index totalforcecounter%
End If
If In4Points%(corners#(i%, 6), corners#(i%, 7), corners#(j%, 0), corners#(j%, 1), corners#(j%, 2), corners#(j%, 3), corners#(j%, 4), corners#(j%, 5), corners#(j%, 6), corners#(j%, 7)) = 1 Then
'If write1%=1 Then Print #5, "CORNER 4"
outer_collision corners#(i%, 6), corners#(i%, 7), i%, j%, totalforcecounter%, forcelist#() 'This sub updates forcelist# at index totalforcecounter%
End If
If In4Points%(corners#(j%, 0), corners#(j%, 1), corners#(i%, 0), corners#(i%, 1), corners#(i%, 2), corners#(i%, 3), corners#(i%, 4), corners#(i%, 5), corners#(i%, 6), corners#(i%, 7)) = 1 Then
'If write1%=1 Then Print #5, "CORNER 5"
outer_collision corners#(j%, 0), corners#(j%, 1), i%, j%, totalforcecounter%, forcelist#() 'This sub updates forcelist# at index totalforcecounter%
End If
If In4Points%(corners#(j%, 2), corners#(j%, 3), corners#(i%, 0), corners#(i%, 1), corners#(i%, 2), corners#(i%, 3), corners#(i%, 4), corners#(i%, 5), corners#(i%, 6), corners#(i%, 7)) = 1 Then
'If write1%=1 Then Print #5, "CORNER 6"
outer_collision corners#(j%, 2), corners#(j%, 3), i%, j%, totalforcecounter%, forcelist#() 'This sub updates forcelist# at index totalforcecounter%
End If
If In4Points%(corners#(j%, 4), corners#(j%, 5), corners#(i%, 0), corners#(i%, 1), corners#(i%, 2), corners#(i%, 3), corners#(i%, 4), corners#(i%, 5), corners#(i%, 6), corners#(i%, 7)) = 1 Then
'If write1%=1 Then Print #5, "CORNER 7"
outer_collision corners#(j%, 4), corners#(j%, 5), i%, j%, totalforcecounter%, forcelist#() 'This sub updates forcelist# at index totalforcecounter%
End If
If In4Points%(corners#(j%, 6), corners#(j%, 7), corners#(i%, 0), corners#(i%, 1), corners#(i%, 2), corners#(i%, 3), corners#(i%, 4), corners#(i%, 5), corners#(i%, 6), corners#(i%, 7)) = 1 Then
'If write1%=1 Then Print #5, "CORNER 8"
outer_collision corners#(j%, 6), corners#(j%, 7), i%, j%, totalforcecounter%, forcelist#() 'This sub updates forcelist# at index totalforcecounter%
End If
If tcheck% <> totalforcecounter% Then objects(i%, 17) = objects(i%, 17) + 1
If write1% = 1 Then Print #5, "TOUCH CHECK AND TOUCHFORCECOUNTER : ", tcheck%, totalforcecounter%, objects(i%, 17)
End If
End If
Next j%
'Cycle Through Game Objects For Physics Effects
For x = 0 To UBound(gameobjectarray)
distance# = Sqr((gameobjectarray(x).ypos - objects(i%, 5)) ^ 2 + (gameobjectarray(x).xpos - objects(i%, 4)) ^ 2)
Select Case gameobjectarray(x).otype
Case -1 'Box Explosion
If objects(i%, 0) >= 2 And distance# < gameobjectarray(x).radius + 0.5 * objects(i%, 2) Then
objects(i%, 8) = objects(i%, 8) + 80 * Cos(_Atan2(objects(i%, 5) - gameobjectarray(x).ypos, objects(i%, 4) - gameobjectarray(x).xpos))
objects(i%, 9) = objects(i%, 9) + 80 * Sin(_Atan2(objects(i%, 5) - gameobjectarray(x).ypos, objects(i%, 4) - gameobjectarray(x).xpos))
End If
Case 3 'Outward magnet
If objects(i%, 0) >= 2 And distance# < gameobjectarray(x).radius + 0.5 * objects(i%, 2) Then
objects(i%, 8) = objects(i%, 8) + 80 * Cos(_Atan2(objects(i%, 5) - gameobjectarray(x).ypos, objects(i%, 4) - gameobjectarray(x).xpos))
objects(i%, 9) = objects(i%, 9) + 80 * Sin(_Atan2(objects(i%, 5) - gameobjectarray(x).ypos, objects(i%, 4) - gameobjectarray(x).xpos))
End If
Case 4 'Inward magnet
If objects(i%, 0) >= 2 And distance# < gameobjectarray(x).radius + 0.5 * objects(i%, 2) Then
objects(i%, 8) = objects(i%, 8) - (300 - 300 * distance# ^ 4 / (distance# + 1) ^ 4 + 50) * Cos(_Atan2(objects(i%, 5) - gameobjectarray(x).ypos, objects(i%, 4) - gameobjectarray(x).xpos))
objects(i%, 9) = objects(i%, 9) - (300 - 300 * distance# ^ 4 / (distance# + 1) ^ 4 + 50) * Sin(_Atan2(objects(i%, 5) - gameobjectarray(x).ypos, objects(i%, 4) - gameobjectarray(x).xpos))
End If
Case 5 'MAGNET BOMB
If objects(i%, 0) >= 2 And distance# < gameobjectarray(x).radius + 0.5 * objects(i%, 2) Then
objects(i%, 8) = objects(i%, 8) + 180 * Cos(_Atan2(objects(i%, 5) - gameobjectarray(x).ypos, objects(i%, 4) - gameobjectarray(x).xpos))
objects(i%, 9) = objects(i%, 9) + 180 * Sin(_Atan2(objects(i%, 5) - gameobjectarray(x).ypos, objects(i%, 4) - gameobjectarray(x).xpos))
End If
Case 7 'Small Bomb
If objects(i%, 0) >= 2 And distance# < gameobjectarray(x).radius + 0.5 * objects(i%, 2) Then
objects(i%, 8) = objects(i%, 8) + 120 * Cos(_Atan2(objects(i%, 5) - gameobjectarray(x).ypos, objects(i%, 4) - gameobjectarray(x).xpos))
objects(i%, 9) = objects(i%, 9) + 120 * Sin(_Atan2(objects(i%, 5) - gameobjectarray(x).ypos, objects(i%, 4) - gameobjectarray(x).xpos))
End If
Case 8 'Large Bomb
If objects(i%, 0) >= 2 And distance# < gameobjectarray(x).radius + 0.5 * objects(i%, 2) Then
objects(i%, 8) = objects(i%, 8) + 200 * Cos(_Atan2(objects(i%, 5) - gameobjectarray(x).ypos, objects(i%, 4) - gameobjectarray(x).xpos))
objects(i%, 9) = objects(i%, 9) + 200 * Sin(_Atan2(objects(i%, 5) - gameobjectarray(x).ypos, objects(i%, 4) - gameobjectarray(x).xpos))
End If
End Select
Next x
'Add environment collisions here
xmincorner% = Int(objects(i%, 4) - objects(i%, 2) * .7072) - 1
ymincorner% = Int(objects(i%, 5) - objects(i%, 2) * .7072) - 1
xmaxcorner% = Int(objects(i%, 4) + objects(i%, 2) * .7072) + 2
ymaxcorner% = Int(objects(i%, 5) + objects(i%, 2) * .7072) + 2
If xmincorner% < 0 Then xmincorner% = 0
If xmincorner% > 960 Then xmincorner% = 960
If ymincorner% < 0 Then ymincorner% = 0
If ymincorner% > 720 Then ymincorner% = 720
If xmaxcorner% < 0 Then xmaxcorner% = 0
If xmaxcorner% > 960 Then xmaxcorner% = 960
If ymaxcorner% < 0 Then ymaxcorner% = 0
If ymaxcorner% > 720 Then ymaxcorner% = 720
'Print scalefactor%
'Dim valuex1#, valuex2#, valuey1#, valuey2#
If write1% = 1 Then
Print #5, ""
Print #5, "Environmental Collision START!"
'Print #5, xmincorner%, xmaxcorner%
'Print #5, ymincorner%, ymaxcorner%
End If
For down% = ymincorner% To ymaxcorner% Step 1
For across% = xmincorner% To xmaxcorner% Step 1
If landscape(across%, down%) >= 2 Then
dist# = Sqr((objects(i%, 4) - across%) ^ 2 + (objects(i%, 5) - down%) ^ 2)
angle1# = _Atan2(objects(i%, 5) - down%, objects(i%, 4) - across%) - 0 'from environment box to cursor box, relative to fixed box
angle2# = _Atan2(down% - objects(i%, 5), across% - objects(i%, 4)) - objects(i%, 14) 'from cursor box to environment box relative to cursor box
'dist1# = 1 / 2 * (1.12412487 - 0.158465548 * Cos(4 * angle1#) + 0.04980645 * Cos(8 * angle1#) - 0.023735474 * Cos(12 * angle1#) + 0.0136513 * Cos(16 * angle1#) - 0.0088865545 * Cos(20 * angle1#))
dist1# = 1 / 2 * radialsquare(angle1#)
'dist2# = objects(i%, 2) / 2 * (1.12412487 - 0.158465548 * Cos(4 * angle2#) + 0.04980645 * Cos(8 * angle2#) - 0.023735474 * Cos(12 * angle2#) + 0.0136513 * Cos(16 * angle2#) - 0.0088865545 * Cos(20 * angle2#))
dist2# = objects(i%, 2) / 2 * radialsquare(angle2#)
correction# = (0.5 * Cos(4 * ((objects(i%, 14) - 0) - _Pi / 4)) + 0.5) * (0.5 * Cos(4 * ((angle1# - 0) - _Pi / 4)) + 0.5) * (0.5 * (Sqr(2) - 1) * (objects(i%, 2) / 2 + 1 / 2))
'use law of cosines to calculate max distance
If dist# > Sqr(0.5 * 1 ^ 2 + 0.5 * objects(i%, 2) ^ 2 - 1 * objects(i%, 2) * Cos(.75 * _Pi)) Then correction# = 0
'collision point approximation
cpx# = across% + 0.5 * Cos(angle1#) 'perhaps I can develop a better formula here later
cpy# = down% + 0.5 * Sin(angle1#)
'total velocity of cursor box approximation
tvx# = objects(i%, 6) - objects(i%, 15) * objects(i%, 2) / 2 * Sin(angle1# + _Pi)
tvy# = objects(i%, 7) + objects(i%, 15) * objects(i%, 2) / 2 * Cos(angle1# + _Pi)
dot# = tvx# * Cos(angle1# + _Pi) + tvy# * Sin(angle1# + _Pi) 'is the collision point coming or going? positive means it's coming
If dist# < (dist1# + dist2# + correction#) Then 'if there is a collision
If totalforcecounter% <= collisionperobjectlimit% Then
If tvx# ^ 2 + tvy# ^ 2 > .001 Then 'if the colliding object is moving
vangle# = _Atan2(tvy#, tvx#) + _Pi 'velocity angle
Else
vangle# = angle1# 'else the angle is the opposite of the away vector
End If
fixangle (angle1#) 'output will be between 0 and 2Pi
If angle1# > 0.25 * _Pi And angle1# < _Pi * .75 Then
pangle# = _Pi / 2
ElseIf angle1# >= 0.75 * _Pi And angle1# <= 1.25 * _Pi Then
pangle# = _Pi
ElseIf angle1# > 1.25 * _Pi And angle1# < 1.75 * _Pi Then
pangle# = -_Pi / 2
Else
pangle# = 0
End If
fangle# = avgangle#(pangle#, vangle#)
forcelist#(totalforcecounter%, 0) = ((dist1# + dist2# + correction#) - dist#) * 1000 * Cos(fangle#)
forcelist#(totalforcecounter%, 1) = ((dist1# + dist2# + correction#) - dist#) * 1000 * Sin(fangle#)
'Add damping if the points are moving away from each other
If dot# < 0 Then 'if the points are moving away from each other, then there is DAMPING
forcelist#(totalforcecounter%, 0) = forcelist#(totalforcecounter%, 0) * 0.90
forcelist#(totalforcecounter%, 1) = forcelist#(totalforcecounter%, 1) * 0.90
ElseIf Sqr(tvx# ^ 2 + tvy# ^ 2) > 3.0 Then
objects(i%, 10) = objects(i%, 10) + 1
'playsound2% = 1 'only play the sound if they are getting closer
End If
If (-Sin(angle1#) * forcelist#(totalforcecounter%, 0) + Cos(angle1#) * forcelist#(totalforcecounter%, 1)) < 0 Then 'inequality reversed because angle is reversed
' dot product of negative recirprocal of normalized angle vector (from sin/cos) with force vector then the rotation is positive
forcelist#(totalforcecounter%, 2) = Sqr(forcelist#(totalforcecounter%, 0) ^ 2 + forcelist#(totalforcecounter%, 1) ^ 2) * perpvector(cpx#, cpy#, forcelist#(totalforcecounter%, 0), forcelist#(totalforcecounter%, 1), objects(i%, 4), objects(i%, 5)) '+F*R
Else
forcelist#(totalforcecounter%, 2) = -Sqr(forcelist#(totalforcecounter%, 0) ^ 2 + forcelist#(totalforcecounter%, 1) ^ 2) * perpvector(cpx#, cpy#, forcelist#(totalforcecounter%, 0), forcelist#(totalforcecounter%, 1), objects(i%, 4), objects(i%, 5)) '+F*R
End If
'The collision does damage to the environment if the total velocity is fast enough
If tvx# ^ 2 + tvy# ^ 2 > 10 And landscape(across%, down%) = 2 Then 'Keep this as a velocity limit, since energy depends on mass, and I don't want a heavy object with lots of mass to still trigger collisions at low velocities
'landscapehealth(across%, down%) = landscapehealth(across%, down%) - 1
numadjacent% = 1
If across% > 1 And across% <= 959 And down% > 1 And down% <= 719 Then
If landscape(across% + 1, down%) >= 2 Then numadjacent% = numadjacent% + 1
If landscape(across%, down% + 1) >= 2 Then numadjacent% = numadjacent% + 1
If landscape(across% + 1, down% + 1) >= 2 Then numadjacent% = numadjacent% + 1
If landscape(across% - 1, down%) >= 2 Then numadjacent% = numadjacent% + 1
If landscape(across%, down% - 1) >= 2 Then numadjacent% = numadjacent% + 1
If landscape(across% - 1, down% - 1) >= 2 Then numadjacent% = numadjacent% + 1
If landscape(across% - 1, down% + 1) >= 2 Then numadjacent% = numadjacent% + 1
If landscape(across% + 1, down% - 1) >= 2 Then numadjacent% = numadjacent% + 1
End If
landscapehealth(across%, down%) = landscapehealth(across%, down%) - .006 / (numadjacent%) * (0.5 * objects(i%, 3) * (objects(i%, 4) ^ 2 + objects(i%, 5) ^ 2) + 0.5 * objects(i%, 13) * objects(i%, 15) ^ 2) 'should velocity be total velocity, or object velocity?
'Box Damage handled in final force/acceleration, not here
If landscapehealth(across%, down%) <= 0 Then
If Rnd < .005 Then
landscape(across%, down%) = 1
Else
landscape(across%, down%) = 0
End If
End If
End If
If write1% = 1 Then
Print #5, "Environmental Collision COLLISION", across%, down%
Print #5, "ANGLE: ", fangle#
Print #5, "ANGLES: ", vangle#, pangle#, angle1#, angle2#
Print #5, "DOT: ", dot#
Print #5, "Perp Vector: ", perpvector(across%, down%, forcelist#(totalforcecounter%, 0), forcelist#(totalforcecounter%, 1), objects(i%, 4), objects(i%, 5))
Print #5, "Collision Point: ", cpx#, cpy#
Print #5, "Total Velocity: ", tvx#, tvy#
Print #5, totalforcecounter%
Print #5, forcelist#(totalforcecounter%, 0), forcelist#(totalforcecounter%, 1), forcelist#(totalforcecounter%, 2)
End If
totalforcecounter% = totalforcecounter% + 1
End If
End If
End If
Next across%
Next down%
End If
'Calculate finalforcelist#
If totalforcecounter% > collisionperobjectlimit% Then
totalforcecounter% = collisionperobjectlimit%
End If
If totalforcecounter% > 0 Then
For k% = 0 To totalforcecounter%
If forcelist#(k%, 0) <> 0 Or forcelist#(k%, 1) <> 0 Then
'Find weighted sum to divide against, based on dot products of vector angles
'normx# = Cos(Atan2(forcelist#(k%, 0), forcelist#(k%, 1)))
'normy# = Sin(Atan2(forcelist#(k%, 0), forcelist#(k%, 1)))
normx# = Cos(_Atan2(forcelist#(k%, 1), forcelist#(k%, 0)))
normy# = Sin(_Atan2(forcelist#(k%, 1), forcelist#(k%, 0)))
sum# = 0 'sum of all the dot products in the direction of the original force
For m% = 0 To totalforcecounter%
If forcelist#(m%, 0) <> 0 Or forcelist#(m%, 1) <> 0 Then
'dot# = normx# * Cos(Atan2(forcelist#(m%, 0), forcelist#(m%, 1))) + normy# * Sin(Atan2(forcelist#(m%, 0), forcelist#(m%, 1)))
dot# = normx# * Cos(_Atan2(forcelist#(m%, 1), forcelist#(m%, 0))) + normy# * Sin(_Atan2(forcelist#(m%, 1), forcelist#(m%, 0)))
If dot# > 0 Then 'only use vectors pointing somewhat in the same direction
'sum# = sum# + normx# * Cos(Atan2(forcelist#(m%, 0), forcelist#(m%, 1))) + normy# * Sin(Atan2(forcelist#(m%, 0), forcelist#(m%, 1)))
sum# = sum# + normx# * Cos(_Atan2(forcelist#(m%, 1), forcelist#(m%, 0))) + normy# * Sin(_Atan2(forcelist#(m%, 1), forcelist#(m%, 0)))
End If
End If
Next m%
finalforcelist#(k%, 0) = forcelist#(k%, 0) / sum#
finalforcelist#(k%, 1) = forcelist#(k%, 1) / sum#
finalforcelist#(k%, 2) = forcelist#(k%, 2) / sum# 'the torque is reduced proportionally with the force, the radius is constant
If write1% = 1 Then Print #5, "SUM: ", sum#, normx#, normy#
Else
finalforcelist#(k%, 2) = 0 'should already be zero, this is just in case
End If
Next k%
'Calculate final forces/accelerations
For k% = 0 To totalforcecounter%
If Sqr(forcelist#(k%, 0) ^ 2 + forcelist#(k%, 1) ^ 2) > 0.0000000001 Then
If write1% = 1 Then
Print #5, "INDEX, Forces: ", k%, forcelist#(k%, 0), forcelist#(k%, 1), forcelist#(k%, 2)
Print #5, "INDEX, FinalForces: ", k%, finalforcelist#(k%, 0), finalforcelist#(k%, 1), finalforcelist#(k%, 2)
End If
tx# = tx# + finalforcelist#(k%, 0)
ty# = ty# + finalforcelist#(k%, 1)
ttorque# = ttorque# + finalforcelist#(k%, 2)
End If
Next k%
If tx# <> 0 Or ty# <> 0 Or ttorque# <> 0 Then
rotperc# = Abs(ttorque# / objects(i%, 2)) / (Abs(ttorque# / objects(i%, 2)) + Sqr(tx# ^ 2 + ty# ^ 2)) ' could also try using the values squared
transperc# = 1 - rotperc#
Else
rotperc# = 0.5
transperc# = 0.5
End If
If tx# <> 0 Or ty# <> 0 Or ttorque# <> 0 Then
objects(i%, 8) = objects(i%, 8) + (transperc# * tx# / objects(i%, 3)) * physicslimit 'F=MA, so A=F/M
objects(i%, 9) = objects(i%, 9) + (transperc# * ty# / objects(i%, 3)) * physicslimit 'F=MA, so A=F/M
objects(i%, 16) = objects(i%, 16) + (rotperc# * ttorque#) / objects(i%, 13) * physicslimit 'Torque=F*R=I*Alpha Alpha=Torque/I
If Abs(objects(i%, 16)) < .00000001 Then objects(i%, 16) = 0 'reduce drift
End If
'DAMAGE to Box itself
'To simplify this, ignore torque
If Sqr(tx# ^ 2 + ty# ^ 2) > 200 Then
objects(i%, 1) = objects(i%, 1) - Sqr(tx# ^ 2 + ty# ^ 2) / 200
End If
If objects(i%, 17) > initialimpact% And (Sqr(objects(i%, 4) ^ 2 + objects(i%, 5) ^ 2) > 5 Or Abs(objects(i%, 15)) > 15) Then
If write1% = 1 Then Print #5, "INITIAL IMPACT"
If objects(i%, 4) >= (-screenx% / scale# - 30) And objects(i%, 4) <= ((-screenx% + 480) / scale# + 30) And objects(i%, 5) >= (-screeny% / scale# - 30) And objects(i%, 5) <= ((-screeny% + 360) / scale# + 30) Then 'if on screen
playsound1% = 1
End If
End If
If objects(i%, 10) > initialimpactenvironment% Then
If objects(i%, 4) >= (-screenx% / scale# - 30) And objects(i%, 4) <= ((-screenx% + 480) / scale# + 30) And objects(i%, 5) >= (-screeny% / scale# - 30) And objects(i%, 5) <= ((-screeny% + 360) / scale# + 30) Then 'if on screen
playsound2% = 1
End If
End If
If write1% = 1 Then
Print #5, "BLOCK-END"
Print #5, "AVERAGED FORCES X, Y, torque ", tx#, ty#, ttorque#
Print #5, "COUNTER ", totalforcecounter%
Print #5, "POS: ", objects(i%, 4), objects(i%, 5)
Print #5, "ANGLE pos, vel, accel: ", objects(i%, 14), objects(i%, 15), objects(i%, 16)
Print #5, "VEL: ", objects(i%, 6), objects(i%, 7)
Print #5, "ACCEL: ", objects(i%, 8), objects(i%, 9)
Print #5, "Colliding Objects (environ, obj): ", objects(i%, 10), objects(i%, 17)
Print #5, "ROT PERC; TRANS PERC: ", rotperc#, transperc#
textstring$ = "Newobject 1, 10, " + Str$(objects(i%, 2)) + ", 10, " + Str$(objects(i%, 4)) + ", " + Str$(objects(i%, 5)) + ", 0, 0, 0, 0, 0, " + Str$(objects(i%, 14)) + ", 0, 0, 0"
Print #5, textstring$ '(otype%, health#, size#, mass#, xpos#, ypos#, xvel#, yvel#, xacc#, yacc#, forcereturn#, angle#, anglevel#)"
End If
'If write2% = 1 Then
' Print #6, "OBJECT: ", i%
' textstring$ = ""
' For y = 0 To UBound(objects, 2)
' textstring$ = textstring$ + Str$(objects(i%, y)) + ","
' Next y
' textstring$ = Left$(textstring$, Len(textstring$) - 1)
' If i% = 0 Then Print #6, textstring$
' Print #6, textstring$
' Print #6, "TOTAL ENERGY: ", 0.5 * objects(i%, 3) * (objects(i%, 6) ^ 2 + objects(i%, 7) ^ 2) + 0.5 * objects(i%, 13) * objects(i%, 15) ^ 2 + objects(i%, 3) * gravity# * (720 - objects(i%, 5))
'End If
End If
Next i%
'Play Sounds, if applicable
If playsound1% = 1 And (soundmode% = 1 Or soundmode% = 3) And gametimer# - soundtimer# > 0 Then
'Sound 78, 1, .8, 0, 2
Play "mbL64o1V20g"
soundtimer# = gametimer# + .02
End If
If playsound2% = 1 And (soundmode% = 2 Or soundmode% = 3) And gametimer# - soundtimer# > 0 Then
'Sound 62, 1, .8, 0, 4
Play "mbL64o1v25d"
soundtimer# = gametimer# + .02
End If
'Update Positions after all collisions have been computed
For i% = 0 To numobjects%
If objects(i%, 0) > 1 And objects(i%, 1) > 0 Then 'object must be the right type, and have positive health
'Update Velocity
objects(i%, 6) = objects(i%, 6) + objects(i%, 8) * 1 / physicslimit
objects(i%, 7) = objects(i%, 7) + objects(i%, 9) * 1 / physicslimit
If Abs(objects(i%, 6)) < .000001 Then objects(i%, 6) = 0 'reduce drift
If Abs(objects(i%, 7)) < .000001 Then objects(i%, 7) = 0 'reduce drift
objects(i%, 4) = objects(i%, 4) + objects(i%, 6) * 1 / physicslimit
objects(i%, 5) = objects(i%, 5) + objects(i%, 7) * 1 / physicslimit
'Update Angular Velocity
objects(i%, 15) = objects(i%, 15) + objects(i%, 16) * 1 / physicslimit
'Update Angle
objects(i%, 14) = objects(i%, 14) + objects(i%, 15) * 1 / physicslimit
End If
Next i%
'Objects out of bounds and with no health or in the goal
For i% = 0 To numobjects%
If (objects(i%, 1) <= 0 Or objects(i%, 19) <= 0) And objects(i%, 0) > 0 Then 'no health
objects(i%, 0) = 0 'remove object
NewGameObject -1, objects(i%, 4), objects(i%, 5), 6, objects(i%, 14), gametimer# + 0.5
If objects(i%, 4) >= (-screenx% / scale# - 30) And objects(i%, 4) <= ((-screenx% + 480) / scale# + 30) And objects(i%, 5) >= (-screeny% / scale# - 30) And objects(i%, 5) <= ((-screeny% + 360) / scale# + 30) Then 'if on screen
Play "mbL64@1o0dbbdcaca"
soundtimer# = gametimer# + .1
End If
boxdestroyed% = boxdestroyed% + 1
End If
If objects(i%, 4) < -2880 Or objects(i%, 4) > 3840 Or objects(i%, 5) < -2160 Or objects(i%, 5) > 2880 Then objects(i%, 0) = 0 'out of bounds
If objects(i%, 0) > 0 And objects(i%, 4) > 1 And objects(i%, 4) < 959 And objects(i%, 5) > 1 And objects(i%, 5) < 719 Then 'if object exist and is in bounds
If landscape(Round(objects(i%, 4)), Round(objects(i%, 5))) = -1 Then ' in goal
objects(i%, 0) = 0
boxsaved% = boxsaved% + 1
NewGameObject 2, objects(i%, 4), objects(i%, 5), 6, objects(i%, 14), gametimer# + 0.6
Play "mbL32o2bL16o3b"
soundtimer# = gametimer# + .1
money% = money% + 100
End If
End If
'Makes output angles easier to understand when troubleshooting
fixangle (objects(i%, 14))
Next i%
End Sub
Sub DrawObjects (scrx%, scry%, scale#)
Dim size#, xx#, yy#
Dim lowerx#, lowery#, upperx#, uppery#
Dim dcorners#(7)
Dim drawpoints#(3, 1)
lowerx# = -scrx% / scale# - 50
upperx# = (-scrx% + 480) / scale# + 50
lowery# = -scry% / scale# - 50
uppery# = (-scry% + 360) / scale# + 50
'Print "Lower ", lowerx#
'Print "Upper ", upperx#
For i% = 0 To UBound(objects)
size# = objects(i%, 2)
xx# = objects(i%, 4)
yy# = objects(i%, 5)
dcorners#(0) = scrx% + (xx# + size# / 2 * (Cos(objects(i%, 14)) - Sin(objects(i%, 14)))) * scale# 'angles are in radians X=1 Y=1
dcorners#(1) = scry% + (yy# + size# / 2 * (Sin(objects(i%, 14)) + Cos(objects(i%, 14)))) * scale# 'angles are in radians X=1 Y=1
dcorners#(2) = scrx% + (xx# + size# / 2 * (-Cos(objects(i%, 14)) - Sin(objects(i%, 14)))) * scale# 'angles are in radians X=-1 Y=1
dcorners#(3) = scry% + (yy# + size# / 2 * (-Sin(objects(i%, 14)) + Cos(objects(i%, 14)))) * scale# 'angles are in radians X=-1 Y=1
dcorners#(4) = scrx% + (xx# + size# / 2 * (-Cos(objects(i%, 14)) + Sin(objects(i%, 14)))) * scale# 'angles are in radians X=-1 Y=-1
dcorners#(5) = scry% + (yy# + size# / 2 * (-Sin(objects(i%, 14)) - Cos(objects(i%, 14)))) * scale# 'angles are in radians X=-1 Y=-1
dcorners#(6) = scrx% + (xx# + size# / 2 * (Cos(objects(i%, 14)) + Sin(objects(i%, 14)))) * scale# 'angles are in radians X=1 Y=-1
dcorners#(7) = scry% + (yy# + size# / 2 * (Sin(objects(i%, 14)) - Cos(objects(i%, 14)))) * scale# 'angles are in radians X=1 Y=-1
drawpoints#(0, 0) = scrx% + (xx# + 0.9 * size# / 2 * (Cos(objects(i%, 14)) - Sin(objects(i%, 14)))) * scale# 'angles are in radians X=1 Y=1
drawpoints#(0, 1) = scry% + (yy# + 0.9 * size# / 2 * (Sin(objects(i%, 14)) + Cos(objects(i%, 14)))) * scale# 'angles are in radians X=1 Y=1
drawpoints#(1, 0) = scrx% + (xx# + 0.9 * size# / 2 * (-Cos(objects(i%, 14)) - Sin(objects(i%, 14)))) * scale# 'angles are in radians X=-1 Y=1
drawpoints#(1, 1) = scry% + (yy# + 0.9 * size# / 2 * (-Sin(objects(i%, 14)) + Cos(objects(i%, 14)))) * scale# 'angles are in radians X=-1 Y=1
drawpoints#(2, 0) = scrx% + (xx# + 0.9 * size# / 2 * (-Cos(objects(i%, 14)) + Sin(objects(i%, 14)))) * scale# 'angles are in radians X=-1 Y=-1
drawpoints#(2, 1) = scry% + (yy# + 0.9 * size# / 2 * (-Sin(objects(i%, 14)) - Cos(objects(i%, 14)))) * scale# 'angles are in radians X=-1 Y=-1
drawpoints#(3, 0) = scrx% + (xx# + 0.9 * size# / 2 * (Cos(objects(i%, 14)) + Sin(objects(i%, 14)))) * scale# 'angles are in radians X=1 Y=-1
drawpoints#(3, 1) = scry% + (yy# + 0.9 * size# / 2 * (Sin(objects(i%, 14)) - Cos(objects(i%, 14)))) * scale# 'angles are in radians X=1 Y=-1
'FIXED OBJECTS
If objects(i%, 0) = 1 And xx# >= lowerx# And xx# <= upperx# And yy# >= lowery# And yy# <= uppery# Then
Line (dcorners#(0), dcorners#(1))-(dcorners#(2), dcorners#(3)), _RGB(255, 255, 255)
Line (dcorners#(2), dcorners#(3))-(dcorners#(4), dcorners#(5)), _RGB(255, 255, 255)
Line (dcorners#(4), dcorners#(5))-(dcorners#(6), dcorners#(7)), _RGB(255, 255, 255)
Line (dcorners#(6), dcorners#(7))-(dcorners#(0), dcorners#(1)), _RGB(255, 255, 255)
'Line (scrx% + (xx# - 0.5 * size#) * scale#, scry% + (yy# - 0.5 * size#) * scale#)-(scrx% + ((xx# + 0.5 * size#) * scale#) - scalefactor%, scry% + ((yy# + 0.5 * size#) * scale#) - scalefactor%), _RGB(255, 255, 255), BF
'Line (objects(i%, 2) - 1, objects(i%, 3) - 1)-(objects(i%, 2) + 1, objects(i%, 3) + 1), _RGB(255, 255, 255), BF
End If
'FREE OBJECTS
If objects(i%, 0) = 2 And xx# >= lowerx# And xx# <= upperx# And yy# >= lowery# And yy# <= uppery# Then
Line (drawpoints#(0, 0), drawpoints#(0, 1))-(drawpoints#(1, 0), drawpoints#(1, 1)), _RGB(255, Int(2.5 * objects(i%, 19)), Int(2.5 * objects(i%, 19)))
Line (drawpoints#(1, 0), drawpoints#(1, 1))-(drawpoints#(2, 0), drawpoints#(2, 1)), _RGB(255, Int(2.5 * objects(i%, 19)), Int(2.5 * objects(i%, 19)))
Line (drawpoints#(2, 0), drawpoints#(2, 1))-(drawpoints#(3, 0), drawpoints#(3, 1)), _RGB(255, Int(2.5 * objects(i%, 19)), Int(2.5 * objects(i%, 19)))
Line (drawpoints#(3, 0), drawpoints#(3, 1))-(drawpoints#(0, 0), drawpoints#(0, 1)), _RGB(255, Int(2.5 * objects(i%, 19)), Int(2.5 * objects(i%, 19)))
Line (dcorners#(0), dcorners#(1))-(dcorners#(2), dcorners#(3)), _RGB(255, 0, 0)
Line (dcorners#(2), dcorners#(3))-(dcorners#(4), dcorners#(5)), _RGB(255, 0, 0)
Line (dcorners#(4), dcorners#(5))-(dcorners#(6), dcorners#(7)), _RGB(255, 0, 0)
Line (dcorners#(6), dcorners#(7))-(dcorners#(0), dcorners#(1)), _RGB(255, 0, 0)
If objects(i%, 1) <= 25 Or objects(i%, 19) <= 25 Then
Line (dcorners#(0), dcorners#(1))-(dcorners#(4), dcorners#(5)), _RGB(255, 0, 0)
Line (dcorners#(2), dcorners#(3))-(dcorners#(6), dcorners#(7)), _RGB(255, 0, 0)
End If
End If
If objects(i%, 0) = 3 And xx# >= lowerx# And xx# <= upperx# And yy# >= lowery# And yy# <= uppery# Then
Line (dcorners#(0), dcorners#(1))-(dcorners#(2), dcorners#(3)), _RGB(0, 63, 0)
Line (dcorners#(2), dcorners#(3))-(dcorners#(4), dcorners#(5)), _RGB(255, 63, 0)
Line (dcorners#(4), dcorners#(5))-(dcorners#(6), dcorners#(7)), _RGB(255, 63, 0)
Line (dcorners#(6), dcorners#(7))-(dcorners#(0), dcorners#(1)), _RGB(255, 63, 0)
End If
Next i%
End Sub
Sub NewObject (otype%, health#, size#, mass#, xpos#, ypos#, xvel#, yvel#, xacc#, yacc#, forcereturn#, angle#, anglevel#, friction#, damping#)
Dim i%
i% = 0
While objects(i%, 0) <> 0 And i% < UBound(objects)
'Print objects(i%, 0)
i% = i% + 1
Wend
objects(i%, 0) = otype% 'Type 1 is fixed permanent, 2 is moveable and has gravity, 3 is movable with no gravity
objects(i%, 1) = health#
objects(i%, 2) = size#
objects(i%, 3) = mass#
objects(i%, 4) = xpos#
objects(i%, 5) = ypos#
objects(i%, 6) = xvel#
objects(i%, 7) = yvel#
objects(i%, 8) = xacc#
objects(i%, 9) = yacc#
objects(i%, 10) = 0 '# of environmental objects touching
objects(i%, 11) = friction# 'Friction Coef
objects(i%, 12) = forcereturn# 'how much the objects rebounds after a collision. Forcereturn of 1 means a full rebound (no energy loss)
If otype% >= 1 Then
objects(i%, 13) = mass# * size# ^ 2 / 6 'I
End If
objects(i%, 14) = angle# 'angular position
objects(i%, 15) = anglevel# 'angular velocity
objects(i%, 16) = 0 'angular acceleration
objects(i%, 17) = 0 '# regular other objects touching
objects(i%, 18) = damping# 'Damping Coef
objects(i%, 19) = 100 'health time
End Sub
Sub NewGameObject (otype%, xpos#, ypos#, radius#, angle#, gtime#)
Dim i%
i% = 0
While gameobjectarray(i%).otype <> 0 And i% < UBound(gameobjectarray)
'Print objects(i%, 0)
i% = i% + 1
Wend
gameobjectarray(i%).otype = otype%
gameobjectarray(i%).xpos = xpos#
gameobjectarray(i%).ypos = ypos#
gameobjectarray(i%).radius = radius#
gameobjectarray(i%).angle = angle#
gameobjectarray(i%).time = gtime#
End Sub
Sub DrawGrid (scrx%, scry%, scale#)
'All values are passed by reference
'You can create local variables to mimic the effect of pass by value
'Draw visible portion of screen
'Static variables retain their value between function calls (define with STATIC)
Dim DrawXcorner%, DrawYcorner%, xmaxcorner%, ymaxcorner%
DrawXcorner% = -scrx% / scale# - 1
DrawYcorner% = -scry% / scale# - 1
xmaxcorner% = DrawXcorner% + 480 / scale# + 2
ymaxcorner% = DrawYcorner% + 360 / scale# + 2
If DrawXcorner% < 0 Then DrawXcorner% = 0
If DrawXcorner% > 960 Then DrawXcorner% = 960
If DrawYcorner% < 0 Then DrawYcorner% = 0
If DrawYcorner% > 720 Then DrawYcorner% = 720
If xmaxcorner% < 0 Then xmaxcorner% = 0
If xmaxcorner% > 960 Then xmaxcorner% = 960
If ymaxcorner% < 0 Then ymaxcorner% = 0
If ymaxcorner% > 720 Then ymaxcorner% = 720
If scale# >= 1 Then scalefactor% = 1 Else scalefactor% = 0
'Print scalefactor%
'Dim valuex1#, valuex2#, valuey1#, valuey2#
For down% = DrawXcorner% To xmaxcorner% Step 1
For across% = DrawYcorner% To ymaxcorner% Step 1
Select Case landscape(down%, across%)
Case -2
Line (scrx% + down% * scale# - 0.5 * scale# * scalefactor%, scry% + across% * scale# - 0.5 * scale# * scalefactor%)-(scrx% + down% * scale# + 0.5 * scale# * scalefactor% - scalefactor%, scry% + across% * scale# + 0.5 * scale# * scalefactor% - scalefactor%), _RGB(44, 166, 50), BF
Case -1
Line (scrx% + down% * scale# - 0.5 * scale# * scalefactor%, scry% + across% * scale# - 0.5 * scale# * scalefactor%)-(scrx% + down% * scale# + 0.5 * scale# * scalefactor% - scalefactor%, scry% + across% * scale# + 0.5 * scale# * scalefactor% - scalefactor%), _RGB(0, 200, 255), BF
Case 1
Line (scrx% + down% * scale# - 0.5 * scale# * scalefactor%, scry% + across% * scale# - 0.5 * scale# * scalefactor%)-(scrx% + down% * scale# + 0.5 * scale# * scalefactor% - scalefactor%, scry% + across% * scale# + 0.5 * scale# * scalefactor% - scalefactor%), _RGB(Int(Rnd * 255) + 1, Int(Rnd * 255) + 1, Int(Rnd * 255) + 1), BF
Case 2
Line (scrx% + down% * scale# - 0.5 * scale# * scalefactor%, scry% + across% * scale# - 0.5 * scale# * scalefactor%)-(scrx% + down% * scale# + 0.5 * scale# * scalefactor% - scalefactor%, scry% + across% * scale# + 0.5 * scale# * scalefactor% - scalefactor%), _RGB(200, 200, 200), BF
Case 3
Line (scrx% + down% * scale# - 0.5 * scale# * scalefactor%, scry% + across% * scale# - 0.5 * scale# * scalefactor%)-(scrx% + down% * scale# + 0.5 * scale# * scalefactor% - scalefactor%, scry% + across% * scale# + 0.5 * scale# * scalefactor% - scalefactor%), _RGB(60, 160, 255), BF
End Select
Next across%
Next down%
End Sub
Sub Savefile
Cls
scansaves
Print "11 CUSTOM FILE NAME"
Print "12 CANCEL"
Dim ss#
Dim name$, filename$
Input "Please select a save slot ", ss#
If ss# = 12 Then Exit Sub
Input "Please add the title for your save ", name$
If ss# > 0 And ss# <= 10 Then
filename$ = "savefile" + Str$(ss#) + ".txt"
Else
Input "Please enter your file name: ", filename$
End If
Open filename$ For Output As #1
Print #1, name$
Print #1, Date$ + " " + Time$
Dim Linestring$
Dim l, w As Integer
l = UBound(landscape, 1)
w = UBound(landscape, 2)
Print #1, l
Print #1, w
For x = 0 To l
Linestring$ = ""
For y = 0 To w
Linestring$ = Linestring$ + Str$(landscape(x, y)) + ","
Next y
Linestring$ = Left$(Linestring$, Len(Linestring$) - 1)
Print #1, Linestring$
Next x
For x = 0 To l
Linestring$ = ""
For y = 0 To w
Linestring$ = Linestring$ + Str$(landscapehealth(x, y)) + ","
Next y
Linestring$ = Left$(Linestring$, Len(Linestring$) - 1)
Print #1, Linestring$
Next x
l = UBound(objects, 1)
w = UBound(objects, 2)
Print #1, l
Print #1, w
For x = 0 To l
Linestring$ = ""
For y = 0 To w
Linestring$ = Linestring$ + Str$(objects(x, y)) + ","
Next y
Linestring$ = Left$(Linestring$, Len(Linestring$) - 1)
Print #1, Linestring$
Next x
Close #1
End Sub
Sub Loadfile
Dim textline$, filename$
Dim position%
Dim lastposition%
Dim l, w As Integer
Dim ans#
Cls
scansaves
Print "11 CUSTOM FILE NAME"
Print "12 CANCEL"
Input "Please select the file you would like to open: ", ans#
If ans# > 0 And ans# <= 10 Then
filename$ = "savefile" + Str$(ans#) + ".txt"
Else
Input "Please enter your file name: ", filename$
End If
Print filename$
If _FileExists(filename$) Then
Open filename$ For Input As #2
Line Input #2, textline$
Line Input #2, textline$
Line Input #2, textline$
l = Val(textline$)
Line Input #2, textline$
w = Val(textline$)
For xx = 0 To l
Line Input #2, textline$
position% = 0
For yy = 0 To w - 1
lastposition% = position%
position% = InStr(position% + 1, textline$, ",")
landscape(xx, yy) = Val(Mid$(textline$, lastposition% + 1, position% - lastposition% - 1))
Next yy
Locate 14, 1
Print "LOADING...", Int(xx * 50 / Int(l))
Locate 14, 20
Print "%"
landscape(xx, w) = Val(Mid$(textline$, position% + 1, Len(textline$) - position%))
_Display
Next xx
For xx = 0 To l
Line Input #2, textline$
position% = 0
For yy = 0 To w - 1
lastposition% = position%
position% = InStr(position% + 1, textline$, ",")
landscapehealth(xx, yy) = Val(Mid$(textline$, lastposition% + 1, position% - lastposition% - 1))
Next yy
Locate 14, 1
Print "LOADING...", 50 + Int(xx * 50 / Int(l))
Locate 14, 20
Print "%"
landscapehealth(xx, w) = Val(Mid$(textline$, position% + 1, Len(textline$) - position%))
_Display
Next xx
Line Input #2, textline$
l = Val(textline$)
Line Input #2, textline$
w = Val(textline$)
ReDim objects(l, w)
For xx = 0 To l
Line Input #2, textline$
position% = 0
For yy = 0 To w - 1
lastposition% = position%
position% = InStr(position% + 1, textline$, ",")
objects(xx, yy) = Val(Mid$(textline$, lastposition% + 1, position% - lastposition% - 1))
Next yy
Locate 15, 1
Print "LOADING...", Int(xx * 100 / Int(l))
Locate 15, 20
Print "%"
objects(xx, w) = Val(Mid$(textline$, position% + 1, Len(textline$) - position%))
_Display
Next xx
Close #2
Else
Input "FILE NOT FOUND", ans#
End If
End Sub
Sub scansaves
Dim filename$
Dim firstline$
Dim secondline$
For x = 1 To 10
filename$ = "savefile" + Str$(x) + ".txt"
'Print filename$
firstline$ = ""
secondline$ = ""
If _FileExists(filename$) Then
Open filename$ For Input As #3
If Not EOF(3) Then
Line Input #3, firstline$
End If
If Not EOF(3) Then
Line Input #3, secondline$
End If
Close #3
End If
Print Str$(x) + " " + firstline$ + " " + secondline$
Next x
End Sub
Sub outputobjects
Open "objectlist.txt" For Output As #4
Print #4, Date$ + " " + Time$
Dim Linestring$
Dim l, w As Integer
l = UBound(objects, 1)
w = UBound(objects, 2)
For x = 0 To l
Linestring$ = ""
For y = 0 To w
Linestring$ = Linestring$ + Str$(objects(x, y)) + ","
Next y
Linestring$ = Left$(Linestring$, Len(Linestring$) - 1)
Print #4, Linestring$
Print #4, "TOTAL ENERGY: ", 0.5 * objects(x, 3) * (objects(x, 6) ^ 2 + objects(x, 7) ^ 2) + 0.5 * objects(x, 13) * objects(x, 15) ^ 2 + objects(x, 3) * gravity# * (720 - objects(x, 5))
Next x
Close #4
Print "Objects Outputed"
End Sub
Function Round% (value#)
If (value# - Int(value#)) >= 0.5 Then Round% = Int(value#) + 1 Else Round% = Int(value#)
End Function
Function In4Points% (testx#, testy#, p1x#, p1y#, p2x#, p2y#, p3x#, p3y#, p4x#, p4y#) 'returns 1 if in 4 points, -1 if not
Dim centerx#, centery#
centerx# = (p1x# + p2x# + p3x# + p4x#) / 4 'could possibly pass these variables over to save CPU cycles if this becomes an issue
centery# = (p1y# + p2y# + p3y# + p4y#) / 4 'calculating them here eliminates the possibility of a bad value if this is used elsewhere
Dim hc#, ht#
Dim vx#, vy#
'If write1%=1 Then Print #5, "POINT VALUES: ", testx#, testy#, p1x#, p1y#, p2x#, p2y#, p3x#, p3y#, p4x#, p4y#
'Points 1 and Points 2, point 1 is fulcrum
vx# = p2x# - p1x#
vy# = p2y# - p1y#
'Calculating distance in both X and Y directions shouldn't be required because it is impossible to have the test pass in one direction but fail in the other. It does however help us avoid singularities
If Abs(vx#) > 0.00001 Then 'Use Y direction first or vx#<>0
hc# = centery# - p1y# - vy# * (centerx# - p1x#) / vx#
ht# = testy# - p1y# - vy# * (testx# - p1x#) / vx#
Else 'use X direction
hc# = centerx# - p1x# '-0, since vx#=0
ht# = testx# - p1x#
End If
Dim test%
test% = Abs(hc# * ht#) / (hc# * ht#) 'passes if both hc and ht are positive or negative, fails if they are opposites
If test% = -1 Then
In4Points% = test%
Exit Function
End If
'Points 2 and Points 3, point 2 is fulcrum
vx# = p3x# - p2x#
vy# = p3y# - p2y#
If Abs(vx#) > 0.00001 Then 'Use Y direction first
hc# = centery# - p2y# - vy# * (centerx# - p2x#) / vx#
ht# = testy# - p2y# - vy# * (testx# - p2x#) / vx#
Else 'use X direction
hc# = centerx# - p2x# '-0, since vx#=0
ht# = testx# - p2x#
End If
test% = Abs(hc# * ht#) / (hc# * ht#) 'passes if both hc and ht are positive or negative, fails if they are opposites
If test% = -1 Then
In4Points% = test%
Exit Function
End If
'Points 3 and Points 4, point 3 is fulcrum
vx# = p4x# - p3x#
vy# = p4y# - p3y#
If Abs(vx#) > 0.00001 Then 'Use Y direction first
hc# = centery# - p3y# - vy# * (centerx# - p3x#) / vx#
ht# = testy# - p3y# - vy# * (testx# - p3x#) / vx#
Else 'use X direction
hc# = centerx# - p3x# '-0, since vx#=0
ht# = testx# - p3x#
End If
test% = Abs(hc# * ht#) / (hc# * ht#) 'passes if both hc and ht are positive or negative, fails if they are opposites
If test% = -1 Then
In4Points% = test%
Exit Function
End If
'Points 4 and Points 1, point 4 is fulcrum
vx# = p1x# - p4x#
vy# = p1y# - p4y#
If Abs(vx#) > 0.00001 Then 'Use Y direction first
hc# = centery# - p4y# - vy# * (centerx# - p4x#) / vx#
ht# = testy# - p4y# - vy# * (testx# - p4x#) / vx#
Else 'use X direction
hc# = centerx# - p4x# '-0, since vx#=0
ht# = testx# - p4x#
End If
test% = Abs(hc# * ht#) / (hc# * ht#) 'passes if both hc and ht are positive or negative, fails if they are opposite
'If test% = 1 Then
'If write1%=1 Then Print #5, "POINT VALUES: ", testx#, testy#, p1x#, p1y#, p2x#, p2y#, p3x#, p3y#, p4x#, p4y#
'End If
In4Points% = test%
End Function
Function perpvector# (px#, py#, vx#, vy#, centerx#, centery#)
'p is the starting point, v is the vector from p, center is the point offset from the vector you are finding the distance to.
'If write1%=1 Then Print #5, "PERP VEC PARAM: ", px#, py#, vx#, vy#, centerx#, centery#
perpvector# = Abs(vx# * (centery# - py#) + vy# * (px# - centerx#)) / Sqr(vx# ^ 2 + vy# ^ 2) 'SQR is for square root
End Function
Sub collisionforceobjects (px#, py#, obj1%, obj2%)
'Forces applied to object1 at px, py
'Sub updates forces 0 and 1
'THIS IS AN APPROXIMATION (HOPEFULLY) THAT PRODUCES BELIEVABLE RESULTS. I haven't yet solved the 4 DOF equation
'Force is:
'2*m1*m2*(v1-v2)/(m1+m2) Sign depends on directions linear movement solution. Use COM velocity for linear components, velocity of point impact for rotational.
'2*I1*I2*(w1-w2)/(I1+I2) Torque only solution is similar. Divide by radius of impacting object to get force
'Forces applied to object1 at px, py
If write1% = 1 Then Print #5, ""
If write1% = 1 Then Print #5, "COLLISION COUNTER: ", collisioncounter%
'If write2% = 1 Then Print #6, "COLLISION COUNTER: ", collisioncounter%
collisioncounter% = collisioncounter% + 1
Dim vel1#, vel2#, vel1f#, vel2f#, torquemag#, force2mag#, force1mag#, transangle#, angle1#, angle2#, angle3#, angle4#, angle5#, finalangle#
Dim finalforce#, radius#, tempangle1#
Dim tvx1#, tvx2#, tvy1#, tvy2#, tv1tot#, tv2tot# 'Total Velocity
Dim obj1topangle#, obj2topangle#, rot_to_rot#, rot_to_trans#, trans_to_trans#, trans_to_rot#, tempforce1#, tempforce2#, temptorque#
Dim cornerflag%, nulvel%, nulrot%
nulvel% = 0
nulrot% = 0
cornerflag% = 0
forces(0) = 0
forces(1) = 0
vel1# = Sqr(objects(obj1%, 6) ^ 2 + objects(obj1%, 7) ^ 2)
vel2# = Sqr(objects(obj2%, 6) ^ 2 + objects(obj2%, 7) ^ 2)
'Maybe useful? If perpvector of obj1 COM's velocity is greater than it's size/2 the the COM is out of line with the collision
'ROTATIONAL ALIGNMENT
'obj1topangle# = Atan2(px# - objects(obj1%, 4), py# - objects(obj1%, 5))
'obj2topangle# = Atan2(px# - objects(obj2%, 4), py# - objects(obj2%, 5))
obj1topangle# = _Atan2(py# - objects(obj1%, 5), px# - objects(obj1%, 4))
obj2topangle# = _Atan2(py# - objects(obj2%, 5), px# - objects(obj2%, 4))
'This effort finished later on after finalangle is determined
'If write1%=1 Then Print #5, "Rot Angles: ", obj1topangle#, obj2topangle#
'THIS CODE REMOVED
'rot_to_rot# = Abs(Cos(obj1topangle#) * Cos(obj2topangle#) + Sin(obj1topangle#) * Sin(obj2topangle#))
'If objects(obj2%, 0) = 1 Then rot_to_rot# = 1 'perhaps a good assumption, gives better results
'rot_to_trans# = 1 - rot_to_rot#
'TRANSLATIONAL ALIGNMENT
Dim sizelimit#, maxsize#, perpoffset#
If vel1# < 0.00000000001 And vel2# < 0.00000000001 Then
trans_to_trans# = 1
trans_to_rot# = 0
angle2# = 0 'This is OK since the force will also be zero
Else
maxsize# = 1.414214 * (objects(obj1%, 2) + objects(obj2%, 2))
'angle2# = Atan2(objects(obj2%, 6) - objects(obj1%, 6), objects(obj2%, 7) - objects(obj1%, 7)) 'angle of relative velocity of obj2 with respect to obj1
angle2# = _Atan2(objects(obj2%, 7) - objects(obj1%, 7), objects(obj2%, 6) - objects(obj1%, 6)) 'angle of relative velocity of obj2 with respect to obj1
If objects(obj2%, 0) = 1 Then
sizelimit# = 0.51 * objects(obj2%, 2) 'use immovable box as limit, else use smaller size
ElseIf objects(obj1%, 2) < objects(obj2%, 2) Then
sizelimit# = Abs(Sin(angle2#) * 0.51 * objects(obj1%, 2))
If sizelimit# < 0.51 * objects(obj1%, 2) Then sizelimit# = 0.51 * objects(obj1%, 2) 'make 0.51 the min for some extra grace
Else
sizelimit# = Abs(Sin(angle2#) * 0.51 * objects(obj2%, 2))
If sizelimit# < 0.51 * objects(obj2%, 2) Then sizelimit# = 0.51 * objects(obj2%, 2)
End If
perpoffset# = perpvector#(objects(obj1%, 4), objects(obj1%, 5), Cos(angle2#), Sin(angle2#), objects(obj2%, 4), objects(obj2%, 5))
If perpoffset# < sizelimit# Then
trans_to_trans# = 1
trans_to_rot# = 0
Else
trans_to_rot# = (perpoffset# - sizelimit#) / (maxsize# - sizelimit#)
If trans_to_rot# > 1 Then trans_to_rot# = 1 'just a safety precaution
trans_to_trans# = 1 - trans_to_rot#
End If
End If
Rem FIND FACE ANGLE:
'Approach: find dot product of obj2 vector to collision point (stepped back by one velocity increment) and obj2 angle vectors (incremented by 90 deg increments)
Dim reflectangle#
Dim dotproducts#(3, 1)
reflectangle# = objects(obj2%, 14)
For i% = 0 To 3
'dotproducts#(i%, 0) = Cos(reflectangle#) * ((px# - objects(obj1%, 6) / physicslimit) - objects(obj2%, 4)) + Sin(reflectangle#) * ((py# - objects(obj1%, 7) / physicslimit) - objects(obj2%, 5))
dotproducts#(i%, 0) = Cos(reflectangle#) * (px# - objects(obj2%, 4)) + Sin(reflectangle#) * (py# - objects(obj2%, 5)) 'Not sure that stepping back position always helps
'If write1%=1 Then Print #5, reflectangle#, (px# - objects(obj2%, 4)), (py# - objects(obj2%, 5))
dotproducts#(i%, 1) = reflectangle#
reflectangle# = reflectangle# + _Pi / 2
Next i%
'the largest positive value will indicate which face of obj2 was hit by obj1, and the angle that points to it.
sortdouble2D dotproducts#(), 0
'If write1% = 1 Then
' Print #5, "SECOND OBJECT DOT PRODUCTS"
' For ii = 0 To 3
' Print #5, dotproducts#(ii, 0), dotproducts#(ii, 1)
' Next ii
'End If
'If two dot products are the same length then you have a corner collision, handled separately
'in all other cases the force is applied in the direction of the angle of obj2 that points to the face, found before
If Abs(dotproducts#(0, 0) - dotproducts#(1, 0)) < .02 * objects(obj2%, 2) Or Abs(dotproducts#(0, 0) - dotproducts#(1, 0)) < .1 Then
'For corner collisions first look at the other object to determine the angle
reflectangle# = objects(obj1%, 14)
For i% = 0 To 3
dotproducts#(i%, 0) = Cos(reflectangle#) * (px# - objects(obj1%, 4)) + Sin(reflectangle#) * (py# - objects(obj1%, 5))
dotproducts#(i%, 1) = reflectangle#
reflectangle# = reflectangle# + _Pi / 2
Next i%
sortdouble2D dotproducts#(), 0
'If write1% = 1 Then
' Print #5, "FIRST OBJECT DOT PRODUCTS"
' For ii = 0 To 3
' Print #5, dotproducts#(ii, 0), dotproducts#(ii, 1)
' Next ii
'End If
If Abs(dotproducts#(0, 0) - dotproducts#(1, 0)) < .02 * objects(obj1%, 2) Or Abs(dotproducts#(0, 0) - dotproducts#(1, 0)) < .1 Then
'angle1# = Atan2(objects(obj1%, 4) - px#, objects(obj1%, 5) - py#) 'points directly to center
angle1# = _Atan2(objects(obj1%, 5) - py#, objects(obj1%, 4) - px#) 'points directly to center
'tempangle1# = Atan2(px# - objects(obj2%, 4), py# - objects(obj2%, 5)) 'points away from center of obj2
tempangle1# = _Atan2(py# - objects(obj2%, 5), px# - objects(obj2%, 4)) 'points away from center of obj2
If Cos(angle1#) * Cos(tempangle1#) + Sin(angle1#) * Sin(tempangle1#) < .707 Then 'if the dot product of the two vectors is <.707 = ABcos(theta) = cos(theta) (since vectors length=1) so if the collision angle is less than 45 degrees...
reflectangle# = objects(obj2%, 14)
For i% = 0 To 3
dotproducts#(i%, 0) = Cos(reflectangle#) * (objects(obj1%, 4) - objects(obj2%, 4)) + Sin(reflectangle#) * (objects(obj1%, 5) - objects(obj2%, 5))
dotproducts#(i%, 1) = reflectangle#
reflectangle# = reflectangle# + _Pi / 2
Next i%
sortdouble2D dotproducts#(), 0
angle1# = dotproducts#(0, 1)
End If 'else angle1# remains unchanged
angle4# = angle1#
cornerflag% = 1
If write1% = 1 Then Print #5, "CORNER COLLISION"
Else
angle1# = dotproducts#(0, 1) + _Pi 'reversed because for object 1 the vectors point away from the center of object 1 (for object 2 they point towards object 1)
If write1% = 1 Then Print #5, "FIRST OBJECT FACE COLLISION"
End If
Else
angle1# = dotproducts#(0, 1) 'references the old dot products due to conditional else statement, points towards object 1 face
If write1% = 1 Then Print #5, "SECOND OBJECT FACE COLLISION"
End If
'COLLISION ANGLE:
'Translation Portion
If vel1# > 0.00000000001 Or vel2# > 0.00000000001 Then 'if something is moving
If (Cos(angle1#) * objects(obj1%, 6) + Sin(angle1#) * objects(obj1%, 7)) > (Cos(angle1#) * objects(obj2%, 6) + Sin(angle1#) * objects(obj2%, 7)) Then 'if objects are moving away from each other
'Rem nullify force if the objects are moving away from each other
nulvel% = 1
transangle# = angle1#
Else
'transangle# = avgangle(angle1#, angle2#)
transangle# = anglemeld#(angle1#, angle2#, 1 - 0.5 * Abs(vel1# - vel2#) ^ 2 / (Abs(vel1# - vel2#) ^ 2 + velocityangletransition#))
End If
Else
transangle# = angle1#
nulvel% = 1
End If
'Rotation Portion
Rem Total Velocity of collision point on object 1
tvx1# = objects(obj1%, 6) - objects(obj1%, 15) * Sqr((px# - objects(obj1%, 4)) ^ 2 + (py# - objects(obj1%, 5)) ^ 2) * Sin(obj1topangle#)
tvy1# = objects(obj1%, 7) + objects(obj1%, 15) * Sqr((px# - objects(obj1%, 4)) ^ 2 + (py# - objects(obj1%, 5)) ^ 2) * Cos(obj1topangle#)
tvx2# = objects(obj2%, 6) - objects(obj2%, 15) * Sqr((px# - objects(obj2%, 4)) ^ 2 + (py# - objects(obj2%, 5)) ^ 2) * Sin(obj2topangle#)
tvy2# = objects(obj2%, 7) + objects(obj2%, 15) * Sqr((px# - objects(obj2%, 4)) ^ 2 + (py# - objects(obj2%, 5)) ^ 2) * Cos(obj2topangle#)
tv1tot# = Sqr(tvx1# ^ 2 + tvy1# ^ 2)
tv2tot# = Sqr(tvx2# ^ 2 + tvy2# ^ 2)
If write1% = 1 Then Print #5, "TVs: ", tvx1#, tvy1#, tvx2#, tvy2#
If (Cos(angle1#) * tvx1# + Sin(angle1#) * tvy1#) < (Cos(angle1#) * tvx2# + Sin(angle1#) * tvy2#) Then 'if the collision points are moving towards each other
'If write1%=1 Then Print #5, "VEL of point on 1 in impact direction: ", Cos(angle1#) * tvx1# + Sin(angle1#) * tvy1#
'If write1%=1 Then Print #5, "VEL of point on 2 in impact direction: ", Cos(angle1#) * tvx2# + Sin(angle1#) * tvy2#
If tv1tot# > .0001 Or tv2tot# > .0001 Then 'if at least one point is moving
If cornerflag% = 0 Then 'If it's not a corner collision, if it's a corner collision then angle4# is already defined
Rem Vectors should be pointing the same direction
If tv1tot# < .0001 Then 'if point 1 is stationary (and point 2 is not)
'angle4# = Atan2(tvx2#, tvy2#)
angle4# = _Atan2(tvy2#, tvx2#)
ElseIf tv2tot# < .0001 Then 'if point 2 is stationary (and point 1 is not)
'angle4# = Atan2(tvx1#, tvy1#)
angle4# = _Atan2(tvy1#, tvx1#)
ElseIf tvx1# * tvx2# + tvy1# * tvy2# < 0 Then
'angle4# = avgangle(Atan2(tvx1#, tvy1#) + _Pi, Atan2(tvx2#, tvy2#)) 'since the vectors are pointing opposite directions, one must be reversed
angle4# = avgangle(_Atan2(tvy1#, tvx1#) + _Pi, _Atan2(tvy2#, tvx2#)) 'since the vectors are pointing opposite directions, one must be reversed
ElseIf tvx1# * tvx2# + tvy1# * tvy2# > 0 Then
'angle4# = avgangle(Atan2(tvx1#, tvy1#), Atan2(tvx2#, tvy2#)) 'since the vectors are pointing the same direction, they can be averaged
angle4# = avgangle(_Atan2(tvy1#, tvx1#), _Atan2(tvy2#, tvx2#)) 'since the vectors are pointing the same direction, they can be averaged
Else
angle4# = angle1#
End If
Rem Vector must be pointing towards the collision face, or away from 1. angle1# already accounts for this, so the two must be aligned.
If Cos(angle1#) * Cos(angle4#) + Sin(angle1#) * Sin(angle4#) <= 0 Then angle4# = angle4# + _Pi 'This checks for alignment
fixangle (angle4#)
fixangle (angle1#)
End If
Else
angle4# = angle1#
nulrot% = 1
End If
If objects(obj1%, 15) <> 0 Or objects(obj2%, 15) <> 0 Then 'Rotation Portion
'angle5# = avgangle(angle1#, angle4#)
angle5# = anglemeld#(angle1#, angle4#, 1 - 0.5 * Abs(tv1tot# - tv2tot#) ^ 2 / (Abs(tv1tot# - tv2tot#) ^ 2 + rotationalangletransition#))
Else
angle5# = angle1#
End If
Else
angle5# = angle1#
nulrot% = 1
End If
'Average
'finalangle# = avgangle(transangle#, angle5#)
If (Abs(tv1tot# - tv2tot#) + Abs(vel1# - vel2#)) <> 0 Then
finalangle# = anglemeld#(angle5#, transangle#, (Abs(tv1tot# - tv2tot#) / (Abs(tv1tot# - tv2tot#) + Abs(vel1# - vel2#))))
Else
finalangle# = avgangle(transangle#, angle5#)
End If
'FINISH ROTATIONAL ALIGNMENT
radius# = perpvector(px#, py#, Cos(finalangle#), Sin(finalangle#), objects(obj1%, 4), objects(obj1%, 5))
rot_to_rot# = radius# / (objects(obj1%, 2) * Sqr(2))
rot_to_trans# = 1 - rot_to_rot#
If write1% = 1 Then
Print #5, "Rot To Rot: ", rot_to_rot#, rot_to_trans#
Print #5, "Trans to Trans: ", trans_to_trans#, trans_to_rot#
Print #5, "Sizelimit#: ", sizelimit#
End If
'ROTATIONAL COLLISION PORTION
'These equations are for the conservation of angular momentum and energy between two colliding rotating bodies
'This becomes less true as this vector points closer to the center of object 1
'In the final extreme final case the rotation smacks the point like a paddle producing pure translation
'A new solution is needed to handle this case, then transition between situations
'For the extreme cases, all translational transfer to rotational energy: 0.5mv^2=0.5Iw^2 w=sqrt(mv^2/I) Torque=I(w-w0) w0=0 to Torque=sqrt(Imv^2)
'A better approximation is all rotational energy from both bodies is transferred to translational energy for both
'In this case, Force = sqrt((I1*w1^2 + I2*w2^2)*m1*m2/(m1+m2)). In the other case Torque=sqrt((m1*v1^2+m2*v2^2)*I1*I2/(I1+I2))
'Similarly for the opposite case, rotaional to translational Torque=sqrt(Imw^2) 'square root of square eliminates sign
If nulrot% = 0 Then 'if the collision points are moving towards each other
If objects(obj2%, 0) = 1 Then 'when the object it's hitting is fixed
torquemag# = Abs(2 * objects(obj1%, 13) * objects(obj1%, 15)) 'limit should be 2*I1*w1
tempforce2# = Sqr(objects(obj1%, 13) * objects(obj1%, 15) ^ 2 * objects(obj1%, 3)) 'Force =sqrt(Iw^2*m)
Else
torquemag# = Abs(2 * objects(obj1%, 13) * objects(obj2%, 13) * (objects(obj1%, 15) - objects(obj2%, 15)) / (objects(obj1%, 13) + objects(obj2%, 13))) '2*I1*I2*(w1-w2)/(I1+I2)
tempforce2# = Sqr((objects(obj1%, 13) * objects(obj1%, 15) ^ 2 + objects(obj2%, 13) * objects(obj2%, 15) ^ 2) * objects(obj1%, 3) * objects(obj2%, 3) / (objects(obj1%, 3) + objects(obj2%, 3))) 'Force = sqrt((I1*w1^2 + I2*w2^2)*m1*m2/(m1+m2))
End If
'radius# = Sqr((px# - objects(obj1%, 4)) ^ 2 + (py# - objects(obj1%, 5)) ^ 2) 'maximum value
If Abs(radius#) < .000000001 Then
tempforce1# = 1 * tempforce2#
Else
tempforce1# = (torquemag# / radius#) 'These values don't depend on knowing the colliding face
End If
If tempforce1# > 1 * tempforce2# Then
If write1% = 1 Then Print #5, "Rotation Force REDUCED from ", tempforce1#
tempforce1# = 1 * tempforce2# 'this ratio is a complete guess, but we can't have a singularity
End If
force2mag# = rot_to_rot# * tempforce1# + rot_to_trans# * tempforce2#
'SUBSTITUTE rot_to_tot* tempforce1# with: radius# / (objects(obj1%, 2) * Sqr(2))* (torquemag# / radius#)= torquemag#/(objects(obj1%, 2) * Sqr(2))
'tempforce1# = (torquemag# / radius#) 'this doesn't work for some reason?
'force2mag# = torquemag# / (objects(obj1%, 2) * Sqr(2)) + rot_to_trans# * tempforce2#
If write1% = 1 Then Print #5, "ROTATION TEMPFORCE 1 & 2 & radius: ", tempforce1#, tempforce2#, radius#
Else
force2mag# = 0 'nullify force if the objects are moving away from each other
If write1% = 1 Then Print #5, "Rotation Force Nullified"
End If
'TRANSLATION PORTION
If nulvel% = 0 Then
If objects(obj2%, 0) = 1 Then 'when the object it's hitting is fixed
tempforce1# = Abs(2 * objects(obj1%, 3) * (Cos(finalangle#) * objects(obj1%, 6) + Sin(finalangle#) * objects(obj1%, 7))) ''limit should be 2*m1*v1, velocity component in line with force (used to use component in-line with face, but this works better)
temptorque# = Sqr(objects(obj1%, 3) * vel1# ^ 2 * objects(obj1%, 13)) 'sqr(m*v1^2*I)
Else
'2*m1*m2*(v1-v2)/(m1+m2) Sign depends on directions linear movement solution. Use COM velocity for linear components, velocity of point impact for rotational.
'tempforce1# = Abs(2 * objects(obj1%, 3) * objects(obj2%, 3) * (vel1# - vel2#) / (objects(obj1%, 3) + objects(obj2%, 3))) '2*m1*m2*(v1-v2)/(m1+m2) force direction agnostic equation
vel1f# = Sqr((Cos(finalangle#) * objects(obj1%, 6)) ^ 2 + (Sin(finalangle#) * objects(obj1%, 7)) ^ 2)
vel2f# = Sqr((Cos(finalangle#) * objects(obj2%, 6)) ^ 2 + (Sin(finalangle#) * objects(obj2%, 7)) ^ 2)
tempforce1# = Abs(2 * objects(obj1%, 3) * objects(obj2%, 3) * (vel1f# - vel2f#) / (objects(obj1%, 3) + objects(obj2%, 3))) 'These equations use the force direction
temptorque# = Sqr((objects(obj1%, 3) * vel1# ^ 2 + objects(obj2%, 3) * vel2# ^ 2) * objects(obj1%, 13) * objects(obj2%, 13) / (objects(obj1%, 13) + objects(obj2%, 13))) 'Torque=sqrt((m1*v1^2+m2*v2^2)*I1*I2/(I1+I2))
End If
'radius# = Sqr((px# - objects(obj1%, 4)) ^ 2 + (py# - objects(obj1%, 5)) ^ 2) 'maximum value
If Abs(radius#) < .0000000001 Then
tempforce2# = 1 * tempforce1#
Else
tempforce2# = (temptorque# / radius#) 'These values don't depend on knowing the colliding face
End If
If tempforce2# > 1 * tempforce1# Then tempforce2# = 1 * tempforce1# 'this ratio is a complete guess, but we can't have a singularity
force1mag# = trans_to_trans# * tempforce1# + trans_to_rot# * tempforce2#
If write1% = 1 Then Print #5, "TRANSLATION TEMPFORCE 1 & 2 & Radius: ", tempforce1#, tempforce2#, radius#
Else
force1mag# = 0 'nullify force is the objects are moving away from each other
If write1% = 1 Then Print #5, "Velocity Force Nullified"
End If
'FORCES
finalforce# = force1mag# + force2mag#
forces(0) = forces(0) + objects(obj1%, 12) * objects(obj2%, 12) * (finalforce# * Cos(finalangle#)) 'reduce by force return
forces(1) = forces(1) + objects(obj1%, 12) * objects(obj2%, 12) * (finalforce# * Sin(finalangle#)) 'reduce by force return
If write1% = 1 Then Print #5, "REDUCED STATIC SUB FORCES"
If write1% = 1 Then Print #5, forces(0), forces(1)
If write1% = 1 Then Print #5, "ANGLE1, ANGLE2, TRANS_ANGLE AND FORCE1MAG"
If write1% = 1 Then Print #5, angle1#, angle2#, transangle#, force1mag#
If write1% = 1 Then Print #5, "ANGLE 3 and ANGLE 4, and ANGLE 5 ", angle3#, angle4#, angle5#
If write1% = 1 Then Print #5, "TRANS FORCE, ROT FORCE, TORQUE ", force1mag#, force2mag#, torquemag#
If write1% = 1 Then Print #5, "FINAL ANGLE AND FINAL FORCE AND FINAL FORCE REDUCED: ", finalangle#, finalforce#, objects(obj1%, 12) * objects(obj2%, 12) * finalforce#
If write1% = 1 Then Print #5, "VELOCITY", vel1#, objects(obj1%, 6), objects(obj1%, 7)
End Sub
Sub springforceobjects (px#, py#, obj1%, obj2%)
If write1% = 1 Then Print #5, ""
If write1% = 1 Then Print #5, "TOUCH COLLISION "
Dim springforce#, angle1#, tempangle1#, reflectangle#
springforce# = 0
forces(0) = 0
forces(1) = 0
Dim corner%% 'a byte, between -128 amd 127
corner%% = 0
Dim dampingcoef#
dampingcoef# = 0.5 * objects(obj1%, 18) + 0.5 * objects(obj2%, 18)
Rem FIND FACE ANGLE:
'Approach: find dot product of obj2 vector to collision point (stepped back by one velocity increment) and obj2 angle vectors (incremented by 90 deg increments)
Dim dotproducts#(3, 1)
reflectangle# = objects(obj2%, 14)
For i% = 0 To 3
'dotproducts#(i%, 0) = Cos(reflectangle#) * ((px# - objects(obj1%, 6) / physicslimit) - objects(obj2%, 4)) + Sin(reflectangle#) * ((py# - objects(obj1%, 7) / physicslimit) - objects(obj2%, 5))
dotproducts#(i%, 0) = Cos(reflectangle#) * (px# - objects(obj2%, 4)) + Sin(reflectangle#) * (py# - objects(obj2%, 5)) 'Not sure that stepping back position always helps
'If write1%=1 Then Print #5, reflectangle#, (px# - objects(obj2%, 4)), (py# - objects(obj2%, 5))
dotproducts#(i%, 1) = reflectangle#
reflectangle# = reflectangle# + _Pi / 2
Next i%
'the largest positive value will indicate which face of obj2 was hit by obj1, and the angle that points to it.
sortdouble2D dotproducts#(), 0
'If write1%=1 Then Print #5, "SECOND OBJECT DOT PRODUCTS"
'If two dot products are the same length then you have a corner collision, handled separately
'in all other cases the force is applied in the direction of the angle of obj2 that points to the face, found before
If Abs(dotproducts#(0, 0) - dotproducts#(1, 0)) < .02 * objects(obj2%, 2) Or Abs(dotproducts#(0, 0) - dotproducts#(1, 0)) < .1 Then
'For corner collisions first look at the other object to determine the angle
reflectangle# = objects(obj1%, 14)
For i% = 0 To 3
dotproducts#(i%, 0) = Cos(reflectangle#) * (px# - objects(obj1%, 4)) + Sin(reflectangle#) * (py# - objects(obj1%, 5))
dotproducts#(i%, 1) = reflectangle#
reflectangle# = reflectangle# + _Pi / 2
Next i%
sortdouble2D dotproducts#(), 0
'If write1%=1 Then Print #5, "FIRST OBJECT DOT PRODUCTS"
If Abs(dotproducts#(0, 0) - dotproducts#(1, 0)) < .02 * objects(obj1%, 2) Or Abs(dotproducts#(0, 0) - dotproducts#(1, 0)) < .1 Then
'angle1# = Atan2(objects(obj1%, 4) - px#, objects(obj1%, 5) - py#) 'points directly to center of obj1
angle1# = _Atan2(objects(obj1%, 5) - py#, objects(obj1%, 4) - px#) 'points directly to center of obj1
'tempangle1# = Atan2(px# - objects(obj2%, 4), py# - objects(obj2%, 5)) 'points away from center of obj2
tempangle1# = _Atan2(py# - objects(obj2%, 5), px# - objects(obj2%, 4)) 'points away from center of obj2
If Cos(angle1#) * Cos(tempangle1#) + Sin(angle1#) * Sin(tempangle1#) < .707 Then 'if the dot product of the two vectors is <.707 = ABcos(theta) = cos(theta) (since vectors length=1) so if the collision angle is less than 45 degrees...
reflectangle# = objects(obj2%, 14)
For i% = 0 To 3
dotproducts#(i%, 0) = Cos(reflectangle#) * (objects(obj1%, 4) - objects(obj2%, 4)) + Sin(reflectangle#) * (objects(obj1%, 5) - objects(obj2%, 5))
dotproducts#(i%, 1) = reflectangle#
reflectangle# = reflectangle# + _Pi / 2
Next i%
sortdouble2D dotproducts#(), 0
angle1# = dotproducts#(0, 1)
End If 'else angle1# remains unchanged
corner%% = 2
'If write1% = 1 Then Print #5, "TOUCH CORNER COLLISION"
Else
angle1# = dotproducts#(0, 1) + _Pi 'reversed because for object 1 the vectors point away from the center of object 1 (for object 2 they point towards object 1)
corner%% = 1 'Because this means it's hitting the corner of the second object
'If write1% = 1 Then Print #5, "TOUCH FIRST OBJECT FACE COLLISION"
End If
Else
angle1# = dotproducts#(0, 1) 'references the old dot products due to conditional else statement, points towards object 1 face
'If write1% = 1 Then Print #5, "TOUCH SECOND OBJECT FACE COLLISION"
End If
'compression Distance
Dim compdist#, fulldist#
If corner%% = 0 Then
fulldist# = perpvector(px#, py#, -Sin(angle1#), Cos(angle1#), objects(obj2%, 4), objects(obj2%, 5)) 'Distance from center is perpvector of negative reciprocal of angle1# with COM of other object and collision point.
compdist# = objects(obj2%, 2) / 2 - fulldist# - springboundary#
If compdist# < 0 Then compdist# = 0
springforce# = compdist# * springconst#
ElseIf corner%% = 1 Then
fulldist# = perpvector(px#, py#, -Sin(angle1#), Cos(angle1#), objects(obj1%, 4), objects(obj1%, 5)) 'Distance from center is perpvector of negative reciprocal of angle1# with COM of this object and collision point.
compdist# = objects(obj1%, 2) / 2 - fulldist# - springboundary#
If compdist# < 0 Then compdist# = 0
springforce# = compdist# * springconst#
Else
fulldist# = Sqr((objects(obj1%, 4) - objects(obj2%, 4)) ^ 2 + (objects(obj1%, 5) - objects(obj2%, 5)) ^ 2)
compdist# = (objects(obj1%, 2) + objects(obj2%, 2)) * Sqr(2) / 2 - fulldist# - springboundary#
If compdist# < 0 Then compdist# = 0
springforce# = compdist# * springconst#
End If
'Reduce springforce by damping coef if object is moving away
Dim tvx1#, tvx2#, tvy1#, tvy2#
Dim obj1topangle#, obj2topangle#
'obj1topangle# = Atan2(px# - objects(obj1%, 4), py# - objects(obj1%, 5))
'obj2topangle# = Atan2(px# - objects(obj2%, 4), py# - objects(obj2%, 5))
obj1topangle# = _Atan2(py# - objects(obj1%, 5), px# - objects(obj1%, 4))
obj2topangle# = _Atan2(py# - objects(obj2%, 5), px# - objects(obj2%, 4))
tvx1# = objects(obj1%, 6) - objects(obj1%, 15) * Sqr((px# - objects(obj1%, 4)) ^ 2 + (py# - objects(obj1%, 5)) ^ 2) * Sin(obj1topangle#)
tvy1# = objects(obj1%, 7) + objects(obj1%, 15) * Sqr((px# - objects(obj1%, 4)) ^ 2 + (py# - objects(obj1%, 5)) ^ 2) * Cos(obj1topangle#)
tvx2# = objects(obj2%, 6) - objects(obj2%, 15) * Sqr((px# - objects(obj2%, 4)) ^ 2 + (py# - objects(obj2%, 5)) ^ 2) * Sin(obj2topangle#)
tvy2# = objects(obj2%, 7) + objects(obj2%, 15) * Sqr((px# - objects(obj2%, 4)) ^ 2 + (py# - objects(obj2%, 5)) ^ 2) * Cos(obj2topangle#)
If damptype% = 1 Then 'if unidirectional damping
If (Cos(angle1#) * tvx1# + Sin(angle1#) * tvy1#) <= (Cos(angle1#) * tvx2# + Sin(angle1#) * tvy2#) Then 'if the collision points are moving towards each other
forces(0) = springforce# * Cos(angle1#)
forces(1) = springforce# * Sin(angle1#)
Else
'Rem FORCES
If write1% = 1 Then Print #5, "Spring Points Moving Away"
forces(0) = (1 - dampingcoef#) * springforce# * Cos(angle1#)
forces(1) = (1 - dampingcoef#) * springforce# * Sin(angle1#)
End If
Else
forces(0) = Cos(angle1#) * (springforce# - dampingcoef# * objects(obj1%, 3) * objects(obj2%, 3) * (Cos(angle1#) * (tvx1# - tvx2#) + Sin(angle1#) * (tvy1# - tvy2#)) / (objects(obj1%, 3) + objects(obj2%, 3)))
forces(1) = Sin(angle1#) * (springforce# - dampingcoef# * objects(obj1%, 3) * objects(obj2%, 3) * (Cos(angle1#) * (tvx1# - tvx2#) + Sin(angle1#) * (tvy1# - tvy2#)) / (objects(obj1%, 3) + objects(obj2%, 3)))
End If
If write1% = 1 Then
Print #5, "SPRING STATIC SUB FORCES"
Print #5, forces(0), forces(1)
End If
'Add friction here, and in collisionforceobjects also? Probably best to just leave them here only
'Normal Force
Dim normalforce#, forceangle#, frictionforce#
If Abs((tvx1# - tvx2#) * Cos(forceangle#) + (tvy1# - tvy2#) * Sin(forceangle#)) > 0.001 Then ' skip this whole thing if there is no tangent velocity or force, use relative velocity
'(tvx1# - tvx2#) * Cos(forceangle#) + (tvy1# - tvy2#) * Sin(forceangle#)
'(objects(obj1%, 6) - objects(obj2%, 6)) * Cos(forceangle#) + (objects(obj1%, 7) - objects(obj2%, 7)) * Sin(forceangle#)
'Use of total velocity and object velocity is different and intentional, but I'm still experimenting with this
forceangle# = angle1# + _Pi / 2
If (tvx1# - tvx2#) * Cos(forceangle#) + (tvy1# - tvy2#) * Sin(forceangle#) > 0 Then forceangle# = forceangle# - _Pi
'friction force should be opposite in direction to the tangent velocity, if no velocity then should be opposite to tangent force. No tangent force here
normalforce# = Sqr(forces(0) ^ 2 + forces(1) ^ 2) 'already in direction for angle1, so no correction needed there
frictionforce# = (0.5 * objects(obj1%, 11) + 0.5 * objects(obj2%, 11)) * normalforce#
If frictionforce# > Abs(objects(obj1%, 3) * objects(obj2%, 3) * (Cos(forceangle#) * (objects(obj1%, 6) - objects(obj2%, 6)) + Sin(forceangle#) * (objects(obj1%, 7) - objects(obj2%, 7))) / (objects(obj1%, 3) + objects(obj2%, 3))) Then
frictionforce# = Abs(objects(obj1%, 3) * objects(obj2%, 3) * (Cos(forceangle#) * (objects(obj1%, 6) - objects(obj2%, 6)) + Sin(forceangle#) * (objects(obj1%, 7) - objects(obj2%, 7))) / (objects(obj1%, 3) + objects(obj2%, 3)))
If write1% = 1 Then Print #5, "FRICTION FORCES CAPPED"
'Friction force should not exceed stopping force
End If
forces(0) = forces(0) + Cos(forceangle#) * frictionforce#
forces(1) = forces(1) + Sin(forceangle#) * frictionforce#
If write1% = 1 Then
Print #5, "FRICTION SUB FORCES"
Print #5, Cos(forceangle#) * frictionforce#, Sin(forceangle#) * frictionforce#
Print #5, "NORMAL FORCE, FRICTION FORCE, FORCE ANGLE: ", normalforce#, frictionforce#, forceangle#
End If
End If
'Reduce Drift
If Abs(forces(0)) < .000000001 Then forces(0) = 0
If Abs(forces(1)) < .000000001 Then forces(1) = 0
If write1% = 1 Then
Print #5, "TOTAL REACTION SUB FORCES"
Print #5, forces(0), forces(1)
Print #5, "ANGLE1 ", angle1#
Print #5, "compdist, fulldist: ", compdist#, fulldist#
Print #5, "VELOCITY", objects(obj1%, 6), objects(obj1%, 7)
End If
End Sub
Function Atan2# (x#, y#)
If x# >= 0 Then
Atan2# = Atn(y# / x#)
Else
Atan2# = Atn(y# / x#) + _Pi
End If 'output ranges from -Pi/2 to 3Pi/2
End Function
Sub outer_collision (px#, py#, obji%, objj%, forcecounter%, forcelist#()) 'updates forcelist# with new forces
Dim angle#
'This sub could probably be included in collisionforceobjects in a future update, unless it becomes more complex
collisionforceobjects px#, py#, obji%, objj% 'This sub updates the forces vectors used below
If Sqr(forces(0) ^ 2 + forces(1) ^ 2) > 0.0000000001 And forcecounter% <= collisionperobjectlimit% Then
forcelist#(forcecounter%, 0) = forces(0)
forcelist#(forcecounter%, 1) = forces(1)
'angle# = Atan2(px# - objects(obji%, 4), py# - objects(obji%, 5)) 'angle from object center to point p
angle# = _Atan2(py# - objects(obji%, 5), px# - objects(obji%, 4)) 'angle from object center to point p
If (-Sin(angle#) * forces(0) + Cos(angle#) * forces(1)) > 0 Then
' dot product of negative recirprocal of normalized angle vector (from sin/cos) with force vector then the rotation is positive
forcelist#(forcecounter%, 2) = Sqr(forces(0) ^ 2 + forces(1) ^ 2) * perpvector(px#, py#, forces(0), forces(1), objects(obji%, 4), objects(obji%, 5)) '+F*R
'If write1% = 1 Then Print #5, "THIS TORQUE 1: ", Sqr(forces(0) ^ 2 + forces(1) ^ 2) * perpvector(px#, py#, forces(0), forces(1), objects(obji%, 4), objects(obji%, 5))
Else
forcelist#(forcecounter%, 2) = -Sqr(forces(0) ^ 2 + forces(1) ^ 2) * perpvector(px#, py#, forces(0), forces(1), objects(obji%, 4), objects(obji%, 5)) '+F*R
'If write1% = 1 Then Print #5, "THIS TORQUE 2: ", -Sqr(forces(0) ^ 2 + forces(1) ^ 2) * perpvector(px#, py#, forces(0), forces(1), objects(obji%, 4), objects(obji%, 5))
End If
If write1% = 1 Then Print #5, "O-TORQUE ", forcelist#(forcecounter%, 2), perpvector(px#, py#, forces(0), forces(1), objects(obji%, 4), objects(obji%, 5))
If write1% = 1 Then Print #5, "angle ", angle#, px#, py#
forcecounter% = forcecounter% + 1
Else
If write1% = 1 Then Print #5, "TOUCHED, NO TOUCH FORCE"
End If
End Sub
Sub inner_collision (px#, py#, obji%, objj%, forcecounter%, forcelist#()) 'updates forcelist# with new forces
Dim angle#
springforceobjects px#, py#, obji%, objj% 'This sub updates the forces vectors used below (I could have made it pass them but instead I made these global)
If Sqr(forces(0) ^ 2 + forces(1) ^ 2) > 0.0000000001 And forcecounter% <= collisionperobjectlimit% Then
forcelist#(forcecounter%, 0) = forces(0)
forcelist#(forcecounter%, 1) = forces(1)
'angle# = Atan2(px# - objects(obji%, 4), py# - objects(obji%, 5)) 'angle from object center to point p
angle# = _Atan2(py# - objects(obji%, 5), px# - objects(obji%, 4)) 'angle from object center to point p
If (-Sin(angle#) * forces(0) + Cos(angle#) * forces(1)) > 0 Then
' dot product of negative recirprocal of normalized angle vector (from sin/cos) with force vector then the rotation is positive
forcelist#(forcecounter%, 2) = Sqr(forces(0) ^ 2 + forces(1) ^ 2) * perpvector(px#, py#, forces(0), forces(1), objects(obji%, 4), objects(obji%, 5)) '+F*R
'If write1% = 1 Then Print #5, "THIS TORQUE 1: ", Sqr(forces(0) ^ 2 + forces(1) ^ 2) * perpvector(px#, py#, forces(0), forces(1), objects(obji%, 4), objects(obji%, 5))
Else
forcelist#(forcecounter%, 2) = -Sqr(forces(0) ^ 2 + forces(1) ^ 2) * perpvector(px#, py#, forces(0), forces(1), objects(obji%, 4), objects(obji%, 5)) '+F*R
'If write1% = 1 Then Print #5, "THIS TORQUE 2: ", -Sqr(forces(0) ^ 2 + forces(1) ^ 2) * perpvector(px#, py#, forces(0), forces(1), objects(obji%, 4), objects(obji%, 5))
End If
If write1% = 1 Then Print #5, "I-TORQUE ", forcelist#(forcecounter%, 2), perpvector(px#, py#, forces(0), forces(1), objects(obji%, 4), objects(obji%, 5))
If write1% = 1 Then Print #5, "angle ", angle#
forcecounter% = forcecounter% + 1
Else
If write1% = 1 Then Print #5, "TOUCHED, NO TOUCH FORCE"
End If
End Sub
Function anycollision% (i%, j%)
Dim test%
test% = 0
If In4Points%(corners#(i%, 0), corners#(i%, 1), corners#(j%, 0), corners#(j%, 1), corners#(j%, 2), corners#(j%, 3), corners#(j%, 4), corners#(j%, 5), corners#(j%, 6), corners#(j%, 7)) = 1 Then
test% = 1
End If
If In4Points%(corners#(i%, 2), corners#(i%, 3), corners#(j%, 0), corners#(j%, 1), corners#(j%, 2), corners#(j%, 3), corners#(j%, 4), corners#(j%, 5), corners#(j%, 6), corners#(j%, 7)) = 1 Then
test% = 1
End If
If In4Points%(corners#(i%, 4), corners#(i%, 5), corners#(j%, 0), corners#(j%, 1), corners#(j%, 2), corners#(j%, 3), corners#(j%, 4), corners#(j%, 5), corners#(j%, 6), corners#(j%, 7)) = 1 Then
test% = 1
End If
If In4Points%(corners#(i%, 6), corners#(i%, 7), corners#(j%, 0), corners#(j%, 1), corners#(j%, 2), corners#(j%, 3), corners#(j%, 4), corners#(j%, 5), corners#(j%, 6), corners#(j%, 7)) = 1 Then
test% = 1
End If
If In4Points%(corners#(j%, 0), corners#(j%, 1), corners#(i%, 0), corners#(i%, 1), corners#(i%, 2), corners#(i%, 3), corners#(i%, 4), corners#(i%, 5), corners#(i%, 6), corners#(i%, 7)) = 1 Then
test% = 1
End If
If In4Points%(corners#(j%, 2), corners#(j%, 3), corners#(i%, 0), corners#(i%, 1), corners#(i%, 2), corners#(i%, 3), corners#(i%, 4), corners#(i%, 5), corners#(i%, 6), corners#(i%, 7)) = 1 Then
test% = 1
End If
If In4Points%(corners#(j%, 4), corners#(j%, 5), corners#(i%, 0), corners#(i%, 1), corners#(i%, 2), corners#(i%, 3), corners#(i%, 4), corners#(i%, 5), corners#(i%, 6), corners#(i%, 7)) = 1 Then
test% = 1
End If
If In4Points%(corners#(j%, 6), corners#(j%, 7), corners#(i%, 0), corners#(i%, 1), corners#(i%, 2), corners#(i%, 3), corners#(i%, 4), corners#(i%, 5), corners#(i%, 6), corners#(i%, 7)) = 1 Then
test% = 1
End If
anycollision% = test%
End Function
Sub update_non_screen_corners
Dim numobjects%
numobjects% = UBound(objects, 1)
'Make a temporary list of all corners of all objects
ReDim corners#(numobjects%, 7) 'Redim also sets everything to zero If write1%=1 Then Print #5, "FIRST OBJECT FACE COLLISION"
ReDim springcorners#(numobjects%, 7) 'Redim also sets everything to zero If write1%=1 Then Print #5, "FIRST OBJECT FACE COLLISION"
For i% = 0 To numobjects%
' corners#(i%, 0) = objects(i%, 4) - objects(i%, 2) / 2 * Cos(objects(i%, 14)) - objects(i%, 2) / 2 * Sin(objects(i%, 14)) 'angles are in radians
' corners#(i%, 1) = objects(i%, 5) - objects(i%, 2) / 2 * Sin(objects(i%, 14)) + objects(i%, 2) / 2 * Cos(objects(i%, 14)) 'angles are in radians
'Side lengths are the same, so this can be further simplified:
corners#(i%, 0) = objects(i%, 4) + objects(i%, 2) / 2 * (Cos(objects(i%, 14)) - Sin(objects(i%, 14))) 'angles are in radians X=1 Y=1
corners#(i%, 1) = objects(i%, 5) + objects(i%, 2) / 2 * (Sin(objects(i%, 14)) + Cos(objects(i%, 14))) 'angles are in radians X=1 Y=1
corners#(i%, 2) = objects(i%, 4) + objects(i%, 2) / 2 * (-Cos(objects(i%, 14)) - Sin(objects(i%, 14))) 'angles are in radians X=-1 Y=1
corners#(i%, 3) = objects(i%, 5) + objects(i%, 2) / 2 * (-Sin(objects(i%, 14)) + Cos(objects(i%, 14))) 'angles are in radians X=-1 Y=1
corners#(i%, 4) = objects(i%, 4) + objects(i%, 2) / 2 * (-Cos(objects(i%, 14)) + Sin(objects(i%, 14))) 'angles are in radians X=-1 Y=-1
corners#(i%, 5) = objects(i%, 5) + objects(i%, 2) / 2 * (-Sin(objects(i%, 14)) - Cos(objects(i%, 14))) 'angles are in radians X=-1 Y=-1
corners#(i%, 6) = objects(i%, 4) + objects(i%, 2) / 2 * (Cos(objects(i%, 14)) + Sin(objects(i%, 14))) 'angles are in radians X=1 Y=-1
corners#(i%, 7) = objects(i%, 5) + objects(i%, 2) / 2 * (Sin(objects(i%, 14)) - Cos(objects(i%, 14))) 'angles are in radians X=1 Y=-1
springcorners#(i%, 0) = objects(i%, 4) + (objects(i%, 2) / 2 - springboundary#) * (Cos(objects(i%, 14)) - Sin(objects(i%, 14))) 'angles are in radians X=1 Y=1
springcorners#(i%, 1) = objects(i%, 5) + (objects(i%, 2) / 2 - springboundary#) * (Sin(objects(i%, 14)) + Cos(objects(i%, 14))) 'angles are in radians X=1 Y=1
springcorners#(i%, 2) = objects(i%, 4) + (objects(i%, 2) / 2 - springboundary#) * (-Cos(objects(i%, 14)) - Sin(objects(i%, 14))) 'angles are in radians X=-1 Y=1
springcorners#(i%, 3) = objects(i%, 5) + (objects(i%, 2) / 2 - springboundary#) * (-Sin(objects(i%, 14)) + Cos(objects(i%, 14))) 'angles are in radians X=-1 Y=1
springcorners#(i%, 4) = objects(i%, 4) + (objects(i%, 2) / 2 - springboundary#) * (-Cos(objects(i%, 14)) + Sin(objects(i%, 14))) 'angles are in radians X=-1 Y=-1
springcorners#(i%, 5) = objects(i%, 5) + (objects(i%, 2) / 2 - springboundary#) * (-Sin(objects(i%, 14)) - Cos(objects(i%, 14))) 'angles are in radians X=-1 Y=-1
springcorners#(i%, 6) = objects(i%, 4) + (objects(i%, 2) / 2 - springboundary#) * (Cos(objects(i%, 14)) + Sin(objects(i%, 14))) 'angles are in radians X=1 Y=-1
springcorners#(i%, 7) = objects(i%, 5) + (objects(i%, 2) / 2 - springboundary#) * (Sin(objects(i%, 14)) - Cos(objects(i%, 14))) 'angles are in radians X=1 Y=-1
Next i%
End Sub
Sub placeobject (xpos#, ypos#)
Dim temp%, tempsize#, temptype%, tempreturnforce#, tempmass#, tempangle#, tempxvel#, tempyvel#, tempanglevel#, tempaccelx#, tempaccely#, tempfriction#, tempdamping#
Cls
Print "PLACE OBJECT"
Print "1 - Size 50 Stationary Square "
Print "2 - Size 10 Free Square Mass 10"
Print "3 - Size 2 Free Square Mass 2"
Print "4 - Size 10 Free Square Mass 10 No Gravity"
Print "5 - Size 4 Free Square Mass 4 No Gravity"
Print "6 - Size 2 Stationary Square "
Print "7 - Custom"
Input "SELECTION: ", temp%
If temp% = 1 Then
tempsize# = 50
temptype% = 1
tempmass# = 10
tempreturnforce# = 1
tempfriction# = 0.1
tempdamping# = 0.05
End If
If temp% = 2 Then
tempsize# = 10
temptype% = 2
tempmass# = 10
tempreturnforce# = 1
tempfriction# = 0.1
tempdamping# = 0.05
End If
If temp% = 3 Then
tempsize# = 2
temptype% = 2
tempmass# = 2
tempreturnforce# = 1
tempfriction# = 0.1
tempdamping# = 0.05
End If
If temp% = 4 Then
tempsize# = 10
temptype% = 3
tempmass# = 10
tempreturnforce# = 1
tempfriction# = 0.1
tempdamping# = 0.05
End If
If temp% = 5 Then
tempsize# = 4
temptype% = 3
tempmass# = 4
tempreturnforce# = 1
tempfriction# = 0.1
tempdamping# = 0.05
End If
If temp% = 6 Then
tempsize# = 2
temptype% = 1
tempmass# = 4
tempreturnforce# = 1
tempfriction# = 0.1
tempdamping# = 0.05
End If
If temp% = 7 Then
Input "Size?: ", tempsize#
Input "Type? (1=Fixed 2=Free 3=Free No Gravity): ", temptype%
Input "Mass? ", tempmass#
Input "Force Return? ", tempreturnforce#
Input "Friction? ", tempfriction#
Input "Damping? ", tempdamping#
End If
Input "Angle: ", tempangle#
If temp% <> 1 And temp% <> 6 Then
Input "X-Velocity: ", tempxvel#
Input "Y-Velocity: ", tempyvel#
Input "Angular Velocity: ", tempanglevel#
End If
NewObject temptype%, 100, tempsize#, tempmass#, xpos#, ypos#, tempxvel#, tempyvel#, 0, 0, tempreturnforce#, tempangle#, tempanglevel#, tempfriction#, tempdamping# '(otype%, health#, size#, mass#, xpos#, ypos#, xvel#, yvel#, xacc#, yacc#, forcereturn#, angle#, anglevel#, friction#, damping#)
End Sub
Sub sortdouble (array#())
Dim size%
size% = UBound(array#)
Dim newarray#(size%)
Dim tagged%(size%)
Dim taggedindex%
For i = 0 To size%
newarray#(i) = -1.797693134862310 * 10 ^ 308
Next i
For i = 0 To size%
For j = 0 To size%
If array#(j) > newarray#(i) And tagged%(j) = 0 Then
newarray#(i) = array#(j)
taggedindex% = j
End If
Next j
tagged%(taggedindex%) = 1
Next i
For i = 0 To size%
'Print newarray#(i)
array#(i) = newarray#(i)
Next i
End Sub
Sub sortdouble2D (array#(), col%)
Dim size%, numcols%
size% = UBound(array#, 1) 'UBOUND command is 1 indexed
numcols% = UBound(array#, 2)
If col% > numcols% Then Exit Sub
Dim newarray#(size%, numcols%)
Dim tagged%(size%)
Dim taggedindex%
For i = 0 To size%
newarray#(i, col%) = -1.797693134862310 * 10 ^ 308
Next i
For i = 0 To size%
For j = 0 To size%
If array#(j, col%) > newarray#(i, col%) And tagged%(j) = 0 Then
For k = 0 To numcols%
newarray#(i, k) = array#(j, k)
Next k
taggedindex% = j
End If
Next j
tagged%(taggedindex%) = 1
Next i
For i = 0 To size%
For j = 0 To numcols%
array#(i, j) = newarray#(i, j)
Next j
Next i
End Sub
Function avgangle# (angle1#, angle2#)
avgangle# = 0
fixangle (angle1#)
fixangle (angle2#)
If angle1# < angle2# Then
While angle2# - angle1# > _Pi
angle1# = angle1# + 2 * _Pi
Wend
End If
If angle2# < angle1# Then
While angle1# - angle2# > _Pi
angle2# = angle2# + 2 * _Pi
Wend
End If
avgangle# = (angle1# + angle2#) / 2
End Function
Function anglemeld# (angle1#, angle2#, angle1percent#)
anglemeld# = 0
fixangle (angle1#)
fixangle (angle2#)
If angle1# < angle2# Then
While angle2# - angle1# > _Pi
angle1# = angle1# + 2 * _Pi
Wend
End If
If angle2# < angle1# Then
While angle1# - angle2# > _Pi
angle2# = angle2# + 2 * _Pi
Wend
End If
anglemeld# = angle1# * angle1percent# + angle2# * (1 - angle1percent#)
End Function
Sub fixangle (angle#) 'all angles will be between 0 and 2Pi
While angle# > 2 * _Pi
angle# = angle# - 2 * _Pi
Wend
While angle# < 0
angle# = angle# + 2 * _Pi
Wend
End Sub
Function fixangle# (angle#) 'all angles will be between 0 and 2Pi
While angle# > 2 * _Pi
angle# = angle# - 2 * _Pi
Wend
While angle# < 0
angle# = angle# + 2 * _Pi
Wend
fixangle# = angle#
End Function
Sub Makelandscape ()
Dim downint%, acrossint%, cursorx%, cursory%, brush%
'-2=DOOR BORDER
'-1=EXIT DOOR
'0=NOTHING
'1=BLINKING STAR
'2=DESTRUCTABLE BLOCK
'3=INVINCIBLE BLOCK
For x = 1 To 3000
downint% = Int(Rnd * 960) + 1
acrossint% = Int(Rnd * 720) + 1
landscape(downint%, acrossint%) = 1
Next x
For x = 0 To 720
landscape(0, x) = 3
landscape(960, x) = 3
Next x
For x = 0 To 960
landscape(x, 0) = 3
landscape(x, 720) = 3
Next x
brush% = 2
For x = 1 To 140
cursorx% = Int(Rnd * 959) + 1
cursory% = Int(Rnd * 699) + 20
While Rnd > .003
If Rnd < .05 Then brush% = Int(Rnd * 6) + 2
brushfill cursorx%, cursory%, brush%, 2
cursorx% = cursorx% + Int(Rnd * 5) - 2
cursory% = cursory% + Int(Rnd * 5) - 2
If cursorx% < 1 Then cursorx% = 1
If cursory% < 21 Then cursory% = 21
If cursorx% > 959 Then cursorx% = 959
If cursory% > 719 Then cursory% = 719
Wend
Next x
'For x = 1 To 959
' For y = 1 To 719
' If Rnd < .5 Then landscape(x, y) = 1
' Next y
'Next x
'Make larger holes
Dim holecounter%, cutoff%
Dim fill_list%(6)
'Fill in holes
fill_list%(0) = 5
fill_list%(1) = 5
fill_list%(2) = 6
fill_list%(3) = 6
fill_list%(4) = 7
fill_list%(5) = 7
fill_list%(6) = 8
For z = 0 To UBound(fill_list%)
For x = 1 To 959
For y = 1 To 719
holecounter% = 0
If landscape(x + 1, y) = 1 Then holecounter% = holecounter% + 1
If landscape(x - 1, y) = 1 Then holecounter% = holecounter% + 1
If landscape(x, y + 1) = 1 Then holecounter% = holecounter% + 1
If landscape(x, y - 1) = 1 Then holecounter% = holecounter% + 1
If landscape(x + 1, y + 1) = 1 Then holecounter% = holecounter% + 1
If landscape(x + 1, y - 1) = 1 Then holecounter% = holecounter% + 1
If landscape(x - 1, y + 1) = 1 Then holecounter% = holecounter% + 1
If landscape(x - 1, y - 1) = 1 Then holecounter% = holecounter% + 1
If holecounter% >= fill_list%(z) Then landscape(x, y) = 2
Next y
Next x
Next z
For x = 1 To 959
For y = 1 To 719
If landscape(x, y) = 2 Then landscapehealth(x, y) = 12
Next y
Next x
'Make Door
For x = 446 To 514
For y = 675 To 719
If x < 450 Or x > 510 Or y < 680 Then
landscape(x, y) = -2
landscapehealth(x, y) = 0
Else
landscape(x, y) = -1
landscapehealth(x, y) = 0
End If
Next y
Next x
End Sub
Sub brushfill (xpos%, ypos%, size%, value%)
Dim x%, y%
For x% = xpos% - Int(size% / 2) - 1 To xpos% + Int(size% / 2) + 1 Step 1
For y% = ypos% - Int(size% / 2) - 1 To ypos% + Int(size% / 2) + 1 Step 1
If Sqr((x% - xpos%) ^ 2 + (y% - ypos%) ^ 2) < .7071 * size% And x% > 0 And y% > 0 And x% < 960 And y% < 720 Then
landscape(x%, y%) = value%
If value% = 2 Then
landscapehealth(x%, y%) = 12
Else
landscapehealth(x%, y%) = 0
End If
End If
Next y%
Next x%
End Sub
Sub brushfillweapon (xpos%, ypos%, size%, value%, cost%)
Dim x%, y%, tempcost%
For x% = xpos% - Int(size% / 2) - 1 To xpos% + Int(size% / 2) + 1 Step 1
For y% = ypos% - Int(size% / 2) - 1 To ypos% + Int(size% / 2) + 1 Step 1
If Sqr((x% - xpos%) ^ 2 + (y% - ypos%) ^ 2) < .7071 * size% And x% > 0 And y% > 0 And x% < 960 And y% < 720 Then
If landscape(x%, y%) <> value% Then
tempcost% = tempcost% + 1
End If
End If
Next y%
Next x%
If money% > Int(CDbl(tempcost%) / 57 * cost%) Then
For x% = xpos% - Int(size% / 2) - 1 To xpos% + Int(size% / 2) + 1 Step 1
For y% = ypos% - Int(size% / 2) - 1 To ypos% + Int(size% / 2) + 1 Step 1
If Sqr((x% - xpos%) ^ 2 + (y% - ypos%) ^ 2) < .7071 * size% And x% > 0 And y% > 0 And x% < 960 And y% < 720 Then
landscape(x%, y%) = value%
If value% = 2 Then
landscapehealth(x%, y%) = 12
Else
landscapehealth(x%, y%) = 0
End If
End If
Next y%
Next x%
money% = money% - Int(CDbl(tempcost%) / 57 * cost%)
End If
End Sub
Function radialsquare (angle#)
fixangle angle#
Select Case angle#
Case 0 To _Pi / 4
radialsquare = Sqr(1 + Tan(angle#) ^ 2)
Case _Pi / 4 To 3 * _Pi / 4
radialsquare = Sqr(1 + (1 / Tan(angle#)) ^ 2)
Case 3 * _Pi / 4 To 5 * _Pi / 4
radialsquare = Sqr(1 + Tan(angle#) ^ 2)
Case 5 * _Pi / 4 To 7 * _Pi / 4
radialsquare = Sqr(1 + (1 / Tan(angle#)) ^ 2)
Case 7 * _Pi / 4 To 2 * _Pi
radialsquare = Sqr(1 + Tan(angle#) ^ 2)
End Select
End Function
Function Inbounds (xpos%, ypos%)
If xpos% > 0 And xpos% <= 960 And ypos% > 0 And ypos% <= 720 Then
Inbounds = 1
Else
Inbound = 0
End If
End Function
RE: Box_Bash game - bplus - 01-12-2025
+1 Very interesting game! Welcome to forum!
After 3 games I saved one box
|