can punch self

main
Bel LaPointe 2025-03-02 18:07:14 -07:00
parent ed5e6d4487
commit f7f46ba96e
10 changed files with 220 additions and 6 deletions

View File

@ -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.

16
src/godot/gd/button.gd Normal file
View File

@ -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()

10
src/godot/gd/name.gd Normal file
View File

@ -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

View File

@ -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"]

View File

@ -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()

View File

@ -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")

View File

@ -7,3 +7,5 @@ unsafe impl ExtensionLibrary for MyExtension {
}
pub mod player;
pub mod mon;
pub mod mon_move;

74
src/rust/src/mon.rs Normal file
View File

@ -0,0 +1,74 @@
use godot::prelude::*;
use godot::classes::{ISprite2D, Sprite2D};
#[derive(GodotClass, Debug)]
#[class(base=Sprite2D)]
pub struct Mon {
base: Base<Sprite2D>,
name: GString,
hp: i32,
damage: i32,
level_d: i32,
}
#[godot_api]
impl ISprite2D for Mon {
fn init(base: Base<Sprite2D>) -> 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
}
}

18
src/rust/src/mon_move.rs Normal file
View File

@ -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);

View File

@ -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");
}
}