✨ Gun and rose
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
@export var speed = 1200
|
||||
@export var speed_multiplier = 20
|
||||
@export var friction = 0.9
|
||||
|
||||
@export var dash_cooldown_duration = 1.0
|
||||
@export var dash_cooldown_timer: Timer
|
||||
|
||||
func deal_move(delta):
|
||||
var input_direction = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
velocity = velocity.move_toward(input_direction * speed, speed * delta)
|
||||
velocity = velocity * friction
|
||||
|
||||
var is_dash = Input.is_action_pressed("skill_dash")
|
||||
if is_dash && dash_cooldown_timer.is_stopped():
|
||||
velocity *= speed_multiplier
|
||||
dash_cooldown_timer.start(dash_cooldown_duration)
|
||||
|
||||
func _on_cooled_down():
|
||||
dash_cooldown_timer.stop()
|
||||
|
||||
func _ready():
|
||||
var screen_size = get_viewport_rect().size
|
||||
position = Vector2(screen_size.x / 2, screen_size.y / 2)
|
||||
|
||||
func _physics_process(delta):
|
||||
deal_move(delta)
|
||||
move_and_slide()
|
@@ -1,5 +1,35 @@
|
||||
extends Area2D
|
||||
|
||||
func _ready():
|
||||
signal tower_broken
|
||||
|
||||
@export var sprite: Sprite2D
|
||||
|
||||
@export var max_health = 100
|
||||
@export var max_energy = 20
|
||||
|
||||
var health: float
|
||||
var energy: float
|
||||
|
||||
func move_to_center():
|
||||
var screen_size = get_viewport_rect().size
|
||||
position = Vector2(screen_size.x / 2, screen_size.y / 2)
|
||||
|
||||
func take_damage(amount: float):
|
||||
health -= amount
|
||||
if health <= 0:
|
||||
tower_broken.emit()
|
||||
get_tree().paused = true
|
||||
|
||||
func _ready():
|
||||
move_to_center()
|
||||
|
||||
health = max_health
|
||||
energy = max_energy
|
||||
|
||||
func _process(_delta):
|
||||
sprite.regeneration_progress = health / max_health
|
||||
|
||||
func _on_someone_entered(body):
|
||||
if body is Enemy:
|
||||
take_damage(body.damage)
|
||||
body.queue_free()
|
||||
|
17
scripts/attacker.gd
Normal file
17
scripts/attacker.gd
Normal file
@@ -0,0 +1,17 @@
|
||||
extends Enemy
|
||||
|
||||
@export var speed = 800
|
||||
@export var friction = 0.9
|
||||
|
||||
@export var target: Node2D
|
||||
|
||||
func deal_move(delta):
|
||||
if target:
|
||||
var angle = get_angle_to(target.position)
|
||||
var direction = Vector2(cos(angle), sin(angle))
|
||||
velocity = velocity.move_toward(direction * speed, speed * delta)
|
||||
velocity = velocity * friction
|
||||
|
||||
func _physics_process(delta):
|
||||
deal_move(delta)
|
||||
move_and_slide()
|
15
scripts/bullet.gd
Normal file
15
scripts/bullet.gd
Normal file
@@ -0,0 +1,15 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
@export var damage = 12.0
|
||||
|
||||
func _physics_process(delta):
|
||||
var collision = move_and_collide(velocity * delta)
|
||||
|
||||
if collision:
|
||||
var collider = collision.get_collider()
|
||||
if collider is Enemy:
|
||||
collider.take_damage(damage)
|
||||
queue_free()
|
||||
|
||||
func _on_timed_out():
|
||||
queue_free()
|
16
scripts/enemy.gd
Normal file
16
scripts/enemy.gd
Normal file
@@ -0,0 +1,16 @@
|
||||
class_name Enemy
|
||||
|
||||
extends CharacterBody2D
|
||||
|
||||
@export var damage = 8.0
|
||||
@export var max_health = 20
|
||||
|
||||
var health: float
|
||||
|
||||
func _ready():
|
||||
health = max_health
|
||||
|
||||
func take_damage(amount: float):
|
||||
health -= amount
|
||||
if health <= 0:
|
||||
queue_free()
|
23
scripts/enemy_farm.gd
Normal file
23
scripts/enemy_farm.gd
Normal file
@@ -0,0 +1,23 @@
|
||||
extends Node2D
|
||||
|
||||
@export var common_parent: Node2D
|
||||
@export var path_follow: PathFollow2D
|
||||
|
||||
@export var target: PackedScene
|
||||
@export var common_target: Node2D
|
||||
|
||||
func spawn():
|
||||
var instance = target.instantiate()
|
||||
|
||||
# Randomize
|
||||
path_follow.progress_ratio = randi()
|
||||
instance.position = path_follow.position
|
||||
|
||||
var target_scale = randf_range(0.2, 0.95)
|
||||
instance.scale = Vector2(target_scale, target_scale)
|
||||
instance.speed = randi_range(800, 1400)
|
||||
|
||||
instance.target = common_target
|
||||
|
||||
# Add into common parent
|
||||
common_parent.add_child(instance)
|
54
scripts/player.gd
Normal file
54
scripts/player.gd
Normal file
@@ -0,0 +1,54 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
@export var speed = 1200
|
||||
@export var speed_multiplier = 20
|
||||
@export var friction = 0.9
|
||||
|
||||
@export var dash_cooldown_duration = 1.0
|
||||
@export var dash_cooldown_timer: Timer
|
||||
|
||||
@export var weapon_bullet_speed = 3200
|
||||
@export var weapon_bullet_scene: PackedScene
|
||||
@export var weapon_bullet_parent: Node2D
|
||||
|
||||
@export var fire_cooldown_duration = 0.2
|
||||
@export var fire_cooldown_timer: Timer
|
||||
|
||||
func deal_move(delta):
|
||||
var input_direction = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
velocity = velocity.move_toward(input_direction * speed, speed * delta)
|
||||
velocity = velocity * friction
|
||||
|
||||
var is_dash = Input.is_action_pressed("skill_dash")
|
||||
if is_dash && dash_cooldown_timer.is_stopped():
|
||||
velocity *= speed_multiplier
|
||||
dash_cooldown_timer.start(dash_cooldown_duration)
|
||||
|
||||
func deal_weapon_shoot():
|
||||
var is_shooting = Input.is_action_pressed("weapon_fire")
|
||||
if is_shooting && fire_cooldown_timer.is_stopped():
|
||||
var mouse_position = get_global_mouse_position()
|
||||
var direction = (mouse_position - position).normalized()
|
||||
var bullet = weapon_bullet_scene.instantiate()
|
||||
bullet.rotation = direction.angle()
|
||||
weapon_bullet_parent.add_child(bullet)
|
||||
|
||||
bullet.global_position = global_position
|
||||
bullet.velocity = direction * weapon_bullet_speed
|
||||
|
||||
fire_cooldown_timer.start(fire_cooldown_duration)
|
||||
|
||||
func _on_dash_cooled_down():
|
||||
dash_cooldown_timer.stop()
|
||||
|
||||
func _on_fire_cooled_down():
|
||||
fire_cooldown_timer.stop()
|
||||
|
||||
func _ready():
|
||||
var screen_size = get_viewport_rect().size
|
||||
position = Vector2(screen_size.x / 2, screen_size.y / 2)
|
||||
|
||||
func _physics_process(delta):
|
||||
deal_move(delta)
|
||||
deal_weapon_shoot()
|
||||
move_and_slide()
|
7
scripts/tower_health_display.gd
Normal file
7
scripts/tower_health_display.gd
Normal file
@@ -0,0 +1,7 @@
|
||||
extends Sprite2D
|
||||
|
||||
@export var regeneration_progress = 0.5
|
||||
|
||||
func _process(delta):
|
||||
set_modulate(Color(1, 1, 1, regeneration_progress))
|
||||
rotation_degrees += 1
|
Reference in New Issue
Block a user