Skip to content

Commit db007f8

Browse files
authored
Merge pull request #15 from ASecondGuy/main
Einfaches Framework für Minigamesammlung & beispielgame
2 parents 17aafe9 + 9edb9fb commit db007f8

15 files changed

+537
-0
lines changed

game/default_env.tres

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[gd_resource type="Environment" load_steps=2 format=2]
2+
23
[sub_resource type="ProceduralSky" id=1]
4+
35
[resource]
46
background_mode = 2
57
background_sky = SubResource( 1 )

game/games/testgame/balloon.png

36.2 KB
Loading
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="StreamTexture"
5+
path="res://.import/balloon.png-a4cb4cec73bb2954300b057639860f49.stex"
6+
metadata={
7+
"vram_texture": false
8+
}
9+
10+
[deps]
11+
12+
source_file="res://games/testgame/balloon.png"
13+
dest_files=[ "res://.import/balloon.png-a4cb4cec73bb2954300b057639860f49.stex" ]
14+
15+
[params]
16+
17+
compress/mode=0
18+
compress/lossy_quality=0.7
19+
compress/hdr_mode=0
20+
compress/bptc_ldr=0
21+
compress/normal_map=0
22+
flags/repeat=0
23+
flags/filter=true
24+
flags/mipmaps=false
25+
flags/anisotropic=false
26+
flags/srgb=2
27+
process/fix_alpha_border=true
28+
process/premult_alpha=false
29+
process/HDR_as_SRGB=false
30+
process/invert_color=false
31+
process/normal_map_invert_y=false
32+
stream=false
33+
size_limit=0
34+
detect_3d=true
35+
svg/scale=1.0

game/games/testgame/balloon.tscn

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[gd_scene load_steps=3 format=2]
2+
3+
[ext_resource path="res://games/testgame/balloon.png" type="Texture" id=1]
4+
[ext_resource path="res://games/testgame/string.png" type="Texture" id=2]
5+
6+
[node name="balloon" type="TextureButton"]
7+
margin_right = 1024.0
8+
margin_bottom = 1024.0
9+
rect_scale = Vector2( 0.1, 0.1 )
10+
texture_normal = ExtResource( 1 )
11+
12+
[node name="String" type="TextureRect" parent="."]
13+
modulate = Color( 0.423529, 0.423529, 0.423529, 1 )
14+
show_behind_parent = true
15+
texture = ExtResource( 2 )

game/games/testgame/balloonPop.gd

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# warning-ignore-all:return_value_discarded
2+
extends MarginContainer
3+
4+
const END_MESSAGE := "You got %s points!"
5+
const COLOR_MESSAGE := "Pop a %s balloon"
6+
const STATUS_MESSAGE := "You'r in stage %s/10 and have %s points!"
7+
8+
var balloon_scene := preload("res://games/testgame/balloon.tscn")
9+
10+
var colors := {
11+
"Red": Color.red,
12+
"Green": Color.green,
13+
"Yellow": Color.yellow,
14+
"Blue": Color.blue,
15+
"Purple": Color.purple,
16+
"Orange": Color.orange,
17+
}
18+
19+
var points := 0
20+
var stage := 0
21+
var search_color: Color
22+
23+
onready var _timer := $Timer
24+
onready var _respawn_timer := $RespawnTimer
25+
onready var _color_label := $VBoxContainer/HBoxContainer/ColorLabel
26+
onready var _status_label := $VBoxContainer/HBoxContainer/StatusLabel
27+
onready var _area := $VBoxContainer/balloonArea
28+
onready var _rng := RandomNumberGenerator.new()
29+
onready var _particles := $VBoxContainer/Particles2D
30+
31+
32+
func _ready():
33+
_rng.randomize()
34+
start()
35+
36+
37+
func start():
38+
var i = _rng.randi_range(0, colors.size() - 1)
39+
_color_label.text = COLOR_MESSAGE % colors.keys()[i]
40+
search_color = colors.values()[i]
41+
call_deferred("_spawn")
42+
43+
44+
# Animates all balloons
45+
func _process(_delta):
46+
var offset := sin(_timer.time_left * 2 * PI)
47+
for balloon in _area.get_children():
48+
balloon.rect_position.y += offset
49+
50+
51+
# spawns all balloons per round
52+
func _spawn():
53+
var possible := colors.values()
54+
possible.erase(search_color)
55+
56+
#spawn 1-3 balloons with the search color
57+
for _i in range(_rng.randi_range(1, 3)):
58+
_spawn_color(search_color)
59+
60+
#spawn 3-7 balloons of any color exept the search color
61+
for _i in range(_rng.randi_range(3, 7)):
62+
_spawn_color(possible[_rng.randi_range(0, possible.size() - 1)])
63+
64+
stage += 1
65+
_update_status()
66+
67+
68+
# spawns one balloon of the given color
69+
func _spawn_color(color: Color):
70+
var b: TextureButton = balloon_scene.instance()
71+
_area.add_child(b)
72+
# position
73+
var max_pos: Vector2 = _area.rect_size - b.rect_size * b.rect_scale
74+
b.rect_position.x = _rng.randf_range(0, max_pos.x)
75+
b.rect_position.y = _rng.randf_range(0, max_pos.y)
76+
77+
# signals
78+
b.connect("pressed", self, "_on_destroy", [color, b])
79+
b.connect("pressed", b, "queue_free")
80+
# modulate
81+
b.self_modulate = color
82+
83+
84+
func _on_destroy(color: Color, button = null):
85+
if color.is_equal_approx(search_color):
86+
points += 1
87+
_delete_all()
88+
if button is TextureButton:
89+
_particles.global_position = (
90+
button.rect_global_position
91+
+ button.rect_size / 2 * button.rect_scale
92+
)
93+
_particles.restart()
94+
_respawn_timer.start()
95+
else:
96+
points -= 1
97+
if points < 0:
98+
points = 0
99+
_update_status()
100+
101+
102+
func _delete_all():
103+
for b in _area.get_children():
104+
b.queue_free()
105+
106+
107+
# timer leaves a little time between stage end and the next stage start or game end
108+
func _on_RespawnTimer_timeout():
109+
if stage >= 10:
110+
GameManager.end_game(END_MESSAGE % points)
111+
return
112+
_spawn()
113+
114+
115+
func _update_status():
116+
_status_label.text = STATUS_MESSAGE % [stage, points]

game/games/testgame/balloonPop.tscn

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
[gd_scene load_steps=3 format=2]
2+
3+
[ext_resource path="res://games/testgame/balloonPop.gd" type="Script" id=1]
4+
5+
[sub_resource type="ParticlesMaterial" id=1]
6+
lifetime_randomness = 0.05
7+
emission_shape = 1
8+
emission_sphere_radius = 10.0
9+
flag_disable_z = true
10+
spread = 180.0
11+
gravity = Vector3( 0, 0, 0 )
12+
initial_velocity = 39.22
13+
initial_velocity_random = 0.18
14+
orbit_velocity = 0.0
15+
orbit_velocity_random = 0.0
16+
angle_random = 1.0
17+
scale = 2.0
18+
scale_random = 1.0
19+
hue_variation = 1.0
20+
hue_variation_random = 1.0
21+
22+
[node name="balloonPop" type="MarginContainer"]
23+
anchor_right = 1.0
24+
anchor_bottom = 1.0
25+
script = ExtResource( 1 )
26+
27+
[node name="Timer" type="Timer" parent="."]
28+
autostart = true
29+
30+
[node name="RespawnTimer" type="Timer" parent="."]
31+
one_shot = true
32+
33+
[node name="VBoxContainer" type="VBoxContainer" parent="."]
34+
margin_right = 1024.0
35+
margin_bottom = 600.0
36+
37+
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
38+
margin_right = 1024.0
39+
margin_bottom = 14.0
40+
41+
[node name="ColorLabel" type="Label" parent="VBoxContainer/HBoxContainer"]
42+
margin_bottom = 14.0
43+
44+
[node name="StatusLabel" type="Label" parent="VBoxContainer/HBoxContainer"]
45+
margin_left = 4.0
46+
margin_right = 1024.0
47+
margin_bottom = 14.0
48+
size_flags_horizontal = 3
49+
align = 2
50+
51+
[node name="balloonArea" type="Control" parent="VBoxContainer"]
52+
margin_top = 18.0
53+
margin_right = 1024.0
54+
margin_bottom = 600.0
55+
size_flags_horizontal = 3
56+
size_flags_vertical = 3
57+
58+
[node name="Particles2D" type="Particles2D" parent="VBoxContainer"]
59+
emitting = false
60+
amount = 80
61+
one_shot = true
62+
explosiveness = 0.64
63+
process_material = SubResource( 1 )
64+
65+
[connection signal="timeout" from="RespawnTimer" to="." method="_on_RespawnTimer_timeout"]

game/games/testgame/game.cfg

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; This example file lists all required and optional Values
2+
; It is meant for easy identification of games.
3+
4+
[game]
5+
; Choose a memorable name
6+
name ="Balloon pop"
7+
; Description supports bbcode. Say what your game is about
8+
desc="Pop the balloons of the right [color=blue]color[/color]"
9+
; These paths are relative to the game folder
10+
main_scene="balloonPop.tscn"
11+
icon="balloon.png"
12+
; Version has no effect. But it might be shown in debug menus.
13+
version="1.0"
14+
; Put your name here
15+
creator="ASecondGuy"

game/games/testgame/string.png

21 KB
Loading

game/games/testgame/string.png.import

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="StreamTexture"
5+
path="res://.import/string.png-0a5bb3bf0e50ed69408bc2c2791dd82a.stex"
6+
metadata={
7+
"vram_texture": false
8+
}
9+
10+
[deps]
11+
12+
source_file="res://games/testgame/string.png"
13+
dest_files=[ "res://.import/string.png-0a5bb3bf0e50ed69408bc2c2791dd82a.stex" ]
14+
15+
[params]
16+
17+
compress/mode=0
18+
compress/lossy_quality=0.7
19+
compress/hdr_mode=0
20+
compress/bptc_ldr=0
21+
compress/normal_map=0
22+
flags/repeat=0
23+
flags/filter=true
24+
flags/mipmaps=false
25+
flags/anisotropic=false
26+
flags/srgb=2
27+
process/fix_alpha_border=true
28+
process/premult_alpha=false
29+
process/HDR_as_SRGB=false
30+
process/invert_color=false
31+
process/normal_map_invert_y=false
32+
stream=false
33+
size_limit=0
34+
detect_3d=true
35+
svg/scale=1.0

game/menu/emptySzene.tscn

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[gd_scene format=2]
2+
3+
[node name="Node" type="Node"]

game/menu/gamedisplay.gd

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
extends MarginContainer
2+
3+
signal pressed(game_file)
4+
5+
var game_file: ConfigFile
6+
7+
8+
func setup(game_cfg: ConfigFile):
9+
game_file = game_cfg
10+
11+
$VBoxContainer/Label.text = game_cfg.get_value("game", "name")
12+
$VBoxContainer/RichTextLabel.bbcode_text = game_cfg.get_value("game", "desc")
13+
14+
var icon: Texture = load(
15+
str(game_cfg.get_meta("folder_path"), game_cfg.get_value("game", "icon"))
16+
)
17+
if icon == null:
18+
icon = load("res://icon.png")
19+
$VBoxContainer/TextureRect.texture = icon
20+
21+
#setup of info Dialog
22+
##setup buttons
23+
$InfoButton.connect("pressed", $InfoDialog, "popup_centered_minsize", [Vector2(500, 250)])
24+
var loadbtn = $InfoDialog.add_button("load")
25+
loadbtn.connect("pressed", $InfoDialog, "hide")
26+
loadbtn.connect("pressed", self, "_on_loadbutton_pressed")
27+
##setup text
28+
$InfoDialog/Container/Label.text = game_cfg.get_value("game", "name")
29+
$InfoDialog/Container/TextureRect.texture = icon
30+
$InfoDialog/Container/descCont/desclab.bbcode_text = game_cfg.get_value("game", "desc")
31+
var text = ""
32+
text += "Author: " + game_cfg.get_value("game", "creator") + "\n"
33+
text += "Version: " + game_cfg.get_value("game", "version") + "\n"
34+
$InfoDialog/Container/descCont/Statslab.text = text
35+
36+
37+
func _on_loadbutton_pressed():
38+
emit_signal("pressed", game_file)

0 commit comments

Comments
 (0)