Player Health, Ghost Enemy
This commit is contained in:
parent
370424a696
commit
6432ac8b13
8 changed files with 131 additions and 12 deletions
|
|
@ -1,7 +1,7 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://jjoyj1ldafkf"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://cy70quh6k3s1j" path="res://icon.svg" id="1_qbwya"]
|
||||
[ext_resource type="Script" path="res://draw_circle.gd" id="2_2bhor"]
|
||||
[ext_resource type="Script" uid="uid://b5fhsy1xlreco" path="res://draw_circle.gd" id="2_2bhor"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_5i67w"]
|
||||
radius = 3000.0
|
||||
|
|
@ -17,6 +17,3 @@ shape = SubResource("CircleShape2D_5i67w")
|
|||
texture = ExtResource("1_qbwya")
|
||||
script = ExtResource("2_2bhor")
|
||||
radius = 3000.0
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
position = Vector2(47, -3283)
|
||||
|
|
|
|||
15
ghost.gd
Normal file
15
ghost.gd
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
extends Area2D
|
||||
var speed = 100
|
||||
var damage = 1
|
||||
var player : CharacterBody2D
|
||||
|
||||
func _ready() -> void:
|
||||
player = get_parent().get_node("Player")
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
var motion = -(position - player.position).normalized() * speed
|
||||
var dist = (position - player.position).length()
|
||||
self.position += motion * delta * min(1, dist/(motion.length()*delta))
|
||||
|
||||
if(self.overlaps_body(player)):
|
||||
player.hurt(damage, self.position-player.position)
|
||||
1
ghost.gd.uid
Normal file
1
ghost.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://12jns4dppxxj
|
||||
17
ghost.tscn
Normal file
17
ghost.tscn
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://chu67ci7sl488"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://12jns4dppxxj" path="res://ghost.gd" id="1_6attn"]
|
||||
[ext_resource type="Texture2D" uid="uid://cy70quh6k3s1j" path="res://icon.svg" id="2_obmiq"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_6attn"]
|
||||
|
||||
[node name="Ghost" type="Area2D"]
|
||||
scale = Vector2(0.4, 0.4)
|
||||
script = ExtResource("1_6attn")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = ExtResource("2_obmiq")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
scale = Vector2(6, 6)
|
||||
shape = SubResource("CircleShape2D_6attn")
|
||||
|
|
@ -1,12 +1,16 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://cxo6bq26huau7"]
|
||||
[gd_scene load_steps=4 format=3 uid="uid://cxo6bq26huau7"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://cmaovvr15b3qk" path="res://player.tscn" id="2_1bvp3"]
|
||||
[ext_resource type="PackedScene" uid="uid://chu67ci7sl488" path="res://ghost.tscn" id="3_h2yge"]
|
||||
[ext_resource type="PackedScene" uid="uid://jjoyj1ldafkf" path="res://earth.tscn" id="3_lquwl"]
|
||||
|
||||
[node name="main" type="Node2D"]
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource("2_1bvp3")]
|
||||
position = Vector2(0, -3100)
|
||||
position = Vector2(500, -3100)
|
||||
scale = Vector2(3, 3)
|
||||
|
||||
[node name="Earth" parent="." instance=ExtResource("3_lquwl")]
|
||||
|
||||
[node name="Ghost" parent="." instance=ExtResource("3_h2yge")]
|
||||
position = Vector2(0, -3200)
|
||||
|
|
|
|||
75
player.gd
75
player.gd
|
|
@ -1,18 +1,81 @@
|
|||
extends Node2D
|
||||
var body : CharacterBody2D;
|
||||
var camera : Camera2D;
|
||||
var earth_center = Vector2.ZERO;
|
||||
var gravity = 500;
|
||||
var max_fall_speed = 700;
|
||||
var jump_strength = 900;
|
||||
var gravity = 100;
|
||||
var hspeed = 150;
|
||||
var angle = 0;
|
||||
|
||||
var bonus_velocity = Vector2.ZERO
|
||||
|
||||
var air_jumps_max = 1;
|
||||
var air_jumps_current = 1;
|
||||
|
||||
var current_hp = 5;
|
||||
var max_hp = 5;
|
||||
|
||||
var inv_time = 0;
|
||||
var hit_invulnerability = 0.5
|
||||
|
||||
var knockback_strength = 1200
|
||||
var damage_knockup = 200
|
||||
|
||||
func _ready() -> void:
|
||||
body = get_parent().get_node("Player")
|
||||
camera = get_node("Camera2D")
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
var local_velocity = Vector2.ZERO
|
||||
if(inv_time > 0):
|
||||
inv_time = max(0, inv_time-delta)
|
||||
|
||||
angle = -(self.position - earth_center).angle_to(Vector2.UP)
|
||||
body.rotation = angle;
|
||||
body.up_direction = (self.position - earth_center).normalized();
|
||||
local_velocity += Vector2(0, gravity)
|
||||
body.velocity = global_from_local(local_velocity)
|
||||
print(body.velocity)
|
||||
|
||||
if(body.is_on_floor()):
|
||||
air_jumps_current = air_jumps_max
|
||||
|
||||
manage_velocity()
|
||||
body.move_and_slide()
|
||||
|
||||
func manage_velocity() -> void:
|
||||
var old_local_velocity = local_from_global(body.velocity)
|
||||
var local_velocity = Vector2(old_local_velocity.x/1.7, old_local_velocity.y);
|
||||
local_velocity += Vector2(0, gravity)
|
||||
|
||||
if(Input.is_action_pressed("move_right")):
|
||||
local_velocity += Vector2(hspeed, 0)
|
||||
if(Input.is_action_pressed("move_left")):
|
||||
local_velocity += Vector2(-hspeed, 0)
|
||||
if(Input.is_action_just_pressed("jump") and (body.is_on_floor() or air_jumps_current > 0)):
|
||||
if(not body.is_on_floor()):
|
||||
air_jumps_current -= 1;
|
||||
local_velocity.y = -jump_strength
|
||||
|
||||
if(local_velocity.y > max_fall_speed):
|
||||
local_velocity.y = max_fall_speed
|
||||
|
||||
local_velocity += bonus_velocity
|
||||
bonus_velocity = Vector2.ZERO
|
||||
body.velocity = global_from_local(local_velocity)
|
||||
|
||||
|
||||
func global_from_local (_velocity: Vector2) -> Vector2:
|
||||
return _velocity # Placeholder
|
||||
return _velocity.rotated(angle)
|
||||
|
||||
func local_from_global (_velocity: Vector2) -> Vector2:
|
||||
return _velocity.rotated(-angle)
|
||||
|
||||
func hurt(dmg: int, dir: Vector2 = Vector2.ZERO):
|
||||
if(inv_time <= 0):
|
||||
current_hp -= dmg
|
||||
if(current_hp <= 0):
|
||||
die()
|
||||
|
||||
inv_time = hit_invulnerability
|
||||
bonus_velocity = Vector2(-sign(local_from_global(dir).x)*knockback_strength, -damage_knockup)
|
||||
|
||||
func die():
|
||||
print("You Died") # Placeholder
|
||||
|
|
|
|||
|
|
@ -15,3 +15,7 @@ shape = SubResource("CapsuleShape2D_onrkg")
|
|||
position = Vector2(5.96046e-08, 0)
|
||||
scale = Vector2(0.15625, 0.234375)
|
||||
texture = ExtResource("2_onrkg")
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
position = Vector2(0, -50)
|
||||
ignore_rotation = false
|
||||
|
|
|
|||
|
|
@ -20,3 +20,21 @@ config/icon="res://icon.svg"
|
|||
window/size/viewport_width=1920
|
||||
window/size/viewport_height=1080
|
||||
window/size/mode=3
|
||||
|
||||
[input]
|
||||
|
||||
move_right={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_left={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
jump={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue