- implementing biom change

- fixing typo in "highscore"
This commit is contained in:
megamichi 2024-10-18 16:34:51 +02:00
parent 520a5db2c6
commit 431fb8220e
24 changed files with 242 additions and 105 deletions

19
scenes/ground/ground.gd Normal file
View file

@ -0,0 +1,19 @@
extends Sprite2D
signal screen_entered
var speed: float
func _ready() -> void:
pass
func _physics_process(delta: float) -> void:
if $"/root/Global".gamerunning:
global_position.x -= $"/root/Global".speed*delta
func screen_e() -> void:
screen_entered.emit()
func screen_exited() -> void:
queue_free()

17
scenes/ground/ground.tscn Normal file
View file

@ -0,0 +1,17 @@
[gd_scene load_steps=3 format=3 uid="uid://cjq8kb0mhjh8r"]
[ext_resource type="Texture2D" uid="uid://bg78j6xxw3ck4" path="res://assets/Ground/n.png" id="1_ocn3x"]
[ext_resource type="Script" path="res://scenes/ground/ground.gd" id="2_eg3te"]
[node name="Ground" type="Sprite2D"]
texture_filter = 1
texture = ExtResource("1_ocn3x")
centered = false
script = ExtResource("2_eg3te")
[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."]
position = Vector2(399.5, 82.5)
scale = Vector2(0.05, -0.05)
[connection signal="screen_entered" from="VisibleOnScreenNotifier2D" to="." method="screen_e"]
[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="screen_exited"]

View file

@ -0,0 +1,51 @@
extends Node2D
var texture_new_sprite : Texture
var biom_n = preload("res://assets/Ground/n.png")
var biom_n_w = preload("res://assets/Ground/n_w.png")
var biom_w_n = preload("res://assets/Ground/w_n.png")
var biom_w = preload("res://assets/Ground/w.png")
var active_biom = "n"
var passed
func probability(prozent):
return randf() > 1-(0.01*20) # 20% warscheinlichkeit um biom zu tauschen
func handle_biom_change():
if active_biom == "n":
if probability(20):
active_biom = "n_w"
elif active_biom == "n_w":
active_biom = "w"
elif active_biom == "w":
active_biom = "w_n"
elif active_biom == "w_n":
active_biom = "n"
set_biom_texture()
func set_biom_texture():
#print("activebiom_s: " + active_biom)
if active_biom == "w":
texture_new_sprite = biom_w
elif active_biom == "n":
texture_new_sprite = biom_n
elif active_biom == "w_n":
texture_new_sprite = biom_w_n
elif active_biom == "n_w":
texture_new_sprite = biom_n_w
func _spawn(last_x_position) -> void:
var new_ground = preload("res://scenes/ground/ground.tscn").instantiate()
new_ground.texture = texture_new_sprite
new_ground.global_position.x = last_x_position+400
add_child(new_ground)
new_ground.connect("screen_entered",_on_ground_sprite_screen_entered)
func _on_ground_sprite_screen_entered() -> void:
handle_biom_change()
_spawn(get_child(0).position.x)