4 way shooting
Blitz3D Forums/Blitz3D Beginners Area/4 way shooting
| ||
| I'm trying to make a 4 way shooting system for a test game... for some reason, I cant get the thing to work... here's the code: first, the actions If KeyDown(200) Then MoveEntity bob,0,0,.1: RotateMesh bob,3,0,0: fire_angle=1 If KeyDown(208) Then MoveEntity bob,0,0,-.1: RotateMesh bob,-3,0,0: fire_angle=2 If KeyDown(205) Then MoveEntity bob,.1,0,0: RotateMesh bob,0,0,-3: fire_angle=3 If KeyDown(203) Then MoveEntity bob,-.1,0,0 RotateMesh bob,0,0,3: fire_angle=4 If KeyHit(54) And fire_angle=1 Then create_bullet_up If KeyHit(54) And fire_angle=2 Then create_bullet_down If KeyHit(54) And fire_angle=3 Then create_bullet_left If KeyHit(54) And fire_angle=4 Then create_bullet_right For b.bullet= Each bullet update_bullet_up update_bullet_down update_bullet_left update_bullet_right Next then, the functions: Function create_bullet_up() b.bullet=New bullet b\direct=1 b\entity=CopyEntity(bullet) PositionEntity b\entity,EntityX(bob),EntityY(bob),EntityZ(bob) End Function Function create_bullet_down() b.bullet=New bullet b\direct=2 b\entity=CopyEntity(bullet) PositionEntity b\entity,EntityX(bob),EntityY(bob),EntityZ(bob) End Function Function create_bullet_left() b.bullet=New bullet b\direct=3 b\entity=CopyEntity(bullet) PositionEntity b\entity,EntityX(bob),EntityY(bob),EntityZ(bob) End Function Function create_bullet_right() b.bullet=New bullet b\direct=4 b\entity=CopyEntity(bullet) PositionEntity b\entity,EntityX(bob),EntityY(bob),EntityZ(bob) End Function Function update_bullet_up() For b.bullet=Each bullet If b\direct=1 Then MoveEntity b\entity,0,0,1 Next End Function Function update_bullet_down() For b.bullet=Each bullet If b\direct=2 Then MoveEntity b\entity,0,0,-1 Next End Function Function update_bullet_left() For b.bullet=Each bullet If b\direct=3 Then MoveEntity b\entity,1,0,0 Next End Function Function update_bullet_right() For b.bullet=Each bullet If b\direct=4 Then MoveEntity b\entity,-1,0,0 Next End Function |
| ||
| Your 4 x update_bullet and 4x create_bullet functions are a bit overkill if you ask me ( you could easily reduce this to one fuction for each action. TBH, I'm not really sure how you want this to work. How exactly is the main BOB mesh to be controlled in terms of the cursors. Do you want it to remain facing in one direction ( vertical SHMUP ) or rotate left and right ( ASTEROIDS ). Do you want it to rotate to face the direction you want to fire? Stevie |
| ||
| I'd like for it to face the direction I want to fire(Zelda style 4 way shooting... up down left or right) |
| ||
| What is the problem ? Are the actions in the main program ? If they are in a function, "fire_angle" should be global. |
| ||
| sorry.. that isnt it either... What I'm trying to do is make it to where the player can shoot the bullet in either the up down left or right directions using a basic flag system (fire_angle) there are four diferent flags for the four diferent directions... I have changed the code up a bit sinse last night.. I'll post the entire code so everyone can see what I'm going for...
Global fire_angle=1
Type coin
Field entity
End Type
Type rchip
Field entity
End Type
Type gchip
Field entity
End Type
Type bchip
Field entity
End Type
Type rdoor
Field entity
End Type
Type gdoor
Field entity
End Type
Type bdoor
Field entity
End Type
Type breaker
End Type
Type bullet
Field entity
Field direct
End Type
Type enemy
End Type
Graphics3D 800,600,16,1
Global r_chip=CreateImage(16,16,2)
Global g_chip=CreateImage(16,16,2)
Global b_chip=CreateImage(16,16,2)
SetBuffer ImageBuffer(r_chip,0)
Color 50,0,0
Rect 0,0,16,16,2
Color 255,255,255
Rect 0,0,16,16,0
SetBuffer ImageBuffer(r_chip,1)
Color 100,0,0
Rect 0,0,16,16,2
Color 255,255,255
Rect 0,0,16,16,0
SetBuffer ImageBuffer(g_chip,0)
Color 0,50,0
Rect 0,0,16,16,2
Color 255,255,255
Rect 0,0,16,16,0
SetBuffer ImageBuffer(g_chip,1)
Color 0,100,0
Rect 0,0,16,16,2
Color 255,255,255
Rect 0,0,16,16,0
SetBuffer ImageBuffer(b_chip,0)
Color 0,0,50
Rect 0,0,16,16,2
Color 255,255,255
Rect 0,0,16,16,0
SetBuffer ImageBuffer(b_chip,1)
Color 0,0,100
Rect 0,0,16,16,2
Color 255,255,255
Rect 0,0,16,16,0
Const type_bob=1
Const type_coin=2
Const type_rchip=3
Const type_gchip=4
Const type_bchip=5
Const type_rdoor=6
Const type_gdoor=7
Const type_bdoor=8
Const type_breaker=9
Const type_enemy=10
Const type_bullet=11
Const type_wall=12
tfloor=CreateTexture(64,64)
bobtex=CreateTexture(64,64)
SetBuffer TextureBuffer(bobtex)
For x=0 To 63
For y=0 To 63
Color Rnd(0,100),Rnd(0,100),0
Plot x,y
Next
Next
SetBuffer TextureBuffer(tfloor)
For x=0 To 31
For y=0 To 31
Color Rnd(0,100),0,0
Plot x,y
Color 200,200,200
Rect 0,0,32,32,0
Next
Next
For x=32 To 63
For y=0 To 31
Color 0,0,Rnd(0,100)
Plot x,y
Color 200,200,200
Rect 32,0,32,32,0
Next
Next
For x=32 To 63
For y=32 To 63
Color Rnd(0,100),0,0
Plot x,y
Color 200,200,200
Rect 32,32,32,32,0
Next
Next
For x=0 To 31
For y=32 To 63
Color 0,0,Rnd(0,100)
Plot x,y
Color 200,200,200
Rect 0,32,32,32,0
Next
Next
SetBuffer BackBuffer()
Viewport 10,10,780,480
Global bob=CreateSphere()
Global coin=CreateSphere()
Global redchip=CreateCube()
Global bluechip=CreateCube()
Global greenchip=CreateCube()
Global reddoor=CreateCube()
Global greendoor=CreateCube()
Global bluedoor=CreateCube()
Global wall=CreateCube()
Global breakwall=CreateCube()
Global bullet=CreateSphere()
Global enemy=CreateCone()
EntityType bob,type_bob
EntityType coin,type_coin
EntityType redchip,type_rchip
EntityType greenchip,type_gchip
EntityType bluechip,type_bchip
EntityType reddoor,type_rdoor
EntityType greendoor,type_gdoor
EntityType bluedoor,type_bdoor
EntityType wall,type_wall
EntityType breakwall,type_breaker
EntityType bullet,type_bullet
EntityType enemy,type_enemy
Collisions type_bob,type_coin,2,1
Collisions type_bob,type_rchip,2,1
Collisions type_bob,type_gchip,2,1
Collisions type_bob,type_bchip,2,1
Collisions type_bob,type_rdoor,2,1
Collisions type_bob,type_gdoor,2,1
Collisions type_bob,type_bdoor,2,1
EntityTexture bob,bobtex
EntityColor coin,200,200,0
EntityColor redchip,100,0,0
EntityColor bluechip,0,0,100
EntityColor greenchip,0,100,0
EntityColor reddoor,100,0,0
EntityColor greendoor,0,100,0
EntityColor bluedoor,0,0,100
EntityColor wall,100,100,50
EntityColor breakwall,100,100,0
EntityColor bullet,200,0,0
EntityColor enemy,100,50,50
ScaleEntity bob,.9,.9,.9
ScaleEntity enemy,.9,.9,.9
ScaleEntity coin,.1,.5,.5
ScaleEntity redchip,.1,.5,.5
ScaleEntity greenchip,.1,.5,.5
ScaleEntity bluechip,.1,.5,.5
ScaleEntity bullet,.5,.5,.5
EntityShininess coin,100
EntityShininess redchip,50
EntityShininess greenchip,50
EntityShininess bluechip,50
HideEntity coin
HideEntity redchip
HideEntity greenchip
HideEntity bluechip
HideEntity reddoor
HideEntity greendoor
HideEntity bluedoor
HideEntity wall
HideEntity breakwall
HideEntity bullet
HideEntity enemy
cam=CreateCamera(bob)
light=CreateLight(2)
world=CreatePlane()
EntityTexture world,tfloor
ScaleTexture tfloor,4,4
rflect=CreateMirror()
EntityAlpha world,.80
PositionEntity cam,0,5,-10
PositionEntity light,0,5,-3
PositionEntity bob,0,1,0
LightRange light,5
AmbientLight 100,100,100
CameraClsColor cam,0,50,100
CameraFogColor cam,0,50,100
CameraFogMode cam,1
CameraFogRange cam,5,40
PointEntity cam,bob
EntityParent cam,bob
EntityParent light,bob
For x=1 To 5
rc.rchip = New rchip
rc\entity=CopyEntity(redchip)
PositionEntity rc\entity,x*2,1,0
gc.gchip = New gchip
gc\entity=CopyEntity(greenchip)
PositionEntity gc\entity,x*2,1,2
bc.bchip = New bchip
bc\entity=CopyEntity(bluechip)
PositionEntity bc\entity,x*2,1,4
Next
For x=0 To 5
For y=0 To 5
c.coin=New coin
c\entity=CopyEntity(coin)
PositionEntity c\entity,x*2+10,1,y*2+10
Next
Next
rd.rdoor=New rdoor
rd\entity=CopyEntity(reddoor)
PositionEntity rd\entity,0,1,10
gd.gdoor=New gdoor
gd\entity=CopyEntity(greendoor)
PositionEntity gd\entity,5,1,10
bd.bdoor=New bdoor
bd\entity=CopyEntity(bluedoor)
PositionEntity bd\entity,10,1,10
While Not KeyHit(1)
Flip
For c.coin=Each coin
TurnEntity c\entity,0,1,0
Next
For rc.rchip=Each rchip
TurnEntity rc\entity,1,1,1
Next
For gc.gchip=Each gchip
TurnEntity gc\entity,1,1,1
Next
For bc.bchip=Each bchip
TurnEntity bc\entity,1,1,1
Next
For colid=1 To CountCollisions(bob)
For c.coin=Each coin
If CollisionEntity(bob,colid)=c\entity Then HideEntity c\entity: coin_get=coin_get+1
next
Next
;--key chips--------------------------------------------------------------------------
For rc_colid=1 To CountCollisions(bob)
For rc.rchip=Each rchip
If rc_get<1 And CollisionEntity(bob,rc_colid)=rc\entity Then HideEntity rc\entity: rc_get=1
Next
Next
For gc_colid=1 To CountCollisions(bob)
For gc.gchip=Each gchip
If gc_get<1 And CollisionEntity(bob,gc_colid)=gc\entity Then HideEntity gc\entity: gc_get=1
Next
Next
For bc_colid=1 To CountCollisions(bob)
For bc.bchip=Each bchip
If bc_get<1 And CollisionEntity(bob,bc_colid)=bc\entity Then HideEntity bc\entity: bc_get=1
Next
Next
;--doors--------------------------------------------------------------------------
For rd_colid=1 To CountCollisions(bob)
For rd.rdoor=Each rdoor
If rc_get=1 And CollisionEntity(bob,rd_colid)=rd\entity Then HideEntity rd\entity: rc_get=0
Next
Next
For gd_colid=1 To CountCollisions(bob)
For gd.gdoor=Each gdoor
If gc_get=1 And CollisionEntity(bob,gd_colid)=gd\entity Then HideEntity gd\entity: gc_get=0
Next
Next
For bd_colid=1 To CountCollisions(bob)
For bd.bdoor=Each bdoor
If bc_get=1 And CollisionEntity(bob,bd_colid)=bd\entity Then HideEntity bd\entity: bc_get=0
Next
Next
If KeyDown(200) Then MoveEntity bob,0,0,.1: RotateMesh bob,3,0,0: fire_angle=1
If KeyDown(208) Then MoveEntity bob,0,0,-.1: RotateMesh bob,-3,0,0: fire_angle=2
If KeyDown(205) Then MoveEntity bob,.1,0,0: RotateMesh bob,0,0,-3: fire_angle=3
If KeyDown(203) Then MoveEntity bob,-.1,0,0 RotateMesh bob,0,0,3: fire_angle=4
If KeyHit(54) Then create_bullet
For b.bullet=Each bullet
If b\direct=1 Then update_bullet_up
If b\direct=2 Then update_bullet_down
If b\direct=3 Then update_bullet_left
If b\direct=4 Then update_bullet_right
Next
Viewport 0,0,800,600
Cls
Color 255,255,255
Text 716,493,"Key Chips"
DrawImage r_chip,716,515,rc_get
DrawImage g_chip,745,515,gc_get
DrawImage b_chip,776,515,bc_get
Text 10,493,"Coins: "+coin_get
Color 255,255,255
Rect 9,9,782,482
UpdateWorld
RenderWorld
Wend
End
Function create_bullet()
b.bullet=New bullet
b\entity=CopyEntity(bullet)
If fire_angle=1 Then b\direct=1
If fire_angle=2 Then b\direct=2
If fire_angle=3 Then b\direct=3
If fire_angle=4 Then b\direct=4
PositionEntity b\entity,EntityX(bob),EntityY(bob),EntityZ(bob)
End Function
Function update_bullet_up()
For b.bullet=Each bullet
MoveEntity b\entity,0,0,1
Next
End Function
Function update_bullet_down()
For b.bullet=Each bullet
MoveEntity b\entity,0,0,-1
Next
End Function
Function update_bullet_left()
For b.bullet=Each bullet
MoveEntity b\entity,1,0,0
Next
End Function
Function update_bullet_right()
For b.bullet=Each bullet
MoveEntity b\entity,-1,0,0
Next
End Function
if anybody can help me to get my four point flag system working so I can shoot right, I'd be very thankful! |
| ||
| It seems that there is a double FOR..NEXT loop in there. Update_bullet is called from inside a loop, but inside this function, there is another loop. Change the functions to this form: Function Update_bullet_right(b.bullet) And remove the FOR and the NEXT inside the function. Then, call the functions like this: Update_bullet_right(b) (edit)by the way, it looks real nice |
| ||
| hey, it works! thanks Bram32 now.. I can finally move on with this code and hopefully get somewhere with it |