-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
249 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
extends Node | ||
class_name WebSocketClient | ||
|
||
@export var handshake_headers : PackedStringArray | ||
@export var supported_protocols : PackedStringArray | ||
@export var tls_trusted_certificate : X509Certificate | ||
@export var tls_verify := true | ||
|
||
|
||
var socket = WebSocketPeer.new() | ||
var last_state = WebSocketPeer.STATE_CLOSED | ||
|
||
|
||
signal connected_to_server() | ||
signal connection_closed() | ||
signal message_received(message: Variant) | ||
|
||
|
||
func connect_to_url(url) -> int: | ||
socket.supported_protocols = supported_protocols | ||
socket.handshake_headers = handshake_headers | ||
var tls_options = TLSOptions.client(tls_trusted_certificate) | ||
var err = socket.connect_to_url(url, tls_options) | ||
if err != OK: | ||
print("i tried :(", err) | ||
return err | ||
last_state = socket.get_ready_state() | ||
return OK | ||
|
||
|
||
func send(message) -> int: | ||
print(socket.get_ready_state()) | ||
if typeof(message) == TYPE_STRING: | ||
return socket.send_text(message) | ||
return socket.send(var_to_bytes(message)) | ||
|
||
|
||
func get_message() -> Variant: | ||
if socket.get_available_packet_count() < 1: | ||
return null | ||
var pkt = socket.get_packet() | ||
if socket.was_string_packet(): | ||
return pkt.get_string_from_utf8() | ||
return bytes_to_var(pkt) | ||
|
||
|
||
func close(code := 1000, reason := "") -> void: | ||
socket.close(code, reason) | ||
last_state = socket.get_ready_state() | ||
|
||
|
||
func clear() -> void: | ||
socket = WebSocketPeer.new() | ||
last_state = socket.get_ready_state() | ||
|
||
|
||
func get_socket() -> WebSocketPeer: | ||
return socket | ||
|
||
|
||
func poll() -> void: | ||
if socket.get_ready_state() != socket.STATE_CLOSED: | ||
socket.poll() | ||
var state = socket.get_ready_state() | ||
if last_state != state: | ||
last_state = state | ||
if state == socket.STATE_OPEN: | ||
connected_to_server.emit() | ||
elif state == socket.STATE_CLOSED: | ||
connection_closed.emit() | ||
while socket.get_ready_state() == socket.STATE_OPEN and socket.get_available_packet_count(): | ||
message_received.emit(get_message()) | ||
|
||
|
||
func _ready(): | ||
connect_to_url("ws://localhost:8000/ws") | ||
|
||
func _process(delta): | ||
poll() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
extends Node2D | ||
@export var on = true | ||
@export var tile_size = 100 | ||
|
||
func _process(delta): | ||
queue_redraw() | ||
|
||
func _draw(): | ||
if !on: | ||
pass | ||
|
||
var camera: CharacterBody2D = get_tree().current_scene.find_child('PlayerCharacter') | ||
|
||
var size = get_viewport_rect().size / 2 | ||
var cam = camera.position | ||
|
||
for i in range(int((cam.x - size.x) / tile_size) - 1, int((size.x + cam.x) / tile_size) + 1): | ||
draw_line(Vector2(i * tile_size, cam.y + size.y + 100), Vector2(i * tile_size, cam.y - size.y - 100), "000000") | ||
for i in range(int((cam.y - size.y) / tile_size) - 1, int((size.y + cam.y) / tile_size) + 1): | ||
draw_line(Vector2(cam.x + size.x + 100, i * tile_size), Vector2(cam.x - size.x - 100, i * tile_size), "000000") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[gd_scene load_steps=3 format=3 uid="uid://2t2nbl4hrw8b"] | ||
|
||
[ext_resource type="PackedScene" uid="uid://xqoiyxrn10js" path="res://scenes/player_character/player_character.tscn" id="1_1c02b"] | ||
[ext_resource type="Script" path="res://scenes/main/main.gd" id="1_47q2m"] | ||
|
||
[node name="GameLevel" type="Node2D"] | ||
script = ExtResource("1_47q2m") | ||
|
||
[node name="PlayerCharacter" parent="." instance=ExtResource("1_1c02b")] | ||
position = Vector2(577, 325) | ||
scale = Vector2(2.9, 2.9) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
extends CharacterBody2D | ||
|
||
|
||
@export var tile_size: float = 100 | ||
@export var is_moving: bool = false | ||
|
||
var inputs = { | ||
"right": Vector2.RIGHT, | ||
"left": Vector2.LEFT, | ||
"up": Vector2.UP, | ||
"down": Vector2.DOWN | ||
} | ||
|
||
var inputs_rev = { | ||
Vector2.RIGHT:"right", | ||
Vector2.LEFT: "left", | ||
Vector2.UP: "up", | ||
Vector2.DOWN: "down" | ||
} | ||
|
||
func _ready(): | ||
position = position.snapped(Vector2.ONE * tile_size) | ||
position += Vector2.ONE * tile_size / 2 | ||
|
||
func _input(event): | ||
var vec = Input.get_vector("left", "right", "up", "down") | ||
if vec.length() == 1: | ||
position += vec*100 | ||
$AnimationPlayer.play(inputs_rev[vec]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
[gd_scene load_steps=8 format=3 uid="uid://xqoiyxrn10js"] | ||
|
||
[ext_resource type="Script" path="res://scenes/player_character/player_character.gd" id="1_rmbqt"] | ||
[ext_resource type="Texture2D" uid="uid://bdap4f6w37byq" path="res://assets/Illustration95.png" id="2_0gsa3"] | ||
|
||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_nrvy8"] | ||
size = Vector2(14, 15.5) | ||
|
||
[sub_resource type="Animation" id="Animation_17yri"] | ||
resource_name = "walk" | ||
tracks/0/type = "value" | ||
tracks/0/imported = false | ||
tracks/0/enabled = true | ||
tracks/0/path = NodePath("../Sprite2D:frame") | ||
tracks/0/interp = 1 | ||
tracks/0/loop_wrap = true | ||
tracks/0/keys = { | ||
"times": PackedFloat32Array(0.00177135, 0.297301, 0.529481, 0.858887), | ||
"transitions": PackedFloat32Array(1, 1, 1, 1), | ||
"update": 1, | ||
"values": [0, 1, 2, 0] | ||
} | ||
|
||
[sub_resource type="Animation" id="Animation_sndo4"] | ||
resource_name = "up" | ||
tracks/0/type = "value" | ||
tracks/0/imported = false | ||
tracks/0/enabled = true | ||
tracks/0/path = NodePath("../Sprite2D:frame") | ||
tracks/0/interp = 1 | ||
tracks/0/loop_wrap = true | ||
tracks/0/keys = { | ||
"times": PackedFloat32Array(0.00553417, 0.15295, 0.32358), | ||
"transitions": PackedFloat32Array(1, 1, 1), | ||
"update": 1, | ||
"values": [3, 4, 5] | ||
} | ||
|
||
[sub_resource type="Animation" id="Animation_v72g0"] | ||
resource_name = "left" | ||
tracks/0/type = "value" | ||
tracks/0/imported = false | ||
tracks/0/enabled = true | ||
tracks/0/path = NodePath("../Sprite2D:frame") | ||
tracks/0/interp = 1 | ||
tracks/0/loop_wrap = true | ||
tracks/0/keys = { | ||
"times": PackedFloat32Array(0.0161553, 0.319068, 0.69064), | ||
"transitions": PackedFloat32Array(1, 1, 1), | ||
"update": 1, | ||
"values": [6, 7, 8] | ||
} | ||
|
||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_hbknw"] | ||
_data = { | ||
"down": SubResource("Animation_17yri"), | ||
"right": SubResource("Animation_v72g0"), | ||
"up": SubResource("Animation_sndo4") | ||
} | ||
|
||
[node name="PlayerCharacter" type="CharacterBody2D"] | ||
script = ExtResource("1_rmbqt") | ||
|
||
[node name="RayCast2D" type="RayCast2D" parent="."] | ||
scale = Vector2(1, 1) | ||
target_position = Vector2(0, 19) | ||
|
||
[node name="Sprite2D" type="Sprite2D" parent="."] | ||
scale = Vector2(0.458, 0.368) | ||
texture = ExtResource("2_0gsa3") | ||
hframes = 3 | ||
vframes = 3 | ||
|
||
[node name="Camera2D" type="Camera2D" parent="."] | ||
position_smoothing_enabled = true | ||
position_smoothing_speed = 10.0 | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] | ||
position = Vector2(0, 2.38419e-07) | ||
scale = Vector2(-0.811343, 1.12881) | ||
shape = SubResource("RectangleShape2D_nrvy8") | ||
|
||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."] | ||
root_node = NodePath("../RayCast2D") | ||
libraries = { | ||
"": SubResource("AnimationLibrary_hbknw") | ||
} | ||
|
||
[node name="AnimationPlayer" type="AnimationPlayer" parent="AnimationPlayer"] | ||
root_node = NodePath("../RayCast2D") | ||
libraries = { | ||
"": SubResource("AnimationLibrary_hbknw") | ||
} |