summaryrefslogtreecommitdiff
path: root/gametypes.bmx
blob: 4b0875a93d2ee9210fc25dabed96414eebc811fe (plain)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
' Missile Lock
'
' Copyright (C) 2006  Ian Cowburn (ianc@noddybox.co.uk)
'
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 2 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program; if not, write to the Free Software
' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
'
' -------------------------------------------------------------------------
'
' $Id$
'
Strict
Import noddybox.algorithm
Import "global.bmx"

Type GameState
	Global	score:Int=0
	Global	x:Double=0
	Global	y:Double=0
	Global	ang:Int=0
	Global	lives:Int=0
	
	Function Reset()
		score=0
		x=400
		y=300
		ang=0
		lives=3
	End Function
	
	Function Control()
		If KeyDown(GameConfig.kleft)
			ang:-2
			If ang<0 Then ang:+360
		End If
		If KeyDown(GameConfig.kright)
			ang=(ang+2) Mod 360
		End If
	End Function
	
	Function Move()
		x=(x+Lookup.si[ang]*2) Mod 800
		y=(y-Lookup.co[ang]*2) Mod 600
		If x<0 Then x:+800
		If y<0 Then y:+600
		Trail.Add()
	End Function
	
	Function Display()
		Local s:String="LIVES "
		
		For Local f:Int=1 To lives
			s:+"~~"
		Next
		
		GFX.font.Draw("SCORE",0,-0)
		GFX.font.Draw(Number.Format(score),0,16,255,255,0)

		GFX.font.Centre(s,0)

		GFX.font.DrawRight("HISCORE",799,0)
		GFX.font.DrawRight(Number.Format(GameConfig.hiscore),799,16,255,255,0)
	End Function	
End Type


Type BackdropStar
	Field x:Double
	Field y:Double
	Field r:Int
	Field g:Int
	Field b:Int
	
	Method New()
		x=Rand(0,800)
		y=Rand(0,600)
		r=Rand(128,255)
		g=Rand(128,255)
		b=Rand(128,255)
	End Method
End Type


Type Backdrop
	Global s:BackdropStar[]
	
	Function Init()
		s=New BackdropStar[400]
		
		For Local f:Int=0 To 399
			s[f]=New BackdropStar
		Next
	End Function
	
	Function Draw()
		For Local f:Int=0 To 399
			SetColor(s[f].r,s[f].g,s[f].b)
			DrawImage(GFX.star,s[f].x,s[f].y)
		Next
	End Function
End Type

Type TrailPart
	Field x:Double
	Field y:Double
	Field ang:Double
	Field al:Double
	Field sc:Double
	
	Method New()
		x=GameState.x
		y=GameState.y
		ang=GameState.ang
		al=1
		sc=1
	End Method
End Type

Type Trail
	Global plist:TList
	
	Function Init()
		plist=CreateList()
	End Function
	
	Function Clear()
		plist.Clear()
	End Function
	
	Function Add()
		plist.AddLast(New TrailPart)
	End Function
	
	Function Draw()
		SetColor(255,255,255)
		Local l:TEasyLink=TEasyLink.Create(plist)
		
		While l.Value()
			Local t:TrailPart=TrailPart(l.Value())

			If t.al>0.1
				SetRotation(t.ang)
				SetScale(t.sc,t.sc)
				SetAlpha(t.al)
				DrawImage(GFX.flame,t.x,t.y)
				t.al:-0.05
				't.sc:+0.1
				l.MoveNext()
			Else
				l.Remove()
			EndIf
		Wend

		SetRotation(0)
		SetAlpha(1)
		SetScale(1,1)
	End Function
End Type