Make a new Character class which both the enemy and player share

This commit is contained in:
CactiChameleon9 2022-07-17 18:23:41 +01:00
parent 3ad8e574dd
commit f2fad3bb0e
4 changed files with 46 additions and 33 deletions

37
Characters/Character.gd Normal file
View File

@ -0,0 +1,37 @@
extends Node2D
class_name Character
export var base_max_health : int = 20
export (int, 1, 5) var level : int = 1 setget level_change
var health
var map_position : Vector2 = Vector2.ZERO
onready var target_position : Vector2 = position
var moving : bool = false
func level_change(new_level):
# when leveing up restore health
health = base_max_health * pow(level, 1.5)
func _physics_process(delta):
# If the 2 positions are close enough, then not moving
moving = false if target_position.round() == position.round() else true
if not moving: return
#TODO: Replace with tween magic
position += (target_position - position)/2.5
func take_damage(damage):
health -= damage
if health <= 0:
die()
func die():
#Animation here
queue_free()

View File

@ -1,16 +1 @@
extends Node2D extends Character
export var map_position : Vector2 = Vector2.ZERO
onready var target_position : Vector2 = position
var moving : bool = false
func _physics_process(delta):
# If the 2 positions are close enough, then not moving
moving = false if target_position.round() == position.round() else true
if not moving: return
#TODO: Replace with tween magic
position += (target_position - position)/2.5

View File

@ -1,16 +1 @@
extends Node2D extends Character
export var map_position : Vector2 = Vector2.ZERO
onready var target_position : Vector2 = position
var moving : bool = false
func _physics_process(delta):
# If the 2 positions are close enough, then not moving
moving = false if target_position.round() == position.round() else true
if not moving: return
#TODO: Replace with tween magic
position += (target_position - position)/2.5

View File

@ -13,9 +13,15 @@ _global_script_classes=[ {
"class": "CardResource", "class": "CardResource",
"language": "GDScript", "language": "GDScript",
"path": "res://Assets/CardDB/CardBD.gd" "path": "res://Assets/CardDB/CardBD.gd"
}, {
"base": "Node2D",
"class": "Character",
"language": "GDScript",
"path": "res://Characters/Character.gd"
} ] } ]
_global_script_class_icons={ _global_script_class_icons={
"CardResource": "" "CardResource": "",
"Character": ""
} }
[application] [application]