Skip to content

Commit

Permalink
Merge branch 'ca-fe-more-godot'
Browse files Browse the repository at this point in the history
  • Loading branch information
chazzox committed Mar 3, 2024
2 parents dcce883 + 4da4d83 commit d600a6f
Show file tree
Hide file tree
Showing 13 changed files with 249 additions and 69 deletions.
79 changes: 79 additions & 0 deletions game-source/WebSockets.gd
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()
Binary file added game-source/assets/Illustration95.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

importer="texture"
type="CompressedTexture2D"
uid="uid://bay85nk58yj5e"
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
uid="uid://bdap4f6w37byq"
path="res://.godot/imported/Illustration95.png-83b3dbf36a7985d78f181801efd673ad.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://icon.svg"
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
source_file="res://assets/Illustration95.png"
dest_files=["res://.godot/imported/Illustration95.png-83b3dbf36a7985d78f181801efd673ad.ctex"]

[params]

Expand All @@ -32,6 +32,3 @@ process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
1 change: 0 additions & 1 deletion game-source/icon.svg

This file was deleted.

22 changes: 0 additions & 22 deletions game-source/main.tscn

This file was deleted.

15 changes: 0 additions & 15 deletions game-source/player_character.gd

This file was deleted.

20 changes: 0 additions & 20 deletions game-source/player_character.tscn

This file was deleted.

11 changes: 9 additions & 2 deletions game-source/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ config_version=5
[application]

config/name="Cosmic Kube"
run/main_scene="res://main.tscn"
run/main_scene="res://scenes/main/main.tscn"
config/features=PackedStringArray("4.2", "GL Compatibility")
config/icon="res://icon.svg"

[autoload]

WebSockets="*res://WebSockets.gd"

[display]

window/stretch/mode="canvas_items"

[input]

Expand Down
4 changes: 2 additions & 2 deletions game-source/box.tscn → game-source/scenes/box/box.tscn
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[gd_scene load_steps=2 format=3 uid="uid://cv6rvnsd8jc4u"]

[ext_resource type="Texture2D" uid="uid://c6jm42o02gsfr" path="res://assets/box.png" id="1_q4dmh"]
[ext_resource type="Texture2D" uid="uid://c6jm42o02gsfr" path="res://assets/box.png" id="1_blfj8"]

[node name="CharacterBody2D" type="CharacterBody2D"]

[node name="Box" type="Sprite2D" parent="."]
position = Vector2(33, 52)
texture = ExtResource("1_q4dmh")
texture = ExtResource("1_blfj8")

[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
visible = false
Expand Down
21 changes: 21 additions & 0 deletions game-source/scenes/main/main.gd
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")

11 changes: 11 additions & 0 deletions game-source/scenes/main/main.tscn
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)
30 changes: 30 additions & 0 deletions game-source/scenes/player_character/player_character.gd
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])

93 changes: 93 additions & 0 deletions game-source/scenes/player_character/player_character.tscn
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")
}

0 comments on commit d600a6f

Please sign in to comment.