From d5c27030c5cb7ec14f6a2f5bc85642ab4715455c Mon Sep 17 00:00:00 2001 From: Tabby <41929769+tabby-cat-nya@users.noreply.github.com> Date: Sun, 11 May 2025 20:04:24 +1000 Subject: [PATCH] made a lil asteroids game but now messing around with packed scenes so putting a save heere --- base modules/channel_controller.gd | 1 + base modules/test_channel.tscn | 19 ++--------- games/asteroids/asteroids.tscn | 43 +++++++++++++++++++++++++ games/asteroids/ship_controller.gd | 13 ++++++++ games/asteroids/ship_controller.gd.uid | 1 + project.godot | 13 ++++++++ sprites/asteroidsShip.png | Bin 0 -> 1185 bytes sprites/asteroidsShip.png.import | 34 +++++++++++++++++++ test_game.tscn | 21 ++++++++++++ 9 files changed, 129 insertions(+), 16 deletions(-) create mode 100644 games/asteroids/asteroids.tscn create mode 100644 games/asteroids/ship_controller.gd create mode 100644 games/asteroids/ship_controller.gd.uid create mode 100644 sprites/asteroidsShip.png create mode 100644 sprites/asteroidsShip.png.import create mode 100644 test_game.tscn diff --git a/base modules/channel_controller.gd b/base modules/channel_controller.gd index 8344125..c222caf 100644 --- a/base modules/channel_controller.gd +++ b/base modules/channel_controller.gd @@ -3,6 +3,7 @@ class_name Channel @export var channel_name : String +@export var channel_scene : PackedScene @export_group("Node References") @export var offline_channel_cover : TextureRect @export var game_viewport : SubViewport diff --git a/base modules/test_channel.tscn b/base modules/test_channel.tscn index 89bedb4..b66bcfe 100644 --- a/base modules/test_channel.tscn +++ b/base modules/test_channel.tscn @@ -1,9 +1,8 @@ -[gd_scene load_steps=6 format=3 uid="uid://63rik2noj8id"] +[gd_scene load_steps=5 format=3 uid="uid://63rik2noj8id"] -[ext_resource type="Texture2D" uid="uid://diilj7xuttpqu" path="res://icon.svg" id="1_iix04"] [ext_resource type="Script" uid="uid://h43mmpjmmir4" path="res://base modules/channel_controller.gd" id="1_r07ln"] [ext_resource type="Texture2D" uid="uid://cyo0wl4dt3td1" path="res://sprites/offline_channel.png" id="2_01b3p"] -[ext_resource type="Script" uid="uid://dlqr0ghj0sh6a" path="res://base modules/move_test.gd" id="2_jbg2j"] +[ext_resource type="PackedScene" uid="uid://ch1x8pfdu2b1g" path="res://test_game.tscn" id="3_27arb"] [sub_resource type="ViewportTexture" id="ViewportTexture_iix04"] viewport_path = NodePath("GameViewport") @@ -48,16 +47,4 @@ handle_input_locally = false size = Vector2i(640, 360) render_target_update_mode = 4 -[node name="ColorRect" type="TextureRect" parent="GameViewport"] -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 -texture = ExtResource("1_iix04") - -[node name="Node2D" type="Node2D" parent="GameViewport"] -script = ExtResource("2_jbg2j") - -[node name="Sprite2D" type="Sprite2D" parent="GameViewport/Node2D"] -texture = ExtResource("1_iix04") +[node name="Game" parent="GameViewport" instance=ExtResource("3_27arb")] diff --git a/games/asteroids/asteroids.tscn b/games/asteroids/asteroids.tscn new file mode 100644 index 0000000..023db0e --- /dev/null +++ b/games/asteroids/asteroids.tscn @@ -0,0 +1,43 @@ +[gd_scene load_steps=7 format=3 uid="uid://bw1hhx7lyfonr"] + +[ext_resource type="Script" uid="uid://brih2jftm2tsa" path="res://games/asteroids/ship_controller.gd" id="1_6dc0m"] +[ext_resource type="Texture2D" uid="uid://dqorec3q3h3pp" path="res://sprites/asteroidsShip.png" id="2_j0tb1"] + +[sub_resource type="Gradient" id="Gradient_4laqq"] +interpolation_mode = 1 +offsets = PackedFloat32Array(0, 0.882845) + +[sub_resource type="FastNoiseLite" id="FastNoiseLite_ceqm6"] +frequency = 0.0683 + +[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_f07rl"] +width = 640 +height = 360 +color_ramp = SubResource("Gradient_4laqq") +noise = SubResource("FastNoiseLite_ceqm6") + +[sub_resource type="CircleShape2D" id="CircleShape2D_dtqgl"] +radius = 26.0192 + +[node name="Asteroids" type="Node"] + +[node name="TextureRect" type="TextureRect" parent="."] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +texture = SubResource("NoiseTexture2D_f07rl") + +[node name="Ship" type="RigidBody2D" parent="."] +position = Vector2(327, 183) +gravity_scale = 0.0 +script = ExtResource("1_6dc0m") +rotation_force = 10 +drag = 10 + +[node name="Sprite2D" type="Sprite2D" parent="Ship"] +texture = ExtResource("2_j0tb1") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Ship"] +shape = SubResource("CircleShape2D_dtqgl") diff --git a/games/asteroids/ship_controller.gd b/games/asteroids/ship_controller.gd new file mode 100644 index 0000000..d90b0aa --- /dev/null +++ b/games/asteroids/ship_controller.gd @@ -0,0 +1,13 @@ +extends RigidBody2D + +@export var rotation_force = 1 +@export var drag = 2 +@export var top_speed = 6 + +func _process(delta: float) -> void: + var input = Input.get_axis("asteroids_left","asteroids_right") + angular_velocity += rotation_force * delta * input + print(angular_velocity) + angular_velocity = clampf(angular_velocity, -top_speed, top_speed) + if(input == 0): + angular_velocity = move_toward(angular_velocity, 0, delta * drag) diff --git a/games/asteroids/ship_controller.gd.uid b/games/asteroids/ship_controller.gd.uid new file mode 100644 index 0000000..eee13c8 --- /dev/null +++ b/games/asteroids/ship_controller.gd.uid @@ -0,0 +1 @@ +uid://brih2jftm2tsa diff --git a/project.godot b/project.godot index 55e8e05..22890bd 100644 --- a/project.godot +++ b/project.godot @@ -21,6 +21,19 @@ window/size/viewport_width=640 window/size/viewport_height=360 window/stretch/mode="canvas_items" +[input] + +asteroids_left={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":67,"key_label":0,"unicode":99,"location":0,"echo":false,"script":null) +] +} +asteroids_right={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":86,"key_label":0,"unicode":118,"location":0,"echo":false,"script":null) +] +} + [rendering] renderer/rendering_method="gl_compatibility" diff --git a/sprites/asteroidsShip.png b/sprites/asteroidsShip.png new file mode 100644 index 0000000000000000000000000000000000000000..cc0640d54b834eba7ea4b4a0e56f582a0c29e9b1 GIT binary patch literal 1185 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucL5ULAh?3y^w370~qEv=}#LT=BJwMkF1yemk zJ)_@yn70AdY)g&sO!M^AV&DLBSQ(@kSs56CEH5CIhO$Af(O_f-i!%Y)hKx)M0zf(n zh%?(+z~WgzHV7mDF-Sj*MzfTGnSo&fI|B<)g@KW=0pkLQsURJ!3m_&<0kT1W31|)z zSY?o<1&{^RWoTdkl6`sgo5iVHIaLe{%mJP*jv*CsZ)f{=_y)=xe?D`=0k<^wX(z%u zKgO$VN>E&KqN~+}+pNoHx<#W>?FxFEw?~%hO-& zsg{4gul(NL=RKcS=I{S*o%y5oUG?{WXD$eKx+qON@!wl@<>QdmS3^ZS1Lv#`(aN86 z{b_T9U69KA6NjE`*Pr9*sXO^*3J0h67F{uU77pW+x+-g~Z?mWoRPa&0K5>Kd?W7aC zIKKt(IJ;w1+NbcR>U%mpI`!$N}Et2^z zY_3NHz4RxlJL-0yU{*PE^%`#+ zr@#aQhnt>mXBvBL%-SbD$SM8i*U-@7J;nFQZp#gYyR51;9UKn%p0fIMQ|5+6^xVCo z3JMPmQ&}tX`Eus0ITyz*FyTYfCEvJN%(G8EQ4;!=JzM@gD~CsgcckCES$M_;mSd|A}iX=S@uI`5$#Vr%B|%gSjqj>;L{dD)Fhf=PJ+t zz}vrA)Ef>yU8`4KTlqS@us0{+$NF3U<}P3{*mLK}lQebny*lS6t>yV2e7jz_hoNo0 z>rUUQGmf)_Q}_@6zqZY=N#MYTVh!h%jg}iGrvGPTvv+y*ma+6>9K&J#1vV-{*%Mdq zoqh24*0cTBnIz)Y?TD$YWWVyMIVbH0_bs#b?LaZR*PmuiKVPRC@4