Add box sprite and scene

main
Santeri Huotari 2024-02-23 02:02:01 +02:00
parent a96da9006f
commit b236a198bb
8 changed files with 134 additions and 2 deletions

8
Tlob.csproj 100644
View File

@ -0,0 +1,8 @@
<Project Sdk="Godot.NET.Sdk/4.2.1">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' ">net7.0</TargetFramework>
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'ios' ">net8.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
</PropertyGroup>
</Project>

19
Tlob.sln 100644
View File

@ -0,0 +1,19 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tlob", "Tlob.csproj", "{DAF2229D-5187-4A27-A81D-0555D20817E2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
ExportDebug|Any CPU = ExportDebug|Any CPU
ExportRelease|Any CPU = ExportRelease|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DAF2229D-5187-4A27-A81D-0555D20817E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DAF2229D-5187-4A27-A81D-0555D20817E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DAF2229D-5187-4A27-A81D-0555D20817E2}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU
{DAF2229D-5187-4A27-A81D-0555D20817E2}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU
{DAF2229D-5187-4A27-A81D-0555D20817E2}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU
{DAF2229D-5187-4A27-A81D-0555D20817E2}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU
EndGlobalSection
EndGlobal

17
scenes/box.tscn 100644
View File

@ -0,0 +1,17 @@
[gd_scene load_steps=3 format=3 uid="uid://dur0i50oao18u"]
[ext_resource type="Texture2D" uid="uid://be6qojhnjml47" path="res://sprites/box.png" id="1_uib42"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_pnqxx"]
size = Vector2(42, 42)
[node name="Node2D" type="Node2D"]
[node name="Sprite2D" type="Sprite2D" parent="."]
scale = Vector2(0.328125, 0.328125)
texture = ExtResource("1_uib42")
[node name="StaticBody2D" type="StaticBody2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
shape = SubResource("RectangleShape2D_pnqxx")

View File

@ -1,3 +1,12 @@
[gd_scene format=3 uid="uid://byuw363qi2nwu"]
[gd_scene load_steps=3 format=3 uid="uid://byuw363qi2nwu"]
[ext_resource type="PackedScene" uid="uid://cpqrufo1gdajy" path="res://scenes/tlob.tscn" id="1_f4jm3"]
[ext_resource type="PackedScene" uid="uid://dur0i50oao18u" path="res://scenes/box.tscn" id="2_n63uh"]
[node name="Main" type="Node2D"]
[node name="Tlob" parent="." instance=ExtResource("1_f4jm3")]
position = Vector2(0, -3)
[node name="Node2D" parent="." instance=ExtResource("2_n63uh")]
position = Vector2(635, -362)

39
scenes/tlob.cs 100644
View File

@ -0,0 +1,39 @@
using Godot;
using System;
public partial class tlob : CharacterBody2D
{
public const float Speed = 300.0f;
public const float JumpVelocity = -400.0f;
// Get the gravity from the project settings to be synced with RigidBody nodes.
public float gravity = ProjectSettings.GetSetting("physics/2d/default_gravity").AsSingle();
public override void _PhysicsProcess(double delta)
{
Vector2 velocity = Velocity;
// Add the gravity.
if (!IsOnFloor())
velocity.Y += gravity * (float)delta;
// Handle Jump.
if (Input.IsActionJustPressed("ui_accept") && IsOnFloor())
velocity.Y = JumpVelocity;
// Get the input direction and handle the movement/deceleration.
// As good practice, you should replace UI actions with custom gameplay actions.
Vector2 direction = Input.GetVector("ui_left", "ui_right", "ui_up", "ui_down");
if (direction != Vector2.Zero)
{
velocity.X = direction.X * Speed;
}
else
{
velocity.X = Mathf.MoveToward(Velocity.X, 0, Speed);
}
Velocity = velocity;
MoveAndSlide();
}
}

View File

@ -1,14 +1,20 @@
[gd_scene load_steps=3 format=3 uid="uid://cpqrufo1gdajy"]
[gd_scene load_steps=4 format=3 uid="uid://cpqrufo1gdajy"]
[ext_resource type="Script" path="res://scenes/tlob.cs" id="1_i865j"]
[ext_resource type="Texture2D" uid="uid://dfjrr8hcd3ol" path="res://sprites/tlob.png" id="1_tg6nh"]
[sub_resource type="CircleShape2D" id="CircleShape2D_5pvct"]
radius = 64.0
[node name="Tlob" type="CharacterBody2D"]
motion_mode = 1
script = ExtResource("1_i865j")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_5pvct")
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("1_tg6nh")
[node name="Camera2D" type="Camera2D" parent="."]
zoom = Vector2(0.5, 0.5)

BIN
sprites/box.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 803 B

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://be6qojhnjml47"
path="res://.godot/imported/box.png-88e8c9a9152bfabd2b270e3db2186223.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/box.png"
dest_files=["res://.godot/imported/box.png-88e8c9a9152bfabd2b270e3db2186223.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