From 00d3088e2184aff6af64d3fa17307f2462f6d49e Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Fri, 26 Jan 2024 21:07:19 +0100 Subject: [PATCH] Initial commit --- .gitattributes | 2 ++ .gitignore | 2 ++ Game.gd | 11 +++++++ entities/Player.gd | 59 +++++++++++++++++++++++++++++++++ icon.svg | 1 + icon.svg.import | 37 +++++++++++++++++++++ project.godot | 64 ++++++++++++++++++++++++++++++++++++ scenes/Game.tscn | 41 +++++++++++++++++++++++ scenes/World.gd | 17 ++++++++++ scenes/World.tscn | 82 ++++++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 316 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 Game.gd create mode 100644 entities/Player.gd create mode 100644 icon.svg create mode 100644 icon.svg.import create mode 100644 project.godot create mode 100644 scenes/Game.tscn create mode 100644 scenes/World.gd create mode 100644 scenes/World.tscn diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8ad74f7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Normalize EOL for all files that Git considers text files. +* text=auto eol=lf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4709183 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Godot 4+ specific ignores +.godot/ diff --git a/Game.gd b/Game.gd new file mode 100644 index 0000000..e08925d --- /dev/null +++ b/Game.gd @@ -0,0 +1,11 @@ +extends Node + + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass diff --git a/entities/Player.gd b/entities/Player.gd new file mode 100644 index 0000000..71dd893 --- /dev/null +++ b/entities/Player.gd @@ -0,0 +1,59 @@ +extends CharacterBody3D + +@export var move_right_action := "move_right" +@export var move_left_action := "move_left" +@export var move_down_action := "move_down" +@export var move_up_action := "move_up" +@export var dash_action := "dash" + +@onready var geometry = $Geometry + +var angle = 0 +var is_dashing = false +var dash_time = 0 + +const SPEED = 5.0 +const JUMP_VELOCITY = 4.5 +const DASH_SPEED: float = 20 +const DASH_DURATION: float = 0.2 + +# Get the gravity from the project settings to be synced with RigidBody nodes. +var gravity = ProjectSettings.get_setting("physics/3d/default_gravity") + +func _physics_process(delta): + # Add the gravity. + if not is_on_floor(): + velocity.y -= gravity * delta + + # Handle jump. + if Input.is_action_just_pressed("ui_accept") and is_on_floor(): + velocity.y = JUMP_VELOCITY + + # Get the input direction and handle the movement/deceleration. + # As good practice, you should replace UI actions with custom gameplay actions. + var input_dir = Input.get_vector(move_left_action, move_right_action, move_up_action, move_down_action) + var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() + if direction: + velocity.x = direction.x * SPEED + velocity.z = direction.z * SPEED + angle = direction.signed_angle_to(Vector3.FORWARD, Vector3.UP) + geometry.global_basis = Basis.from_euler(Vector3(0, -angle, 0)) + else: + velocity.x = move_toward(velocity.x, 0, SPEED) + velocity.z = move_toward(velocity.z, 0, SPEED) + + if Input.is_action_just_pressed("dash_p1"): + is_dashing = true; + dash_time = DASH_DURATION + + if is_dashing: + velocity.x = sin(angle) * DASH_SPEED + velocity.z = -cos(angle) * DASH_SPEED + + geometry.global_basis = Basis.from_euler(Vector3(-0.3, -angle, 0)) + + dash_time -= delta + if dash_time <= 0: + is_dashing = false + + move_and_slide() diff --git a/icon.svg b/icon.svg new file mode 100644 index 0000000..b370ceb --- /dev/null +++ b/icon.svg @@ -0,0 +1 @@ + diff --git a/icon.svg.import b/icon.svg.import new file mode 100644 index 0000000..e5c50a5 --- /dev/null +++ b/icon.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://5xyjcnjoqxjm" +path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.svg" +dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +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 diff --git a/project.godot b/project.godot new file mode 100644 index 0000000..aead39b --- /dev/null +++ b/project.godot @@ -0,0 +1,64 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=5 + +[application] + +config/name="DashBoomColorClash" +run/main_scene="res://scenes/Game.tscn" +config/features=PackedStringArray("4.2", "GL Compatibility") +config/icon="res://icon.svg" + +[dotnet] + +project/assembly_name="DashBoomColorClash" + +[input] + +move_up_p1={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":-1.0,"script":null) +, 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":87,"key_label":0,"unicode":118,"echo":false,"script":null) +] +} +move_down_p1={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null) +, 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":83,"key_label":0,"unicode":105,"echo":false,"script":null) +] +} +move_left_p1={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null) +, 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":65,"key_label":0,"unicode":117,"echo":false,"script":null) +] +} +move_right_p1={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null) +, 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":68,"key_label":0,"unicode":97,"echo":false,"script":null) +] +} +dash_p1={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"script":null) +, 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":79,"key_label":0,"unicode":102,"echo":false,"script":null) +] +} +bomp_p1={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":1,"pressure":0.0,"pressed":true,"script":null) +, 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":80,"key_label":0,"unicode":113,"echo":false,"script":null) +] +} + +[rendering] + +renderer/rendering_method="gl_compatibility" +renderer/rendering_method.mobile="gl_compatibility" diff --git a/scenes/Game.tscn b/scenes/Game.tscn new file mode 100644 index 0000000..9b16c83 --- /dev/null +++ b/scenes/Game.tscn @@ -0,0 +1,41 @@ +[gd_scene load_steps=5 format=3 uid="uid://rd48gl8k5x34"] + +[ext_resource type="Script" path="res://Game.gd" id="1_7jqda"] +[ext_resource type="PackedScene" uid="uid://b1nm5h3yccr16" path="res://scenes/World.tscn" id="2_voimb"] + +[sub_resource type="World3D" id="World3D_5g233"] + +[sub_resource type="ViewportTexture" id="ViewportTexture_2lmj8"] +viewport_path = NodePath("Viewport") + +[node name="Game" type="Node"] +script = ExtResource("1_7jqda") + +[node name="Viewport" type="SubViewport" parent="."] +own_world_3d = true +world_3d = SubResource("World3D_5g233") +size = Vector2i(256, 256) + +[node name="World" parent="Viewport" instance=ExtResource("2_voimb")] + +[node name="Panel" type="Panel" parent="."] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_horizontal = 6 +size_flags_vertical = 6 + +[node name="WorldView" type="TextureRect" parent="Panel"] +texture_filter = 1 +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 +texture = SubResource("ViewportTexture_2lmj8") +stretch_mode = 6 diff --git a/scenes/World.gd b/scenes/World.gd new file mode 100644 index 0000000..3548fc1 --- /dev/null +++ b/scenes/World.gd @@ -0,0 +1,17 @@ +extends Node3D + +@onready var player1: CharacterBody3D = $Player1 +@onready var camera: Camera3D = $Camera3D + +var camera_offset: Vector3; + +# Called when the node enters the scene tree for the first time. +func _ready(): + camera_offset = camera.global_position - player1.global_position + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + camera.global_position = player1.global_position + camera_offset + pass diff --git a/scenes/World.tscn b/scenes/World.tscn new file mode 100644 index 0000000..47b6f09 --- /dev/null +++ b/scenes/World.tscn @@ -0,0 +1,82 @@ +[gd_scene load_steps=11 format=3 uid="uid://b1nm5h3yccr16"] + +[ext_resource type="Script" path="res://entities/Player.gd" id="1_ca7jo"] +[ext_resource type="Script" path="res://scenes/World.gd" id="1_gtcjp"] + +[sub_resource type="FastNoiseLite" id="FastNoiseLite_wonuc"] +noise_type = 0 +frequency = 0.014 +fractal_lacunarity = 3.0 + +[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_iklfu"] +width = 32 +height = 32 +seamless = true +seamless_blend_skirt = 0.857 +normalize = false +noise = SubResource("FastNoiseLite_wonuc") + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_b5tqf"] +albedo_color = Color(0.113725, 0.431373, 0.266667, 0.933333) +albedo_texture = SubResource("NoiseTexture2D_iklfu") +uv1_triplanar = true +texture_filter = 0 + +[sub_resource type="CylinderMesh" id="CylinderMesh_a3rev"] +material = SubResource("StandardMaterial3D_b5tqf") +top_radius = 20.0 +bottom_radius = 20.0 +height = 0.2 +radial_segments = 8 + +[sub_resource type="CylinderShape3D" id="CylinderShape3D_ar5d4"] +height = 0.2 +radius = 20.0 + +[sub_resource type="BoxMesh" id="BoxMesh_yle83"] +size = Vector3(0.24, 0.75, 0.24) + +[sub_resource type="CylinderShape3D" id="CylinderShape3D_rwgp3"] +height = 0.75 +radius = 0.15 + +[sub_resource type="Environment" id="Environment_f3jci"] +ambient_light_source = 3 +ambient_light_color = Color(0.521569, 0.521569, 0.521569, 1) +ambient_light_energy = 2.64 + +[node name="World" type="Node3D"] +script = ExtResource("1_gtcjp") + +[node name="Platform" type="StaticBody3D" parent="."] + +[node name="MeshInstance3D" type="MeshInstance3D" parent="Platform"] +mesh = SubResource("CylinderMesh_a3rev") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="Platform"] +shape = SubResource("CylinderShape3D_ar5d4") + +[node name="Player1" type="CharacterBody3D" parent="."] +script = ExtResource("1_ca7jo") +move_right_action = "move_right_p1" +move_left_action = "move_left_p1" +move_down_action = "move_down_p1" +move_up_action = "move_up_p1" + +[node name="Geometry" type="MeshInstance3D" parent="Player1"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.472544, 0) +mesh = SubResource("BoxMesh_yle83") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="Player1"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.496337, 0) +shape = SubResource("CylinderShape3D_rwgp3") + +[node name="WorldEnvironment" type="WorldEnvironment" parent="."] +environment = SubResource("Environment_f3jci") + +[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] +transform = Transform3D(-4.37114e-08, -0.528438, 0.848972, 0, 0.848972, 0.528438, -1, 2.30988e-08, -3.71097e-08, 0.936448, 2.01321, 1.19116) +shadow_enabled = true + +[node name="Camera3D" type="Camera3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 0.305147, 0.952305, 0, -0.952305, 0.305147, -4.26326e-13, 4.70264, 1.09419)