A little folders cleanup
This commit is contained in:
parent
997e3c0982
commit
545da7be1f
90 changed files with 68 additions and 1661 deletions
|
|
@ -1,16 +1,18 @@
|
|||
extends Node
|
||||
class_name Game
|
||||
|
||||
## TODO: rewrite item system
|
||||
|
||||
enum ITEM_TYPE {VALUABLE, WEAPON, HULL, SHIELD, ENGINE, AMMUNITION}
|
||||
enum AMMO_TYPE {NULL, LASER_ENERGY, ROCKETS}
|
||||
enum BASE_TYPE {POWER, MINING, FOOD, TRADING, MODULE}
|
||||
enum Faction {None, Player, Peaceful, Neutral, Aggressive}
|
||||
|
||||
const DEFAULT_ITEM = preload("res://items/test_item.tres")
|
||||
const DEFAULT_WEAPON = preload("res://scenes/weapons/presets/SingleLaserMk1.tscn")
|
||||
const DEFAULT_HULL = preload("res://scenes/hulls/starterhull.tscn")
|
||||
const DEFAULT_ENGINE = preload("res://scenes/engines/starterengine.tscn")
|
||||
const DEFAULT_SHIELD = preload("res://scenes/shields/startershield.tscn")
|
||||
#const DEFAULT_ITEM = preload("res://items/test_item.tres")
|
||||
#const DEFAULT_WEAPON = preload("res://scenes/weapons/presets/SingleLaserMk1.tscn")
|
||||
#const DEFAULT_HULL = preload("res://scenes/hulls/starterhull.tscn")
|
||||
#const DEFAULT_ENGINE = preload("res://scenes/engines/starterengine.tscn")
|
||||
#const DEFAULT_SHIELD = preload("res://scenes/shields/startershield.tscn")
|
||||
|
||||
const salt = "2ndbeam"
|
||||
const gameversion = "Ifre 1.0"
|
||||
|
|
@ -115,27 +117,15 @@ static func get_item(id : String) -> Item:
|
|||
if ResourceLoader.exists(path):
|
||||
var res = load(path)
|
||||
return res.duplicate()
|
||||
return DEFAULT_ITEM
|
||||
return null
|
||||
|
||||
## Returns weapon packed scene if it exists or DEFAULT_WEAPON instead
|
||||
static func get_weapon(id : String) -> PackedScene:
|
||||
var path = "res://scenes/weapons/presets/{name}.tscn".format({"name": id})
|
||||
var res = load(path)
|
||||
if res != null:
|
||||
return res
|
||||
else:
|
||||
return DEFAULT_WEAPON
|
||||
return res
|
||||
|
||||
static func get_module(id : String, type : String) -> PackedScene:
|
||||
var path = "res://scenes/{type}s/{name}.tscn".format({"name": id, "type": type})
|
||||
var res = load(path)
|
||||
if res != null:
|
||||
return res
|
||||
match type:
|
||||
"hull":
|
||||
return DEFAULT_HULL
|
||||
"engine":
|
||||
return DEFAULT_ENGINE
|
||||
"shield":
|
||||
return DEFAULT_SHIELD
|
||||
return DEFAULT_HULL
|
||||
return res
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
extends MenuDefaultButton
|
||||
|
||||
func action():
|
||||
get_tree().current_scene.recolor()
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
extends MenuDefaultButton
|
||||
|
||||
func action():
|
||||
ship.destroy()
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
extends StaticBody2D
|
||||
|
||||
var faction = "none"
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
extends Area2D
|
||||
|
||||
func _on_body_entered(body):
|
||||
if body is NPCShip:
|
||||
body.switchdestination()
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
extends Camera2D
|
||||
|
||||
@onready var ship = get_parent()
|
||||
var engine
|
||||
@onready var cur_scale = zoom.x
|
||||
@onready var min_scale = cur_scale / 1.5
|
||||
@onready var max_scale = cur_scale * 2
|
||||
var rdy = false
|
||||
|
||||
func _ready():
|
||||
get_tree().create_timer(0.05).timeout.connect(is_rdy)
|
||||
|
||||
func is_rdy():
|
||||
rdy = true
|
||||
engine = ship.engine
|
||||
|
||||
func _process(_delta):
|
||||
if !rdy:
|
||||
return
|
||||
engine = ship.engine
|
||||
var speed_percentage = engine.max_speed / engine.speed
|
||||
var factor : float
|
||||
if get_parent().allow_shooting:
|
||||
factor = clamp(speed_percentage, min_scale, max_scale)
|
||||
if engine.speed < 0:
|
||||
factor = max_scale
|
||||
else:
|
||||
factor = 1.0
|
||||
zoom = Vector2(factor, factor)
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
extends Label
|
||||
|
||||
@export var counter_id : String
|
||||
@onready var ship = $"../../.."
|
||||
var hull
|
||||
var shield
|
||||
var rdy = false
|
||||
|
||||
func _ready():
|
||||
get_tree().create_timer(0.05).timeout.connect(is_rdy)
|
||||
|
||||
func is_rdy():
|
||||
rdy = true
|
||||
hull = ship.hull
|
||||
shield = ship.shield
|
||||
|
||||
func _process(_delta) -> void:
|
||||
if !rdy:
|
||||
return
|
||||
hull = ship.hull
|
||||
shield = ship.shield
|
||||
match counter_id:
|
||||
"ammo":
|
||||
text = str(hull.ammunition)
|
||||
"fuel":
|
||||
text = "Fuel: {fuel} / {max} units".format({"fuel":hull.fuel, "max":hull.max_fuel})
|
||||
"hp":
|
||||
text = "Hull Strength: {hp} / {max} units".format({"hp":"%0.2f" % hull.hp, "max":hull.max_hp})
|
||||
"money":
|
||||
text = "Available Money: {money} units".format({"money":ship.money})
|
||||
"shield":
|
||||
text = "Shield Capacity: {shield} / {max} units".format({"shield":"%0.2f" % shield.capacity, "max":shield.max_capacity})
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
extends GPUParticles2D
|
||||
|
||||
@onready var engine = $".."
|
||||
|
||||
func _process(_delta):
|
||||
var speed_percentage = clamp(engine.speed / engine.max_speed, 0.75, 1.5)
|
||||
speed_scale = speed_percentage if engine.speed > 0 else 1
|
||||
emitting = engine.speed > 0
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
extends Node2D
|
||||
|
||||
@export var faction : bool
|
||||
|
||||
func changeitemscolor():
|
||||
var items = get_children()
|
||||
var ship = get_tree().current_scene.ship
|
||||
for item in items:
|
||||
#item.modulate = modulate
|
||||
if item.material:
|
||||
item.material.set_shader_parameter("color",modulate)
|
||||
if faction:
|
||||
ship.minimap.add_marker(item, "hostile")
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
extends Area2D
|
||||
|
||||
@export var amount: float = 20
|
||||
|
||||
@onready var text = $Label
|
||||
|
||||
func _on_body_entered(body):
|
||||
if body is MainShip:
|
||||
body.money += amount
|
||||
queue_free()
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
extends Node2D
|
||||
|
||||
#class_name Hull
|
||||
|
||||
@export var max_hp : float = 30
|
||||
@export var max_fuel : float = 1000
|
||||
@export var max_weight : float = 100
|
||||
@export var id : String = "starterhull"
|
||||
@onready var hp : float = max_hp
|
||||
@onready var fuel : float = max_fuel
|
||||
|
||||
var weight : float = 0
|
||||
|
||||
var ammunition = {
|
||||
"n/a" : 0,
|
||||
"Laser Energy" : 100,
|
||||
"Rockets" : 10
|
||||
}
|
||||
|
||||
var max_ammunition = {
|
||||
"n/a" : 0,
|
||||
"Laser Energy" : 100,
|
||||
"Rockets" : 20
|
||||
}
|
||||
|
||||
var cargo = {}
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
extends Node2D
|
||||
|
||||
#class_name Shield
|
||||
|
||||
@export var max_capacity : int = 8
|
||||
@export var shield_charge_rate : float = 1
|
||||
@export var recharge_timer : Timer
|
||||
@export var laser_timer : Timer
|
||||
@export var laser_charge_rate : float = 20
|
||||
@export var id : String = "startershield"
|
||||
|
||||
@onready var ship = get_parent()
|
||||
@onready var capacity : float = max_capacity
|
||||
var can_recharge : bool = false
|
||||
var laser_recharge : bool = true
|
||||
|
||||
var wave_distances = [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]
|
||||
var wave_positions = [Vector2.ZERO,Vector2.ZERO,Vector2.ZERO,Vector2.ZERO,Vector2.ZERO,Vector2.ZERO,Vector2.ZERO,Vector2.ZERO,Vector2.ZERO,Vector2.ZERO]
|
||||
|
||||
func _ready():
|
||||
recharge_timer.timeout.connect(recharging_timer_out)
|
||||
laser_timer.timeout.connect(laser_timer_out)
|
||||
material = ship.material
|
||||
|
||||
func deal_damage(damage : float,hit_position : Vector2):
|
||||
# Shield wave
|
||||
var shield_tween = create_tween()
|
||||
var wave_index = find_free_index()
|
||||
shield_tween.tween_method(set_wave_distance.bind(wave_index),0,material.get_shader_parameter("max_distance"),0.5)
|
||||
shield_tween.tween_callback(reset_wave_distance.bind(wave_index))
|
||||
shield_tween.custom_step(0.1)
|
||||
|
||||
wave_positions[wave_index] = hit_position
|
||||
|
||||
material.set_shader_parameter("wave_centers",wave_positions)
|
||||
material.set_shader_parameter("wave_distances",wave_distances)
|
||||
|
||||
capacity -= damage
|
||||
if capacity < 0:
|
||||
ship.hull.hp += capacity
|
||||
capacity = 0
|
||||
can_recharge = false
|
||||
recharge_timer.start()
|
||||
laser_timer.start()
|
||||
|
||||
func set_wave_distance(value,index):
|
||||
wave_distances[index] = value
|
||||
material.set_shader_parameter("wave_distances",wave_distances)
|
||||
|
||||
func reset_wave_distance(index):
|
||||
wave_distances[index] = -1
|
||||
material.set_shader_parameter("wave_distances",wave_distances)
|
||||
|
||||
func find_free_index() -> int:
|
||||
for i in range(wave_distances.size()):
|
||||
if wave_distances[i] == -1:
|
||||
return i
|
||||
return 0
|
||||
|
||||
func recharging_timer_out():
|
||||
can_recharge = true
|
||||
|
||||
func _physics_process(delta):
|
||||
if can_recharge:
|
||||
capacity += shield_charge_rate * delta
|
||||
if capacity > max_capacity:
|
||||
capacity = max_capacity
|
||||
can_recharge = false
|
||||
if laser_recharge:
|
||||
ship.hull.ammunition["Laser Energy"] += laser_charge_rate * delta
|
||||
if ship.hull.ammunition["Laser Energy"] > ship.hull.max_ammunition["Laser Energy"]:
|
||||
ship.hull.ammunition["Laser Energy"] = ship.hull.max_ammunition["Laser Energy"]
|
||||
laser_recharge = false
|
||||
|
||||
func laser_timer_out():
|
||||
laser_recharge = true
|
||||
|
|
@ -1,109 +0,0 @@
|
|||
extends Node2D
|
||||
|
||||
# TODO: rewrite movement system to be impulse based
|
||||
|
||||
# class_name ShipEngine
|
||||
|
||||
@export var max_speed : float = 200
|
||||
@export var max_turbo_speed : float = 300
|
||||
@export var acceleration : float = 50
|
||||
@export var fuel_consumption : float = 100
|
||||
@export var rotation_speed : int = 90
|
||||
@export var id : String = "starterengine"
|
||||
@export var dash_recharge_timer : Timer
|
||||
@export_range(1, 10, 1) var dashes_count : int = 3
|
||||
|
||||
@onready var ship = get_parent()
|
||||
@onready var double_tap_timer = Timer.new()
|
||||
@onready var dash_timer = Timer.new()
|
||||
|
||||
var hull
|
||||
var speed = 0
|
||||
var min_speed = max_speed / -4
|
||||
var turbo_enabled = false
|
||||
var alternative_movement = false
|
||||
var destination_angle : float
|
||||
var destination_difference : float
|
||||
var dash_direction_left = true
|
||||
var is_double_tapping = false
|
||||
var is_dashing = false
|
||||
|
||||
func _ready():
|
||||
dash_recharge_timer.timeout.connect(dash_recharge)
|
||||
add_child(double_tap_timer)
|
||||
add_child(dash_timer)
|
||||
double_tap_timer.one_shot = true
|
||||
double_tap_timer.timeout.connect(not_double_tapping)
|
||||
dash_timer.one_shot = true
|
||||
dash_timer.timeout.connect(not_dashing)
|
||||
|
||||
func _physics_process(delta):
|
||||
hull = ship.hull
|
||||
modulate = ship.material.get_shader_parameter('color')
|
||||
var turbo_input = Input.get_action_raw_strength("turbo")
|
||||
var acceleration_input = Input.get_axis("deccelerate", "accelerate") if ship is MainShip else 1.0
|
||||
var rotation_input = Input.get_axis("rotateleft", "rotateright")
|
||||
# проверка на рывок
|
||||
var left_released = Input.is_action_just_released("rotateleft")
|
||||
var right_released = Input.is_action_just_released("rotateright")
|
||||
if (left_released or right_released):
|
||||
if !is_double_tapping and !is_dashing:
|
||||
double_tap_timer.start(0.25)
|
||||
is_double_tapping = true
|
||||
print("first tap")
|
||||
else:
|
||||
dash_direction_left = left_released
|
||||
is_dashing = true
|
||||
is_double_tapping = false
|
||||
dash_timer.start(0.1)
|
||||
double_tap_timer.stop()
|
||||
print("second tap")
|
||||
|
||||
if destination_angle - ship.rotation_degrees == clamp(destination_angle - ship.rotation_degrees, -180, 180):
|
||||
destination_difference = destination_angle - ship.rotation_degrees
|
||||
else:
|
||||
destination_difference = ship.rotation_degrees - destination_angle
|
||||
if destination_difference != clamp(destination_difference, -1, 1):
|
||||
ship.rotation_degrees += sign(destination_difference) * rotation_speed * delta
|
||||
else:
|
||||
ship.rotation_degrees = destination_angle
|
||||
if alternative_movement:
|
||||
destination_angle += rotation_input * rotation_speed * delta
|
||||
if destination_angle > 180: destination_angle = -180
|
||||
if destination_angle < -180: destination_angle = 180
|
||||
if Vector2.ZERO.distance_to(global_position) >= 5800:
|
||||
destination_angle = rad_to_deg(global_position.angle_to_point(Vector2.ZERO))
|
||||
elif ship is MainShip:
|
||||
destination_angle = rad_to_deg(ship.global_position.angle_to_point(get_global_mouse_position()))
|
||||
turbo_enabled = clamp(turbo_input * hull.fuel, 0, 1) if ship is MainShip else (ship.state == "runaway" and hull.fuel > 0)
|
||||
if !turbo_enabled:
|
||||
speed = clamp(speed + acceleration_input * acceleration * delta, min_speed, max(max_speed, speed))
|
||||
if speed > max_speed:
|
||||
speed -= acceleration * delta if acceleration_input != -1 else 0
|
||||
else:
|
||||
if hull.fuel > 0:
|
||||
speed = clamp(speed + acceleration * delta, min_speed, max_turbo_speed)
|
||||
if speed > max_speed:
|
||||
hull.fuel -= fuel_consumption * delta
|
||||
if hull.fuel < 0:
|
||||
hull.fuel = 0
|
||||
var additional_rotation = 0
|
||||
var additional_speed = 0
|
||||
if is_dashing and ship is MainShip:
|
||||
print("wanna dash")
|
||||
additional_speed = 500
|
||||
additional_rotation = deg_to_rad(-90) if dash_direction_left else deg_to_rad(90)
|
||||
ship.velocity = Vector2.from_angle(ship.rotation + additional_rotation) * (speed + additional_speed)
|
||||
ship.move_and_slide()
|
||||
|
||||
if Input.is_action_just_released("alternatemovement") and ship is MainShip:
|
||||
alternative_movement = !alternative_movement
|
||||
|
||||
func dash_recharge():
|
||||
pass
|
||||
|
||||
func not_double_tapping():
|
||||
is_double_tapping = false
|
||||
|
||||
func not_dashing():
|
||||
is_dashing = false
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
extends CharacterBody2D
|
||||
# TODO: rewrite NPC to use state machine
|
||||
# TODO: create class_name which is used to inherit common attributes to mainship and npc ship
|
||||
class_name NPCShip
|
||||
|
||||
@export var destination_timer : Timer
|
||||
@export var faction = "Enemy"
|
||||
@export var bounty_min : int = 20
|
||||
@export var bounty_max : int = 30
|
||||
@export var bounty : PackedScene
|
||||
@onready var ship = get_tree().current_scene.get_node("MainShip")
|
||||
@onready var engine = $"Engine"
|
||||
@onready var hull = $"Hull"
|
||||
@onready var debug_label = $DebugLabel
|
||||
@onready var target_snap = $TargetSnap
|
||||
@onready var healthbar = $Zalupa/ZalupaTwo/Health
|
||||
@onready var shield = $Shield
|
||||
var state = "idle"
|
||||
var shooting = false
|
||||
var allow_shooting = true
|
||||
signal destroyed
|
||||
|
||||
func _ready():
|
||||
destination_timer.timeout.connect(switchdestination)
|
||||
target_snap.mouse_entered.connect(get_tree().current_scene.addtargetlist.bind(self))
|
||||
target_snap.mouse_exited.connect(get_tree().current_scene.removetargetlist.bind(self))
|
||||
destroyed.connect(get_tree().current_scene.enemydestroyed)
|
||||
shield.material = material
|
||||
material.set_shader_parameter("color",modulate)
|
||||
|
||||
func _physics_process(_delta):
|
||||
match state:
|
||||
"idle":
|
||||
idlestate()
|
||||
"chase":
|
||||
chasestate()
|
||||
"maintaindistance":
|
||||
maintaindistancestate()
|
||||
"runaway":
|
||||
runawaystate()
|
||||
var format = {"HP" : "%0.2f" % hull.hp, "SC" : "%0.2f" % shield.capacity}
|
||||
healthbar.text = "{HP} HS + {SC} SC".format(format)
|
||||
if hull.hp <= 0:
|
||||
destroy()
|
||||
if Vector2.ZERO.distance_to(global_position) > 5800:
|
||||
destroy(true)
|
||||
|
||||
func switchdestination():
|
||||
engine.destination_angle = randi_range(0, 360)
|
||||
|
||||
func idlestate():
|
||||
shooting = false
|
||||
if global_position.distance_to(ship.global_position) <= 512 and ship.allow_shooting:
|
||||
state = "chase"
|
||||
|
||||
func chasestate():
|
||||
engine.destination_angle = rad_to_deg(global_position.angle_to_point(ship.global_position))
|
||||
shooting = true if abs(engine.destination_difference) <= 5 else false
|
||||
if global_position.distance_to(ship.global_position) > 512 or !ship.allow_shooting:
|
||||
state = "idle"
|
||||
if hull.hp < hull.max_hp * 0.2: state = "runaway"
|
||||
if global_position.distance_to(ship.global_position) <= 128:
|
||||
state = "maintaindistance"
|
||||
|
||||
func maintaindistancestate():
|
||||
engine.destination_angle += 1
|
||||
shooting = true if abs(engine.destination_difference) <= 5 else false
|
||||
if global_position.distance_to(ship.global_position) > 128:
|
||||
state = "chase"
|
||||
if !ship.allow_shooting:
|
||||
state = "idle"
|
||||
|
||||
func runawaystate():
|
||||
shooting = false
|
||||
engine.destination_angle = rad_to_deg(global_position.angle_to_point(ship.global_position)) - 180
|
||||
if global_position.distance_to(ship.global_position) > 1024 or !ship.allow_shooting:
|
||||
state = "idle"
|
||||
|
||||
func destroy(silent : bool = false):
|
||||
hull.hp = hull.max_hp
|
||||
hull.fuel = hull.max_fuel
|
||||
shield.capacity = shield.max_capacity
|
||||
state = "idle"
|
||||
var bounty_inst = bounty.instantiate()
|
||||
get_tree().current_scene.add_child(bounty_inst)
|
||||
bounty_inst.global_position = global_position
|
||||
bounty_inst.amount = randi_range(bounty_min, bounty_max)
|
||||
bounty_inst.text.text = str(bounty_inst.amount) + " MU"
|
||||
global_position = Vector2(randi_range(-4096, 4096), randi_range(-4096, 4096))
|
||||
if !silent:
|
||||
destroyed.emit(self)
|
||||
Loading…
Add table
Add a link
Reference in a new issue