EDIT: More accurate representation i think
// Project: shells
// Created: 19-12-16
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "arcade mania" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 0, 0, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 )
//SetVSync(1)
Create3DPhysicsWorld(4)
Set3DPhysicsGravity(0, -10, 0)
SetSunDirection(0, -1, .2)
SetAmbientColor(0xa0, 0xa0, 0xa0)
SetSunColor(0x80, 0x80, 0x80)
type point
x as float
y as float
z as float
endtype
mouseSetup()
lastTime as float
lastTime = timer()
v as point
global dolly as integer
global camera as integer
global balls as integer[]
type tShot
id as integer
reset as float
endtype
global shots as tShot[]
do
mouseControl()
if timer() - lastTime > 0.15
v = Shoot()
lastTime = timer()
endif
cleanup()
Print("("+str(GetCameraX(1), 2)+","+str(GetCameraY(1), 2)+","+str(GetCameraZ(1), 2)+")")
Print( "Balls="+str(balls.length)+" Shot="+str(shots.length) )
Print( ScreenFPS() )
Step3DPhysicsWorld()
SetCameraPosition(1, GetObjectWorldX(camera), GetObjectWorldY(camera), GetObjectWorldZ(camera))
SetCameraRotation(1, GetObjectWorldAngleX(camera), GetObjectWorldAngleY(camera), GetObjectWorldAngleZ(camera))
Sync()
loop
function mouseSetup()
lastMousePoint.x = GetPointerX()
lastMousePoint.y = GetPointerY()
dolly = CreateObjectBox(.1, .1, .1)
camera = CreateObjectBox(.1, .1, .1)
SetObjectPosition(camera, 0, 0, 15)
FixObjectToObject(camera, dolly)
SetObjectPosition(dolly, 0, -7, 0)
endfunction
global lastMousePoint as point
function cleanUp()
b as integer
i as integer
for i=0 to balls.length
b = balls[i]
if GetObjectY(b) < -30
Delete3DPhysicsBody(b)
DeleteObject(b)
balls.remove(i)
dec i
endif
next
endfunction
function mouseControl()
p as point
a as float
p.x = GetPointerX()
p.y = GetPointerY()
a = (p.x * 360) / (GetWindowWidth() * .5)
SetObjectRotation(dolly, GetObjectWorldAngleX(dolly), a, GetObjectWorldAngleZ(dolly))
//RotateObjectLocalY(dolly, (p.x - lastMousePoint.x) * 0.5)
a = (p.y * 60) / GetWindowHeight() - 30
SetObjectRotation(camera, a, GetObjectAngleY(camera), GetObjectAngleZ(camera))
lastMousePoint = p
endfunction
function Shoot()
ball as integer
f as point
t as point
v as point
v.x = GetWindowWidth() * .6
v.y = GetWindowHeight() * 1.1
f.x = Get3DVectorXFromScreen( v.x, v.y ) + GetCameraX(1)
f.y = Get3DVectorYFromScreen( v.x, v.y ) + GetCameraY(1)
f.z = Get3DVectorZFromScreen( v.x, v.y ) + GetCameraZ(1)
v.x = GetWindowWidth() * 1.0
v.y = GetWindowHeight() * .9
t.x = Get3DVectorXFromScreen( v.x, v.y * .3 ) * 3.0 + GetCameraX(1)
t.y = Get3DVectorYFromScreen( v.x, v.y * .3 ) * 3.0 + GetCameraY(1)
t.z = Get3DVectorZFromScreen( v.x, v.y * .3 ) * 3.0 + GetCameraZ(1)
v.x = t.x - f.x : v.y = t.y - f.y : v.z = t.z - f.z
ball = CreateObjectCylinder(.2, .1, 8)
SetObjectColor(ball, 0xff, 0, 0, 0xff)
RotateObjectLocalX(ball, 90)
SetObjectPosition(ball, f.x, f.y, f.z)
Create3DPhysicsDynamicBody(ball)
SetObject3DPhysicsMass(ball, 2)
SetObject3DPhysicsAngularVelocity( ball, random(1,360), random(1,360), random(1,360), 50)
SetObject3DPhysicsLinearVelocity(ball, v.x, v.y, v.z, 10)
balls.insert(ball)
endfunction v
function GetObjectLocalPos(id as integer)
pos as point
pos.x = GetObjectX(id)
pos.y = GetObjectY(id)
pos.z = GetObjectZ(id)
endfunction pos
function GetObjectPos(id as integer)
pos as point
pos.x = GetObjectWorldX(id)
pos.y = GetObjectWorldY(id)
pos.z = GetObjectWorldZ(id)
endfunction pos