-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogic.js
More file actions
170 lines (146 loc) · 5.26 KB
/
Copy pathlogic.js
File metadata and controls
170 lines (146 loc) · 5.26 KB
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
// ===========================================================================
/// <summary>
/// logic.js
/// Entity
/// created by Mehrdad Soleimanimajd on 12.10.2019
/// </summary>
/// <created>ʆϒʅ, 12.10.2019</created>
/// <changed>ʆϒʅ, 27.06.2023</changed>
// ===========================================================================
var screenWidth = configs.getWidth()
var screenHeight = configs.getHeight()
var debug = configs.setGetDebug()
var healthJS = 20
var items = new Array(20)
var component = Qt.createComponent("./qml/Fragment.qml")
// game's different states initializer
function initializeGame(response) {
if (response === "NotInitialized") {
if (debug) {
sentencesFieldOne.time = 130
sentencesFieldTwo.time = 130
}
quitter = false
welcomeText.visible = true
welcomeTextTimer.start()
smily.scale = 0.5
sentencesFieldOneTimer.stop()
sentencesFieldOne.proceed = false
sentencesFieldOne.feed = [tale.getTitle()]
sentencesFieldOne.proceed = true
} else if (response === "Welcomed" && !quitter) {
gameExitButton.visible = false
taleArea.height = 500
sentencesFieldOne.proceed = false
sentencesFieldOne.feed = tale.getTaleSentences()
sentencesFieldOne.loop = false
sentencesFieldOne.proceed = true
newGameTimer.start()
} else if (response === "Quitted") {
// guide: Nerd Snow's saying: a quitter is never going to be the same size as of the past!
if (!quitter)
smily.scale = 1.0
gameExitButton.visible = true
welcomeText.visible = true
if (tickTimer.running) {
tickTimer.stop()
LogicJs.endGame()
// logic.endGame()
}
taleArea.height = 100
gameExitButton.visible = true
sentencesFieldOne.proceed = false
sentencesFieldOne.feed = ["This one build itself on its own! :)"]
sentencesFieldOne.loop = true
sentencesFieldOne.proceed = true
sentencesFieldOneTimer.start()
}
}
function newGame() {
gameCanvas.health = healthJS
for (var index = 0; index < healthJS; index++) {
items[index] = null
createItem(index)
}
}
function createItem(index) {
if (component.status === Component.Ready) {
var dynamicObj = component.createObject(gameCanvas)
if (dynamicObj === null) {
console.log("error creating item")
console.log(component.errorString())
return false
}
dynamicObj.type = Math.floor(Math.random(
) * 3) + 1 // Note: for the time being
dynamicObj.objData = (Math.floor(Math.random() * 2) + 1) * 100
// randomized creation location (probably somehow out of blue! :))
var temp = Math.floor(Math.random() * 200)
if (temp <= 50) {
dynamicObj.x = -20
dynamicObj.y = Math.floor(Math.random() * screenHeight)
dynamicObj.objData += 11 // Note: for the time being
}
if (temp > 50 && temp <= 100) {
dynamicObj.x = Math.floor(Math.random() * screenWidth)
dynamicObj.y = -20
dynamicObj.objData += 11 // Note: for the time being
}
if (temp > 100 && temp <= 150) {
dynamicObj.x = screenWidth + 20
dynamicObj.y = Math.floor(Math.random() * screenHeight)
dynamicObj.objData += 22 // Note: for the time being
}
if (temp > 150 && temp <= 200) {
dynamicObj.x = Math.floor(Math.random() * screenWidth)
dynamicObj.y = screenHeight + 20
dynamicObj.objData += 22 // Note: for the time being
}
dynamicObj.width = gameCanvas.itemSize
dynamicObj.height = gameCanvas.itemSize
items[index] = dynamicObj
} else {
console.log("error loading item component")
console.log(component.errorString())
return false
}
return true
}
function conflict() {// Todo: show some action
}
function tick() {
if (items[0]) {
// Todo: each tick:
// 1. updates to game's timer
// 2. updates to game's universe based on the user input
// Todo: randomized movement based on current entity position
// Todo: speed based on game level
// movement direction based on the randomized location (for the time being)
for (var index = 0; index < healthJS; index++) {
if (Math.floor(items[index].objData / 100) === 2) {
if ((items[index].objData % 100) === 11) {
items[index].x += 5
items[index].y += 5
} else {
items[index].x -= 5
items[index].y -= 5
}
} else {
if ((items[index].objData % 100) === 11) {
items[index].x += 3
items[index].y += 3
} else {
items[index].x -= 3
items[index].y -= 3
}
}
}
}
}
function endGame() {
gameCanvas.health = 0
for (var index = 0; index < healthJS; index++) {
items[index].destroy()
items[index] = null
}
}