exampleShittyPlatformer

This commit is contained in:
Misha Vicha
2026-03-22 16:08:40 +01:00
commit 6b640f5090
15 changed files with 386 additions and 0 deletions

75
code/Blorbo.cs Normal file
View File

@@ -0,0 +1,75 @@
using Godot;
using System;
public partial class Blorbo : CharacterBody2D
{
public const float TerminalVelocity = 500.0f; // Max falling speed
public const float Speed = 60.0f;
public const float JumpVelocity = -160.0f;
public const float Acceleration = 400.0f; // How much we speed up/second
public const float Decelleration = 400.0f; // Slow down/second
public const float AirFrictionMultiplier = 0.2f; // How much less control and speedup we have in the air
public override void _PhysicsProcess(double delta)
{
Vector2 velocity = Velocity;
// Add the gravity.
if (!IsOnFloor())
{
velocity += GetGravity() * (float)delta;
velocity.Y = Math.Min(TerminalVelocity, velocity.Y);
}
// 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");
float friction_multiplier = 1.0f * getFloorFriction();
if (!IsOnFloor()){
friction_multiplier *= AirFrictionMultiplier;
}
if (direction != Vector2.Zero)
{
velocity.X += direction.X * Acceleration * (float)delta * friction_multiplier;
velocity.X = Math.Min(Speed, velocity.X);
}
else
{
velocity.X = Mathf.MoveToward(Velocity.X, 0, Decelleration * (float)delta * friction_multiplier);
}
Velocity = velocity;
MoveAndSlide();
}
private float getFloorFriction() {
Marker2D floorCheck = GetNode<Marker2D>("FloorCheck");
Vector2 checkedPosition = floorCheck.GlobalPosition;
GD.Print(checkedPosition);
for (int i = 0; i < GetSlideCollisionCount(); i++)
{
var collision = GetSlideCollision(i);
var collider = collision.GetCollider();
if (collider is TileMapLayer tileMap)
{
TileData data = tileMap.GetCellTileData(
tileMap.LocalToMap(
tileMap.ToLocal(checkedPosition)));
GD.Print(collider.ToString());
if (data != null)
{
return (float)data.GetCustomData("frictionMul");
}
}
}
return 1.0f;
}
}

1
code/Blorbo.cs.uid Normal file
View File

@@ -0,0 +1 @@
uid://bl3pxakeoapd2

View File

@@ -0,0 +1,8 @@
<Project Sdk="Godot.NET.Sdk/4.6.1">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' ">net9.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
<RootNamespace>funnyplatformertest</RootNamespace>
</PropertyGroup>
</Project>

19
funny-platformer-test.sln Normal file
View File

@@ -0,0 +1,19 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "funny-platformer-test", "funny-platformer-test.csproj", "{36BD6405-AC97-4E60-B10A-F036901DBC8E}"
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
{36BD6405-AC97-4E60-B10A-F036901DBC8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{36BD6405-AC97-4E60-B10A-F036901DBC8E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{36BD6405-AC97-4E60-B10A-F036901DBC8E}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU
{36BD6405-AC97-4E60-B10A-F036901DBC8E}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU
{36BD6405-AC97-4E60-B10A-F036901DBC8E}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU
{36BD6405-AC97-4E60-B10A-F036901DBC8E}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU
EndGlobalSection
EndGlobal

1
icon.svg Normal file
View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128"><rect width="124" height="124" x="2" y="2" fill="#363d52" stroke="#212532" stroke-width="4" rx="14"/><g fill="#fff" transform="translate(12.322 12.322)scale(.101)"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 814 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H446l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c0 34 58 34 58 0v-86c0-34-58-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042" transform="translate(12.322 12.322)scale(.101)"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></svg>

After

Width:  |  Height:  |  Size: 995 B

43
icon.svg.import Normal file
View File

@@ -0,0 +1,43 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bs8l3d8dqiojf"
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/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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

BIN
icons/mob/blorbo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 B

View File

@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bu43jlfcn6utc"
path="res://.godot/imported/blorbo.png-fa2feb106dcafa361191aabc22c4d5f9.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icons/mob/blorbo.png"
dest_files=["res://.godot/imported/blorbo.png-fa2feb106dcafa361191aabc22c4d5f9.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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

BIN
icons/tiles/tileset.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 839 B

View File

@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://ct2nodxxidsxi"
path="res://.godot/imported/tileset.png-73f5675dd765da508cb18be4efc563ee.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icons/tiles/tileset.png"
dest_files=["res://.godot/imported/tileset.png-73f5675dd765da508cb18be4efc563ee.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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

38
project.godot Normal file
View File

@@ -0,0 +1,38 @@
; 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="funny-platformer-test"
run/main_scene="uid://b1gniim34ay75"
config/features=PackedStringArray("4.6", "C#", "GL Compatibility")
config/icon="res://icon.svg"
[dotnet]
project/assembly_name="funny-platformer-test"
[layer_names]
2d_physics/layer_1="AlwaysCollide"
2d_physics/layer_2="Killision"
2d_physics/layer_3="Player"
[physics]
3d/physics_engine="Jolt Physics"
2d/default_gravity=350.0
[rendering]
textures/canvas_textures/default_texture_filter=0
rendering_device/driver.windows="d3d12"
renderer/rendering_method="gl_compatibility"
renderer/rendering_method.mobile="gl_compatibility"

23
scenes/blorbo.tscn Normal file
View File

@@ -0,0 +1,23 @@
[gd_scene format=3 uid="uid://6hvtko6ur466"]
[ext_resource type="Script" uid="uid://bl3pxakeoapd2" path="res://code/Blorbo.cs" id="1_mfum6"]
[ext_resource type="Texture2D" uid="uid://bu43jlfcn6utc" path="res://icons/mob/blorbo.png" id="2_3sc2b"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_dn5c8"]
size = Vector2(14, 15)
[node name="Blorbo" type="CharacterBody2D" unique_id=297375332]
platform_floor_layers = 4294967041
platform_wall_layers = 1
script = ExtResource("1_mfum6")
[node name="Blorbo-Icon" type="Sprite2D" parent="." unique_id=383159907]
texture_filter = 1
texture = ExtResource("2_3sc2b")
[node name="Collider" type="CollisionShape2D" parent="." unique_id=368836316]
position = Vector2(0, 0.5)
shape = SubResource("RectangleShape2D_dn5c8")
[node name="FloorCheck" type="Marker2D" parent="." unique_id=1675033941]
position = Vector2(0, 9)

58
scenes/mainscene.tscn Normal file
View File

@@ -0,0 +1,58 @@
[gd_scene format=4 uid="uid://b1gniim34ay75"]
[ext_resource type="PackedScene" uid="uid://6hvtko6ur466" path="res://scenes/blorbo.tscn" id="1_golqe"]
[ext_resource type="Texture2D" uid="uid://ct2nodxxidsxi" path="res://icons/tiles/tileset.png" id="2_golqe"]
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_nx3wj"]
texture = ExtResource("2_golqe")
0:0/0 = 0
0:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)
0:0/0/custom_data_0 = 1.0
1:0/0 = 0
1:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)
1:0/0/custom_data_0 = 1.0
3:0/0 = 0
3:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)
3:0/0/custom_data_0 = 0.1
[sub_resource type="TileSet" id="TileSet_dn5c8"]
physics_layer_0/collision_layer = 1
physics_layer_0/collision_mask = 0
custom_data_layer_0/name = "frictionMul"
custom_data_layer_0/type = 3
sources/1 = SubResource("TileSetAtlasSource_nx3wj")
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_nx3wj"]
distance = -81.0
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_golqe"]
normal = Vector2(1, 0)
distance = -145.0
[node name="Node2D" type="Node2D" unique_id=2013336402]
[node name="Blorbo" parent="." unique_id=297375332 instance=ExtResource("1_golqe")]
position = Vector2(-134, 6)
collision_layer = 5
collision_mask = 7
[node name="Layer0" type="TileMapLayer" parent="." unique_id=1892214682]
texture_filter = 1
tile_map_data = PackedByteArray("AAD+/wQAAQADAAAAAAD9/wQAAQADAAAAAAD5/wQAAQAAAAAAAAD4/wQAAQAAAAAAAAD3/wQAAQAAAAAAAAADAAEAAQABAAAAAAAEAAEAAQABAAAAAAD3/wEAAQABAAAAAAD4/wEAAQABAAAAAAD5/wEAAQABAAAAAAD5/wIAAQAAAAAAAAD5/wMAAQAAAAAAAAD4/wMAAQAAAAAAAAD4/wIAAQAAAAAAAAD3/wIAAQAAAAAAAAD3/wMAAQAAAAAAAAD9/wMAAQADAAAAAAD+/wMAAQADAAAAAAD+/wIAAQADAAAAAAD9/wIAAQADAAAAAAADAAIAAQAAAAAAAAADAAMAAQAAAAAAAAADAAQAAQAAAAAAAAAEAAQAAQAAAAAAAAAEAAMAAQAAAAAAAAAEAAIAAQAAAAAAAAD//wIAAQADAAAAAAD//wMAAQADAAAAAAD//wQAAQADAAAAAAAAAAQAAQADAAAAAAAAAAMAAQADAAAAAAAAAAIAAQADAAAAAAABAP3/AQADAAAAAAACAP3/AQADAAAAAAADAP3/AQADAAAAAAAGAP//AQAAAAAAAAAHAP//AQAAAAAAAAD+//3/AQADAAAAAAD9//3/AQADAAAAAAD6//3/AQADAAAAAAD5//3/AQADAAAAAAA=")
tile_set = SubResource("TileSet_dn5c8")
[node name="WorldKill" type="RigidBody2D" parent="." unique_id=930846306]
collision_layer = 2
collision_mask = 0
[node name="Kill" type="CollisionShape2D" parent="WorldKill" unique_id=418013596]
shape = SubResource("WorldBoundaryShape2D_nx3wj")
[node name="WorldWalls" type="StaticBody2D" parent="." unique_id=1591273250]
collision_mask = 0
[node name="Side" type="CollisionShape2D" parent="WorldWalls" unique_id=185994871]
shape = SubResource("WorldBoundaryShape2D_golqe")
[node name="MainCam" type="Camera2D" parent="." unique_id=290301959]
zoom = Vector2(4, 4)

BIN
tileset.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 983 B

40
tileset.png.import Normal file
View File

@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://chy3r2u2lsr18"
path="res://.godot/imported/tileset.png-a39e944f25b35d62f55d4f98a36e2b5e.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://tileset.png"
dest_files=["res://.godot/imported/tileset.png-a39e944f25b35d62f55d4f98a36e2b5e.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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