Ok - this was really fun.
This is the most I've done on a 'game' since I got blitz a few months ago.
Totally motivating.
So, I got a little carried away and used Tomak - I know it's probably not allowed for the contest - but it was too much fun.
I took out the sound in order to post this - but it's much more satisfying to blast these things with sound ;-)
I have never posted here - so I have no idea if this will work for everyone.
This would be fun to do again in another few weeks - maybe with a 'theme' like '2D Game in a week' or 'RPG Game in a week' -
Anyway - thanks Frank!
; Game in a day - well - more like 5 days
Graphics3D 800, 600, 16, 2
SetBuffer BackBuffer()
AppTitle "Master Blaster!"
;set up the fonts for the screen feedback
Global big
Global small
big = LoadFont("Fixedsys", 32)
small = LoadFont("Fixedsys", 16)
start_screen()
;set up tomak
Const numobj = 20
Const FPS=90
Const Rigid_Bodies=20,Animated_Bodies=6,Rigid_Particles=0
Global coll
Dim tname$(20),tMindex(20)
Global cur=0
Const PLAYER_COL= 1
Const LEVEL_COL = 2
Const ENEMY_COL = 3
Const BULLET_COL= 4
Const BOSS_COL = 5
Dim blocks(10)
Dim tok_block(10)
TOKSIM_SetRigidBodiesCount 100
TOKSIM_SetAnimatedBodiesCount Animated_Bodies
TOKSIM_SetRigidParticleCount Rigid_Particles
TOKSIM_SetControllersCount 0
TOKSIM_SetGeometriesCount 100
TOKSIM_CreateSimulator(0,-10,0)
TOKSIM_SetCollisionResponse PLAYER_COL, LEVEL_COL, 3
TOKSIM_SetCollisionResponse PLAYER_COL, ENEMY_COL, 3
TOKSIM_SetCollisionResponse ENEMY_COL, BULLET_COL, 3
TOKSIM_SetCollisionResponse ENEMY_COL, LEVEL_COL, 3
TOKSIM_SetCollisionResponse BULLET_COL, LEVEL_COL, 3
TOKSIM_SetCollisionResponse BULLET_COL, BOSS_COL, 3
;collisions
Collisions PLAYER_COL, LEVEL_COL, 2, 2 ;player to level
Collisions PLAYER_COL, ENEMY_COL, 1, 2 ;player to badguy
Collisions ENEMY_COL, LEVEL_COL, 2, 2 ;badguy to level
Collisions BULLET_COL, LEVEL_COL, 2, 2 ;bullet to level
Collisions BULLET_COL, ENEMY_COL, 3, 2 ;bullet to badguy
Collisions BULLET_COL, BOSS_COL, 3,2
;lightning info
Global Range# = 0
Global Division# = 0
Global DummyEntity = CreatePivot()
Type LightningType
Field Entity
End Type
Global ang#=0
;TOKSIM_SetMaterial 2,1.0,.9 ; Rubber(Orange)
Type level
Field rb
Field speed#
Field gun
Field lev
Field force
Field enemyhealth
Field enemy_count
Field speed_adjustment
Field num_boss
Field boss_size
Field boss_mass
Field boss_start_health
Field boss_vel#
Field city_size
Field level_inc
Field enemyhealth_org
Field enemy_count_org
Field enemy_dist_shot
Field boss_health
Field boss_dead
End Type
Type boss
Field ent
Field rb
Field x#
Field y#
Field z#
Field speed#
Field health
Field vel#
Field hit
End Type
Type objects
Field obj
Field rb
Field state
Field num
Field health
End Type
Type bullettype
Field entityhandle
Field tomak_i
Field tomak
Field dead
Field num
End Type
Type scene
Field ground
Field wall1, wall2, wall3, wall4
Field beep, guns
Field boss_shock, enemy_tick
Field boss_kill
End Type
Type player
Field ent
Field weapon1
Field weapon2
Field camera
Field score
Field speed#
Field health
Field hit
Field hit_time
Field num_bullets
End Type
Type city
Field block_ent
Field rb_ent
End Type
Global level.level = New level
Global scene.scene = New scene
Global player.player = New player
Global boss.boss = New boss
Global city.city = New city
light = CreateLight()
RotateEntity light, 30, 30, 0
player\ent = CreatePivot()
;put a tomak wrapper around the camera
; box = CreateCube( player )
; cameratomak = TOKRB_Create()
; geom = TOKRB_AddBox( cameratomak,2.0,2.0,2.0)
; TOKGEOM_SetMaterialIndex geom,1
; TOKRB_SetPosition cameratomak,EntityX( player ) ,EntityY(player),EntityZ(player)
; TOKRB_SetLinearDamping cameratomak,0.001
; TOKRB_SetAngularDamping cameratomak,0.001
; TOKRB_SetMass cameratomak,2.0
; TOKRB_SetBoxInertiaTensor cameratomak,2.0,1.0,1.0,2.0
; EntityColor box,Rnd(100,230),Rnd(100,230),Rnd(100,230)
;create rearview mirror
; cam2 = CreateCamera( camera )
;rotate it
; RotateEntity cam2, 0,0,0
;hide it
; HideEntity p\cam2
;specify viewport
; CameraViewport cam2,10,335,160,110
player\camera = CreateCamera(player\ent)
CameraRange player\camera, .01, 2500
CameraClsColor player\camera, 108,122,255
;start with level 1
level\rb = 5
level\speed = 4
level\gun = 1
level\lev = 1
level\enemyhealth = 30
level\enemyhealth_org = 30
level\enemy_count_org = 5
level\force = 1000 ;2250
level\num_boss = 1
level\boss_size = 1
level\boss_mass = 6
level\enemy_count = 5
level\boss_vel = .1
level\city_size = 10
level\level_inc = 1.25
level\enemy_dist_shot = 5
level\boss_start_health = 100
level\boss_dead = 0
boss\hit = 0
level\boss_health = level\boss_start_health
;set up player
player\score = 0
player\speed = .3
player\health = 100
;set up boss health
boss\health = level\boss_health
;create the first scene
create_scene()
;Create Level
create_level( )
;create the player
create_player( )
;create the boss
create_boss()
;for some reason this needs to be here ???
EntityType scene\ground, LEVEL_COL
rot#=0
period=1000/FPS
time=MilliSecs()-period
imptime=MilliSecs()
While Not KeyHit(1) ;ESC key
Repeat
elapsed=MilliSecs()-time
Until elapsed
ticks=elapsed/period
tween#=Float(elapsed Mod period)/Float(period)
For k=1 To ticks
time=time+period
If k=ticks Then CaptureWorld
TOKSIM_Advance(1.5/FPS,1)
camx#=Cos(rot#)*20
camz#=Sin(rot#)*20
Next
If rot#>360 Then rot#=0
;always reset the lightning
ResetLightning()
;how close is enemy?
enemy_distance()
;tomak
For ob.objects = Each Objects
PositionEntity ob\obj,TOKRB_GetX#(ob\rb),TOKRB_GetY#(ob\rb),TOKRB_GetZ#(ob\rb)
RotateEntity ob\obj,TOKRB_GetPitch#(ob\rb),TOKRB_GetYaw#(ob\rb),TOKRB_GetRoll#(ob\rb),False
If KeyDown(57) Then
TOKRB_ApplyImpulse2 ob\rb,Rnd(-.3,.3),Rnd(-1.5,3.0),Rnd(-.3,.3),Rnd(-.05,.05),Rnd(.05,.05),Rnd(-.05,.05)
; TOKRB_ApplyImpulse2 cameratomak, Rnd(-.3,.3),Rnd(-1.5,3.0),Rnd(-.3,.3),Rnd(-.05,.05),Rnd(.05,.05),Rnd(-.05,.05)
;if the block falls out of the zone - delete it
If TOKRB_GetY( ob\rb ) < 0 Then
TOKRB_Free ob\rb
FreeEntity ob\obj
Delete ob
;then take down the count
level\enemy_count = level\enemy_count -1
End If
EndIf
Next
;end tomak
wkey = KeyDown(17)
skey = KeyDown(31)
akey = KeyDown(30)
dkey = KeyDown(32)
mouse1 = MouseHit(1)
mouse2 = MouseHit(2)
move=0
If wkey Then
MoveEntity player\ent, 0, 0, player\speed
move=1
End If
If skey Then
MoveEntity player\ent, 0, 0, -player\speed
move=1
End If
If akey Then
MoveEntity player\ent, -player\speed, 0, 0
move=1
End If
If dkey Then
MoveEntity player\ent, player\speed, 0, 0
move=1
End If
TurnEntity player\ent, 0, -MouseXSpeed()/5.0, 0
TurnEntity player\camera, MouseYSpeed()/5.0, 0, 0
If EntityPitch( player\camera ) < -45
RotateEntity player\camera, -45, EntityYaw( player\camera ), EntityRoll( player\camera )
EndIf
If EntityPitch( player\camera ) > 45 ;don't allow camera to look above 45 degrees
RotateEntity player\camera, 45, EntityYaw( player\camera ), EntityRoll( player\camera )
EndIf
MoveMouse GraphicsWidth()/2, GraphicsHeight()/2 ;reset mouse position to middle of screen
TranslateEntity player\ent, 0, -.1, 0 ;simple gravity
;when the user moves - add a little bounce for the blocks
If move=1 Then
For ob.objects = Each objects
TOKRB_ApplyImpulse ob\rb,0,.25,0
Next
move=0
End If
If mouse1
shoot( 1 )
End If
If mouse2
shoot( 2 )
End If
For bullet.bullettype = Each bullettype ;iterate through all of the bullets
PositionEntity bullet\tomak,TOKRB_GetX#(bullet\tomak_i),TOKRB_GetY#(bullet\tomak_i),TOKRB_GetZ#(bullet\tomak_i)
RotateEntity bullet\tomak,TOKRB_GetPitch#(bullet\tomak_i),TOKRB_GetYaw#(bullet\tomak_i),TOKRB_GetRoll#(bullet\tomak_i),False
;can we delete these bullets?
;first check for bullet dead
If bullet\dead Then
TOKRB_Free bullet\tomak_i
FreeEntity bullet\tomak
Delete bullet
End If
If Abs(EntityX(bullet\tomak, 1)) > 1000
TOKRB_Free bullet\tomak_i
FreeEntity bullet\tomak
Delete bullet
ElseIf Abs(EntityY( bullet\tomak, 1)) > 1000
TOKRB_Free bullet\tomak_i
FreeEntity bullet\tomak
Delete bullet
ElseIf Abs(EntityZ ( bullet\tomak, 1)) > 1000
TOKRB_Free bullet\tomak_i
FreeEntity bullet\tomak
Delete bullet ;delete the bullet
EndIf
Next
UpdateWorld ;figures out collisions
For bullet = Each bullettype
coll = CountCollisions( bullet\tomak )
If CountCollisions(bullet\tomak) > 0
enemyhit = EntityCollided(bullet\tomak, ENEMY_COL )
bos@#!* = EntityCollided(bullet\tomak, BOSS_COL )
If enemyhit > 0
For ob.objects = Each objects
If enemyhit = ob\obj
bullet\dead = 1
player\score = player\score + 1
;health of the enemy goes down by 10
ob\health = ob\health - 10
EndIf
;while we're iterating - check their health
If ob\health =< 0 Then
TOKRB_Free ob\rb
FreeEntity ob\obj
Delete ob
level\enemy_count = level\enemy_count -1
End If
Next
EndIf
; did the boss get hit
If bos@#!* > 0 Then
level\boss_health = level\boss_health - 10
boss\hit = 1
End If
EndIf
; after the collisions - check for death of the bullets
If bullet\dead = 1 Then
TOKRB_Free bullet\tomak_i
FreeEntity bullet\tomak ;delete the bullet mesh;
Delete bullet
player\num_bullets = player\num_bullets -1
End If
Next
If KeyHit(57) Then
For ob.objects = Each objects
TOKRB_ApplyImpulse ob\rb,0,25,0
; TOKRB_ApplyImpulse cameratomak, 0,25,0
Next
EndIf
; check for bullets - can we delete idle ones?
check_bullets()
;still alive?
still_alive()
boss_update()
RenderWorld tween ;draws the 3d scene
SetFont small
Color 255,255,255
Text 10, 10, "X: " + EntityX( player\ent )
Text 10, 20, "Y: " + EntityY( player\ent )
Text 10, 30, "Z: " + EntityZ( player\ent )
Text 10, 40, "Bullets Out: " + player\num_bullets
Text 10, 60, "Enemy Count: " + level\enemy_count
Text 10, 70, "Score: " + player\score
Text 10, 80, "Player Health: " + player\health
Text 10, 90, "Boss Health: " + level\boss_health
Flip False ;displays the scene to the screen
Wend ;loop until the ESC key is pressed
For ob.objects = Each objects
TOKRB_Free ob\rb
FreeEntity ob\obj
Delete ob
Next
For b.bullettype = Each bullettype
TOKRB_Free b\tomak_i
FreeEntity b\tomak ;delete the bullet mesh
Delete b
Next
TOKSIM_DestroySimulator()
End
Function start_screen()
SetBuffer(BackBuffer())
SetFont big
Color 0,128,255
screen = GraphicsHeight()/2-90
Repeat
Text(GraphicsWidth()/2,screen,"Master Blaster",1)
Text(GraphicsWidth()/2,screen+40,"Shoot everything - ",1)
Text(GraphicsWidth()/2,screen+80,"...ha ha ha ha ha...",1)
Text(GraphicsWidth()/2,screen+160,"press <space> to start",1)
Flip()
Until KeyDown(57)
FlushKeys()
End Function
Function create_level( )
For i=1 To level\rb
ob.Objects = New Objects
ob\obj = CreateCube()
ScaleEntity ob\obj,1,0.5,0.5
;collision info
EntityType ob\obj, ENEMY_COL
EntityRadius ob\obj, .5, .95
; end collision
;id them
ob\num = i
ob\health = level\enemyhealth
; end id
ob\rb = TOKRB_Create()
geom = TOKRB_AddBox( ob\rb ,2.0,1.0,1.0)
TOKGEOM_SetMaterialIndex geom,1
TOKRB_SetPosition ob\rb,x#,2+i*0.2,z#
TOKRB_SetLinearDamping ob\rb,0.001
TOKRB_SetAngularDamping ob\rb,0.001
TOKRB_SetMass ob\rb,2.0
TOKRB_SetBoxInertiaTensor ob\rb,2.0,1.0,1.0,2.0
TOKRB_SetCollisionID( ob\rb,ENEMY_COL)
EntityColor ob\obj,Rnd(100,230),Rnd(100,230),Rnd(100,230)
Next
End Function
Function start_level()
;clear the screen
Cls
; create the scene - depending on the level
; create the box
create_scene()
;create the player - depending on the level
;return and ready to rumble!
End Function
Function create_scene()
scene\ground = CreateCube()
EntityColor scene\ground,5,5,55
ScaleEntity scene\ground,50,5,50
;EntityType scene\ground, LEVEL_COL
PositionEntity scene\ground,0,-5,0
abground = TOKAB_Create()
TOKAB_AddBox(abground,100.0,10.0,100.0)
TOKAB_SetPosition(abground,0.0,-5.0,0.0)
scene\wall1 = CreateCube()
EntityColor scene\wall1,25,25,55
ScaleEntity scene\wall1,2,10,50
PositionEntity scene\wall1,50,0,0
EntityType scene\wall1, LEVEL_COL
abwall1 = TOKAB_Create()
TOKAB_AddBox(abwall1,4.0,20.0,100.0)
TOKAB_SetPosition(abwall1,50.0,0,0.0)
scene\wall2 = CreateCube()
EntityColor scene\wall2,25,25,55
ScaleEntity scene\wall2,2,10,50
EntityType scene\wall2, LEVEL_COL
PositionEntity scene\wall2,-50,0,0
abwall2 = TOKAB_Create()
TOKAB_AddBox(abwall2,4.0,20.0,100.0)
TOKAB_SetPosition(abwall2,-50.0,0,0.0)
scene\wall3 = CreateCube()
EntityColor scene\wall3,25,25,55
EntityType scene\wall3, LEVEL_COL
ScaleEntity scene\wall3,50,10,2
PositionEntity scene\wall3,0,0,-50
abwall3 = TOKAB_Create()
TOKAB_AddBox(abwall3,100.0,20.0,4.0)
TOKAB_SetPosition(abwall3,0.0,0,-50.0)
scene\wall4 = CreateCube()
EntityColor scene\wall4,25,25,55
EntityType scene\wall4, LEVEL_COL
ScaleEntity scene\wall4,50,10,2
PositionEntity scene\wall4,0,0,50
abwall4 = TOKAB_Create()
TOKAB_AddBox(abwall4,100.0,20.0,4.0)
TOKAB_SetPosition(abwall4,0.0,0,50.0)
draw_city()
End Function
Function create_player( )
player\num_bullets = 0
;right gun
player\weapon1 = CreateCylinder(32, 1, player\camera)
RotateMesh player\weapon1, 90, 0, 0
ScaleEntity player\weapon1, .05, .05, .2
EntityColor player\weapon1, 50, 50, 50
; EntityType player\weapon1, PLAYER_COL
;megaweapon - if we're on level 2
If level\gun = 2 Then
player\weapon2 = CreateCylinder( 32,1, player\camera)
PositionEntity player\weapon2, -.45,-.20,.5
RotateMesh player\weapon2, 90, 0,0
ScaleEntity player\weapon2, .05,.05,.2
EntityColor player\weapon2, 50,50,50
End If
MoveEntity player\camera, 0, .9, 0
MoveEntity player\weapon1, .1, -.15, .1
MoveEntity player\ent, 20, 1, -20
EntityType player\ent, PLAYER_COL
EntityRadius player\ent, .3, .95
End Function
Function shoot( how )
If how = 1 Then
bullet.bullettype = New bullettype ;create a bullet
;1st bullet
player\num_bullets = player\num_bullets + 1
bullet\tomak = CreateSphere()
bullet\dead = 0
ScaleEntity bullet\tomak, .25, .25, .25
EntityType bullet\tomak, BULLET_COL
EntityRadius bullet\tomak, .1, .95
bullet\tomak_i = TOKRB_Create()
TOKRB_GravityEnable bullet\tomak_i, 1
TOKRB_AddSphere bullet\tomak_i,.5
TOKGEOM_SetMaterialIndex bullet\tomak_i,1
TOKRB_SetPosition bullet\tomak_i,EntityX( player\weapon1, 1), EntityY( player\weapon1, 1), EntityZ( player\weapon1, 1)
TOKRB_SetAngularDamping bullet\tomak_i,0.002
TOKRB_SetLinearDamping bullet\tomak_i,0.001
TOKRB_SetMass bullet\tomak_i,17.0 ; was 7
TOKRB_SetSphereInertiaTensor bullet\tomak_i,2,2.0
TOKRB_SetCollisionID( bullet\tomak_i,BULLET_COL)
EntityColor bullet\tomak,Rnd(100,230),Rnd(100,230),Rnd(100,230)
amount#= level\force ;was 150
TFormVector 0,0,1,player\camera,0
TOKRB_ApplyImpulse bullet\tomak_i,TFormedX()*amount#,TFormedY()*amount#,TFormedZ()*amount#
;second bullet - is there a second gun?
If level\gun = 2 Then
player\num_bullets = player\num_bullets + 1
bullet.bullettype = New bullettype ;create a bullet
;2st bullet
bullet\tomak = CreateSphere()
bullet\dead = 0
ScaleEntity bullet\tomak, .25, .25, .25
EntityType bullet\tomak, BULLET_COL
EntityRadius bullet\tomak, .1, .95
bullet\tomak_i = TOKRB_Create()
TOKRB_GravityEnable bullet\tomak_i, 1
TOKRB_AddSphere bullet\tomak_i,.5
TOKGEOM_SetMaterialIndex bullet\tomak_i,1
TOKRB_SetPosition bullet\tomak_i,EntityX( player\weapon2, 1), EntityY( player\weapon2, 1), EntityZ( player\weapon2, 1)
TOKRB_SetAngularDamping bullet\tomak_i,0.002
TOKRB_SetLinearDamping bullet\tomak_i,0.001
TOKRB_SetMass bullet\tomak_i,17.0 ; was 7
TOKRB_SetSphereInertiaTensor bullet\tomak_i,2,2.0
TOKRB_SetCollisionID( bullet\tomak_i,BULLET_COL)
EntityColor bullet\tomak,Rnd(100,230),Rnd(100,230),Rnd(100,230)
amount#=level\force
TFormVector 0,0,1,camera,0
TOKRB_ApplyImpulse bullet\tomak_i,TFormedX()*amount#,TFormedY()*amount#,TFormedZ()*amount#
End If
ElseIf how=2 Then ;shooting at the boss
bullet.bullettype = New bullettype ;create a bullet
;1st bullet
player\num_bullets = player\num_bullets + 1
bullet\tomak = CreateSphere()
bullet\dead = 0
ScaleEntity bullet\tomak, .75, .75, .75
EntityType bullet\tomak, BULLET_COL
EntityRadius bullet\tomak, .1, 2
bullet\tomak_i = TOKRB_Create()
TOKRB_GravityEnable bullet\tomak_i, 1
TOKRB_AddSphere bullet\tomak_i,2
TOKGEOM_SetMaterialIndex bullet\tomak_i,1
TOKRB_SetPosition bullet\tomak_i,EntityX( player\weapon1, 1), EntityY( player\weapon1, 1), EntityZ( player\weapon1, 1)
TOKRB_SetAngularDamping bullet\tomak_i,0.002
TOKRB_SetLinearDamping bullet\tomak_i,0.001
TOKRB_SetMass bullet\tomak_i,57.0 ; was 7
TOKRB_SetSphereInertiaTensor bullet\tomak_i,2,57
TOKRB_SetCollisionID( bullet\tomak_i,BULLET_COL)
EntityColor bullet\tomak,Rnd(100,230),Rnd(100,230),Rnd(100,230)
amount#= level\force*1.5 ;was 150
TFormVector 0,0,1,player\camera,0
TOKRB_ApplyImpulse bullet\tomak_i,TFormedX()*amount#,TFormedY()*amount#,TFormedZ()*amount#
End If
End Function
Function next_level()
;give a few seconds to change
Delay 3000
Cls
FlushKeys
FlushMouse
SetBuffer(BackBuffer())
SetFont big
Color 0,128,255
screen = GraphicsHeight()/2-90
Repeat
Text(GraphicsWidth()/2,screen ,"Master Blaster- level " + level\lev,1)
Text(GraphicsWidth()/2,screen +40,"Shoot everything - again!",1)
Text(GraphicsWidth()/2,screen +80,"...ha ha ha ha ha...",1)
Text(GraphicsWidth()/2,screen +160,"press <space> to start",1)
Flip()
Until KeyDown(57)
FlushKeys()
player\speed = player\speed + level\speed_adjustment
;update level attributes
;start with level 1
level\lev = level\lev + 1
level\rb = level\rb * 1.5
level\speed# = level\speed# * level\level_inc
level\enemyhealth = level\enemyhealth * level\level_inc
level\force = level\force * level\level_inc
level\enemy_count = level\rb
level\boss_vel = level\boss_vel * level\level_inc
level\city_size = level\city_size * level\level_inc
level\boss_mass = level\boss_mass * level\level_inc
level\enemy_dist_shot = level\enemy_dist_shot * level\level_inc
level\boss_health= level\boss_start_health * level\level_inc
If level\lev => 4 Then
level\gun = 2
level\num_boss = 2
level\boss_size = 2
level\boss_dead = 0
;with new guns - re-arm the player
create_player()
End If
;destroy the old city
destroy_city()
;create the new city
draw_city()
create_level()
create_boss()
End Function
Function still_alive()
; ob.objects = New objects
; If ob = Null Then
; next_level()
; End If
If level\enemy_count <= 0 Then
next_level()
End If
; For ob.objects = Each objects
; ;if all the objects are gone - start a new level
; If ob = Null Then
; next_level()
; End If
; Next
End Function
Function create_boss()
;each level has one or more boses - they are big - massive creatures (well really spheres) that chase you
boss.boss = New boss
x# = 0
y# = 0
z# = 0
boss\vel# = level\boss_vel#
boss\ent = CreateSphere()
ScaleEntity boss\ent,level\boss_size, level\boss_size, level\boss_size
;collision info
EntityType boss\ent, BOSS_COL
PositionEntity boss\ent, x#, y#+1, z#
EntityRadius boss\ent, 1, 1
EntityColor boss\ent, 255,255,255
; end collision
;id them
boss\health = level\boss_start_health
; end id
;texture the boss
testtex=CreateTexture(128,128)
; SetBuffer TextureBuffer(testtex)
For x=0 To 10
Color 0,0,0
Plot 4+Rand(120),4+Rand(120)
Next
; SetBuffer BackBuffer()
; EntityTexture boss\ent,testtex
w=MeshWidth( boss\ent) * level\boss_size
h=MeshHeight( boss\ent) * level\boss_size
d=MeshDepth( boss\ent) * level\boss_size
boss\rb = TOKRB_Create()
geom = TOKRB_AddSphere( boss\rb, level\boss_size*2 )
TOKRB_GravityEnable boss\rb, 1
TOKGEOM_SetMaterialIndex geom,1
TOKRB_SetPosition boss\rb,x#,y#+1,z#
TOKRB_SetLinearDamping boss\rb,0.002
TOKRB_SetAngularDamping boss\rb,0.002
TOKRB_SetMass boss\rb, level\boss_mass
TOKRB_SetSphereInertiaTensor boss\rb,level\boss_size,level\boss_mass
TOKRB_SetCollisionID( boss\rb, ENEMY_COL )
End Function
Function boss_update( )
;can't do this if the boss isn't alive!
If level\boss_health > 0 Then
x# = EntityX(player\ent)
y# = EntityY(player\ent)
z# = EntityZ(player\ent)
;vector to x,y,z
dx#=(x-EntityX(boss\ent))
dy#=(y-EntityY(boss\ent))
dz#=(z-EntityZ(boss\ent))
;length of vector
l#=Sqr(dx*dx+dy*dy+dz*dz)
;make the vector a unit vector, length = 1
dx=dx/l
dy=dy/l
dz=dz/l
;check if he is hit - if so - stop him
If boss\hit = 0 Then
TranslateEntity boss\ent,dx*boss\vel#,dy*boss\vel#,dz*boss\vel#
Else
boss\hit = 1
End If
Else
If level\boss_dead = 0 Then ;only do this if boss isn't already dead
;kill boss - add to score -
TOKRB_Free boss\rb
FreeEntity boss\ent
Delete boss
player\score = player\score + 100
level\boss_dead = 1
End If
End If
End Function
Function check_bullets()
For bullet.bullettype = Each bullettype
;also while we're iterating, check to see if they're idle - if so - delete them
If TOKRB_IsIdle( bullet\tomak_i ) Then
TOKRB_Free bullet\tomak_i
FreeEntity bullet\tomak ;delete the bullet mesh;
Delete bullet
player\num_bullets = player\num_bullets - 1
End If
Next
; if we have more than 10 bullets on the scene - start deleting
If player\num_bullets >= 10 Then
bullet.bullettype = First bullettype
TOKRB_Free bullet\tomak_i
FreeEntity bullet\tomak ;delete the bullet mesh;
Delete bullet
player\num_bullets = player\num_bullets - 1
End If
End Function
Function draw_city()
;add these extra objects in
For i=1 To level\city_size
c.city = New city
c\block_ent =CreateCube()
;EntityTexture fillers(i),testtex
scale_x# = Rand(5,10)
scale_y# = Rand(10,25)
scale_z# = Rand(5,10)
x# = Rand(-40,40)
y# = Rand(-40,40)
z# = Rand(-40,40)
ScaleEntity c\block_ent,scale_x#,scale_y#,scale_z#
PositionEntity c\block_ent,x#,0,z#
EntityType c\block_ent,LEVEL_COL
;texture them
testtex=CreateTexture(128,128)
SetBuffer TextureBuffer(testtex)
For x=0 To 100
Color 193,193,0
Plot 4+Rand(120),4+Rand(120)
Next
SetBuffer BackBuffer()
EntityTexture c\block_ent,testtex
c\rb_ent = TOKRB_Create()
w=MeshWidth( c\block_ent )*scale_x
h=MeshHeight( c\block_ent )*scale_y
d=MeshDepth( c\block_ent )*scale_z
geom = TOKRB_AddBox( c\rb_ent ,w*2,h*2,d*2 )
TOKGEOM_SetMaterialIndex geom,1
TOKRB_SetPosition c\rb_ent ,x#,y#,z#
TOKRB_SetLinearDamping c\rb_ent ,0.001
TOKRB_SetAngularDamping c\rb_ent ,0.001
TOKRB_SetMass c\rb_ent,2.0
TOKRB_SetBoxInertiaTensor c\rb_ent,2.0,1.0,1.0,2.0
TOKRB_SetCollisionID( c\rb_ent ,LEVEL_COL )
EntityColor c\block_ent ,255,255,255 ;Rnd(100,230),Rnd(100,230),Rnd(100,230)
Next
End Function
Function destroy_city()
For c.city = Each city
TOKRB_Free c\rb_ent
FreeEntity c\block_ent
Delete c
Next
;destroy all the left over bullets
For b.bullettype = Each bullettype
TOKRB_Free b\tomak_i
FreeEntity b\tomak
Delete b
Next
End Function
Function enemy_distance()
;can't do this if the boss isn't alive!
If level\boss_health > 0 Then
;check the distance
If EntityDistance( player\ent, boss\ent ) < level\enemy_dist_shot Then
CreateLightning( boss\ent, player\ent, 10, .5 )
;now I'm hit with that lightning - show red screen / and jolt
CameraClsColor player\camera, 255,0,0
TranslateEntity player\ent, EntityX( player\ent )* .02 , EntityY( player\ent ) * .02 , EntityZ( player\ent ) * .02
;if i'm hit - then let the player recover - a few secs..
player\hit = True
End If
If player\hit = True Then
If player\hit_time <= 0 Then
CameraClsColor player\camera, 108,122,255
;if i'm hit - decrease health
player\health = player\health - 10
player\hit_time = 100
player\hit = False
Else
player\hit_time = player\hit_time - 10
End If
End If
End If
End Function
Function CreateLightning( FromEntity, ToEntity, Parts, Deviation# )
;got this function from EdzUp
Local DeviationEntity = CreatePivot()
Local TargetEntity = CreatePivot()
Local TE=CreatePivot()
Local PartCount = 0
PositionEntity DummyEntity, EntityX#( FromEntity ), EntityY#( FromEntity ), EntityZ#( FromEntity )
PointEntity DummyEntity, ToEntity
Range# = EntityDistance#( FromEntity, ToEntity )
Division# = Range# / Parts
PositionEntity DeviationEntity, EntityX#( FromEntity ), EntityY#( FromEntity ), EntityZ#( FromEntity )
For PartCount = 0 To Parts-1
PositionEntity TargetEntity, EntityX#( DummyEntity ), EntityY#( DummyEntity ), EntityZ#( DummyEntity )
MoveEntity TargetEntity, 0, Rnd( Deviation# )-Rnd( Deviation# ), Rnd( Deviation# )-Rnd(Deviation#)
Lightning.LightningType = New LightningType
Lightning\Entity = CreateSight()
PointEntity DeviationEntity, TargetEntity
PositionEntity Lightning\Entity, EntityX#( Deviationentity ), EntityY#( Deviationentity ), EntityZ#( Deviationentity )
RotateEntity Lightning\Entity, EntityPitch#( DeviationEntity ), EntityYaw#( DeviationEntity ), EntityRoll#( DeviationEntity )
ScaleEntity Lightning\Entity, EntityDistance#( DeviationEntity, TargetEntity ), .02, 1
TurnEntity Lightning\Entity, 0, 90, 0
;move the deviationentity to the target
PositionEntity DeviationEntity, EntityX#( TargetEntity, 1 ), EntityY#( TargetEntity, 1 ), EntityZ#( TargetEntity, 1 )
MoveEntity DummyEntity, 0, 0, Division#
Next
PositionEntity TargetEntity, EntityX#( ToEntity ), EntityY#( ToEntity ), EntityZ#( ToEntity )
Lightning.LightningType = New LightningType
Lightning\Entity = CreateSight()
PointEntity DeviationEntity, TargetEntity
PositionEntity Lightning\Entity, EntityX#( Deviationentity ), EntityY#( Deviationentity ), EntityZ#( Deviationentity )
RotateEntity Lightning\Entity, EntityPitch#( DeviationEntity ), EntityYaw#( DeviationEntity ), EntityRoll#( DeviationEntity )
ScaleEntity Lightning\Entity, EntityDistance#( DeviationEntity, TargetEntity ), .02, 1
TurnEntity Lightning\Entity, 0, 90, 0
FreeEntity DeviationEntity
FreeEntity TargetEntity
End Function
Function CreateSight()
;by Zenith
sprite=CreateMesh()
he=CreateBrush(255,255,255)
v=CreateSurface(sprite,he)
FreeBrush he
AddVertex ( v,0,1,0,1,0) ; top left 0,1;1,0
AddVertex ( v,1,1,0,0,0) ; top right 1,1;1,1
AddVertex ( v,0,-1,0,1,1) ; bottom left 0,0;,0,0
AddVertex ( v,1,-1,0,0,1) ; bottom right 1,0;0,1
AddTriangle( v,0,1,2)
AddTriangle( v,3,2,1)
TurnEntity sprite,0,0,0
EntityFX sprite,17
Return sprite
End Function
Function ResetLightning()
For Lightning.LightningType = Each LightningType
If Lightning<>Null
If Lightning\Entity<>0 Then FreeEntity Lightning\Entity
Delete Lightning
EndIf
Next
End Function