Merge branch 'develop' into feature/Prototype_R_LEVEL
# Conflicts: # godot/Main.tscn # godot/gui/GameOver.tscn # src/gui/game_over/GameOverScreen.cpp
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
[gd_scene load_steps=4 format=2]
|
||||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://Main.gdns" type="Script" id=1]
|
||||
[ext_resource path="res://levels/PrototypeR.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://GUI/GameOver.tscn" type="PackedScene" id=3]
|
||||
[ext_resource path="res://gui/GameOver.tscn" type="PackedScene" id=3]
|
||||
[ext_resource path="res://gui/GameWon.tscn" type="PackedScene" id=4]
|
||||
|
||||
[node name="Main" type="Node"]
|
||||
pause_mode = 2
|
||||
@@ -14,3 +15,6 @@ pause_mode = 1
|
||||
|
||||
[node name="GameOver" parent="." instance=ExtResource( 3 )]
|
||||
visible = false
|
||||
|
||||
[node name="GameWon" parent="." instance=ExtResource( 4 )]
|
||||
visible = false
|
||||
|
@@ -16,6 +16,7 @@ func _ready() -> void:
|
||||
$AnimatedSprite.flip_h = true
|
||||
$FloorChecker.position.x = $CollisionShape2D.shape.get_extents().x * direction
|
||||
$FloorChecker.enabled = detect_edges
|
||||
Event.connect("level_loaded", self, "_on_level_loaded")
|
||||
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
@@ -33,6 +34,13 @@ func _physics_process(_delta: float) -> void:
|
||||
if collision.collider.name == "Player":
|
||||
emit_signal("player_touched")
|
||||
|
||||
Event.emit_signal("object_updated", self.get_name(), "Walking", global_position, velocity)
|
||||
|
||||
|
||||
func squash() -> void:
|
||||
Event.emit_signal("object_removed", self.get_name())
|
||||
queue_free()
|
||||
|
||||
|
||||
func _on_level_loaded() -> void:
|
||||
Event.emit_signal("object_created", self.get_name(), "Walking", global_position, Vector2(0, 0))
|
||||
|
@@ -22,6 +22,8 @@ func _ready() -> void:
|
||||
if direction == 1:
|
||||
$AnimatedSprite.flip_h = true
|
||||
|
||||
Event.connect("level_loaded", self, "_on_level_loaded")
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if $LeftWallChecker.is_colliding():
|
||||
@@ -29,17 +31,18 @@ func _physics_process(delta: float) -> void:
|
||||
elif $RightWallChecker.is_colliding():
|
||||
wall_checker_collided($RightWallChecker)
|
||||
|
||||
var velocity: Vector2 = Vector2(0, 0)
|
||||
if not follow_path:
|
||||
var target_position = position
|
||||
target_position.x *= 2 * direction
|
||||
position = position.move_toward(target_position, round(speed * delta))
|
||||
|
||||
var velocity = get_velocity_towards_target(delta)
|
||||
velocity = get_velocity_towards_target(delta)
|
||||
var collision = move_and_collide(velocity, true, true, true)
|
||||
if collision and collision.collider.name != "Player":
|
||||
var _collision = move_and_collide(velocity)
|
||||
else:
|
||||
var velocity = get_velocity_towards_target(delta)
|
||||
velocity = get_velocity_towards_target(delta)
|
||||
|
||||
var collision = move_and_collide(velocity, true, true, true)
|
||||
if collision and collision.collider.name != "Player":
|
||||
@@ -60,6 +63,8 @@ func _physics_process(delta: float) -> void:
|
||||
elif start_position.x + target.x < position.x:
|
||||
$AnimatedSprite.flip_h = false
|
||||
|
||||
Event.emit_signal("object_updated", self.get_name(), "Flying", global_position, velocity)
|
||||
|
||||
|
||||
func get_velocity_towards_target(delta: float) -> Vector2:
|
||||
var velocity = Vector2(0, 0)
|
||||
@@ -80,3 +85,7 @@ func wall_checker_collided(wall_checker: RayCast2D) -> void:
|
||||
emit_signal("player_touched")
|
||||
direction *= -1
|
||||
$AnimatedSprite.flip_h = not $AnimatedSprite.flip_h
|
||||
|
||||
|
||||
func _on_level_loaded() -> void:
|
||||
Event.emit_signal("object_created", self.get_name(), "Flying", global_position, Vector2(0, 0))
|
||||
|
@@ -11,9 +11,14 @@ export var fall_speed = 75.0
|
||||
var return_to_start: bool = false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
Event.connect("level_loaded", self, "_on_level_loaded")
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if return_to_start:
|
||||
position = position.move_toward(start_position, speed * delta)
|
||||
Event.emit_signal("object_updated", self.get_name(), "Rising", global_position, velocity)
|
||||
else:
|
||||
var collision = move_and_collide(Vector2(0, (position.y + fall_speed) * delta))
|
||||
if collision:
|
||||
@@ -21,7 +26,12 @@ func _physics_process(delta: float) -> void:
|
||||
$AnimatedSprite.play("normal")
|
||||
if collision.collider.name == "Player":
|
||||
emit_signal("player_touched")
|
||||
Event.emit_signal("object_updated", self.get_name(), "Falling", global_position, velocity)
|
||||
|
||||
if position.y <= start_position.y:
|
||||
return_to_start = false
|
||||
$AnimatedSprite.play("angry")
|
||||
|
||||
|
||||
func _on_level_loaded() -> void:
|
||||
Event.emit_signal("object_created", self.get_name(), "Falling", global_position, Vector2(0, 0))
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
[ext_resource path="res://assets/fonts/ttf/PixelOperator8.ttf" type="DynamicFontData" id=1]
|
||||
[ext_resource path="res://assets/fonts/ttf/PixelOperatorHB8.ttf" type="DynamicFontData" id=2]
|
||||
[ext_resource path="res://GUI/botonreiniciar.gdns" type="Script" id=3]
|
||||
[ext_resource path="res://gui/GameOverScreen.gdns" type="Script" id=3]
|
||||
[ext_resource path="res://assets/sounds/died.wav" type="AudioStream" id=4]
|
||||
|
||||
[sub_resource type="DynamicFont" id=1]
|
48
godot/gui/GameWon.tscn
Normal file
48
godot/gui/GameWon.tscn
Normal file
@@ -0,0 +1,48 @@
|
||||
[gd_scene load_steps=7 format=2]
|
||||
|
||||
[ext_resource path="res://assets/fonts/ttf/PixelOperator8.ttf" type="DynamicFontData" id=1]
|
||||
[ext_resource path="res://assets/fonts/ttf/PixelOperatorHB8.ttf" type="DynamicFontData" id=2]
|
||||
[ext_resource path="res://gui/GameWonScreen.gdns" type="Script" id=3]
|
||||
|
||||
[sub_resource type="DynamicFont" id=1]
|
||||
size = 50
|
||||
font_data = ExtResource( 1 )
|
||||
|
||||
[sub_resource type="DynamicFont" id=2]
|
||||
font_data = ExtResource( 2 )
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id=3]
|
||||
bg_color = Color( 0.0705882, 0.917647, 0, 1 )
|
||||
|
||||
[node name="GameWon" type="CanvasLayer"]
|
||||
script = ExtResource( 3 )
|
||||
|
||||
[node name="Control" type="Control" parent="."]
|
||||
margin_right = 40.0
|
||||
margin_bottom = 40.0
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="Control"]
|
||||
margin_right = 512.0
|
||||
margin_bottom = 288.0
|
||||
rect_min_size = Vector2( 512, 288 )
|
||||
color = Color( 0, 0, 0, 1 )
|
||||
|
||||
[node name="Label" type="Label" parent="Control"]
|
||||
margin_left = 66.0
|
||||
margin_top = 17.0
|
||||
margin_right = 456.0
|
||||
margin_bottom = 71.0
|
||||
custom_fonts/font = SubResource( 1 )
|
||||
text = "GANASTE!"
|
||||
align = 1
|
||||
|
||||
[node name="QuitButton" type="Button" parent="Control"]
|
||||
margin_left = 194.0
|
||||
margin_top = 150.0
|
||||
margin_right = 338.0
|
||||
margin_bottom = 180.0
|
||||
custom_fonts/font = SubResource( 2 )
|
||||
custom_styles/hover = SubResource( 3 )
|
||||
text = "SALIR"
|
||||
|
||||
[connection signal="pressed" from="Control/QuitButton" to="." method="_on_quit_button_pressed"]
|
8
godot/gui/GameWonScreen.gdns
Normal file
8
godot/gui/GameWonScreen.gdns
Normal file
@@ -0,0 +1,8 @@
|
||||
[gd_resource type="NativeScript" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://gdnative/alai.tres" type="GDNativeLibrary" id=1]
|
||||
|
||||
[resource]
|
||||
resource_name = "GameWonScreen"
|
||||
class_name = "GameWonScreen"
|
||||
library = ExtResource( 1 )
|
@@ -1,10 +1,8 @@
|
||||
extends Node
|
||||
|
||||
|
||||
signal monitor_loaded()
|
||||
|
||||
|
||||
export var monitor_enabled: bool = false
|
||||
export var debug: bool = false
|
||||
export var development_url: String = "http://localhost:4050/api/v1"
|
||||
var url_real: String = "https://alai.cromer.cl/api/v1"
|
||||
export var use_development_url: bool = false
|
||||
@@ -53,7 +51,11 @@ func _ready() -> void:
|
||||
Event.connect("object_created", self, "_object_created")
|
||||
Event.connect("object_updated", self, "_object_updated")
|
||||
Event.connect("object_removed", self, "_object_removed")
|
||||
Event.connect("game_started", self, "_on_game_started")
|
||||
Event.connect("player_died", self, "_on_game_over")
|
||||
Event.connect("player_won", self, "_on_game_won")
|
||||
Event.connect("coin_collected", self, "_on_coin_update")
|
||||
|
||||
game_version = get_parent().game_version
|
||||
|
||||
player["rut"] = ""
|
||||
@@ -108,7 +110,7 @@ func _physics_process(_delta: float) -> void:
|
||||
if monitor_enabled:
|
||||
if has_node("MonitorGUI") and not $MonitorGUI.visible:
|
||||
$MonitorGUI.visible = true
|
||||
emit_signal("monitor_loaded")
|
||||
Event.emit_signal("monitor_loaded")
|
||||
|
||||
if started and not get_tree().paused:
|
||||
var frame = empty_frame.duplicate(true)
|
||||
@@ -130,13 +132,14 @@ func _physics_process(_delta: float) -> void:
|
||||
start_monitor()
|
||||
else:
|
||||
get_tree().paused = false
|
||||
emit_signal("monitor_loaded")
|
||||
Event.emit_signal("monitor_loaded")
|
||||
queue_free()
|
||||
|
||||
|
||||
func _on_input_validated(validated_player: Dictionary) -> void:
|
||||
$MonitorGUI.queue_free()
|
||||
get_tree().paused = false
|
||||
Event.emit_signal("game_started")
|
||||
player = validated_player.duplicate(true)
|
||||
game["player"] = player
|
||||
|
||||
@@ -161,6 +164,8 @@ func start_monitor() -> void:
|
||||
frames.clear()
|
||||
game["level_id"] = 2 # PrototypeR
|
||||
game["won"] = false
|
||||
coins = 0
|
||||
points = 0
|
||||
game["timestamp"] = int(Time.get_unix_time_from_system())
|
||||
start_time = Time.get_ticks_msec()
|
||||
started = true
|
||||
@@ -186,6 +191,7 @@ func remove_object(name: String) -> void:
|
||||
for i in range(0, objects.size()):
|
||||
if objects[i]["name"] == name:
|
||||
objects.remove(i)
|
||||
return
|
||||
|
||||
|
||||
func _on_coin_update(amount: int) -> void:
|
||||
@@ -217,7 +223,16 @@ func send_data() -> void:
|
||||
print("Body B: " + String(body.length()))
|
||||
print("Body MB: " + String(body.length() / pow(2, 20)))
|
||||
|
||||
$HTTPRequest.request(url + "/game", headers, false, HTTPClient.METHOD_POST, body)
|
||||
if not debug:
|
||||
$HTTPRequest.request(url + "/game", headers, false, HTTPClient.METHOD_POST, body)
|
||||
else:
|
||||
var file = File.new()
|
||||
if file.open("user://game.json", File.WRITE) != 0:
|
||||
print_debug("Could not open game.json for writing!")
|
||||
return
|
||||
|
||||
file.store_string(json)
|
||||
file.close()
|
||||
|
||||
|
||||
func compress_payload(payload: String) -> String:
|
||||
@@ -229,3 +244,21 @@ func compress_payload(payload: String) -> String:
|
||||
return new_payload
|
||||
|
||||
|
||||
func _on_game_started() -> void:
|
||||
print_debug("started game")
|
||||
if not started:
|
||||
start_monitor()
|
||||
|
||||
|
||||
func _on_game_over() -> void:
|
||||
if started:
|
||||
stop_monitor()
|
||||
game["won"] = false
|
||||
send_data()
|
||||
|
||||
|
||||
func _on_game_won() -> void:
|
||||
if started:
|
||||
stop_monitor()
|
||||
game["won"] = true
|
||||
send_data()
|
||||
|
Reference in New Issue
Block a user