collision between two animated characters

Blitz3D Forums/Blitz3D Programming/collision between two animated characters

Isac(Posted 2016) [#1]
how to make animated characters lose health points


Isac(Posted 2016) [#2]
; Graphics
;-------------------------------------------------------------
Graphics3D 640,480,16,2 ;
SetBuffer BackBuffer() ;
;-------------------------------------------------------------


; Ninja2 Keys
;-------------------------------------------------------------
Const RIGHT_KEY = 205 ; Move Right ;
Const LEFT_KEY = 203 ; Move Left ;
Const FOUR_KEY = 75 ; Punch ;
Const FIVE_KEY = 76 ; Weapon ;
Const SIX_KEY = 77 ; Jump ;
;-------------------------------------------------------------


; Ninja Keys
;-------------------------------------------------------------
Const Q_KEY = 16 ; Move Left ;
Const W_KEY = 17 ; Move Right ;
Const D_KEY = 32 ; Punch ;
Const F_KEY = 33 ; Weapon ;
Const G_KEY = 34 ; Jump ;
;-------------------------------------------------------------


Const ESC_KEY = 1
ninja_HP = 100
ninja_HP2 = 100
Game = 1


; Create Camera
;-------------------------------------------------------------
camera=CreateCamera() ;
PositionEntity camera,0,6.5,-6 ;
;-------------------------------------------------------------


; Create the Light
;-------------------------------------------------------------
light=CreateLight(camera) ;
;-------------------------------------------------------------


; Creating the Terrain
;-------------------------------------------------------------
ground=CreateTerrain (512) ;
PositionEntity ground, -500,-1,-500 ;
ScaleEntity ground, 10,15,10 ;
;-------------------------------------------------------------


; Texture Terrain
;-------------------------------------------------------------
fighting_tex=LoadTexture("../images/fighting_tex.jpg") ;
EntityTexture ground,fighting_tex ;
;-------------------------------------------------------------


; Creating the Sky
;-------------------------------------------------------------
sky = CreateSphere (40) ;
FlipMesh sky ;
ScaleEntity sky, 500,100,500 ;
;-------------------------------------------------------------



; Loading the Heightmap
;-------------------------------------------------------------
terrain=LoadTerrain("../images/valley.jpg") ;
ScaleEntity terrain,5,100,5 ;
PositionEntity terrain,-500,0,-500 ;
tex=LoadTexture("../images/fighting_tex.jpg") ;
ScaleTexture tex,50,50 ;
EntityTexture terrain,tex ;
PositionEntity sky, 0,50,0 ;
sky_tex = LoadTexture("../images/sky_tex.jpg") ;
EntityTexture sky,sky_tex ;
EntityFX sky,1 ;
;-------------------------------------------------------------



; Codes to Include Other Files into the Program
;-------------------------------------------------------------
Include "ninja.bb" ;
Include "ninja2.bb" ;
Include "extra_stuff.bb" ;
;-------------------------------------------------------------



Local anim = 0
Local anim2 = 0



; This following code deals with cameras and terrain
;-------------------------------------------------------------
While Not KeyDown(ESC_KEY) ;
;-------------------------------------------------------------

If KeyHit(2) And game = 1 ninja_hp = ninja_hp-10
If KeyHit(3) And game = 1 ninja_hp2 = ninja_hp2-10


; Move Ninja
;-------------------------------------------------------------
If KeyDown(2) ;
;
Animate ninja,3,.25,1,5 ;
ElseIf KeyDown(Q_KEY) ;
TranslateEntity (ninja,-.1,0,0) ;
If anim<>ninja_walk Then ;
anim=ninja_walk ;
Animate(ninja,1,-0.3,anim) ;
EndIf ;
ElseIf KeyDown(W_KEY) ;
TranslateEntity (ninja,.1,0,0) ;
If anim<>ninja_walk Then ;
anim=ninja_walk ;
Animate(ninja,1,0.3,anim) ;
EndIf ;
ElseIf KeyDown(D_KEY) ;
If anim<>ninja_punch Then ;
anim=ninja_punch ;
Animate(ninja,3,-0.3,anim) ;
EndIf ;
ElseIf KeyDown(F_KEY) ;
If anim<>ninja_sword Then ;
anim=ninja_sword ;
Animate(ninja,3,-0.3,anim) ;
EndIf ;
ElseIf KeyDown(G_KEY) ;
If anim<>ninja_jump Then ;
anim=ninja_jump ;
Animate(ninja,3,-0.3,anim) ;
EndIf ;
ElseIf anim<>ninja_idle2 Then ;
anim=ninja_idle2 ; Idle ;
Animate(ninja,1,0.1,anim) ;
EndIf ;
;-------------------------------------------------------------


; Collisions
;-------------------------------------------------------------





; Move Ninja2
;-------------------------------------------------------------
If KeyDown(3) ;
;
Animate ninja2,3,.25,1,5 ;
;
ElseIf KeyDown(RIGHT_KEY) ;
TranslateEntity (ninja2,0.1,0,0) ;
If anim2<>ninja2_walk Then ;
anim2=ninja2_walk ;
Animate(ninja2,1,-0.3,anim2) ;
EndIf ;
;
ElseIf KeyDown(LEFT_KEY) ;
TranslateEntity (ninja2,-0.1,0,0) ;
If anim2<>ninja2_walk Then ;
anim2=ninja2_walk ;
Animate(ninja2,1,0.3,anim2) ;
EndIf ;
ElseIf KeyDown(FOUR_KEY) ;
If anim2<>ninja2_punch Then ;
anim2=ninja2_punch ;
Animate(ninja2,3,-0.3,anim2) ;
EndIf ;
ElseIf KeyDown(FIVE_KEY) ;
If anim2<>ninja2_sword Then ;
anim2=ninja2_sword ;
Animate(ninja2,3,-0.3,anim2) ;
EndIf ;
ElseIf KeyDown(SIX_KEY) ;
If anim2<>ninja2_jump Then ;
anim2=ninja2_jump ;
Animate(ninja2,3,-0.3,anim2) ;
EndIf ;
ElseIf anim2<>ninja2_idle2 Then ;
anim2=ninja2_idle2 ; Idle ;
Animate(ninja2,1,0.1,anim2) ;
EndIf ;
;-------------------------------------------------------------




UpdateWorld

RenderWorld

If ninja_hp <= 0
Text GraphicsWidth()/2,GraphicsHeight()/2,"Player 1 is dead!!!!", True,True
Game = 0
EndIf

If ninja_hp2 <= 0
Text GraphicsWidth()/2,GraphicsHeight()/2,"Player 2 is dead!!!!", True,True
Game = 0
EndIf

Text 0,0, "Player 1 Health = "+ninja_HP
Text 470,0, "Player 2 Health = "+ninja_HP2


Flip

Wend
End


Isac(Posted 2016) [#3]
ninja=LoadAnimMesh("../ninja/ninja.b3d")
ScaleEntity ninja,.5,.5,.5
PositionEntity ninja,-5,4,5

;;;Animate ninja,2
RotateEntity ninja,0,-85,0

ninja_walk = ExtractAnimSeq( ninja,1,14 ) ;anim sequence 1: Walk (normal)
ninja_walk2 = ExtractAnimSeq( ninja,15,30 ) ;anim sequence 2: Stealth Walk
ninja_punch = ExtractAnimSeq( ninja,32,44 ) ;anim sequence 3: Punch and swipe sword
ninja_sword = ExtractAnimSeq( ninja,45,59 ) ;anim sequence 4: Swipe and spin sword
ninja_downswipe = ExtractAnimSeq( ninja,60,68 ) ;anim sequence 5: Overhead twohanded downswipe
ninja_backwards = ExtractAnimSeq( ninja,69,72 ) ;anim sequence 6: Up to block position (play backwards to lower sword if you want)
ninja_fkick = ExtractAnimSeq( ninja,73,83 ) ;anim sequence 7: Forward kick
ninja_pickup = ExtractAnimSeq( ninja,84,93 ) ;anim sequence 8: Pick up from floor (or down to crouch at frame 87)
ninja_jump = ExtractAnimSeq( ninja,94,102 ) ;anim sequence 9: Jump
ninja_jumpwithouthight = ExtractAnimSeq( ninja,103,111 ) ;anim sequence 10: Jump without height (for programmer controlled jumps)
ninja_jumpsowrdkick = ExtractAnimSeq( ninja,112,125 ) ;anim sequence 11: High jump to Sword Kill (Finish em off move??)
ninja_sidekick = ExtractAnimSeq( ninja,126,133 ) ;anim sequence 12: Side Kick
ninja_spinngsword = ExtractAnimSeq( ninja,134,145 ) ;anim sequence 13: Spinning Sword attack (might wanna speed this up in game)
ninja_backflip = ExtractAnimSeq( ninja,146,158 ) ;anim sequence 14: Backflip
ninja_climwall = ExtractAnimSeq( ninja,159,165 ) ;anim sequence 15: Climb wall
ninja_fallback = ExtractAnimSeq( ninja,166,173 ) ;anim sequence 16: Death 1 , Fall back onto ground
ninja_fallforward = ExtractAnimSeq( ninja,174,182 ) ;anim sequence 17: Death 2 , Fall forward onto ground
ninja_idle1 = ExtractAnimSeq( ninja,184,205 ) ;anim sequence 18: Idle 1 , Breathe heavily
ninja_idle2 = ExtractAnimSeq( ninja,206,250 ) ;anim sequence 19: Idle 2
ninja_idle2 = ExtractAnimSeq( ninja,251,300 ) ;anim sequence 20: Idle 3


Isac(Posted 2016) [#4]
ninja2=LoadAnimMesh("../ninja/ninja.b3d")
LoadTexture ("../ninja/nskinrd.jpg")
ScaleEntity ninja2,.5,.5,.5
PositionEntity ninja2,5,4,5

;;;Animate ninja2,2
RotateEntity ninja2,0,90,0

ninja2_walk = ExtractAnimSeq( ninja2,1,14 ) ;anim sequence 1: Walk (normal)
ninja2_walk2 = ExtractAnimSeq( ninja2,15,30 ) ;anim sequence 2: Stealth Walk
ninja2_punch = ExtractAnimSeq( ninja2,32,44 ) ;anim sequence 3: Punch and swipe sword
ninja2_sword = ExtractAnimSeq( ninja2,45,59 ) ;anim sequence 4: Swipe and spin sword
ninja2_downswipe = ExtractAnimSeq( ninja2,60,68 ) ;anim sequence 5: Overhead twohanded downswipe
ninja2_backwards = ExtractAnimSeq( ninja2,69,72 ) ;anim sequence 6: Up to block position (play backwards to lower sword if you want)
ninja2_fkick = ExtractAnimSeq( ninja2,73,83 ) ;anim sequence 7: Forward kick
ninja2_pickup = ExtractAnimSeq( ninja2,84,93 ) ;anim sequence 8: Pick up from floor (or down to crouch at frame 87)
ninja2_jump = ExtractAnimSeq( ninja2,94,102 ) ;anim sequence 9: Jump
ninja2_jumpwithouthight = ExtractAnimSeq( ninja2,103,111 ) ;anim sequence 10: Jump without height (for programmer controlled jumps)
ninja2_jumpsowrdkick = ExtractAnimSeq( ninja2,112,125 ) ;anim sequence 11: High jump to Sword Kill (Finish em off move??)
ninja2_sidekick = ExtractAnimSeq( ninja2,126,133 ) ;anim sequence 12: Side Kick
ninja2_spinngsword = ExtractAnimSeq( ninja2,134,145 ) ;anim sequence 13: Spinning Sword attack (might wanna speed this up in game)
ninja2_backflip = ExtractAnimSeq( ninja2,146,158 ) ;anim sequence 14: Backflip
ninja2_climwall = ExtractAnimSeq( ninja2,159,165 ) ;anim sequence 15: Climb wall
ninja2_fallback = ExtractAnimSeq( ninja2,166,173 ) ;anim sequence 16: Death 1 , Fall back onto ground
ninja2_fallforward = ExtractAnimSeq( ninja2,174,182 ) ;anim sequence 17: Death 2 , Fall forward onto ground
ninja2_idle1 = ExtractAnimSeq( ninja2,184,205 ) ;anim sequence 18: Idle 1 , Breathe heavily
ninja2_idle2 = ExtractAnimSeq( ninja2,206,250 ) ;anim sequence 19: Idle 2
ninja2_idle2 = ExtractAnimSeq( ninja2,251,300 ) ;anim sequence 20: Idle 3


Guy Fawkes(Posted 2016) [#5]
Isac. Please use [ codebox]CODE HERE[ /codebox] WITHOUT the spaces & add the WHOLE code inbetween codebox & /codebox.

~GF