Skip to content

Commit

Permalink
save blockdrawer
Browse files Browse the repository at this point in the history
  • Loading branch information
limuy2022 committed Jun 6, 2024
1 parent 4567b1b commit 1c23b3a
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/Zenith.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 29 additions & 3 deletions gdrust/src/fight_items/block_drawer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use godot::engine::{INode2D, Node2D};
use godot::engine::{Area2D, CollisionPolygon2D, INode2D, Node2D};
use godot::obj::WithBaseField;
use godot::prelude::*;

Expand Down Expand Up @@ -26,11 +26,26 @@ impl INode2D for BlockDrawer {
}
}

fn ready(&mut self) {
let mut collision_obj = self
.base_mut()
.get_node_as::<CollisionPolygon2D>("collision/collision");
let mut points = PackedVector2Array::new();
points.push(Vector2::new(self.x, self.y));
points.push(Vector2::new(self.get_opposite_x(), self.y));
points.push(Vector2::new(
self.get_opposite_x(),
self.y + Self::Y_SIZE_DEFAULT,
));
points.push(Vector2::new(self.x, self.y + Self::Y_SIZE_DEFAULT));
collision_obj.set_polygon(points);
collision_obj.set_disabled(false);
}

fn process(&mut self, delta: f64) {}

fn draw(&mut self) {
let tmp = self.x;
let xsize = self.base_mut().get_viewport_rect().size.x - tmp * 2.0;
let xsize = self.get_opposite_x();

godot_print!("enter");
let tmp = Vector2::new(self.x, self.y);
Expand All @@ -45,6 +60,14 @@ impl INode2D for BlockDrawer {
}
}

impl BlockDrawer {
fn get_opposite_x(&self) -> f32 {
let tmp = self.x;
let xsize = self.base().get_viewport_rect().size.x - tmp * 2.0;
xsize
}
}

#[godot_api]
impl BlockDrawer {
const BOX_START_POS_X: f32 = 400.0;
Expand All @@ -71,4 +94,7 @@ impl BlockDrawer {
// self.base().
(self.base().get_viewport_rect().size.x - self.x) as i32
}

#[func]
fn collision_signal(&mut self, obj: Gd<Area2D>) {}
}
14 changes: 14 additions & 0 deletions scenes/bar.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[gd_scene format=3 uid="uid://dv2la4fxkryss"]

[node name="Bar" type="Bar"]
anchors_preset = 7
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = -20.0
offset_top = 6.0
offset_right = 20.0
offset_bottom = 46.0
grow_horizontal = 2
grow_vertical = 0
12 changes: 12 additions & 0 deletions scenes/block_drawer.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[gd_scene load_steps=2 format=3 uid="uid://cfpti2pe03p53"]

[ext_resource type="Script" path="res://scripts/BlockDrawer.gd" id="1_tkxse"]

[node name="BlockDrawer" type="BlockDrawer"]
script = ExtResource("1_tkxse")

[node name="collision" type="Area2D" parent="."]

[node name="collision" type="CollisionPolygon2D" parent="collision"]

[connection signal="area_entered" from="collision" to="." method="_on_collision_area_entered"]
10 changes: 9 additions & 1 deletion scenes/fight.tscn
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[gd_scene load_steps=15 format=3 uid="uid://cibwxaqnuodid"]
[gd_scene load_steps=16 format=3 uid="uid://cibwxaqnuodid"]

[ext_resource type="Script" path="res://scripts/fight.gd" id="1_fov6f"]
[ext_resource type="Texture2D" uid="uid://cqp3l8q7xbxrt" path="res://resources/images/weapons/Zenith.webp" id="3_2spkb"]
[ext_resource type="Script" path="res://scripts/Player.gd" id="3_6nc6b"]
[ext_resource type="PackedScene" uid="uid://dn2ixin15jtt3" path="res://scenes/weapons/star_wrath.tscn" id="4_8ipx5"]
[ext_resource type="Texture2D" uid="uid://c71fsdux0i1r3" path="res://resources/images/PlayerHeart/Default/000.png" id="5_3ufqu"]
[ext_resource type="Texture2D" uid="uid://b37v3b41jrx1x" path="res://resources/images/UIFight/Default/000.png" id="6_5cs44"]
[ext_resource type="Script" path="res://scripts/BlockDrawer.gd" id="6_6q3lq"]
[ext_resource type="Texture2D" uid="uid://dscxanl5ikwrj" path="res://resources/images/UIFight/Highlight/000.png" id="7_rklqi"]
[ext_resource type="Texture2D" uid="uid://cvx31mw3e38mx" path="res://resources/images/UIAct/Default/000.png" id="8_yjyfq"]
[ext_resource type="Texture2D" uid="uid://cho5eldvgpv3j" path="res://resources/images/UIAct/Highlight/000.png" id="9_2s82g"]
Expand All @@ -15,6 +16,7 @@
[ext_resource type="Texture2D" uid="uid://wawi1y6785j5" path="res://resources/images/UIMercy/Highlight/000.png" id="13_lrcvx"]

[sub_resource type="CircleShape2D" id="CircleShape2D_yfrnq"]
radius = 52.67

[node name="Fight" type="Control"]
layout_mode = 3
Expand Down Expand Up @@ -54,10 +56,16 @@ script = ExtResource("3_6nc6b")
shape = SubResource("CircleShape2D_yfrnq")

[node name="Sprite2D" type="Sprite2D" parent="Player"]
modulate = Color(1, 0, 0, 1)
scale = Vector2(6.6, 6.6)
texture = ExtResource("5_3ufqu")

[node name="BlockDrawer" type="BlockDrawer" parent="."]
script = ExtResource("6_6q3lq")

[node name="collision" type="Area2D" parent="BlockDrawer"]

[node name="collision" type="CollisionPolygon2D" parent="BlockDrawer/collision"]

[node name="Bar" type="Bar" parent="."]
layout_mode = 1
Expand Down
9 changes: 9 additions & 0 deletions scenes/player.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=3 uid="uid://k0xrl25jvanb"]

[ext_resource type="Script" path="res://scripts/Player.gd" id="1_igj8d"]

[node name="Player" type="Player"]
position = Vector2(570, 463)
rotation = 1.5708
scale = Vector2(0.2, 0.2)
script = ExtResource("1_igj8d")
6 changes: 6 additions & 0 deletions scenes/zenith_begin.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[gd_scene format=3 uid="uid://dknmaa8domjoh"]

[node name="ZenithBegin" type="ZenithBegin"]
position = Vector2(576, 137)
rotation = -0.787703
scale = Vector2(3.28571, 3.28571)
15 changes: 15 additions & 0 deletions scripts/BlockDrawer.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
extends BlockDrawer


# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass


func _on_collision_area_entered(area:Area2D):
self.collision_signal(area)

0 comments on commit 1c23b3a

Please sign in to comment.