use sprites for foreground
This commit is contained in:
parent
fac981d078
commit
225a55bacd
7 changed files with 112 additions and 67 deletions
|
@ -110,9 +110,8 @@ func update_score():
|
||||||
|
|
||||||
|
|
||||||
func _on_player_score() -> void:
|
func _on_player_score() -> void:
|
||||||
if game_mode == "score":
|
update_score()
|
||||||
update_score()
|
|
||||||
|
|
||||||
func _on_Timer_timeout() -> void:
|
func _on_Timer_timeout() -> void:
|
||||||
if game_mode == "time":
|
update_score()
|
||||||
update_score()
|
|
||||||
|
|
35
mini-game/scenes/decor/ForegroundSprite.gd
Normal file
35
mini-game/scenes/decor/ForegroundSprite.gd
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
extends Sprite
|
||||||
|
|
||||||
|
export var scroll_speed = 9
|
||||||
|
|
||||||
|
var moving = false
|
||||||
|
|
||||||
|
signal viewport_entered(object)
|
||||||
|
signal viewport_exited(object)
|
||||||
|
|
||||||
|
|
||||||
|
func start():
|
||||||
|
moving = true
|
||||||
|
|
||||||
|
|
||||||
|
func stop():
|
||||||
|
moving = false
|
||||||
|
|
||||||
|
|
||||||
|
func _physics_process(delta):
|
||||||
|
if moving:
|
||||||
|
move()
|
||||||
|
|
||||||
|
|
||||||
|
func move():
|
||||||
|
position.x -= scroll_speed
|
||||||
|
|
||||||
|
|
||||||
|
func _on_VisibilityNotifier2D_viewport_entered(viewport: Viewport) -> void:
|
||||||
|
print("viewport_entered")
|
||||||
|
emit_signal("viewport_entered", self)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_VisibilityNotifier2D_viewport_exited(viewport: Viewport) -> void:
|
||||||
|
print("viewport_exited")
|
||||||
|
emit_signal("viewport_exited", self)
|
36
mini-game/scenes/decor/ForegroundSprite.tscn
Normal file
36
mini-game/scenes/decor/ForegroundSprite.tscn
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
[gd_scene load_steps=5 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://mini-game/ressources/backgrounds/road3.png" type="Texture" id=1]
|
||||||
|
[ext_resource path="res://mini-game/scenes/decor/ForegroundSprite.gd" type="Script" id=2]
|
||||||
|
|
||||||
|
[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
|
||||||
|
|
||||||
|
[node name="ForegroundSprite" type="Sprite"]
|
||||||
|
material = SubResource( 2 )
|
||||||
|
texture = ExtResource( 1 )
|
||||||
|
offset = Vector2( 960, 540 )
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
__meta__ = {
|
||||||
|
"_editor_description_": ""
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="."]
|
||||||
|
position = Vector2( 1930, 540 )
|
||||||
|
|
||||||
|
[connection signal="viewport_entered" from="VisibilityNotifier2D" to="." method="_on_VisibilityNotifier2D_viewport_entered"]
|
||||||
|
[connection signal="viewport_exited" from="VisibilityNotifier2D" to="." method="_on_VisibilityNotifier2D_viewport_exited"]
|
|
@ -1,28 +1,38 @@
|
||||||
extends Node2D
|
extends Node2D
|
||||||
|
|
||||||
onready var texture : TextureRect = $TextureRect
|
var sprite_scene = preload("res://mini-game/scenes/decor/ForegroundSprite.tscn")
|
||||||
|
|
||||||
var force_stop = false
|
var textures := []
|
||||||
var moving = false
|
var moving := false
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
textures.append($ForegroundSprite)
|
||||||
stop()
|
stop()
|
||||||
|
|
||||||
|
|
||||||
func stop():
|
func stop():
|
||||||
moving = false
|
moving = false
|
||||||
force_stop = true
|
for t in textures:
|
||||||
texture.material.set_shader_param("scroll_speed", 0)
|
t.stop()
|
||||||
|
|
||||||
|
|
||||||
func start():
|
func start():
|
||||||
moving = true
|
moving = true
|
||||||
force_stop = false
|
for t in textures:
|
||||||
texture.material.set_shader_param("scroll_speed", 0.282)
|
t.start()
|
||||||
#texture.material.set_shader_param("scroll_speed", 0.2)
|
|
||||||
|
|
||||||
func _process(delta):
|
|
||||||
if not force_stop:
|
func _on_ForegroundSprite_viewport_entered(object: Sprite) -> void:
|
||||||
if get_tree().paused and moving:
|
var new_sprite = sprite_scene.instance()
|
||||||
stop()
|
new_sprite.position = Vector2(1920, 0)
|
||||||
force_stop = false
|
new_sprite.connect("viewport_entered", self, "_on_ForegroundSprite_viewport_entered")
|
||||||
elif not get_tree().paused and not moving:
|
new_sprite.connect("viewport_exited", self, "_on_ForegroundSprite_viewport_exited")
|
||||||
start()
|
if moving:
|
||||||
|
new_sprite.start()
|
||||||
|
add_child(new_sprite)
|
||||||
|
textures.append(new_sprite)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_ForegroundSprite_viewport_exited(object: Sprite) -> void:
|
||||||
|
textures.remove(textures.find(object))
|
||||||
|
object.queue_free()
|
||||||
|
|
|
@ -1,45 +1,21 @@
|
||||||
[gd_scene load_steps=6 format=2]
|
[gd_scene load_steps=4 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://mini-game/scenes/decor/foreground.gd" type="Script" 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/scenes/decor/ForegroundSprite.tscn" type="PackedScene" id=2]
|
||||||
|
|
||||||
[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]
|
[sub_resource type="RectangleShape2D" id=3]
|
||||||
extents = Vector2( 958.398, 78.6175 )
|
extents = Vector2( 958.398, 78.6175 )
|
||||||
|
|
||||||
[node name="foreground" type="Node2D"]
|
[node name="foreground" type="Node2D"]
|
||||||
pause_mode = 2
|
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
[node name="TextureRect" type="TextureRect" parent="."]
|
|
||||||
material = SubResource( 2 )
|
|
||||||
margin_right = 1920.0
|
|
||||||
margin_bottom = 1080.0
|
|
||||||
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( 960, 1080 )
|
position = Vector2( 960, 1080 )
|
||||||
shape = SubResource( 3 )
|
shape = SubResource( 3 )
|
||||||
|
|
||||||
|
[node name="ForegroundSprite" parent="." instance=ExtResource( 2 )]
|
||||||
|
|
||||||
|
[connection signal="viewport_entered" from="ForegroundSprite" to="." method="_on_ForegroundSprite_viewport_entered"]
|
||||||
|
[connection signal="viewport_exited" from="ForegroundSprite" to="." method="_on_ForegroundSprite_viewport_exited"]
|
||||||
|
|
|
@ -27,7 +27,7 @@ var au_sol = true
|
||||||
var current_lives = max_lives
|
var current_lives = max_lives
|
||||||
|
|
||||||
onready var animation = $AnimatedSprite
|
onready var animation = $AnimatedSprite
|
||||||
onready var bonus_texture = $BonusControl/TextureRect
|
onready var bonus_texture = $BonusControl/Sprite
|
||||||
onready var bonus_tween = $BonusControl/Tween
|
onready var bonus_tween = $BonusControl/Tween
|
||||||
onready var bonus_timer = $BonusControl/Timer
|
onready var bonus_timer = $BonusControl/Timer
|
||||||
|
|
||||||
|
@ -95,6 +95,7 @@ func play_bonus_anim():
|
||||||
bonus_tween.stop_all()
|
bonus_tween.stop_all()
|
||||||
bonus_timer.stop()
|
bonus_timer.stop()
|
||||||
bonus_tween.interpolate_property(bonus_texture, "modulate", null, Color(1, 1, 1, 1), 0.3, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
|
bonus_tween.interpolate_property(bonus_texture, "modulate", null, Color(1, 1, 1, 1), 0.3, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
|
||||||
|
bonus_tween.interpolate_property(bonus_texture, "position", Vector2(bonus_texture.position.x, 0), Vector2(bonus_texture.position.x, bonus_texture.position.y), 0.3, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
|
||||||
bonus_tween.start()
|
bonus_tween.start()
|
||||||
bonus_timer.start()
|
bonus_timer.start()
|
||||||
|
|
||||||
|
|
|
@ -73,24 +73,12 @@ position = Vector2( -0.0400658, 9.23466 )
|
||||||
scale = Vector2( 0.609429, 0.281311 )
|
scale = Vector2( 0.609429, 0.281311 )
|
||||||
shape = SubResource( 3 )
|
shape = SubResource( 3 )
|
||||||
|
|
||||||
[node name="BonusControl" type="Control" parent="."]
|
[node name="BonusControl" type="Node2D" parent="."]
|
||||||
margin_right = 40.0
|
|
||||||
margin_bottom = 40.0
|
|
||||||
__meta__ = {
|
|
||||||
"_edit_use_anchors_": false
|
|
||||||
}
|
|
||||||
|
|
||||||
[node name="TextureRect" type="TextureRect" parent="BonusControl"]
|
[node name="Sprite" type="Sprite" parent="BonusControl"]
|
||||||
margin_left = -10.7864
|
position = Vector2( 0, -15 )
|
||||||
margin_top = -26.3001
|
scale = Vector2( 0.02, 0.02 )
|
||||||
margin_right = 10.2136
|
|
||||||
margin_bottom = -11.3001
|
|
||||||
texture = ExtResource( 22 )
|
texture = ExtResource( 22 )
|
||||||
expand = true
|
|
||||||
stretch_mode = 6
|
|
||||||
__meta__ = {
|
|
||||||
"_edit_use_anchors_": false
|
|
||||||
}
|
|
||||||
|
|
||||||
[node name="Tween" type="Tween" parent="BonusControl"]
|
[node name="Tween" type="Tween" parent="BonusControl"]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue