mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:05:34 +00:00
New player add method
This commit is contained in:
parent
83e8b9081c
commit
a235183c61
8 changed files with 116 additions and 58 deletions
|
|
@ -1,11 +1,38 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://c567m475j0axf"]
|
||||
[gd_scene load_steps=3 format=3 uid="uid://dkwi1hu1bixoe"]
|
||||
|
||||
[ext_resource type="FontFile" uid="uid://ccm3u37q1hvux" path="res://fonts/Xolonium-Regular.ttf" id="1_ye2ho"]
|
||||
[ext_resource type="Script" path="res://Scripts/Hud.cs" id="1_m0hb0"]
|
||||
[ext_resource type="FontFile" uid="uid://ccm3u37q1hvux" path="res://fonts/Xolonium-Regular.ttf" id="2_0xmx2"]
|
||||
|
||||
[node name="Hud" type="CanvasLayer"]
|
||||
[node name="HUD" type="CanvasLayer"]
|
||||
script = ExtResource("1_m0hb0")
|
||||
|
||||
[node name="HealthLabel" type="Label" parent="."]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 23.0
|
||||
theme_override_fonts/font = ExtResource("1_ye2ho")
|
||||
text = "100"
|
||||
[node name="Health" type="Label" parent="."]
|
||||
anchors_preset = 2
|
||||
anchor_top = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = -78.0
|
||||
offset_right = 305.0
|
||||
grow_vertical = 0
|
||||
theme_override_fonts/font = ExtResource("2_0xmx2")
|
||||
theme_override_font_sizes/font_size = 64
|
||||
text = "100/100"
|
||||
|
||||
[node name="Message" type="Label" parent="."]
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -217.0
|
||||
offset_top = -39.0
|
||||
offset_right = 217.0
|
||||
offset_bottom = 39.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_fonts/font = ExtResource("2_0xmx2")
|
||||
theme_override_font_sizes/font_size = 64
|
||||
text = "GAME OVER"
|
||||
|
||||
[node name="MessageTimer" type="Timer" parent="."]
|
||||
wait_time = 2.0
|
||||
one_shot = true
|
||||
|
|
|
|||
|
|
@ -1,38 +0,0 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://dkwi1hu1bixoe"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/Hud.cs" id="1_m0hb0"]
|
||||
[ext_resource type="FontFile" uid="uid://ccm3u37q1hvux" path="res://fonts/Xolonium-Regular.ttf" id="2_0xmx2"]
|
||||
|
||||
[node name="HUD" type="CanvasLayer"]
|
||||
script = ExtResource("1_m0hb0")
|
||||
|
||||
[node name="Health" type="Label" parent="."]
|
||||
anchors_preset = 2
|
||||
anchor_top = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = -78.0
|
||||
offset_right = 305.0
|
||||
grow_vertical = 0
|
||||
theme_override_fonts/font = ExtResource("2_0xmx2")
|
||||
theme_override_font_sizes/font_size = 64
|
||||
text = "100/100"
|
||||
|
||||
[node name="Message" type="Label" parent="."]
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -217.0
|
||||
offset_top = -39.0
|
||||
offset_right = 217.0
|
||||
offset_bottom = 39.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_fonts/font = ExtResource("2_0xmx2")
|
||||
theme_override_font_sizes/font_size = 64
|
||||
text = "GAME OVER"
|
||||
|
||||
[node name="MessageTimer" type="Timer" parent="."]
|
||||
wait_time = 2.0
|
||||
one_shot = true
|
||||
|
|
@ -1,11 +1,10 @@
|
|||
[gd_scene load_steps=28 format=3 uid="uid://bghghp5ep4w2j"]
|
||||
[gd_scene load_steps=27 format=3 uid="uid://bghghp5ep4w2j"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/PlayerMovement.cs" id="1_m27vu"]
|
||||
[ext_resource type="Texture2D" uid="uid://la06powu57hu" path="res://Sprites/Cirno_Big.png" id="2_bwf6x"]
|
||||
[ext_resource type="PackedScene" uid="uid://b1qnfiuokpvsr" path="res://Scenes/Weapons/bullet.tscn" id="2_ov36d"]
|
||||
[ext_resource type="PackedScene" uid="uid://chkpk7erlqajg" path="res://Scenes/Selector.tscn" id="3_8wt6s"]
|
||||
[ext_resource type="Script" path="res://addons/smoothing/smoothing_2d.gd" id="4_j4xhu"]
|
||||
[ext_resource type="Script" path="res://Scenes/CameraTarget.gd" id="5_cxvyt"]
|
||||
[ext_resource type="PackedScene" uid="uid://cfb3nsay84xdb" path="res://Scenes/Weapons/crosshair.tscn" id="6_l43rf"]
|
||||
[ext_resource type="Script" path="res://Scenes/InteractionController.cs" id="7_uvgjg"]
|
||||
[ext_resource type="PackedScene" uid="uid://crry0rgk7a8sm" path="res://Scenes/Weapons/BaseWeapon.tscn" id="9_wblq0"]
|
||||
|
|
@ -176,9 +175,6 @@ hframes = 3
|
|||
vframes = 4
|
||||
frame = 1
|
||||
|
||||
[node name="CameraTarget" type="Node2D" parent="Smoothing2D"]
|
||||
script = ExtResource("5_cxvyt")
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="Smoothing2D" groups=["player_sprite"]]
|
||||
y_sort_enabled = true
|
||||
sprite_frames = SubResource("SpriteFrames_q0rt3")
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
[gd_scene load_steps=25 format=4 uid="uid://bv451a8wgty4u"]
|
||||
[gd_scene load_steps=28 format=4 uid="uid://bv451a8wgty4u"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scripts/GameManager.cs" id="1_8tmoj"]
|
||||
[ext_resource type="PackedScene" uid="uid://bghghp5ep4w2j" path="res://Scenes/player.tscn" id="2_8mh54"]
|
||||
[ext_resource type="PackedScene" uid="uid://rp4jhx0tuh24" path="res://Scenes/fragola.tscn" id="4_s7wq6"]
|
||||
[ext_resource type="PackedScene" uid="uid://bj28qiai2x2ar" path="res://Scenes/Props/Barrel.tscn" id="5_3uba3"]
|
||||
|
|
@ -21,6 +22,8 @@
|
|||
[ext_resource type="PackedScene" uid="uid://v8s3kubgb2qg" path="res://Scenes/Enemy.tscn" id="18_ixcwn"]
|
||||
[ext_resource type="PackedScene" uid="uid://dxs3ks2ucaxl4" path="res://Scenes/Red_Keycard.tscn" id="19_8fb73"]
|
||||
[ext_resource type="PackedScene" uid="uid://cymtsmui4yo17" path="res://Scenes/Keycard_Pad.tscn" id="20_0aphx"]
|
||||
[ext_resource type="PackedScene" uid="uid://dkwi1hu1bixoe" path="res://Scenes/HUD/HUD.tscn" id="22_krk0o"]
|
||||
[ext_resource type="Script" path="res://Scenes/CameraTarget.gd" id="24_0c2yt"]
|
||||
|
||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_jwf4b"]
|
||||
resource_name = "Factory"
|
||||
|
|
@ -220,8 +223,11 @@ physics_layer_1/collision_mask = 18
|
|||
sources/0 = SubResource("TileSetAtlasSource_jwf4b")
|
||||
sources/1 = SubResource("TileSetScenesCollectionSource_qg3vu")
|
||||
|
||||
[node name="GameScene" type="Node2D"]
|
||||
[node name="GameScene" type="Node2D" node_paths=PackedStringArray("PlayerSpawnMarker")]
|
||||
position = Vector2(38, 39)
|
||||
script = ExtResource("1_8tmoj")
|
||||
PlayerTemplate = ExtResource("2_8mh54")
|
||||
PlayerSpawnMarker = NodePath("PlayerStartPosition")
|
||||
|
||||
[node name="Factory Tilemaps" type="Node2D" parent="."]
|
||||
|
||||
|
|
@ -311,9 +317,6 @@ position = Vector2(-944, 160)
|
|||
script = ExtResource("6_t8ide")
|
||||
pixel_snap = false
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource("2_8mh54")]
|
||||
position = Vector2(-790, -165)
|
||||
|
||||
[node name="ReferenceRect" type="ReferenceRect" parent="."]
|
||||
visible = false
|
||||
offset_left = -38.0
|
||||
|
|
@ -356,3 +359,13 @@ position = Vector2(-1164, 208)
|
|||
position = Vector2(-1094, 135)
|
||||
Target = NodePath("../Factory Tilemaps/HorizontalDoor")
|
||||
RequiresKeycard = false
|
||||
|
||||
[node name="HUD" parent="." instance=ExtResource("22_krk0o")]
|
||||
visible = false
|
||||
|
||||
[node name="CameraTarget" type="Node2D" parent="."]
|
||||
position = Vector2(-791, -153)
|
||||
script = ExtResource("24_0c2yt")
|
||||
|
||||
[node name="PlayerStartPosition" type="Marker2D" parent="."]
|
||||
position = Vector2(-779, -160)
|
||||
|
|
|
|||
54
Scripts/GameManager.cs
Normal file
54
Scripts/GameManager.cs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
using Godot;
|
||||
using System;
|
||||
using Cirno.Scripts;
|
||||
|
||||
public partial class GameManager : Node2D
|
||||
{
|
||||
private Hud _hud;
|
||||
|
||||
private PlayerMovement _player;
|
||||
|
||||
private Node2D _cameraTarget;
|
||||
|
||||
[Export]
|
||||
public PackedScene PlayerTemplate { get; set; }
|
||||
|
||||
[Export]
|
||||
public Marker2D PlayerSpawnMarker { get; set; }
|
||||
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
_hud = GetNode<Hud>("HUD");
|
||||
_cameraTarget = GetNode<Node2D>("CameraTarget");
|
||||
|
||||
if (PlayerSpawnMarker != null)
|
||||
{
|
||||
SpawnPlayer();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
}
|
||||
|
||||
public void SpawnPlayer()
|
||||
{
|
||||
if (_player == null)
|
||||
{
|
||||
//_player = this.CreateChild<PlayerMovement>(PlayerTemplate, PlayerSpawnMarker.Position );
|
||||
_player = PlayerTemplate.Instantiate<PlayerMovement>();
|
||||
|
||||
this.CallDeferred("add_child", _player);
|
||||
_player.Transform = this.GlobalTransform;
|
||||
|
||||
_player.GlobalPosition = PlayerSpawnMarker.Position;
|
||||
|
||||
_cameraTarget.Reparent(_player, true);
|
||||
_cameraTarget.GlobalPosition = _player.Position;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -37,7 +37,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
[Export] public Weapon EquippedWeapon;
|
||||
|
||||
private float _currentHealth = 0f;
|
||||
|
||||
|
||||
private bool _isDestroyed = false;
|
||||
|
||||
//private InventoryManager _inventoryManager;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,11 @@ namespace Cirno.Scripts;
|
|||
public static class Tools
|
||||
{
|
||||
public static T CreateChild<T>(this Node2D node, PackedScene prefab) where T : Node2D
|
||||
{
|
||||
return CreateChild<T>(node, prefab, node.Position);
|
||||
}
|
||||
|
||||
public static T CreateChild<T>(this Node2D node, PackedScene prefab, Vector2 position) where T : Node2D
|
||||
{
|
||||
if (prefab == null) return null;
|
||||
var newInstance = prefab.Instantiate<T>();
|
||||
|
|
@ -12,7 +17,7 @@ public static class Tools
|
|||
// Need to use parent instead of owner because tilemap scenes have no owner
|
||||
//node.Owner.CallDeferred("add_child", newInstance);
|
||||
newInstance.Transform = node.GlobalTransform;
|
||||
newInstance.Position = node.Position;
|
||||
newInstance.Position = position;
|
||||
|
||||
return newInstance;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ public partial class Weapon : Node2D
|
|||
}
|
||||
|
||||
// TODO: Shoot at muzzle position, need to provide a way to turn it, on a radius?
|
||||
// TODO: Create not as child but as standalone
|
||||
var bullet = this.CreateChild<Bullet>(BulletScene);
|
||||
bullet.SetDirection(ShootDirection);
|
||||
bullet.Speed = BulletSpeed;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue