diff --git a/godot/GrandTheftArena.gdextension b/godot/GrandTheftArena.gdextension new file mode 100644 index 0000000..fb8229c --- /dev/null +++ b/godot/GrandTheftArena.gdextension @@ -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" diff --git a/godot/GrandTheftArena.gdextension.uid b/godot/GrandTheftArena.gdextension.uid new file mode 100644 index 0000000..09be3c6 --- /dev/null +++ b/godot/GrandTheftArena.gdextension.uid @@ -0,0 +1 @@ +uid://dxnrp4bcwyqny diff --git a/godot/assets/car.png b/godot/assets/car.png new file mode 100644 index 0000000..6b6e27d Binary files /dev/null and b/godot/assets/car.png differ diff --git a/godot/assets/car.png.import b/godot/assets/car.png.import new file mode 100644 index 0000000..d72ca06 --- /dev/null +++ b/godot/assets/car.png.import @@ -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 diff --git a/godot/assets/police_car.jpg b/godot/assets/police_car.jpg new file mode 100644 index 0000000..c3e6419 Binary files /dev/null and b/godot/assets/police_car.jpg differ diff --git a/godot/assets/police_car.jpg.import b/godot/assets/police_car.jpg.import new file mode 100644 index 0000000..0c63695 --- /dev/null +++ b/godot/assets/police_car.jpg.import @@ -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 diff --git a/godot/project.godot b/godot/project.godot index 019f7c3..7db6084 100644 --- a/godot/project.godot +++ b/godot/project.godot @@ -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) +] +} diff --git a/godot/test.tscn b/godot/test.tscn new file mode 100644 index 0000000..035e613 --- /dev/null +++ b/godot/test.tscn @@ -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") diff --git a/rust/crates/grand-theft-arena/src/lib.rs b/rust/crates/grand-theft-arena/src/lib.rs index 8b13789..4f84726 100644 --- a/rust/crates/grand-theft-arena/src/lib.rs +++ b/rust/crates/grand-theft-arena/src/lib.rs @@ -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, +} + +#[godot_api] +impl ISprite2D for Player { + fn init(base: Base) -> 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); + } +}