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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
'
' Actor objects
'
' $Id$
'
Strict
Import "sprite.bmx"
Type TActor Abstract
' These fields are public
'
Field sprite:TSprite
' These fields are private
'
Field m_bullets:TList
Field m_bullet:TImage
Field m_bullet_del:Int
Field m_init_del:Int
Field m_bullet_speed:Float
Method InitActor(img:TImage,bullet:TImage,bullet_del:Int,bullet_speed:Float,anim_speed:Int,ping_pong:Int,anim_with_delta:Int,col_mask:Int)
sprite=TSprite.Create(img,anim_speed,ping_pong,anim_with_delta,col_mask)
m_bullet=bullet
m_bullets=CreateList()
m_bullet_del=bullet_del
m_init_del=bullet_del
m_bullet_speed=bullet_speed
sprite.x=0
sprite.y=0
sprite.v.x=0
sprite.v.y=0
End Method
Method Centre()
sprite.x=GraphicsWidth()/2
sprite.y=GraphicsHeight()/2
sprite.v.x=0
sprite.v.y=0
End Method
Method Update()
sprite.Update()
For Local s:TSprite=EachIn m_bullets
s.Update()
Next
End Method
Method AddBullet(x:Int,y:Int)
Local dx:Int=x-sprite.x
Local dy:Int=y-sprite.y
If (dx=0 And dy=0)
Return
EndIf
If m_bullet_del=0
m_bullet_del=m_init_del
If (m_bullets.Count()>50)
m_bullets.RemoveFirst()
EndIf
Local s:TSprite=TSprite.Create(m_bullet,2,False,False,0)
s.x=sprite.x
s.y=sprite.y
s.v.x=dx
s.v.y=dy
s.v.Normalise()
s.v.Scale(m_bullet_speed)
m_bullets.AddLast(s)
Else
m_bullet_del:-1
EndIf
End Method
End Type
Type TPlayer Extends TActor
' These fields are public
'
Field lives:Int
Function Create:TPlayer(img:TImage,bullet:TImage,anim_speed:Int,ping_pong:Int,anim_with_delta:Int,col_mask:Int)
Local p:TPlayer=New TPlayer
p.InitActor(img,bullet,10,4,anim_speed,ping_pong,anim_with_delta,col_mask)
p.lives=3
Return p
End Function
Method NewGame()
Centre()
lives=3
m_bullets.Clear()
m_bullet_del=m_init_del
End Method
Method ResetPosition()
sprite.x=GraphicsWidth()/2
sprite.y=GraphicsHeight()/2
sprite.v.x=0
sprite.v.y=0
End Method
End Type
Type TEnemy Extends TActor
Function Create:TEnemy(img:TImage,bullet:TImage,bullet_del:Int,bullet_speed:Float,anim_speed:Int,ping_pong:Int,anim_with_delta:Int,col_mask:Int)
Local p:TEnemy=New TEnemy
p.InitActor(img,bullet,bullet_del,bullet_speed,anim_speed,ping_pong,anim_with_delta,col_mask)
Return p
End Function
End Type
|