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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
|
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
import QtQuick 2.0
import QtQuick.Particles 2.0
import "content"
Rectangle {
id: root
property bool readySetGo: false
//Debugging
property int hits: 0
property int misses: 0
property real ratio: hits/(misses?misses:1)
//Move to JS file?
property Ship redVar1: Ship {shipType: 1; gunType: 1}
property Ship redVar2: Ship {shipType: 1; gunType: 2}
property Ship redVar3: Ship {shipType: 1; gunType: 3}
property Ship greenVar1: Ship {shipType: 3; gunType: 1}
property Ship greenVar2: Ship {shipType: 2; gunType: 2}
property Ship greenVar3: Ship {shipType: 1; gunType: 3}
property string winner: "0"
property int players: 0
function aiSet(ship) {
ship.gunType = Math.floor(Math.random() * 3) + 1
ship.shipType = Math.floor(Math.random() * 3) + 1
}
width: 360
height: 600
color: "black"
SequentialLoader {
anchors.fill: parent
//General Children
Image {
anchors.centerIn: parent
source: "../images/finalfrontier.png"
}
ParticleSystem {
id: particles
}
PlasmaPatrolParticles { sys: particles; z: 100 }//Renders all particles on the one plane
//Component parts
id: pageControl
Component.onCompleted: advance();
pages:[
Component {Item {
id: menu
width: root.width
height: root.height
Column {
anchors.verticalCenter: parent.verticalCenter
width: parent.width
spacing: 8
Item {
id: title
width: root.width
height: 240
Emitter {
anchors.fill: parent
system: particles
enabled: true
group: "default"
emitRate: 1200
lifeSpan: 1200
shape: MaskShape {source:"content/pics/TitleText.png"}
size: 16
endSize: 0
sizeVariation: 8
speed: AngleDirection {angleVariation:360; magnitudeVariation: 6}
}
}
Button {
text: "1P"
onClicked: {root.players = 1; pageControl.advance();}
anchors.horizontalCenter: parent.horizontalCenter
}
Button {
text: "2P"
onClicked: {root.players = 2; pageControl.advance();}
anchors.horizontalCenter: parent.horizontalCenter
}
Button {
text: "Demo"
anchors.horizontalCenter: parent.horizontalCenter
onClicked: {root.players = 0;
aiSet(redVar1);
aiSet(redVar2);
aiSet(redVar3);
aiSet(greenVar1);
aiSet(greenVar2);
aiSet(greenVar3);
pageControl.at = 5;//TODO: Not a magic number
pageControl.advance();}
}
Button {
text: "Help"
anchors.horizontalCenter: parent.horizontalCenter
onClicked: {
pageControl.at = 7;//TODO: Not a magic number
pageControl.advance();
}
}
Button {
text: "Quit"
anchors.horizontalCenter: parent.horizontalCenter
onClicked: Qt.quit();
}
}
}},
Component {Item {
id: p1Screen
z: 101
width: root.width
height: root.height
Rectangle {
anchors.fill: parent
color: "red"
}
Text {
anchors.centerIn: parent
color: "white"
font.pixelSize: 64
font.bold: true
text: "Player\n 1"
horizontalAlignment: Text.AlignHCenter
}
MouseArea {
anchors.fill: parent
onClicked: pageControl.advance()
}
}},
Component {Item {
id: p1Choices
z: 3
width: root.width
height: root.height
Rectangle {
color: "black"
anchors.fill: parent
}
Column {
spacing: 16
width: root.width
anchors.horizontalCenter: parent.horizontalCenter
ChoiceBox {
target: redVar1
system: particles
}
ChoiceBox {
target: redVar2
system: particles
}
ChoiceBox {
target: redVar3
system: particles
}
Button {
anchors.horizontalCenter: parent.horizontalCenter
text: "Next"
onClicked: {
if (root.players < 2) {
aiSet(greenVar1);
aiSet(greenVar2);
aiSet(greenVar3);
pageControl.at = 5;//TODO: Not a magic number
}
pageControl.advance();
}
}
}
}},
Component {Item {
id: p2Screen
z: 101
width: root.width
height: root.height
Rectangle {
anchors.fill: parent
color: "green"
}
Text {
anchors.centerIn: parent
color: "white"
font.pixelSize: 64
font.bold: true
text: "Player\n 2"
horizontalAlignment: Text.AlignHCenter
}
MouseArea {
anchors.fill: parent
onClicked: pageControl.advance()
}
}},
Component {Item {
id: p2Choices
z: 1
width: root.width
height: root.height
Rectangle {
color: "black"
anchors.fill: parent
}
Column {
spacing: 16
width: root.width
anchors.horizontalCenter: parent.horizontalCenter
ChoiceBox {
target: greenVar1
system: particles
}
ChoiceBox {
target: greenVar2
system: particles
}
ChoiceBox {
target: greenVar3
system: particles
}
Button {
anchors.horizontalCenter: parent.horizontalCenter
text: "Next"
onClicked: pageControl.advance()
}
}
}},
Component {Item {
id: arena
width: root.width
height: root.height
z: 0
Component.onCompleted: root.readySetGo = true
Component.onDestruction: root.readySetGo = false
property bool victory: redShip3.hp <= 0 || greenShip3.hp <=0
onVictoryChanged: {
if (redShip3.hp <= 0) {
if (greenShip3.hp <= 0) {
root.winner = "1&2"
}else {
root.winner = "2"
}
} else {
root.winner = "1"
}
winTimer.start()
}
Timer {
id: winTimer
interval: 1200
repeat: false
running: false
onTriggered: pageControl.advance();
}
Ship {
id: redShip1
shipParticle: "redTeam"
system: particles
x: 180-64
y: 128
shipType: redVar1.shipType
gunType: redVar1.gunType
targets: [greenShip1, greenShip2, greenShip3]
}
Ship {
id: redShip2
shipParticle: "redTeam"
system: particles
x: 0
y: 0
shipType: redVar2.shipType
gunType: redVar2.gunType
targets: [greenShip1, greenShip2, greenShip3]
}
Ship {
id: redShip3
shipParticle: "redTeam"
system: particles
x: 360-128
y: 0
shipType: redVar3.shipType
gunType: redVar3.gunType
targets: [greenShip1, greenShip2, greenShip3]
}
Ship {
id: greenShip1
shipParticle: "greenTeam"
system: particles
x: 180-64
y: 600 - 128 - 128
shipType: greenVar1.shipType
gunType: greenVar1.gunType
targets: [redShip1, redShip2, redShip3]
}
Ship {
id: greenShip2
shipParticle: "greenTeam"
system: particles
x: 0
y: 600-128
shipType: greenVar2.shipType
gunType: greenVar2.gunType
targets: [redShip1, redShip2, redShip3]
}
Ship {
id: greenShip3
shipParticle: "greenTeam"
system: particles
x: 360 - 128
y: 600 - 128
shipType: greenVar3.shipType
gunType: greenVar3.gunType
targets: [redShip1, redShip2, redShip3]
}
}},
Component {Item {
id: winScreen
z: 101
width: root.width
height: root.height
/*
Rectangle {
anchors.fill: parent
color: "black"
}
*/
Text {//TODO: Particle Text?
anchors.fill: parent
color: "white"
font.pixelSize: 64
font.bold: true
text: "Player " + root.winner + " wins!"
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
MouseArea {
anchors.fill: parent
onClicked: {pageControl.at = 0; pageControl.advance();}
}
}},
Component {
HelpScreens {
onExitDesired: {pageControl.at = 0; pageControl.advance();}
}
}
]
}
}
|