bullet type help

Blitz3D Forums/Blitz3D Beginners Area/bullet type help

cermit(Posted 2003) [#1]
I need help with bullet types in 2d to create a bullet
when keyhit space..

;Graphics
Graphics 320,240,16,1
;Select Buffer
SetBuffer BackBuffer()

;Global
Global player,frmplayer,tmrplayer

;Player Options
player=LoadAnimImage("Image/Sprites/player.png" ,9,11,0,16)
MaskImage player,255,0,255

;Player Co-ords
player_x=160
player_y=120

;Player Movement Speed
lt=1
rt=1
up=1
dn=1


;Players Bullet
bullet=LoadImage("Image/Sprites/bullet.png")

;Bullet Co-ords
bullet_x=0
bullet_y=0
bullet_left=False

;Map Co-ords
map_x=0
map_y=0

Type bullet
Field bullet_x
Field bullet_y
Field bullet_left
End Type

;Duplicate Tilemap and Tile
Dim tilemap(200,150)
Dim tile(200)

;Load Tiles
For width=0 To 19
tile(width)=LoadImage("Image/Tiles/tile"+width+".png")
MaskImage tile(width),255,0,255
Next

gras=LoadImage("Image/Tiles/tile0.png")

;Gettiles
Gosub gettiles


;Begin
While Not KeyDown(1)


;Move Player
If KeyDown(203) Then
player_x=player_x-lt
move_player=True
lowframe=1
highframe=4
Else If KeyDown(205) Then
player_x=player_x+rt
move_player=True
lowframe=5
highframe=8
Else If KeyDown(200) Then
player_y=player_y-up
move_player=True
lowframe=8
highframe=12
Else If KeyDown(208) Then
player_y=player_y+dn
move_player=True
lowframe=12
highframe=16
EndIf


;Update Player_direction 1=Left,2=Right,3=Up,4=Down
If frmplayer>=0 And frmplayer<=3 Then
player_dir=1
Else If frmplayer>=5 And frmplayer<=7 Then
player_dir=2
Else If frmplayer>=8 And frmplayer<=11 Then
player_dir=3
Else If frmplayer>=12 And frmplayer<=16 Then
player_dir=4
EndIf


;If Stop Moving Stand Correct
If player_dir=1 And KeyDown(203)=False Then
frmplayer=0
Else If player_dir=2 And KeyDown(205)=False Then
frmplayer=4
Else If player_dir=3 And KeyDown(200)=False Then
frmplayer=8
Else If player_dir=4 And KeyDown(208)=False Then
frmplayer=12
EndIf


;Place The Bullet
If KeyHit(57) Then
If player_dir=1
le=2
ri=0
do=0
u2=0
x=0
y=3
bullet_x=player_x+x
bullet_y=player_y+y
bullet_left=True
Else If player_dir=2
ri=2
le=0
do=0
u2=0
x=6
y=3
bullet_x=player_x+x
bullet_y=player_y+y
bullet_left=True
Else If player_dir=3
do=2
u2=0
ri=0
le=0
x=5
y=3
bullet_x=player_x+x
bullet_y=player_y+y
bullet_left=True
Else If player_dir=4
u2=2
do=0
ri=0
le=0
x=1
y=3
bullet_x=player_x+x
bullet_y=player_y+y
bullet_left=True
EndIf
EndIf

;Fire The Bullet
If bullet_left
bullet_x=bullet_x-le
bullet_x=bullet_x+ri
bullet_y=bullet_y-do
bullet_y=bullet_y+u2
EndIf


;Animation Mode
If move_player=True
If MilliSecs()>tmrplayer+100 Then
tmrplayer=MilliSecs()
frmplayer=(frmplayer+1) Mod highframe
If frmplayer<lowframe Then frmplayer=lowframe
EndIf
EndIf


;Stop Animating If Keys=False
If KeyDown(203)=0 Or KeyDown(205)=0 Or KeyDown(200)=0 Or KeyDown(208)=0 Then
move_player=0
EndIf


;Move TilaMap
If player_x>=211 Then
sp=1
rt=0
map_x=map_x-sp
If KeyDown(205)=False Then
player_x=210
EndIf
EndIf

If player_x<=110 Then
sp=1
lt=0
map_x=map_x+sp
If KeyDown(203)=False Then
player_x=111
EndIf
EndIf

If player_y<0 Then player_y=0

If player_y>229 Then player_y=229

If player_x<=210 And player_x>=111 Then
lt=1
rt=1
EndIf


;Simply Clear The Screen And Set ClsColor
Cls

;Draw Stuff
TileImage gras,map_x,map_y
Gosub updatetiles

If bullet_left Then DrawImage bullet,bullet_x,bullet_y

DrawImage player,player_x,player_y,frmplayer


;Flip The Buffer
Flip
;End The Wend
Wend

;Well.. End Heh
End


;Get Tile Position
.gettiles
For height=0 To 14
For width=0 To 79
Read tilemap(width,height)
Next
Next
Return

;Draw Tiles
.updatetiles
For height=0 To 14
For width=0 To 79
If tilemap(width,height)>=0 And tilemap(width,height)<20 Then
If tilemap(width,height)<>20 Then
DrawImage tile(tilemap(width,height)),width*16+map_x,height*16+map_y
EndIf
EndIf
Next
Next
Return

; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
Data 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0,15,17,17,17,16, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Data 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0,15,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,16,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Data 0, 0, 0, 0, 0, 0, 0,13, 0, 0, 0, 0,18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Data 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,15,16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Data 0, 0, 0, 0, 0, 0, 0, 0, 0,18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
Data 0, 0, 0, 0, 0, 0, 0, 0, 0,18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

if you need the tiles mail me.


Sunteam Software(Posted 2003) [#2]
OK, your problem is that you need to treat the bullet Type like a place-holder description. Then for each bullet you want you must create an instance of the bullet Type to use.

i.e. when they press space the following needs to be done:

;create an instance of bullet type
b.bullet=New bullet


This assigns the variable 'b' as a bullet type and assigns a new bullet place-holder to it. Then to access each of the fields within b (as it is now a bullet Type) you do the following:

;set x to 0
b\bullet_x=0 

;set y to 0
b\bullet_y=0 

;set left to false
b\bullet_left=False 


Now the other 2 important things to know about types is how to go through all the different instances you have created and manipulate them and also how to delete them.

To go through each bullet instance you've created you would do the following:

;go through all the bullets created
For b.bullet=Each bullet
    If b\bullet_left 
        b\bullet_x=b\bullet_x-le 
        b\bullet_x=b\bullet_x+ri 
        b\bullet_y=b\bullet_y-do 
        b\bullet_y=b\bullet_y+u2 
    EndIf 
Next


To delete a bullet you simply use Delete var.bullet where var is the variable currently assigned with the bullet you want to delete.

;delete all bullets
For b.bullet=Each bullet
    Delete b
Next


It's not a full explanation but should help. There's some more text in your help files under Tutorials I think.