improve minigame
This commit is contained in:
parent
7e00d5a054
commit
0a61adf7b0
10 changed files with 163 additions and 62 deletions
45
mini-game/MiniGame.gd
Normal file
45
mini-game/MiniGame.gd
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
signal game_over
|
||||||
|
|
||||||
|
onready var background := $background
|
||||||
|
onready var foreground := $foreground
|
||||||
|
onready var spawner := $spawner
|
||||||
|
onready var player := $player2
|
||||||
|
onready var scoreUI := $scoreUI
|
||||||
|
|
||||||
|
var next_timeline := ""
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
Signals.connect("die", self, "on_game_over")
|
||||||
|
|
||||||
|
|
||||||
|
func setup(mode: String, next: String):
|
||||||
|
print("minigame: " + mode + " " + next)
|
||||||
|
set_mode(mode)
|
||||||
|
next_timeline = next
|
||||||
|
|
||||||
|
|
||||||
|
func set_mode(mode: String):
|
||||||
|
match mode:
|
||||||
|
_:
|
||||||
|
print("unkonwn mini-game mode")
|
||||||
|
|
||||||
|
|
||||||
|
func start():
|
||||||
|
print("starting minigame")
|
||||||
|
foreground.start()
|
||||||
|
player.start()
|
||||||
|
spawner.start()
|
||||||
|
|
||||||
|
|
||||||
|
func stop():
|
||||||
|
foreground.stop()
|
||||||
|
player.stop()
|
||||||
|
spawner.stop()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func on_game_over():
|
||||||
|
stop()
|
||||||
|
emit_signal("game_over", next_timeline)
|
|
@ -1,12 +1,14 @@
|
||||||
[gd_scene load_steps=6 format=2]
|
[gd_scene load_steps=7 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://mini-game/scenes/decor/background.tscn" type="PackedScene" id=1]
|
[ext_resource path="res://mini-game/scenes/decor/background.tscn" type="PackedScene" id=1]
|
||||||
[ext_resource path="res://mini-game/scenes/decor/foreground.tscn" type="PackedScene" id=2]
|
[ext_resource path="res://mini-game/scenes/decor/foreground.tscn" type="PackedScene" id=2]
|
||||||
[ext_resource path="res://mini-game/scenes/players/player2.tscn" type="PackedScene" id=3]
|
[ext_resource path="res://mini-game/scenes/players/player2.tscn" type="PackedScene" id=3]
|
||||||
|
[ext_resource path="res://mini-game/MiniGame.gd" type="Script" id=4]
|
||||||
[ext_resource path="res://mini-game/scenes/spawner/spawner.tscn" type="PackedScene" id=6]
|
[ext_resource path="res://mini-game/scenes/spawner/spawner.tscn" type="PackedScene" id=6]
|
||||||
[ext_resource path="res://mini-game/scenes/decor/scoreUI.tscn" type="PackedScene" id=7]
|
[ext_resource path="res://mini-game/scenes/decor/scoreUI.tscn" type="PackedScene" id=7]
|
||||||
|
|
||||||
[node name="main" type="Node2D"]
|
[node name="MiniGame" type="Node2D"]
|
||||||
|
script = ExtResource( 4 )
|
||||||
|
|
||||||
[node name="background" parent="." instance=ExtResource( 1 )]
|
[node name="background" parent="." instance=ExtResource( 1 )]
|
||||||
position = Vector2( 1, -125 )
|
position = Vector2( 1, -125 )
|
9
mini-game/scenes/decor/foreground.gd
Normal file
9
mini-game/scenes/decor/foreground.gd
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
onready var texture : TextureRect = $TextureRect
|
||||||
|
|
||||||
|
func stop():
|
||||||
|
texture.material.set_shader_param("scroll_speed", 0)
|
||||||
|
|
||||||
|
func start():
|
||||||
|
texture.material.set_shader_param("scroll_speed", 0.2)
|
|
@ -1,23 +1,46 @@
|
||||||
[gd_scene load_steps=4 format=2]
|
[gd_scene load_steps=6 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://mini-game/scenes/effets/ScrollingBG.tscn" type="PackedScene" id=1]
|
[ext_resource path="res://mini-game/scenes/decor/foreground.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://mini-game/ressources/backgrounds/road3.png" type="Texture" id=2]
|
[ext_resource path="res://mini-game/ressources/backgrounds/road3.png" type="Texture" id=2]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id=1]
|
[sub_resource type="Shader" id=1]
|
||||||
|
code = "shader_type canvas_item;
|
||||||
|
|
||||||
|
uniform float scroll_speed;
|
||||||
|
|
||||||
|
void fragment(){
|
||||||
|
vec2 u = UV;
|
||||||
|
u.x += scroll_speed*TIME;
|
||||||
|
vec4 color = texture(TEXTURE,u);
|
||||||
|
COLOR = color;
|
||||||
|
}
|
||||||
|
"
|
||||||
|
|
||||||
|
[sub_resource type="ShaderMaterial" id=2]
|
||||||
|
shader = SubResource( 1 )
|
||||||
|
shader_param/scroll_speed = 0.0
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id=3]
|
||||||
extents = Vector2( 552.889, 78.6175 )
|
extents = Vector2( 552.889, 78.6175 )
|
||||||
|
|
||||||
[node name="foreground" type="Node2D"]
|
[node name="foreground" type="Node2D"]
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="ScrollingBG" parent="." instance=ExtResource( 1 )]
|
[node name="TextureRect" type="TextureRect" parent="."]
|
||||||
margin_left = 0.734742
|
material = SubResource( 2 )
|
||||||
margin_top = -356.907
|
margin_top = -356.0
|
||||||
margin_right = 1920.73
|
margin_right = 1920.0
|
||||||
margin_bottom = 723.093
|
margin_bottom = 723.0
|
||||||
rect_scale = Vector2( 0.533041, 0.912837 )
|
rect_scale = Vector2( 0.533, 0.913 )
|
||||||
texture = ExtResource( 2 )
|
texture = ExtResource( 2 )
|
||||||
|
stretch_mode = 2
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false,
|
||||||
|
"_editor_description_": ""
|
||||||
|
}
|
||||||
|
|
||||||
[node name="StaticBody2D" type="StaticBody2D" parent="."]
|
[node name="StaticBody2D" type="StaticBody2D" parent="."]
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
|
||||||
position = Vector2( 497.671, 612.885 )
|
position = Vector2( 497.671, 612.885 )
|
||||||
shape = SubResource( 1 )
|
shape = SubResource( 3 )
|
||||||
|
|
11
mini-game/scenes/decor/scoreUI.gd
Normal file
11
mini-game/scenes/decor/scoreUI.gd
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
extends Control
|
||||||
|
|
||||||
|
onready var label : RichTextLabel = $RichTextLabel
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
Signals.connect("update_score",self,"update_score")
|
||||||
|
|
||||||
|
|
||||||
|
func update_score(score: int):
|
||||||
|
label.text = String(score)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[gd_scene load_steps=4 format=2]
|
[gd_scene load_steps=4 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://mini-game/scripts/update_score.gd" type="Script" id=1]
|
[ext_resource path="res://mini-game/scenes/decor/scoreUI.gd" type="Script" id=2]
|
||||||
|
|
||||||
[sub_resource type="DynamicFontData" id=1]
|
[sub_resource type="DynamicFontData" id=1]
|
||||||
antialiased = false
|
antialiased = false
|
||||||
|
@ -12,6 +12,7 @@ outline_color = Color( 0, 0, 0, 1 )
|
||||||
font_data = SubResource( 1 )
|
font_data = SubResource( 1 )
|
||||||
|
|
||||||
[node name="scoreUI" type="Control"]
|
[node name="scoreUI" type="Control"]
|
||||||
|
script = ExtResource( 2 )
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
@ -32,7 +33,6 @@ tab_size = 1
|
||||||
text = "0"
|
text = "0"
|
||||||
fit_content_height = true
|
fit_content_height = true
|
||||||
scroll_active = false
|
scroll_active = false
|
||||||
script = ExtResource( 1 )
|
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,4 +11,6 @@ scenes = [ ExtResource( 3 ), ExtResource( 2 ) ]
|
||||||
[node name="Timer" type="Timer" parent="."]
|
[node name="Timer" type="Timer" parent="."]
|
||||||
wait_time = 2.094
|
wait_time = 2.094
|
||||||
autostart = true
|
autostart = true
|
||||||
|
|
||||||
|
[node name="items" type="Node2D" parent="."]
|
||||||
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]
|
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]
|
||||||
|
|
|
@ -13,6 +13,8 @@ enum {
|
||||||
IDLE
|
IDLE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var player_enabled = false;
|
||||||
|
|
||||||
var state = RUN
|
var state = RUN
|
||||||
var au_sol = true
|
var au_sol = true
|
||||||
|
|
||||||
|
@ -23,54 +25,56 @@ onready var animation = $AnimatedSprite
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
|
stop()
|
||||||
Signals.connect("gain",self,"increase_score")
|
Signals.connect("gain",self,"increase_score")
|
||||||
Signals.connect("die",self,"player_die")
|
Signals.connect("die",self,"player_die")
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
match state:
|
if player_enabled:
|
||||||
RUN:
|
match state:
|
||||||
animation.play("run")
|
RUN:
|
||||||
JUMP:
|
animation.play("run")
|
||||||
vitesse = Vector2.ZERO
|
JUMP:
|
||||||
vitesse.y -= jump_vitesse
|
vitesse = Vector2.ZERO
|
||||||
animation.play("jump")
|
vitesse.y -= jump_vitesse
|
||||||
state = IDLE
|
animation.play("jump")
|
||||||
print("jump")
|
state = IDLE
|
||||||
IDLE:
|
IDLE:
|
||||||
pass
|
pass
|
||||||
vitesse.y += gravite
|
vitesse.y += gravite
|
||||||
move_and_collide(vitesse*delta)
|
move_and_collide(vitesse*delta)
|
||||||
|
|
||||||
func _input(event):
|
|
||||||
if state == RUN and event.is_action_pressed("ui_accept"):
|
|
||||||
state = JUMP
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
||||||
#func _process(delta):
|
func _input(event):
|
||||||
# pass
|
if player_enabled and state == RUN and event.is_action_pressed("ui_accept"):
|
||||||
|
state = JUMP
|
||||||
|
|
||||||
|
|
||||||
func _on_Area2D_body_entered(body):
|
func _on_Area2D_body_entered(body):
|
||||||
print("landing")
|
|
||||||
if body is StaticBody2D:
|
if body is StaticBody2D:
|
||||||
print("Yep a dino is landing")
|
|
||||||
state = RUN
|
state = RUN
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func _on_Area2D_body_exited(body):
|
func _on_Area2D_body_exited(body):
|
||||||
print("jumping")
|
|
||||||
if body is StaticBody2D:
|
if body is StaticBody2D:
|
||||||
print("Yep a dino is jumping")
|
|
||||||
state = JUMP
|
state = JUMP
|
||||||
|
|
||||||
|
|
||||||
func increase_score(scoretoadd):
|
func increase_score(scoretoadd):
|
||||||
score+=scoretoadd
|
score+=scoretoadd
|
||||||
Signals.emit_signal("update_score",score)
|
Signals.emit_signal("update_score",score)
|
||||||
print(score)
|
|
||||||
|
|
||||||
func player_die():
|
func player_die():
|
||||||
queue_free()
|
stop()
|
||||||
|
|
||||||
|
|
||||||
|
func start():
|
||||||
|
show()
|
||||||
|
player_enabled = true
|
||||||
|
|
||||||
|
|
||||||
|
func stop():
|
||||||
|
hide()
|
||||||
|
player_enabled = false
|
||||||
|
|
|
@ -7,20 +7,35 @@ var scene_index = 0;
|
||||||
var last_object
|
var last_object
|
||||||
var end_of_game = false
|
var end_of_game = false
|
||||||
|
|
||||||
|
var spawner_enabled = false
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
Signals.connect("die",self,"game_over")
|
Signals.connect("die",self,"game_over")
|
||||||
|
|
||||||
|
|
||||||
func _on_Timer_timeout():
|
func _on_Timer_timeout():
|
||||||
random_scene.randomize()
|
if spawner_enabled:
|
||||||
scene_index = random_scene.randi_range(0,scenes.size()-1)
|
random_scene.randomize()
|
||||||
print(scene_index)
|
scene_index = random_scene.randi_range(0,scenes.size()-1)
|
||||||
var tmp = scenes[scene_index].instance()
|
var tmp = scenes[scene_index].instance()
|
||||||
add_child_below_node(self,tmp)
|
$items.add_child(tmp)
|
||||||
last_object = tmp
|
last_object = tmp
|
||||||
self.get_node("Timer").wait_time *= 0.99
|
self.get_node("Timer").wait_time *= 0.99
|
||||||
self.get_node("Timer").start()
|
self.get_node("Timer").start()
|
||||||
|
|
||||||
|
|
||||||
func game_over():
|
func game_over():
|
||||||
self.get_node("Timer").set_paused(true)
|
self.get_node("Timer").set_paused(true)
|
||||||
last_object.queue_free()
|
last_object.queue_free()
|
||||||
|
|
||||||
|
|
||||||
|
func start():
|
||||||
|
spawner_enabled = true
|
||||||
|
|
||||||
|
|
||||||
|
func stop():
|
||||||
|
spawner_enabled = false
|
||||||
|
for obj in $items.get_children():
|
||||||
|
remove_child(obj)
|
||||||
|
obj.queue_free()
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
extends RichTextLabel
|
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
|
||||||
Signals.connect("update_score",self,"update_score")
|
|
||||||
|
|
||||||
|
|
||||||
func update_score(score):
|
|
||||||
self.text = String(score)
|
|
||||||
|
|
Loading…
Reference in a new issue