-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.gd
More file actions
111 lines (96 loc) · 3.28 KB
/
Main.gd
File metadata and controls
111 lines (96 loc) · 3.28 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
extends Node2D
export (PackedScene) var ColorBlock
export (Resource) var mainConfig
var playerList
var blockList
var score = 0
var index = 0
var correctAnswer
onready var expression = Expression.new()
func getCorrectAnswer():
if (mainConfig.gameMode == "math"):
var error = expression.parse($Player.value, [])
if (error != OK):
print(error)
var result = expression.execute([], null, true)
if (expression.has_execute_failed()):
print("ruhroh")
return result
elif (mainConfig.gameMode == "english"):
return mainConfig.letterList[mainConfig.wordList.find($Player.value)]
elif (mainConfig.gameMode == "shape"):
return mainConfig.blockShapeList[mainConfig.playerShapeList.find($Player.value)]
func getPlayerList():
if (mainConfig.gameMode == "math"):
return mainConfig.expressionList.duplicate()
elif (mainConfig.gameMode == "english"):
return mainConfig.wordList.duplicate()
elif (mainConfig.gameMode == "shape"):
return mainConfig.playerShapeList.duplicate()
func getBlockList():
if (mainConfig.gameMode == "english"):
return mainConfig.letterList.duplicate()
elif (mainConfig.gameMode == "shape"):
return mainConfig.blockShapeList.duplicate()
# Called when the node enters the scene tree for the first time.
func _ready():
randomize()
$ColorTimer.start()
$Hud/GameTimer.start(mainConfig.gameTime)
# warning-ignore:return_value_discarded
$Hud/GameTimer.connect("timeout", self, "_on_GameTimer_timeout")
$ColorPath.curve.clear_points()
$ColorPath.curve.add_point(Vector2.ZERO)
$ColorPath.curve.add_point(Vector2(get_viewport().size.x, 0))
playerList = getPlayerList()
playerList.shuffle()
$Player.value = playerList[index]
correctAnswer = getCorrectAnswer()
$GameOver.hide()
$audio_player.play_audio("bodenstaendig2000InRock4Bit", false, true)
func scoring(block):
if (block.value == correctAnswer):
score+=1
func setBlockValue(color):
if (mainConfig.gameMode == "math"):
if (randf() <= mainConfig.correctProbability):
color.value = correctAnswer
else:
var randomValue = correctAnswer
while (randomValue == correctAnswer):
randomValue = randi()%10 + 1
color.value = randomValue
else:
blockList = getBlockList()
blockList.erase(correctAnswer)
if (randf() <= mainConfig.correctProbability):
color.value = correctAnswer
else:
color.value = blockList[randi()%blockList.size()]
func createBlock(color):
color.position = $ColorPath/ColorSpawn.position
color.velocity = Vector2.DOWN
#color.connect("body_entered", color, "_on_ColorBlock_body_entered")
color.connect("body_entered", self, "_on_ColorBlock_body_entered", [color])
func activatePlayerParticles():
$Player/PlayerSprite/Value/particles.emitting = true;
func _on_ColorTimer_timeout():
$ColorPath/ColorSpawn.offset = randi()%int(get_viewport_rect().size.x)
var color = ColorBlock.instance()
setBlockValue(color)
add_child(color)
createBlock(color)
func _on_ColorBlock_body_entered(_body, block):
scoring(block)
if (block.value == correctAnswer):
index+=1
$Player.value = playerList[index%playerList.size()]
$audio_player.play_audio("jingle", true, false)
block.queue_free()
activatePlayerParticles()
correctAnswer = getCorrectAnswer()
$Hud/ScoreLabel.text = ("Score: " + str(score))
func _on_GameTimer_timeout():
$GameOver.score = score
$GameOver.show()
get_tree().paused = true