diff --git a/src/godot/gd/bree_l_player.gd b/src/godot/gd/bree_l_player.gd new file mode 100644 index 0000000..a42e53e --- /dev/null +++ b/src/godot/gd/bree_l_player.gd @@ -0,0 +1,16 @@ +extends BreeLPlayer + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass + + +func _on_speed_increased() -> void: + print("SPEED INCREASED") + pass # Replace with function body. diff --git a/src/godot/gd/button.gd b/src/godot/gd/button.gd new file mode 100644 index 0000000..718d466 --- /dev/null +++ b/src/godot/gd/button.gd @@ -0,0 +1,16 @@ +extends Button + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass + + +func _on_button_up() -> void: + print("button up") + get_parent().get_parent().tackled() diff --git a/src/godot/gd/name.gd b/src/godot/gd/name.gd new file mode 100644 index 0000000..965afb1 --- /dev/null +++ b/src/godot/gd/name.gd @@ -0,0 +1,10 @@ +extends RichTextLabel + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + self.text = get_parent().mon_name() + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass diff --git a/src/godot/gd/node_2d.tscn b/src/godot/gd/node_2d.tscn index f806a05..10014b8 100644 --- a/src/godot/gd/node_2d.tscn +++ b/src/godot/gd/node_2d.tscn @@ -1,9 +1,58 @@ -[gd_scene load_steps=2 format=3 uid="uid://dg85xsdqg6wj0"] +[gd_scene load_steps=5 format=3 uid="uid://dg85xsdqg6wj0"] [ext_resource type="Texture2D" uid="uid://cneqjngiworik" path="res://icon.svg" id="1_swwii"] +[ext_resource type="Script" path="res://gd/texture_progress_bar.gd" id="2_2jm7r"] +[ext_resource type="Script" path="res://gd/name.gd" id="3_u8x5l"] +[ext_resource type="Script" path="res://gd/button.gd" id="4_iyywh"] [node name="Node2D" type="Node2D"] -[node name="BreeLPlayer" type="BreeLPlayer" parent="."] -position = Vector2(556, 302) +[node name="Camera2D" type="Camera2D" parent="."] +position = Vector2(2, 0) + +[node name="Sprite2D" type="Sprite2D" parent="."] +z_index = -10 +position = Vector2(-9.53674e-06, 4.29153e-06) +scale = Vector2(9, 5.0625) texture = ExtResource("1_swwii") + +[node name="attacker" type="Mon" parent="."] +position = Vector2(-408.5, 157.5) +scale = Vector2(2.41406, 2.41406) + +[node name="TextureProgressBar" type="TextureProgressBar" parent="attacker"] +z_index = 10 +offset_right = 40.0 +offset_bottom = 40.0 +texture_progress = ExtResource("1_swwii") +script = ExtResource("2_2jm7r") + +[node name="name" type="RichTextLabel" parent="attacker"] +z_index = 10 +offset_right = 348.0 +offset_bottom = 40.0 +text = "asdf" +script = ExtResource("3_u8x5l") + +[node name="sprite" type="Sprite2D" parent="attacker"] +texture = ExtResource("1_swwii") + +[node name="actions" type="Node2D" parent="attacker"] +position = Vector2(169.217, -65.2427) +scale = Vector2(0.414239, 0.414239) + +[node name="button" type="Button" parent="attacker/actions"] +offset_left = 435.0 +offset_top = 180.0 +offset_right = 435.0 +offset_bottom = 180.0 +icon = ExtResource("1_swwii") +script = ExtResource("4_iyywh") + +[node name="opponent" type="Sprite2D" parent="."] +position = Vector2(420, -166) +scale = Vector2(2.41406, 2.41406) +texture = ExtResource("1_swwii") + +[connection signal="hp_changed" from="attacker" to="attacker/TextureProgressBar" method="_on_mon_hp_changed"] +[connection signal="button_up" from="attacker/actions/button" to="attacker/actions/button" method="_on_button_up"] diff --git a/src/godot/gd/texture_progress_bar.gd b/src/godot/gd/texture_progress_bar.gd new file mode 100644 index 0000000..71a6039 --- /dev/null +++ b/src/godot/gd/texture_progress_bar.gd @@ -0,0 +1,15 @@ +extends TextureProgressBar + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass + + +func _on_mon_hp_changed() -> void: + self.value = 100 * get_parent().hp() diff --git a/src/godot/gd/touch_screen_button.gd b/src/godot/gd/touch_screen_button.gd new file mode 100644 index 0000000..a5e99c5 --- /dev/null +++ b/src/godot/gd/touch_screen_button.gd @@ -0,0 +1,14 @@ +extends TouchScreenButton + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass + +func _on_pressed() -> void: + print("pressed") diff --git a/src/rust/src/lib.rs b/src/rust/src/lib.rs index 68895e0..404065a 100644 --- a/src/rust/src/lib.rs +++ b/src/rust/src/lib.rs @@ -7,3 +7,5 @@ unsafe impl ExtensionLibrary for MyExtension { } pub mod player; +pub mod mon; +pub mod mon_move; diff --git a/src/rust/src/mon.rs b/src/rust/src/mon.rs new file mode 100644 index 0000000..130b730 --- /dev/null +++ b/src/rust/src/mon.rs @@ -0,0 +1,74 @@ +use godot::prelude::*; + +use godot::classes::{ISprite2D, Sprite2D}; +#[derive(GodotClass, Debug)] +#[class(base=Sprite2D)] +pub struct Mon { + base: Base, + name: GString, + hp: i32, + damage: i32, + level_d: i32, +} + +#[godot_api] +impl ISprite2D for Mon { + fn init(base: Base) -> Self { + Self{ + base: base, + name: "my_name".into(), + hp: 100, + damage: 0, + level_d: 0, + } + } + + fn ready(&mut self) { + self.hp_change() + } +} + +use crate::mon_move; +#[godot_api] +impl Mon { + #[func] + pub fn mon_name(&self) -> GString { + self.name.clone() + } + + #[func] + pub fn hp(&self) -> f32 { + (self.hp - self.damage) as f32 / self.hp as f32 + } + + #[func] + pub fn tackled(&mut self) { + self.recv(mon_move::TACKLE); + self.hp_change() + } + + fn hp_change(&mut self) { + self.base_mut().emit_signal("hp_changed", &[]); + } + + #[signal] + fn hp_changed(); +} + +impl Mon { + fn recv(&mut self, m: mon_move::MonMove) { + m.use_on(self); + } + + pub fn hit_for(&mut self, power: i32) { + self.damage += power; + } + + pub fn damage_scalar(&self) -> f32 { + let mut result = 1.0; + for _ in 0..self.level_d { + result /= 2.0; + } + result + } +} diff --git a/src/rust/src/mon_move.rs b/src/rust/src/mon_move.rs new file mode 100644 index 0000000..0ce3437 --- /dev/null +++ b/src/rust/src/mon_move.rs @@ -0,0 +1,18 @@ +use crate::mon; + +pub struct MonMove { + power: i32, +} + +impl MonMove { + const fn new(power: i32) -> Self { + Self{power: power} + } + + pub fn use_on(&self, dest: &mut mon::Mon) { + let power = self.power as f32 * dest.damage_scalar(); + dest.hit_for(power as i32); + } +} + +pub const TACKLE: MonMove = MonMove::new(25); diff --git a/src/rust/src/player.rs b/src/rust/src/player.rs index ce19c8f..df7c2d4 100644 --- a/src/rust/src/player.rs +++ b/src/rust/src/player.rs @@ -1,4 +1,6 @@ -use godot::{prelude::*, classes::{ISprite2D, Sprite2D}}; +use godot::prelude::*; + +use godot::classes::{ISprite2D, Sprite2D}; #[derive(GodotClass)] #[class(base=Sprite2D)] struct BreeLPlayer { @@ -41,5 +43,3 @@ impl BreeLPlayer { eprintln!("drop"); } } - -