start player control code
This commit is contained in:
parent
d5a6585999
commit
65149fcb42
48
scenes/player/Player.cs
Normal file
48
scenes/player/Player.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using Godot;
|
||||
|
||||
public class Player : KinematicBody2D
|
||||
{
|
||||
[Export]
|
||||
private bool _invincible { get; set; }
|
||||
private Event _eventBus;
|
||||
private Vector2 _velocity;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_eventBus = GetNode<Event>("/root/Event");
|
||||
_eventBus.Connect("PlayerTouched", this, "PlayerTouched");
|
||||
_invincible = false;
|
||||
_velocity = new Vector2();
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(float delta)
|
||||
{
|
||||
_velocity.x = 0;
|
||||
|
||||
if (Input.IsActionPressed("right"))
|
||||
{
|
||||
_velocity.x += 50;
|
||||
}
|
||||
|
||||
if (Input.IsActionPressed("left")) {
|
||||
_velocity.x -= 50;
|
||||
}
|
||||
|
||||
_velocity = MoveAndSlide(_velocity, Vector2.Up);
|
||||
|
||||
var count = GetSlideCount();
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
KinematicCollision2D collision = GetSlideCollision(i);
|
||||
var collider = (Node) collision.Collider;
|
||||
if (collider.IsInGroup("Enemy"))
|
||||
{
|
||||
_eventBus.EmitSignal("PlayerTouched");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void PlayerTouched() {
|
||||
GD.Print("Touched");
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=29 format=2]
|
||||
[gd_scene load_steps=30 format=2]
|
||||
|
||||
[ext_resource path="res://assets/player/idle.png" type="Texture" id=1]
|
||||
[ext_resource path="res://assets/player/death.png" type="Texture" id=2]
|
||||
@ -9,6 +9,7 @@
|
||||
[ext_resource path="res://assets/player/walking.png" type="Texture" id=7]
|
||||
[ext_resource path="res://assets/player/surface_rising.png" type="Texture" id=8]
|
||||
[ext_resource path="res://assets/player/climbing.png" type="Texture" id=9]
|
||||
[ext_resource path="res://scenes/player/Player.cs" type="Script" id=10]
|
||||
|
||||
[sub_resource type="AtlasTexture" id=18]
|
||||
atlas = ExtResource( 9 )
|
||||
@ -131,11 +132,11 @@ extents = Vector2( 6, 6.5 )
|
||||
|
||||
[node name="Player" type="KinematicBody2D"]
|
||||
collision_mask = 0
|
||||
script = ExtResource( 10 )
|
||||
|
||||
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
||||
frames = SubResource( 3 )
|
||||
animation = "idle"
|
||||
frame = 1
|
||||
playing = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
|
Loading…
Reference in New Issue
Block a user