PROJECT SO FAR
main.agc
// Project: Joust
// Created: 2018-05-29
// show all errors
SetErrorMode(1)
#constant DevW =1024 //screenwidth
#constant DevH =768 //screenheight
#constant KEY_LEFT =37 //the left arrow key scancode
#constant KEY_UP =38 //the up arrow key scancode
#constant KEY_RIGHT =39 //the right arrow key scancode
#constant KEY_DOWN =40 //the down arrow key scancode
#constant KEY_SPACE =32 //the space key
#constant playerObj =100 //The players object
#constant platformStartObj =1 //the platforms starter object id
#constant platformLastObj =8 //the platforms last object id
#constant firepitObj =9
#constant playerImg =100 //the players object texture
#constant playerShieldImg =101 //the players texture with shield activated
#constant platformImg =102 //the image used for texturing the platforms
#constant platformImgGetReady=103 //the image used for texturing the platforms when spawning is near
#constant firepitImg =104
#constant camera =1 //the main camera used by agk
//#constant enemyObject =200 //the enemy Objects start
#constant enemyObjectImg1 =200 //the enemy Objects texture
#constant enemyObjectImg2 =201 //the enemy Objects texture
#constant enemyEggImg1 =202 //the enemy Objects texture after destroyed
#constant enemyEggImg2 =203 //the enemy Objects texture after destroyed
#constant enemyBulletImg =204
#constant myGravity =-.5 //the gravity i apply for the spheres
#constant sphereRadius =5.0 //used for the spherecast for players collision
#constant maxSpeed# =4.0 //The Maximum speed the player will move
#constant minSpeed# =0
#constant AccelerationFactor#=.05
#constant DecelerationFactor#=.05
//#constant skyboxObj =300
//#constant skyboxImg =300
// set window properties
SetWindowTitle( "Joust" )
SetWindowSize( DevW, DevH, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( DevW, DevH ) // 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()
Set3DPhysicsGravity( 0,0, 0 )
#include "boom.agc"
type _enemyType
ID as integer
imgID as integer
xDir as float
yDir as float
fallTime as float
lastFiredTime as float
canShoot as integer
endtype
type _bullet
ID as integer
time as float // a time used because bullets die over time
endtype
type _player
ID as float
imgID as integer
shield as integer
shieldTime as float
endtype
Global enemyArray as _enemyType[]
Global enemyEggs as _enemyType[]
Global bullets as _bullet[]
Global maxEnemy=4
Global enemyCount=0
Global lives =5
Global totalEnemySofar=0
Global player as _player
Global eggsCollected
//SetCameraRange( camera, 1, 3000 )
SetCameraPosition( camera, 0, 0, -20 )
LoadImage(platformImg,"cubeA1.png")
LoadImage(platformImgGetReady,"cubeA2.png")
LoadImage(playerImg,"sphere1.png")
LoadImage(playerShieldImg,"sphere1b.png")
LoadImage(enemyObjectImg1,"sphere2.png")
LoadImage(enemyObjectImg2,"sphere2b.png")
LoadImage(enemyEggImg1,"sphere3b.png")
LoadImage(enemyEggImg2,"sphere3.png")
LoadImage(enemyBulletImg,"sphere4.png")
LoadImage(firepitImg,"firepitb.png")
boom(BOOM_LOAD,0,0)
createPlatforms()
SetImageWrapU(firepitImg,1)
SetImageWrapV(firepitImg,1 )
x#=0:y#=-80:z#=100
loadObject(playerObj,"sphere.obj")
player.ID=playerObj:player.imgID=playerShieldImg
player.shield=1:player.shieldTime=timer()
SetObjectPosition(player.ID,x#,y#,z#)
SetObjectImage(player.ID,player.imgID,0)
SetObjectScale(player.ID,1,1,1)
SetObjectTransparency(player.ID,1)
SetObjectCollisionMode(player.ID,0)
bottomU#=0:bottomV#=0
rndStart=0:eggsCollected=0
spawnTime#=timer()
time#=timer()
SetCameraRange( camera,1,1000 )
do
//only spawn a set maximum of enemies and after 3 sec
if enemyCount< maxEnemy
if timer()>spawnTime#+1 and timer()<spawnTime#+3 and rndStart=0
rndStart=prepare_spawn() //change texture and set the spawn location
elseif timer()>spawnTime#+3 and rndStart>0
spawn_enemy(rndStart)
SetObjectImage(rndStart,platformImg,0)
rndStart=0:spawnTime#=timer()
endif
else
rndStart=0:spawnTime#=timer()
endif
if player.shield=1 and timer()>player.shieldTime+5
player.shield=0:player.imgID=playerImg
SetObjectImage(player.ID,player.imgID,0)
endif
//***************************************************************************************************************************************
//player input
//***************************************************************************************************************************************
if GetRawKeyState(KEY_UP)
if lastMoveY=0 or lastmoveY=2
SpeedY#=minSpeed#
endif
lastMoveY=1
SpeedY#=SpeedY#+((maxSpeed#-SpeedY#)*AccelerationFactor#)
if Speed#>maxSpeed# then Speed#=maxSpeed#
elseif GetRawKeyState(KEY_DOWN)
if lastMoveY=0 or lastMoveY=1
SpeedY#=minSpeed#
endif
lastMoveY=2
SpeedY#=SpeedY#+((maxSpeed#-SpeedY#)*(AccelerationFactor#))
if SpeedY#>maxSpeed# then SpeedY#=maxSpeed#
else
SpeedY#=SpeedY#-((maxSpeed#-SpeedY#)*DecelerationFactor#+.01)
if SpeedY#<minSpeed# then SpeedY#=minSpeed#
endif
if GetRawKeyState(KEY_LEFT)
if lastMoveX=0 or lastMoveX=2
SpeedX#=minSpeed#
endif
lastMoveX=1
SpeedX#=SpeedX#+((maxSpeed#-SpeedX#)*AccelerationFactor#)
if SpeedX#>maxSpeed# then SpeedX#=maxSpeed#
elseif GetRawKeyState(KEY_RIGHT)
if lastMoveX=0 or lastMoveX=1
SpeedX#=minSpeed#
endif
lastMoveX=2
SpeedX#=SpeedX#+((maxSpeed#-SpeedX#)*(AccelerationFactor#))
if SpeedX#>maxSpeed# then SpeedX#=maxSpeed#
else
SpeedX#=SpeedX#-((maxSpeed#-SpeedX#)*DecelerationFactor#+.01)
if SpeedX#<minSpeed# then SpeedX#=minSpeed#
endif
//***************************************************************************************************************************************
//Player Movement
//***************************************************************************************************************************************
//move the platforms on the x in relation to player
for num = platformStartObj to platformLastObj
if lastMoveX=1
MoveObjectLocalX(num,SpeedX#)
else
MoveObjectLocalX(num,-SpeedX#)
endif
if getObjectX(num)<-120 then SetObjectPosition(num,120,getObjectY(num),getObjectZ(num))
if getObjectX(num)>120 then SetObjectPosition(num,-120,getObjectY(num),getObjectZ(num))
next num
//move the enemy in relation to the player
count=enemyArray.length
for num = count to 0 step-1
if lastMoveX=1
MoveObjectLocalX(enemyArray[num].ID,SpeedX#)
else
MoveObjectLocalX(enemyArray[num].ID,-SpeedX#)
endif
next num
//move the enemyEggs in relation to the player
count=enemyEggs.length
for num = count to 0 step-1
if lastMoveX=1
MoveObjectLocalX(enemyEggs[num].ID,SpeedX#)
else
MoveObjectLocalX(enemyEggs[num].ID,-SpeedX#)
endif
next num
//move the bullets in relation to the player
//count=bullets.length
//for num = count to 0 step-1
// if lastMoveX=1
// MoveObjectLocalX(bullets[num].ID,SpeedX#)
// else
// MoveObjectLocalX(bullets[num].ID,-SpeedX#)
// endif
//next num
//move the UV of the bottom firepit in relation to the player
if lastMoveX=1
bottomU#=bottomU#-(SpeedX#/200)
else
bottomU#=bottomU#+(SpeedX#/200)
endif
SetObjectUVOffset(firepitObj,0,bottomU#,bottomV#)
// get player input
old_x# = GetObjectX(player.ID)
old_y# = GetObjectY(player.ID)
old_z# = GetObjectZ(player.ID)
if lastMoveY=1
MoveObjectLocalY(player.ID,SpeedY#)
else
MoveObjectLocalY(player.ID,-SpeedY#)
endif
If GetObjectY(player.ID)>10 //player went to high
old_y# = 5:SetObjectPosition(player.ID,old_x#,old_y#,old_z#)
//old_y# = -150:SetObjectPosition(player.ID,old_x#,old_y#,old_z#)
endif
If GetObjectY(player.ID)<-150 //player went to low
old_y# = 10:SetObjectPosition(player.ID,old_x#,old_y#,old_z#)
endif
MoveObjectLocalY(player.ID,myGravity) //apply my own gravity
//***************************************************************************************************************************************
CheckCollide(old_x#,old_y#,old_z#,sphereRadius)
moveEnemy()
enemyShoot()
//Step3DPhysicsWorld()
print("Jousting Eggs")
print("Eggs Collected "+str(eggsCollected))
print("Enemy count "+str(enemyCount))
print("Lives "+str(lives))
Step3DPhysicsWorld()
//print("Ypos "+str(getobjecty(player.ID)))
boom(BOOM_FRAME,0,0)
sync()
loop
//***************************************************************************************************************************************
//Delete all enemy enemyeggs and bullets and make sure the platform images are set correct
//reset all variables
//***************************************************************************************************************************************
function restartLevel()
x#=0:y#=-80:z#=100:eggsCollected=0
SetObjectPosition(player.ID,x#,y#,z#)
//exitfunction
count=enemyArray.length
for index=count to 0 step-1
deleteObject(enemyArray[index].ID)
enemyArray.remove(index)
next index
enemyCount=0
count=enemyEggs.length
for index=count to 0 step-1
deleteObject(enemyEggs[index].ID)
enemyEggs.remove(index)
next index
count=bullets.length
for index=count to 0 step-1
deleteObject(bullets[index].ID)
bullets.remove(index)
next index
for index=platformStartObj to platformLastObj
SetObjectImage(index,platformImg,0)
next index
rndStart=0:spawnTime#=timer()
endfunction
//***************************************************************************************************************************************
//***************************************************************************************************************************************
//move the enemy with sliding collisions and move eggs
//***************************************************************************************************************************************
function moveEnemy()
radius# = 1.0
//if enemyArray.length=-1 then exitfunction
count=enemyArray.length
for index=count to 0 step-1
if GetObjectExists(enemyArray[index].ID)
old_x# = GetObjectX(enemyArray[index].ID)
old_y# = GetObjectY(enemyArray[index].ID)
old_z# = GetObjectZ(enemyArray[index].ID)
MoveObjectLocalX(enemyArray[index].ID,enemyArray[index].xDir)
MoveObjectLocalY(enemyArray[index].ID,enemyArray[index].yDir)
If GetObjectX(enemyArray[index].ID)<-120 //enemy moved off screen to left
old_x# = 80:SetObjectPosition(enemyArray[index].ID,old_x#,old_y#,old_z#)
endif
If GetObjectX(enemyArray[index].ID)>120 //enemy moved offscreen tp right
old_x# = -80:SetObjectPosition(enemyArray[index].ID,old_x#,old_y#,old_z#)
endif
MoveObjectLocalY(enemyArray[index].ID,myGravity) //apply my own gravity
new_x# = GetObjectX(enemyArray[index].ID)
new_y# = GetObjectY(enemyArray[index].ID)
new_z# = GetObjectZ(enemyArray[index].ID)
// sphere cast between the old and new positions of the sphere
object_hit = ObjectSphereSlide(0,old_x#,old_y#,old_z#,new_x#,new_y#,new_z#,radius#)
// the sphere has collide with a box then calculate sphere new position to give sliding collision
// we do not need to know the Y component of the collision as the sphere only moves on the xz plane
if object_hit >= platformStartObj and object_hit <= platformLastObj
if getObjectExists(enemyArray[index].ID) then SetObjectPosition(enemyArray[index].ID, GetObjectRayCastSlideX(0),GetObjectRayCastSlideY(0), new_z# )
endif
endif
next index
count=enemyEggs.length
for index=count to 0 step-1
if GetObjectExists(enemyEggs[index].ID)
old_x# = GetObjectX(enemyEggs[index].ID)
old_y# = GetObjectY(enemyEggs[index].ID)
old_z# = GetObjectZ(enemyEggs[index].ID)
if Timer()>enemyEggs[index].falltime+1 and enemyEggs[index].falltime<>0
enemyEggs[index].xDir=enemyEggs[index].xDir*0.075
enemyEggs[index].fallTime=timer()
endif
MoveObjectLocalX(enemyEggs[index].ID,enemyEggs[index].xDir)
MoveObjectLocalY(enemyEggs[index].ID,enemyEggs[index].yDir)
If GetObjectX(enemyEggs[index].ID)<-120 //enemy moved off screen to left
old_x# = 80:SetObjectPosition(enemyEggs[index].ID,old_x#,old_y#,old_z#)
endif
If GetObjectX(enemyEggs[index].ID)>120 //enemy moved offscreen tp right
old_x# = -80:SetObjectPosition(enemyEggs[index].ID,old_x#,old_y#,old_z#)
endif
If GetObjectY(enemyEggs[index].ID)<-150 //the egg has fallen too low
//old_y# = 10:SetObjectPosition(enemyArray[index].ID,old_x#,old_y#,old_z#)
deleteObject(enemyEggs[index].ID)
enemyEggs.remove(index)
exitfunction
endif
MoveObjectLocalY(enemyEggs[index].ID,myGravity) //apply my own gravity
new_x# = GetObjectX(enemyEggs[index].ID)
new_y# = GetObjectY(enemyEggs[index].ID)
new_z# = GetObjectZ(enemyEggs[index].ID)
// sphere cast between the old and new positions of the sphere
object_hit = ObjectSphereSlide(0,old_x#,old_y#,old_z#,new_x#,new_y#,new_z#,radius#)
// the sphere has collide with a box then calculate sphere new position to give sliding collision
// we do not need to know the Y component of the collision as the sphere only moves on the xz plane
if object_hit >= platformStartObj and object_hit <= platformLastObj
if getObjectExists(enemyEggs[index].ID) then SetObjectPosition(enemyEggs[index].ID, GetObjectRayCastSlideX(0),GetObjectRayCastSlideY(0), new_z# )
endif
endif
next index
endfunction
//***************************************************************************************************************************************
//***************************************************************************************************************************************
//Delete all old bullets
//Check if its a red enemy that can shoot and its been 3 seconds since last shot
//***************************************************************************************************************************************
function enemyShoot ()
count=bullets.length
for index=count to 0 step-1
if (bullets[index].time)+1.5<timer() //delete old bullets
DeleteObject(bullets[index].ID)
bullets.remove(index)
endif
next
count=enemyArray.length
for index=count to 0 step-1
if enemyArray[index].canShoot=1 and timer()>enemyArray[index].lastFiredTime+2
enemyArray[index].lastFiredTime=timer()
shootEgg(enemyArray[index].ID, 50.0, 100.0)
endif
next
endfunction
//***************************************************************************************************************************************
function prepare_spawn()
rndStart=random(1,8)
SetObjectImage(rndStart,platformImgGetReady,0)
endfunction rndStart
//***************************************************************************************************************************************
//Spawn enemy at the correct platform object
//***************************************************************************************************************************************
function spawn_enemy(rndStart)
enemyObject=InstanceObject(player.ID)
SetObjectImage(enemyObject,enemyObjectImg1,0)
SetObjectScale(enemyObject,1,1,1)
//SetObjectTransparency(enemyObject,1)
SetObjectCollisionMode(enemyObject,1)
//Create3DPhysicsDynamicBody(enemyObject)
yAdd=8
select rndStart
case 1
SetObjectPosition(enemyObject,getObjectX(platformStartObj),getObjectY(platformStartObj)+yAdd,getObjectZ(platformStartObj))
endcase
case 2
SetObjectPosition(enemyObject,getObjectX(platformStartObj+1),getObjectY(platformStartObj+1)+yAdd,getObjectZ(platformStartObj+1))
endcase
case 3
SetObjectPosition(enemyObject,getObjectX(platformStartObj+2),getObjectY(platformStartObj+2)+yAdd,getObjectZ(platformStartObj+2))
endcase
case 4
SetObjectPosition(enemyObject,getObjectX(platformStartObj+3),getObjectY(platformStartObj+3)+yAdd,getObjectZ(platformStartObj+3))
endcase
case 5
SetObjectPosition(enemyObject,getObjectX(platformStartObj+4),getObjectY(platformStartObj+4)+yAdd,getObjectZ(platformStartObj+4))
endcase
case 6
SetObjectPosition(enemyObject,getObjectX(platformStartObj+5),getObjectY(platformStartObj+5)+yAdd,getObjectZ(platformStartObj+5))
endcase
case 7
SetObjectPosition(enemyObject,getObjectX(platformStartObj+6),getObjectY(platformStartObj+6)+yAdd,getObjectZ(platformStartObj+6))
endcase
case 8
SetObjectPosition(enemyObject,getObjectX(platformStartObj+7),getObjectY(platformStartObj+7)+yAdd,getObjectZ(platformStartObj+7))
endcase
endselect
dir=random(1,2)
enemy as _enemyType
enemy.ID=enemyObject
if dir=1
enemy.xDir=0.85
else
enemy.xDir=-0.85
endif
enemy.yDir=.5
enemy.fallTime=0
if Mod(totalEnemySofar, 4) = 0
enemy.canShoot=1
enemy.imgID=enemyObjectImg2
SetObjectimage(enemy.ID,enemyObjectImg2,0)
else
enemy.canShoot=0
enemy.imgID=enemyObjectImg1
SetObjectimage(enemy.ID,enemyObjectImg1,0)
endif
enemyArray.insert(enemy)
inc enemyCount:Inc totalEnemySofar
endfunction
//***************************************************************************************************************************************
//***************************************************************************************************************************************
//Check collision of the player object with all other objects
//index enemy
//indexB enemy eggs
//indexC bullets
//***************************************************************************************************************************************
function checkCollide(old_x#,old_y#,old_z#,radius#)
// get the new position of the sphere
new_x# = GetObjectX(player.ID)
new_y# = GetObjectY(player.ID)
new_z# = GetObjectZ(player.ID)
// sphere cast between the old and new positions of the sphere
object_hit = ObjectSphereSlide(0,old_x#,old_y#,old_z#,new_x#,new_y#,new_z#,radius#)
if object_hit>0
//count=enemyArray.length
//for num = count to 0 step-1
// if object_hit = enemyArray[num].ID then index=num
//next num
//count=enemyEggs.length
//for num = count to 0 step-1
// if object_hit = enemyEggs[num].ID then index2=num
//next num
//count=bullets.length
//for num = count to 0 step-1
// if object_hit = bullets[num].ID then index3=num
//next num
// the sphere has collide with a box then calculate sphere new position to give sliding collision
// we do not need to know the Y component of the collision as the sphere only moves on the xz plane
index=enemyArray.find(object_hit)
indexB=enemyEggs.find(object_hit)
indexC=bullets.find(object_hit)
if object_hit >= platformStartObj and object_hit <= platformLastObj
SetObjectPosition(player.ID, GetObjectRayCastSlideX(0),GetObjectRayCastSlideY(0), new_z# )
elseif object_hit=firepitObj
boom(BOOM_BOOM,player.ID,playerImg)
dec lives
restartLevel()
elseif index<>-1
if object_hit=enemyArray[index].ID
if getObjectY(object_hit)+1<getObjectY(player.ID) //destroy enemy and create an egg if enemy is lower
enemyEgg as _enemyType
enemyEgg.ID=InstanceObject(player.ID)
if Random(1,5) <=4
enemyEgg.imgID=enemyEggImg1
SetObjectImage(enemyEgg.ID,enemyEggImg1,0)
else
enemyEgg.imgID=enemyEggImg2
SetObjectImage(enemyEgg.ID,enemyEggImg2,0)
endif
SetObjectScale(enemyEgg.ID,.5,.5,.5)
SetObjectCollisionMode(enemyEgg.ID,1)
SetObjectPosition(enemyEgg.ID,getObjectX(enemyArray[index].ID),getObjectY(enemyArray[index].ID),getObjectZ(enemyArray[index].ID))
enemyEgg.xDir=enemyArray[index].xDir*0.075
enemyEgg.yDir=0
enemyEgg.fallTime=timer()
enemyEgg.canShoot=0
enemyEggs.insert(enemyEgg)
boom(BOOM_BOOM,enemyArray[index].ID,enemyArray[index].imgID)
deleteObject(enemyArray[index].ID)
enemyArray.remove(index)
dec enemyCount
elseif player.imgID=playerImg //enemy kills player if shield not active
boom(BOOM_BOOM,player.ID,playerImg)
dec lives
restartLevel()
endif
endif
elseif indexB<>-1
if object_hit=enemyEggs[indexB].ID
if enemyEggs[indexB].imgID=enemyEggImg2
player.shield=1:player.imgID=playerShieldImg:player.shieldTime=timer()
SetObjectImage(player.ID,playerShieldImg,0)
endif
deleteObject(enemyEggs[indexB].ID)
enemyEggs.remove(indexB)
inc eggsCollected
endif
elseif indexC<>-1
//check if bullets have collided
if player.imgID=playerImg //and no shield
if object_hit=bullets[indexC].ID
boom(BOOM_BOOM,player.ID,playerImg)
dec lives
restartLevel()
endif
endif
endif
endif
endfunction
//***************************************************************************************************************************************
//***************************************************************************************************************************************
//Create all spawning platforms and firepit object
//***************************************************************************************************************************************
function createPlatforms()
LoadObject(platformStartObj,"cube.obj")
//CloneObject(platformStartObj+2,platformStartObj)
SetObjectPosition(platformStartObj,0,-30,100)
SetObjectImage(platformStartObj,platformImg,0)
SetObjectScale(platformStartObj,4,.05,4)
SetObjectTransparency(platformStartObj,1)
SetObjectCollisionMode(platformStartObj,1)
SetObjectLightMode(platformStartObj, 0)
SetObjectCullMode(platformStartObj, 0)
//Create3DPhysicsStaticBody(platformStartObj )
CloneObject(platformStartObj+1,platformStartObj)
SetObjectPosition(platformStartObj+1,-60,-60,100)
SetObjectImage(platformStartObj+1,platformImg,0)
SetObjectScale(platformStartObj+1,4,.05,4)
SetObjectTransparency(platformStartObj+1,1)
SetObjectCollisionMode(platformStartObj+1,1)
SetObjectLightMode(platformStartObj+1, 0)
SetObjectCullMode(platformStartObj+1, 0)
//Create3DPhysicsStaticBody(platformStartObj+1 )
CloneObject(platformStartObj+2,platformStartObj)
SetObjectPosition(platformStartObj+2,60,-60,100)
SetObjectImage(platformStartObj+2,platformImg,0)
SetObjectScale(platformStartObj+2,4,.05,4)
SetObjectTransparency(platformStartObj+2,1)
SetObjectCollisionMode(platformStartObj+2,1)
SetObjectLightMode(platformStartObj+2, 0)
SetObjectCullMode(platformStartObj+2, 0)
//Create3DPhysicsStaticBody(platformStartObj+2)
CloneObject(platformStartObj+3,platformStartObj)
SetObjectPosition(platformStartObj+3,0,-110,100)
SetObjectImage(platformStartObj+3,platformImg,0)
SetObjectScale(platformStartObj+3,8,.05,4)
SetObjectTransparency(platformStartObj+3,1)
SetObjectCollisionMode(platformStartObj+3,1)
SetObjectLightMode(platformStartObj+3, 0)
SetObjectCullMode(platformStartObj+3, 0)
//Create3DPhysicsStaticBody(platformStartObj+3)
//CloneObject(firepitObj,platformStartObj)
CreateObjectBox(firepitObj,12,.05,10)
SetObjectPosition(firepitObj,0,-150,100)
SetObjectImage(firepitObj,firepitImg,0)
SetObjectScale(firepitObj,20,.05,4)
SetObjectUVScale(firepitObj,0,1,1)
SetObjectTransparency(firepitObj,1)
SetObjectCollisionMode(firepitObj,1)
SetObjectLightMode(firepitObj, 0)
SetObjectCullMode(firepitObj, 0)
//Create3DPhysicsStaticBody(firepitObj )
//***********************************************************
CloneObject(platformStartObj+4,platformStartObj)
SetObjectPosition(platformStartObj+4,-120,-30,100)
SetObjectImage(platformStartObj+4,platformImg,0)
SetObjectScale(platformStartObj+4,4,.05,4)
SetObjectTransparency(platformStartObj+4,1)
SetObjectCollisionMode(platformStartObj+4,1)
SetObjectLightMode(platformStartObj+4, 0)
SetObjectCullMode(platformStartObj+4, 0)
//Create3DPhysicsStaticBody(platformStartObj+4 )
CloneObject(platformStartObj+5,platformStartObj)
SetObjectPosition(platformStartObj+5,-120,-110,100)
SetObjectImage(platformStartObj+5,platformImg,0)
SetObjectScale(platformStartObj+5,4,.05,4)
SetObjectTransparency(platformStartObj+5,1)
SetObjectCollisionMode(platformStartObj+5,1)
SetObjectLightMode(platformStartObj+5, 0)
SetObjectCullMode(platformStartObj+5, 0)
//Create3DPhysicsStaticBody(platformStartObj+5)
CloneObject(platformStartObj+6,platformStartObj)
SetObjectPosition(platformStartObj+6,120,-30,100)
SetObjectImage(platformStartObj+6,platformImg,0)
SetObjectScale(platformStartObj+6,4,.05,4)
SetObjectTransparency(platformStartObj+6,1)
SetObjectCollisionMode(platformStartObj+6,1)
SetObjectLightMode(platformStartObj+6, 0)
SetObjectCullMode(platformStartObj+6, 0)
//Create3DPhysicsStaticBody(platformStartObj+6 )
CloneObject(platformStartObj+7,platformStartObj)
SetObjectPosition(platformStartObj+7,120,-110,100)
SetObjectImage(platformStartObj+6,platformImg,0)
SetObjectScale(platformStartObj+7,4,.05,4)
SetObjectTransparency(platformStartObj+7,1)
SetObjectCollisionMode(platformStartObj+7,1)
SetObjectLightMode(platformStartObj+7, 0)
SetObjectCullMode(platformStartObj+7, 0)
//Create3DPhysicsStaticBody(platformStartObj+7)
endfunction
//***************************************************************************************************************************************
//***************************************************************************************************************************************
//Calculate vectors for the shooting egg and set the missileEgg in motion
//***************************************************************************************************************************************
function shootEgg(objectId as integer,initialSpeed as float, mass as float)
gunPositionVec= CreateVector3(GetObjectWorldX(objectId),GetObjectWorldY(objectId),GetObjectWorldZ(objectId))
//Create a tempory projectile block to calculate movement vectors of bullets
projectileDirBox as integer
projectileDirBox = CreateObjectBox( 1.0, 1.0, 1.0 )
FixObjectToObject(projectileDirBox,ObjectId)
x#=GetObjectWorldX(projectileDirBox):y#=GetObjectWorldY(projectileDirBox):z#=GetObjectWorldZ(projectileDirBox)
FixObjectToObject(projectileDirBox,0)
SetObjectPosition(projectileDirBox,x#,y#,z#)
SetObjectLookAt(projectiledirbox,GetObjectWorldX(player.ID),GetObjectWorldY(player.ID),GetObjectWorldZ(player.ID),0)
MoveObjectLocalZ( projectileDirBox, 1.0 )
projectileDirVec = CreateVector3( GetobjectWorldX( projectileDirBox )-GetVector3X( gunPositionVec ), GetobjectWorldY( projectileDirBox )-GetVector3Y( gunPositionVec ), GetobjectWorldZ( projectileDirBox )-GetVector3Z( gunPositionVec ) )
missile as integer
missile = InstanceObject(player.ID)
SetObjectScale(missile,.5,.5,.5)
//SetObjectColor(missile, 255,0,0,255 )
SetObjectImage(missile,enemyBulletImg,0)
//SetObjectLightMode(missile,0)
SetObjectPosition(missile, GetVector3X( gunPositionVec ), GetVector3Y( gunPositionVec ), GetVector3Z( gunPositionVec ) )
SetObjectRotation(missile,GetObjectAngleX(projectileDirBox),GetObjectAngleY(projectileDirBox),GetObjectAngleZ(projectileDirBox)+180)
DeleteObject( projectileDirBox )
//3D Physics code
SetObjectCollisionMode(missile,1)
Create3DPhysicsDynamicBody(missile)
SetObject3DPhysicsMass(missile, mass )
SetObject3DPhysicsLinearVelocity(missile, projectileDirVec, initialSpeed )
myItem as _bullet
myItem.ID = missile //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
bullets.insert(myItem) //update bullet arrow as there is unlimeted bullets
//inc missileCount //used for a bullet counter to check if theyve timed out or not
deletevector3(projectileDirVec)
deletevector3(gunPositionVec)
endfunction missile
//***************************************************************************************************************************************
boom.agc
/*************************************************************************************************************************************/
//boom(BOOM_LOAD, 0,0) This will initialize everything and load in the parts
//boom(BOOM_BOOM, Object,ObjectImage)This will blow up a object you need to pass the object as the second parameter and the objects image as the third
//boom(BOOM_FRAME, 0,0) This need to be called once every frame
//*************************************************************************************************************************************/
type joustBit
ID as integer
offsetX as float
offsetY as float
offsetZ as float
offsetAngX as float
offsetAngY as float
offsetAngZ as float
scale as float
time as float
endtype
type joustPart
ID as integer
img as integer
endtype
#constant BOOM_LOAD = 0
#constant BOOM_BOOM = 1
#constant BOOM_VISIBLE = 2
#constant BOOM_FRAME = 3
global joustParts as joustPart[]
global joustBits as joustBit[]
//global bam as integer
function boom(fct as integer, obj as integer,img as integer)
n as string
o as integer
i as integer
b as joustBit
myjoustPart as joustPart
//bi as integer
//ti as integer
//print("Boom")
select fct
case BOOM_FRAME
count=joustBits.length
for i=count to 0 step-1
SetObjectVisible(joustBits[i].ID,1)
SetObjectPosition(joustBits[i].ID,GetObjectWorldX(joustBits[i].ID)+joustBits[i].offsetX,GetObjectWorldY(joustBits[i].ID)+joustBits[i].offsetY,GetObjectWorldZ(joustBits[i].ID)+joustBits[i].offsetZ)
SetObjectRotation(joustBits[i].ID,GetObjectAngleX(joustBits[i].ID)+joustBits[i].offsetAngX,GetObjectAngleY(joustBits[i].ID)+joustBits[i].offsetAngY,GetObjectAngleZ(joustBits[i].ID)+joustBits[i].offsetAngZ)
joustBits[i].scale=joustBits[i].scale-0.01 :if joustBits[i].scale >0 then SetObjectScale(joustBits[i].ID,joustBits[i].scale,joustBits[i].scale,joustBits[i].scale)
next
count=joustBits.length
for i=count to 0 step-1
if joustBits[i].time+2 <timer()
DeleteObject(joustBits[i].ID)
joustBits.remove(i)
endif
next
endcase
case BOOM_LOAD
SetFolder("joust")
n = GetFirstFile()
while n <> ""
myjoustPart.ID = LoadObject(n)
SetObjectLightMode(myjoustPart.ID, 0)
SetObjectCullMode(myjoustPart.ID, 0)
SetObjectImage(myjoustPart.ID,enemyObjectImg1,0)
myjoustPart.img=enemyObjectImg1
//SetObjectColor(myjoustPart.ID,0,255,0,255)
SetObjectVisible(myjoustPart.ID, 0)
joustParts.insert(myjoustPart)
n = GetNextFile()
endwhile
SetFolder("..")
endcase
case BOOM_VISIBLE
count=joustBits.length
for i=0 to count
SetObjectVisible(joustBits[i].ID, 1)
next
endcase
case BOOM_BOOM
count=joustParts.length
for i=0 to count
b.ID = InstanceObject(joustParts[i].ID)
b.time = timer()
SetObjectImage(b.ID,img,0)
//SetObjectColor(b.ID,0,255,0,255)
SetObjectVisible(b.ID, 1)
SetObjectPosition(b.ID, GetObjectWorldx(obj), GetObjectWorldy(obj), GetObjectWorldz(obj))
SetObjectRotation(b.ID, GetObjectAnglex(obj), GetObjectAngley(obj), GetObjectAnglez(obj))
b.offsetX=.2:if random(1,2)=2 then b.offsetX=-.2
b.offsetY=.2:if random(1,2)=2 then b.offsetY=-.2
b.offsetZ=.2:if random(1,2)=2 then b.offsetZ=-.2
b.offsetAngX=5:if random(1,2)=2 then b.offsetAngX=-5
b.offsetAngY=5:if random(1,2)=2 then b.offsetAngY=-5
b.offsetAngZ=5:if random(1,2)=2 then b.offsetAngZ=-5
b.scale=1
joustBits.insert(b)
next
//SetObjectVisible(obj, 0)
endcase
endselect
endfunction
Edited Rewrote the collision handling
The needed media
http://users.tpg.com.au/subarpk/media.rarfubar