feat: moveable car

This commit is contained in:
Asger Juul Brunshøj 2025-05-27 11:52:34 +02:00
parent c7e036ca3d
commit 5b370c0679
9 changed files with 175 additions and 0 deletions

View File

@ -0,0 +1,14 @@
[configuration]
entry_symbol = "gdext_rust_init"
compatibility_minimum = 4.1
reloadable = true
[libraries]
linux.debug.x86_64 = "res://../target/debug/libgrand_theft_arena.so"
linux.release.x86_64 = "res://../target/release/libgrand_theft_arena.so"
windows.debug.x86_64 = "res://../target/debug/grand_theft_arena.dll"
windows.release.x86_64 = "res://../target/release/grand_theft_arena.dll"
macos.debug = "res://../target/debug/libgrand_theft_arena.dylib"
macos.release = "res://../target/release/libgrand_theft_arena.dylib"
macos.debug.arm64 = "res://../target/debug/libgrand_theft_arena.dylib"
macos.release.arm64 = "res://../target/release/libgrand_theft_arena.dylib"

View File

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

BIN
godot/assets/car.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 KiB

View File

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

BIN
godot/assets/police_car.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://uf7xajus600u"
path="res://.godot/imported/police_car.jpg-20b412ed016320875c4b6f10294a674e.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/police_car.jpg"
dest_files=["res://.godot/imported/police_car.jpg-20b412ed016320875c4b6f10294a674e.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

View File

@ -11,5 +11,29 @@ config_version=5
[application]
config/name="Grand Theft Arena"
run/main_scene="uid://y1wcwxtxgsy5"
config/features=PackedStringArray("4.4", "Forward Plus")
config/icon="res://icon.svg"
[input]
move_forward={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
move_backward={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
turn_left={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
turn_right={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}

8
godot/test.tscn Normal file
View File

@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=3 uid="uid://y1wcwxtxgsy5"]
[ext_resource type="Texture2D" uid="uid://by4cbmcpktbmf" path="res://assets/car.png" id="1_37kl0"]
[node name="MyNode" type="Player"]
position = Vector2(582, 324)
scale = Vector2(0.143817, 0.143817)
texture = ExtResource("1_37kl0")

View File

@ -1 +1,61 @@
//! Grand Theft Arena
use godot::classes::ISprite2D;
use godot::classes::Sprite2D;
use godot::prelude::*;
struct MyExtension;
#[gdextension]
unsafe impl ExtensionLibrary for MyExtension {}
#[derive(GodotClass)]
#[class(base=Sprite2D)]
struct Player {
speed: f64,
angular_speed: f64,
base: Base<Sprite2D>,
}
#[godot_api]
impl ISprite2D for Player {
fn init(base: Base<Sprite2D>) -> Self {
Self {
speed: 400.0,
angular_speed: std::f64::consts::PI,
base,
}
}
fn physics_process(&mut self, delta: f64) {
let input = Input::singleton();
let speed = self.speed;
let angular_speed = self.angular_speed;
let mut base = self.base_mut();
// Rotation
if input.is_action_pressed("turn_left") {
let radians = -angular_speed * delta;
base.rotate(radians as f32);
}
if input.is_action_pressed("turn_right") {
let radians = angular_speed * delta;
base.rotate(radians as f32);
}
// Movement
let mut velocity = Vector2::ZERO;
if input.is_action_pressed("move_forward") {
let forward = Vector2::UP.rotated(base.get_rotation());
velocity += forward * speed as f32;
}
if input.is_action_pressed("move_backward") {
let backward = Vector2::UP.rotated(base.get_rotation());
velocity -= backward * speed as f32;
}
base.translate(velocity * delta as f32);
}
}