Thought ide try the bottle down throwing one too
#constant swidth = 1024
#constant sheight = 768
#constant white = MakeColor(0,0,255)
#constant green = MakeColor(0,255,0)
#constant blue = MakeColor(0,0,255)
#constant yellow = MakeColor(255,255,0)
#constant black = MakeColor(0,0,0)
#constant playerObj = 500 //object ID of player
#constant camOff_y# = 5
#constant bulletLife = .4 //time to keep bullets alive
#constant Depth#=55
SetWindowTitle("Pop UPs" )
SetWindowSize( swidth, sheight, 0 )
SetVirtualResolution( swidth, sheight ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 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 ) // since version 2.0.22 we can use nicer default fonts
create3DPhysicsWorld()
type objectType
ID as integer
time as float
endtype
loadImage(1,"duck2.png")
loadImage(2,"tarpee.png")
// the type used for bullets
type bullet
ID as integer
time as float // a time used because bullets die over time
endtype
global myBullet as bullet[0]
dim myDucks[7] as objectType
global bulletCount=0 //keeps track of the ammount of bullets currently alive used for processing
global Angle_x#
global Angle_y#
//circleImg=createCircleImage()
//triangleImg=createTriangleImage()
//SetObjectImage(obj1,circleImg,0)
//obj2=CreateObjectPlane(2,4)
CreateObjectBox(playerObj,20,20,20)
SetObjectPosition(playerObj,0,0,-20)
SetObjectVisible(playerObj,0)
//SetCameraPosition(1,0,10,-120)
LoadObject(100,"carnival.3ds")
SetObjectRotation(100,0,90,0)
SetObjectScale(100,6,6.5,10)
SetObjectPosition(100,2,-17,-1)
SetObjectCollisionMode(100,0)
SetObjectimage(100,2,0)
SetObjectcolor(100,0,0,200,255)
Create3DPhysicsStaticBody(100)
/*
LoadObject(101,"bottle.obj")
SetObjectScale(101,2,2,2)
SetObjectPosition(101,0,-10,20)
SetObjectColor(101,100,100,100,150)
SetObjectTransparency(101,1)
Create3DPhysicsDynamicBody(101)
SetObject3DPhysicsMass(101,100 )
CloneObject(102,101)
SetObjectPosition(102,-2,-10,20)
Create3DPhysicsDynamicBody(102)
SetObject3DPhysicsMass(102,100 )
CloneObject(103,101)
SetObjectPosition(103,2,-10,20)
Create3DPhysicsDynamicBody(103)
SetObject3DPhysicsMass(103,100 )
CloneObject(104,101)
SetObjectPosition(104,-1,-10,19)
Create3DPhysicsDynamicBody(104)
SetObject3DPhysicsMass(104,100 )
CloneObject(105,101)
SetObjectPosition(105,1,-10,19)
Create3DPhysicsDynamicBody(105)
SetObject3DPhysicsMass(105,100 )
CloneObject(106,101)
SetObjectPosition(106,0,-10,18)
Create3DPhysicsDynamicBody(106)
SetObject3DPhysicsMass(106,100 )
do
//duckshoot()
VectorX# = Get3DVectorXFromScreen( GetPointerX(), GetPointerY() )
VectorY# = Get3DVectorYFromScreen( GetPointerX(), GetPointerY() )
VectorZ# = Get3DVectorZFromScreen( GetPointerX(), GetPointerY()*2 )
// get a vector that points in the direction the camera is looking
VectorX2# = Get3DVectorXFromScreen( GetVirtualWidth()/2.0, GetVirtualHeight()/2.0 )
VectorY2# = Get3DVectorYFromScreen( GetVirtualWidth()/2.0, GetVirtualHeight()/2.0 )
VectorZ2# = Get3DVectorZFromScreen( GetVirtualWidth()/2.0, GetVirtualHeight()/2.0 )
// normalise Vector in the direction of Vector2
Dot# = VectorX#*VectorX2# + VectorY#*VectorY2# + VectorZ#*VectorZ2#
if ( Dot# > 0 )
VectorX# = VectorX# / Dot#
VectorY# = VectorY# / Dot#
VectorZ# = VectorZ# / Dot#
endif
WorldX# = VectorX# * Depth# + GetCameraX(1)
WorldY# = VectorY# * Depth# + GetCameraY(1)
WorldZ# = VectorZ# * Depth# + GetCameraZ(1)
SetObjectLookAt(playerObj,WorldX#,WorldY#,WorldZ#,0)
//SetObjectRotation(playerObj,Angle_x#,Angle_y#,GetObjectAngleZ(playerObj))
if GetPointerPressed()
ThrowBall( 600.0, 10.0.2)
endif
Step3DPhysicsWorld()
sync()
loop
*/
duckShoot()
function duckShoot()
ducksShot=0
for num = 0 to 7
obj=CreateObjectBox(2,4,.1)
SetObjectPosition(obj,num*5-20,-10,20)
imgRan=random(0,1)
//if imgRan=0
// SetObjectImage(obj,circleImg,0)
//else
// SetObjectImage(obj,triangleImg,0)
//endif
SetObjectImage(obj,1,0)
SetObjectTransparency(obj,1)
//SetObjectCollisionMode(obj,1)
Create3DPhysicsKinematicBody(obj)
myDucks[num].ID=obj
myDucks[num].time=0
next num
CreateText(1,"Ducks Shot=0")
SetTextSize(1,40)
SetTextPosition(1,0,0)
do
VectorX# = Get3DVectorXFromScreen( GetPointerX(), GetPointerY() )
VectorY# = Get3DVectorYFromScreen( GetPointerX(), GetPointerY() )
VectorZ# = Get3DVectorZFromScreen( GetPointerX(), GetPointerY() )
// get a vector that points in the direction the camera is looking
VectorX2# = Get3DVectorXFromScreen( GetVirtualWidth()/2.0, GetVirtualHeight()/2.0 )
VectorY2# = Get3DVectorYFromScreen( GetVirtualWidth()/2.0, GetVirtualHeight()/2.0 )
VectorZ2# = Get3DVectorZFromScreen( GetVirtualWidth()/2.0, GetVirtualHeight()/2.0 )
// normalise Vector in the direction of Vector2
Dot# = VectorX#*VectorX2# + VectorY#*VectorY2# + VectorZ#*VectorZ2#
if ( Dot# > 0 )
VectorX# = VectorX# / Dot#
VectorY# = VectorY# / Dot#
VectorZ# = VectorZ# / Dot#
endif
WorldX# = VectorX# * Depth# + GetCameraX(1)
WorldY# = VectorY# * Depth# + GetCameraY(1)
WorldZ# = VectorZ# * Depth# + GetCameraZ(1)
SetObjectLookAt(playerObj,WorldX#,WorldY#,WorldZ#,0)
//SetObjectRotation(playerObj,Angle_x#,Angle_y#,GetObjectAngleZ(playerObj))
if GetPointerPressed()
ThrowBall( 300.0, 10.0,1.0)
endif
for ducks = 0 to 7
/*
hit=checkCollision(objects[num].ID)
if hit>0
if GetObjectAngleX(objects[num].ID)=0
RotateObjectLocalX(objects[num].ID,90)
objects[num].time=timer()
inc ducksShot
else
endif
endif
*/
if GetObject3DPhysicsFirstContact(myDucks[ducks].ID)
contactObjB = GetObject3DPhysicsContactObjectB()
for num=0 to bulletCount
if contactObjB= myBullet[num].ID
if GetObjectAngleX(myDucks[ducks].ID)=0
RotateObjectLocalX(myDucks[ducks].ID,90)
myDucks[ducks].time=timer()
inc ducksShot
endif
endif
while GetObject3DPhysicsNextContact()
contactObjB = GetObject3DPhysicsContactObjectB()
for num=0 to bulletCount
if contactObjB= myBullet[num].ID
if GetObjectAngleX(myDucks[ducks].ID)=0
RotateObjectLocalX(myDucks[ducks].ID,90)
myDucks[ducks].time=timer()
inc ducksShot
endif
endif
next num
endwhile
next num
endif
MoveObjectLocalX(myDucks[ducks].ID,-.1)
if getObjectX(myDucks[ducks].ID)<-20 then SetObjectPosition(myDucks[ducks].ID,20,-10,20)
if GetObjectAngleX(myDucks[ducks].ID)>89 and myDucks[ducks].time+3<timer()
RotateObjectLocalX(myDucks[ducks].ID,-90)
myDucks[ducks].time=0
endif
next ducks
Step3DPhysicsWorld()
//There is no limit to bullets but a timer of bulletlife for how long they live
for num=0 to bulletCount
hit=checkCollision(myBullet[num].ID)
if (myBullet[num].time)+bulletLife<timer() or hit=100
DeleteObject(myBullet[num].ID)
myBullet.remove(num)
dec bulletCount
endif
next num
SetTextString(1,"Ducks Shot="+Str(ducksShot))
sync()
//SetCameraRotation(1,GetObjectWorldAngleX(playerObj),GetObjectWorldAngleY(playerObj),GetObjectWorldAngleZ(playerObj) )
loop
endfunction
function ThrowBall( initialSpeed as float, mass as float, size as float)
//To move dynamic physics bodies we need to apply velocity to the physics body.
gunPositionVec= CreateVector3(GetObjectWorldX(playerObj),GetObjectWorldY(playerObj)+camOff_y#,GetObjectWorldZ(playerObj)) //im using the camera position as the gun position
//Create a tempory projectile block to calculate movement vectors of bullets
projectileDirBox as integer
projectileDirBox = CreateObjectBox( 1.0, 1.0, 1.0 )
SetObjectPosition( projectileDirBox, GetVector3X( gunPositionVec ), GetVector3Y( gunPositionVec ), GetVector3Z( gunPositionVec ) )
setobjectrotation(projectiledirbox,GetObjectWorldAngleX(playerObj),GetObjectWorldAngleY(playerObj),GetObjectWorldAngleZ(playerObj))
MoveObjectLocalZ( projectileDirBox, 1.0 )
projectileDirVec = CreateVector3( GetobjectWorldX( projectileDirBox )-GetVector3X( gunPositionVec ), GetobjectWorldY( projectileDirBox )-GetVector3Y( gunPositionVec ), GetobjectWorldZ( projectileDirBox )-GetVector3Z( gunPositionVec ) )
DeleteObject( projectileDirBox )
throwBall as integer
throwBall = CreateObjectSphere(size, 16, 32 )
SetObjectColor( throwBall, 255, 0,0,255 )
SetObjectPosition( throwBall, GetVector3X( gunPositionVec ), GetVector3Y( gunPositionVec ), GetVector3Z( gunPositionVec ) )
//3D Physics code
Create3DPhysicsDynamicBody( throwBall )
SetObjectShapeSphere( throwBall )
SetObject3DPhysicsMass( throwBall, mass )
SetObject3DPhysicsLinearVelocity( throwBall, projectileDirVec, initialSpeed )
//SetObject3DPhysicsFriction( throwBall, 0.8 )
//SetObject3DPhysicsRollingFriction( throwBall, 0.7 )
//SetObject3DPhysicsCanSleep(throwBall,0)
myItem as bullet
myItem.ID = throwBall //the object id of the bullet
myItem.time = timer() //timer is used to set there life time as bullets will die off after so long
myBullet.insert(myItem) //update bullet arrow as there is unlimeted bullets
inc bulletCount //used for a bullet counter to check if theyve timed out or not
deletevector3(projectileDirVec)
deletevector3(gunPositionVec)
endfunction
function checkCollision(object)
//this checks for colliion between an object with any other object and returns its id
width#=.5
height#=1.5
depth2#=.025
x#=getObjectWorldX(object)
y#=GetObjectWorldY(object)
z#=getObjectWorldZ(object)
// calculate the start of the ray cast
start_x# = x#-width#
start_y# = y#+height#
start_z# = z#-depth2#
// calculate the end of the ray cast
end_x# = x#+width#
end_y# = y#-height#
end_z# = z#+depth2#
// determine which object has been hit
object_hit = ObjectRayCast(0,start_x#,start_y#,start_z#,end_x#,end_y#,end_z#)
endfunction object_hit
function createTriangleImage()
rem draw a triangle image used for the player sprite on radar
SetClearColor(0,0,0)
ClearScreen()
Render()
DrawLine(5,0,9,9,green,green)
DrawLine(1,8,8,8,green,green)
DrawLine(1,9,5,0,green,green)
//DrawLine(5,0,5,9,green,green)
//draw these if you want it filled
DrawLine(4,0,8,9,green,green)
DrawLine(0,9,8,9,green,green)
DrawLine(0,9,4,0,green,green)
DrawBox(4,1,6,8,green,green,green,green,1)
swap()
img = getimage(0,0,10,10)
SetImageTransparentColor(img,0,0,0)
endfunction img
function createCircleImage()
rem draw a triangle image used for the player sprite on radar
SetClearColor(0,0,0)
ClearScreen()
Render()
DrawEllipse(6,6,4,4,yellow,yellow,0)
DrawEllipse(6,6,3,3,yellow,yellow,0)
swap()
img = getimage(0,0,12,12)
SetImageTransparentColor(img,0,0,0)
endfunction img
I have the bottles as dynamic atm cos I cant remember if or how to get the kinematic ones to fall over
Video Removed for space please see latest post
Media
http://users.tpg.com.au/subarpk/Bottle.objfubar