Дубликат в дубликате
Я создаю врагов и мне нужно заставить их стрелять не зависимо друг от друга, но что-то нефига не работает, помогите найти ошибку :dontknow:
Вот код:
Основной код:
Код:
;--begin--;
Graphics3D 640,480,16,1
SetBuffer BackBuffer()
;--begin--;
Include "functions.bb"
;--constants--;
Global health%=100;--health
Global pl_sp#=0.5;--player`s speed
Global half_pl_sp#=0.25;--1/2 player`s speed
Global gravity# = 0.09;--gravity
Global yspeed#=0;--player`s veltical speed
Global jspeed# = 1.4;--jump speed
Global simp_m=1;--one-key movement
Global weapon=1;--type of weapon
Global move=1
Global w_s1=1;--action weapon 1
Global w_s2=1;--action weapon 2
Global gun_b1%=100;--weapon 1 ammo
Global gun_b2%=50;--weapon 2 ammo
Global h_m#=0.08;--veltical speed objects
Global h_dir#=-0.005;--direction with speed
Global en_wait=10
;--constants--;
;--images--;
health_im=LoadImage("textures\health.bmp")
el_gun_ammo=LoadImage("textures\el_gun_ammo.bmp")
pl_gun_ammo=LoadImage("textures\pl_gun_ammo.bmp")
;--images--;
;--sounds--;
gun_s1=LoadSound("sounds\gun1.ogg")
;--sounds--;
;--collision types--;
Global TYPE_PLAYER=1, TYPE_BULLET=2, TYPE_WALL=3, TYPE_HEALTH=4, TYPE_IMP_AMMO=5, TYPE_PL_AMMO=6, TYPE_EN_BULLET=7
;--collision types--;
;--types--;
Type T_bullet
Field ent
Field time
End Type
Type T_aspirin
Field ent
End Type
Type T_plasma
Field ent
End Type
Type T_impulse
Field ent
End Type
Type T_bullet_en
Field ent
Field time
End Type
Type T_enemy
Field ent
End Type
;--types--;
;--sprites--;
Global shot1=LoadSprite("textures\shot1.bmp")
ScaleSprite shot1,3,3
EntityRadius shot1,1.5
EntityType shot1,TYPE_BULLET
HideEntity shot1
Global shot2=LoadSprite("textures\shot2.bmp")
ScaleSprite shot2,3,3
EntityRadius shot2,1.5
EntityType shot2,TYPE_BULLET
HideEntity shot2
Global shot_en1=LoadSprite("textures\shot3.bmp",2)
ScaleSprite shot_en1,5,5
EntityRadius shot_en1,1.5
EntityType shot_en1,TYPE_EN_BULLET
HideEntity shot_en1
;--sprites--;
;--main--;
pln=CreatePlane()
PositionEntity pln,0,-1,0
EntityType pln,TYPE_WALL
EntityColor pln,50,100,150
Global player=CreateSphere()
PositionEntity player,0,10,50
EntityRadius player,4
EntityType player, TYPE_PLAYER
EntityAlpha player,1
Global cam=CreateCamera()
EntityParent cam,player
PositionEntity cam,0,5,0
Global enemy=LoadMesh("models\level1\enemy1.3ds")
PositionEntity enemy,-5,10,-5
ScaleEntity enemy,0.5,0.5,0.5
;--main--;
;--models--;
gun1=LoadMesh("models\level1\gun1.3ds")
ScaleEntity gun1,0.05,0.05,0.05
EntityParent gun1,cam
PositionEntity gun1,-1,-3,3
RotateEntity gun1,0,-90,0
HideEntity gun1
EntityOrder gun1,-1
gun2=LoadMesh("models\level1\gun2.3ds")
ScaleEntity gun2,0.05,0.05,0.05
EntityParent gun2,cam
PositionEntity gun2,-2,-7,0
RotateEntity gun2,0,-90,0
HideEntity gun2
EntityOrder gun2,-1
Global h_asp=LoadMesh("models\level1\health.3ds")
ScaleEntity h_asp,0.25,0.25,0.25
EntityType h_asp, TYPE_HEALTH
HideEntity h_asp
EntityFX h_asp,1
Global pl_am=LoadMesh("models\level1\pl_am.b3d")
ScaleEntity pl_am,0.1,0.1,0.1
EntityType pl_am, TYPE_PL_AMMO
EntityFX pl_am,1
HideEntity pl_am
Global im_am=LoadMesh("models\level1\im_am.b3d")
ScaleEntity im_am,0.1,0.1,0.1
EntityType im_am, TYPE_IMP_AMMO
PositionEntity im_am,5,1,5
EntityFX im_am,1
HideEntity im_am
;--models--;
;--pivots--;
Global piv_fire=CreatePivot()
EntityParent piv_fire,cam
PositionEntity piv_fire,-1.5,-1.5,8
;--pivots--;
;--collisions--;
Collisions TYPE_PLAYER, TYPE_WALL, 2, 3
Collisions TYPE_BULLET, TYPE_WALL, 2, 3
Collisions TYPE_PLAYER, TYPE_HEALTH, 2, 3
Collisions TYPE_PLAYER, TYPE_IMP_AMMO, 2, 3
Collisions TYPE_PLAYER, TYPE_PL_AMMO, 2, 3
Collisions TYPE_PLAYER, TYPE_EN_BULLET, 2, 3
;--collisions--;
;--creations--;
CreateFirstAid()
CreateImpulseAmmo()
CreatePlasmaAmmo()
CreateEnemy()
;--creations--;
;-------------------------------------------------------------
While Not KeyHit(1)
;-------------------------------------------------------------
;--enemy fire waiting--;
en_wait=en_wait-1
If en_wait<0
CreateEnemyBullet.T_bullet_en()
en_wait=20
EndIf
;--enemy fire waiting--;
If KeyHit(18)
health=health-1
EndIf
;--death--;
If health<=0
health = 0
move=0
PositionEntity cam,0,-2,0
RotateEntity cam,0,0,-80
HideEntity gun1
HideEntity gun2
EndIf
;--death--;
;--changing direction Y movement objects--;
h_m=h_m+h_dir
If h_m<-0.08
h_dir=0.005
ElseIf h_m>0.08
h_dir=-0.005
EndIf
;--changing direction Y movement objects--;
;--FIRE!!!--;
If move=1
If MouseHit(1)
If weapon=1
If w_s1=1
gun_b1=gun_b1-1
CreateBullet()
PlaySound gun_s1
EndIf
ElseIf weapon=2
If w_s2=1
gun_b2=gun_b2-1
CreateBullet()
PlaySound gun_s1
EndIf
EndIf
EndIf
EndIf
;--FIRE!!!--;
;--changing weapon--;
If move=1
wheel=MouseZSpeed()
If wheel=-1
weapon=weapon+1
If weapon=3
weapon=1
EndIf
ElseIf wheel=1
If weapon=1
weapon=3
EndIf
weapon=weapon-1
EndIf
If weapon=1
ShowEntity gun1
HideEntity gun2
ElseIf weapon=2
ShowEntity gun2
HideEntity gun1
EndIf
EndIf
;--changing weapon--;
;--ammo limit--;
If gun_b1=0
w_s1=0
Else
w_s1=1
EndIf
If gun_b1>200
gun_b1=200
EndIf
If gun_b2=0
w_s2=0
Else
w_s2=1
EndIf
If gun_b2>100
gun_b2=100
EndIf
;--ammo limit--;
;--bullet movement--;
For ex_bul.T_bullet = Each T_bullet
UpdateBullet(ex_bul)
Next
For ex_bul_en.T_bullet_en = Each T_bullet_en
UpdateEnemyBullet(ex_bul_en)
Next
;--bullet movement--;
;--first aid actions--;
UpdateFirstAid(ex_asp.T_aspirin)
;--first aid actions--;
;--impulse ammo actions--;
UpdateImpulseAmmo(ex_im.T_impulse)
;--impulse ammo actions--;
;--plasma ammo actions--;
UpdatePlasmaAmmo(ex_pl.T_plasma)
;--plasma ammo actions--;
;--jump--;
JumpPlayer()
;--jump--;
;--player`s movement--;
MovementPlayer()
;--player`s movement--;
;--enemy`s movement--;
UpdateEnemy(ex_en.T_enemy)
;--enemy`s movement--;
UpdateWorld()
RenderWorld()
;--ammo indicator--;
If weapon=1
DrawImage el_gun_ammo,540,430
Text 575,450,Str(gun_b1)
ElseIf weapon=2
DrawImage pl_gun_ammo,540,430
Text 575,450,Str(gun_b2)
EndIf
;--ammo indicator--;
;--health indicator--;
DrawImage health_im,0,430
Text 55,450,Str(health)
;--health indicator--;
Flip
Wend
End
Функции:
Код:
Function MovementPlayer()
If move=1
;--movement--;
If simp_m=1
If KeyDown(17) MoveEntity player,0,0,pl_sp
If KeyDown(31) MoveEntity player,0,0,-pl_sp
If KeyDown(30) MoveEntity player,-pl_sp,0,0
If KeyDown(32) MoveEntity player,pl_sp,0,0
EndIf
If KeyDown(17) And KeyDown(30)
simp_m=0
MoveEntity player,-half_pl_sp,0,half_pl_sp
ElseIf KeyDown(17) And KeyDown(32)
MoveEntity player,half_pl_sp,0,half_pl_sp
simp_m=0
ElseIf KeyDown(31) And KeyDown(30)
MoveEntity player,-half_pl_sp,0,-half_pl_sp
simp_m=0
ElseIf KeyDown(31) And KeyDown(32)
MoveEntity player,half_pl_sp,0,-half_pl_sp
simp_m=0
Else
simp_m=1
EndIf
;--movement--;
;--free look--;
TurnEntity player, 0, 0 -MouseXSpeed()*0.1, 0
TurnEntity cam, MouseYSpeed()*0.1, 0, 0
MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
RotateEntity cam, EntityPitch#(cam), 0, 0
;--free look--;
EndIf
End Function
;-------------------------------------------------------------
Function JumpPlayer()
;--gravity--;
yspeed=yspeed-gravity
TranslateEntity player,0,yspeed,0
;--gravity--;
;--jump--;
coll = EntityCollided(player,TYPE_WALL)
If coll
collide_y = CollisionNY(player,CountCollisions(player) )
If 0<collide_y
yspeed=0
jump=1
Else
jump=0
EndIf
Else
jump=0
EndIf
;--jump--;
If move=1
;--jump on--;
If jump=1
If KeyDown(57)
yspeed = jspeed
EndIf
EndIf
;--jump on--;
EndIf
End Function
;-------------------------------------------------------------
Function CreateBullet.T_bullet()
ex_bul.T_bullet = New T_bullet
ex_bul\time = 150
If weapon=1
ex_bul\ent = CopyEntity(shot2,piv_fire)
ElseIf weapon=2
ex_bul\ent = CopyEntity(shot1,piv_fire)
EndIf
EntityParent ex_bul\ent,0
Return ex_bul
End Function
;-------------------------------------------------------------
Function UpdateBullet(ex_bul.T_bullet)
ex_bul\time = ex_bul\time-1
MoveEntity ex_bul\ent,0,0,5
If ex_bul\time<=0 Or EntityCollided(ex_bul\ent,TYPE_WALL)
FreeEntity ex_bul\ent
Delete ex_bul
Return
EndIf
End Function
;-------------------------------------------------------------
Function CreateFirstAid()
ex_asp.T_aspirin = New T_aspirin
ex_asp\ent = CopyEntity(h_asp)
NameEntity (ex_asp\ent,Handle(ex_asp))
PositionEntity ex_asp\ent,20,0,0
ex_asp.T_aspirin = New T_aspirin
ex_asp\ent = CopyEntity(h_asp)
NameEntity (ex_asp\ent,Handle(ex_asp))
PositionEntity ex_asp\ent,40,0,0
ex_asp.T_aspirin = New T_aspirin
ex_asp\ent = CopyEntity(h_asp)
NameEntity (ex_asp\ent,Handle(ex_asp))
PositionEntity ex_asp\ent,60,0,0
End Function
;-------------------------------------------------------------
Function UpdateFirstAid(ex_asp.T_aspirin)
For ex_asp.T_aspirin = Each T_aspirin
TurnEntity ex_asp\ent,0,2,0
MoveEntity ex_asp\ent,0,h_m,0
Next
Local asp_col% = EntityCollided(player,TYPE_HEALTH)
If(asp_col<>0)
If health<100
ex_asp.T_aspirin = Object.T_aspirin(EntityName(asp_col))
FreeEntity(asp_col)
Delete(ex_asp)
health=health+20
EndIf
EndIf
End Function
;-------------------------------------------------------------
Function CreateImpulseAmmo()
ex_im.T_impulse = New T_impulse
ex_im\ent = CopyEntity(im_am)
NameEntity (ex_im\ent,Handle(ex_im))
PositionEntity ex_im\ent,20,2,20
ex_im.T_impulse = New T_impulse
ex_im\ent = CopyEntity(im_am)
NameEntity (ex_im\ent,Handle(ex_im))
PositionEntity ex_im\ent,40,2,20
ex_im.T_impulse = New T_impulse
ex_im\ent = CopyEntity(im_am)
NameEntity (ex_im\ent,Handle(ex_im))
PositionEntity ex_im\ent,60,2,20
ex_im.T_impulse = New T_impulse
ex_im\ent = CopyEntity(im_am)
NameEntity (ex_im\ent,Handle(ex_im))
PositionEntity ex_im\ent,80,2,20
ex_im.T_impulse = New T_impulse
ex_im\ent = CopyEntity(im_am)
NameEntity (ex_im\ent,Handle(ex_im))
PositionEntity ex_im\ent,100,2,20
End Function
;-------------------------------------------------------------
Function UpdateImpulseAmmo(ex_im.T_impulse)
For ex_im.T_impulse = Each T_impulse
TurnEntity ex_im\ent,0,2,0
MoveEntity ex_im\ent,0,h_m,0
Next
Local im_col% = EntityCollided(player,TYPE_IMP_AMMO)
If(im_col<>0)
If gun_b1<200
ex_im.T_impulse = Object.T_impulse(EntityName(im_col))
FreeEntity(im_col)
Delete(ex_im)
gun_b1=gun_b1+50
EndIf
EndIf
End Function
;-------------------------------------------------------------
Function CreatePlasmaAmmo()
ex_pl.T_plasma = New T_plasma
ex_pl\ent = CopyEntity(pl_am)
NameEntity (ex_pl\ent,Handle(ex_pl))
PositionEntity ex_pl\ent,20,2,40
ex_pl.T_plasma = New T_plasma
ex_pl\ent = CopyEntity(pl_am)
NameEntity (ex_pl\ent,Handle(ex_pl))
PositionEntity ex_pl\ent,40,2,40
ex_pl.T_plasma = New T_plasma
ex_pl\ent = CopyEntity(pl_am)
NameEntity (ex_pl\ent,Handle(ex_pl))
PositionEntity ex_pl\ent,60,2,40
ex_pl.T_plasma = New T_plasma
ex_pl\ent = CopyEntity(pl_am)
NameEntity (ex_pl\ent,Handle(ex_pl))
PositionEntity ex_pl\ent,80,2,40
ex_pl.T_plasma = New T_plasma
ex_pl\ent = CopyEntity(pl_am)
NameEntity (ex_pl\ent,Handle(ex_pl))
PositionEntity ex_pl\ent,100,2,40
ex_pl.T_plasma = New T_plasma
ex_pl\ent = CopyEntity(pl_am)
NameEntity (ex_pl\ent,Handle(ex_pl))
PositionEntity ex_pl\ent,120,2,40
End Function
;-------------------------------------------------------------
Function UpdatePlasmaAmmo(ex_pl.T_plasma)
For ex_pl.T_plasma = Each T_plasma
TurnEntity ex_pl\ent,0,2,0
MoveEntity ex_pl\ent,0,h_m,0
Next
Local pl_col% = EntityCollided(player,TYPE_PL_AMMO)
If(pl_col<>0)
If gun_b2<100
ex_pl.T_plasma = Object.T_plasma(EntityName(pl_col))
FreeEntity(pl_col)
Delete(ex_pl)
gun_b2=gun_b2+10
EndIf
EndIf
End Function
;-------------------------------------------------------------
Function CreateEnemyBullet.T_bullet_en()
ex_bul_en.T_bullet_en = New T_bullet_en
ex_bul_en\time = 150
ex_bul_en\ent = CopyEntity(shot_en1,ex_en)
RotateEntity ex_bul_en\ent,0,180,0
PositionEntity ex_bul_en\ent,-3.5,-1.5,-3
EntityParent ex_bul_en\ent,0
Return ex_bul_en
End Function
;-------------------------------------------------------------
Function UpdateEnemyBullet(ex_bul_en.T_bullet_en)
ex_bul_en\time = ex_bul_en\time-1
MoveEntity ex_bul_en\ent,0,0,1
If ex_bul_en\time<=0 Or EntityCollided(ex_bul_en\ent,TYPE_WALL) Or EntityCollided(ex_bul_en\ent,TYPE_PLAYER)
FreeEntity ex_bul_en\ent
Delete ex_bul_en
Return
EndIf
If EntityCollided(ex_bul_en\ent,TYPE_PLAYER)
health=health-5
EndIf
End Function
;-------------------------------------------------------------
Function CreateEnemy()
ex_en.T_enemy = New T_enemy
ex_en\ent = CopyEntity(enemy)
NameEntity (ex_en\ent,Handle(ex_en))
PositionEntity ex_en\ent,-5,10,-15
ex_en.T_enemy = New T_enemy
ex_en\ent = CopyEntity(enemy)
NameEntity (ex_en\ent,Handle(ex_en))
PositionEntity ex_en\ent,-5,10,-25
ex_en.T_enemy = New T_enemy
ex_en\ent = CopyEntity(enemy)
NameEntity (ex_en\ent,Handle(ex_en))
PositionEntity ex_en\ent,-5,10,-35
ex_en.T_enemy = New T_enemy
ex_en\ent = CopyEntity(enemy)
NameEntity (ex_en\ent,Handle(ex_en))
PositionEntity ex_en\ent,-5,10,-45
End Function
;-------------------------------------------------------------
Function UpdateEnemy(ex_en.T_enemy)
For ex_en.T_enemy = Each T_enemy
PointEntity ex_en\ent,player
TurnEntity ex_en\ent,0,181.5,0
Next
End Function
|