Add player scripts and stuff

This commit is contained in:
SondreElg
2025-10-04 00:04:24 +02:00
parent 255aac0ee9
commit 1102b73197
9 changed files with 180 additions and 0 deletions

5
growth/enums.gd Normal file
View File

@@ -0,0 +1,5 @@
extends Node
# ^Is this needed?
export enum PlayerState {Still, Moving, Dashing, Firing}
# export enum PlayerActionability {None, Move, All}

1
growth/enums.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://b7uho5n7e7su7

97
growth/player.gd Normal file
View File

@@ -0,0 +1,97 @@
extends Node2D
# ActionState should probably be expandable to
enum ActionState {None, Deploying, Firing, Charging}
enum MoveState {Still, Moving, Dashing, Loading}
@export var speed = 100 # How fast the player will move (pixels/sec).
@export var dashSpeed = 200
@export var dashEnd = 0.8
@export var dashCooldown = 0.5
var screen_size # Size of the game window.
var actionState = ActionState.None
var moveState = MoveState.Still
var chargeLevel = 0;
var chargeRate = 1;
var charged = false;
var dashTime = 0;
var dashCooldownTime = 0;
var dashOnCooldown = false;
var dashEaseFactorMinimum = speed / float(dashSpeed)
var moveDirection = Vector2.ZERO;
var velocity = Vector2.ZERO # The player's movement vector.
func updateMoveDirection():
if Input.is_action_pressed("move_right"):
moveDirection.x += 1
if moveDirection.is_action_pressed("move_left"):
moveDirection.x -= 1
if Input.is_action_pressed("move_down"):
moveDirection.y += 1
if Input.is_action_pressed("move_up"):
moveDirection.y -= 1
func charge():
# Charge attack
if not charged and actionState == ActionState.Charging:
chargeLevel += chargeRate;
if chargeLevel >= 100:
charged = false;
chargeLevel = 0;
elif chargeLevel > 0:
# Gradual charge dropoff
chargeLevel = max(chargeLevel - chargeRate * 2, 0);
func dash(delta):
dashTime += delta;
const easeFactor = 1;
velocity = moveDirection.normalize() * dashSpeed * easeFactor;
if (dashTime >= dashEnd):
dashOnCooldown = true;
dashTime = 0;
func _ready():
screen_size = get_viewport_rect().size
func _process(delta):
if (dashOnCooldown):
dashCooldownTime += delta;
if (dashCooldownTime >= dashCooldown):
dashOnCooldown = false;
dashCooldownTime = 0;
# handle moveState
if moveState == MoveState.Loading:
null
# Idk dude, thought it might be a fun effect when you take damage
elif moveState != MoveState.Dashing:
updateMoveDirection();
velocity = moveDirection.normalize() * speed;
if velocity.x || velocity.y:
moveState = MoveState.Moving;
elif moveState != MoveState.Dashing:
moveState = MoveState.Still;
elif Input.is_action_pressed("dash") or actionState == MoveState.Dashing:
if (moveState != MoveState.Dashing):
updateMoveDirection();
moveState = MoveState.Dashing;
dash(delta);
# Handle actionState
if Input.is_action_pressed("deploy"):
actionState = ActionState.Deploying;
# Deploy
elif Input.is_action_pressed("fire"):
actionState = ActionState.Firing;
# Fire
elif Input.is_action_pressed("charge"):
actionState = ActionState.Charging;
charge();

1
growth/player.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://b6lfgkrbmr8ee

13
growth/player.tscn Normal file
View File

@@ -0,0 +1,13 @@
[gd_scene load_steps=2 format=3 uid="uid://dhhnr3xkxbxlu"]
[ext_resource type="Script" uid="uid://b6lfgkrbmr8ee" path="res://player.gd" id="1_4flbx"]
[node name="Player" type="Node2D"]
script = ExtResource("1_4flbx")
metadata/_edit_group_ = true
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
[node name="Area2D" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]

View File

@@ -14,6 +14,41 @@ config/name="growth"
config/features=PackedStringArray("4.5", "GL Compatibility")
config/icon="res://icon.svg"
[input]
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":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null)
]
}
move_down={
"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":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
]
}
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":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
]
}
move_up={
"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":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
]
}
deploy={
"deadzone": 0.2,
"events": []
}
fire={
"deadzone": 0.2,
"events": []
}
dash={
"deadzone": 0.2,
"events": []
}
[rendering]
renderer/rendering_method="gl_compatibility"

16
growth/virus.gd Normal file
View File

@@ -0,0 +1,16 @@
extends Node2D
@export var speed = 400 # How fast the player will move (pixels/sec).
func _ready():
# Initalize with random abilities from available abilities
func _process(delta):
# Grow in size
# RayCast towards player (every N frames), moving towards it if close enough
# Or should we always move towards the player?
# Use abilities if:
## Raycast hit
## Regular intervals (if close enough to player)?

1
growth/virus.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://bwhxwf77egesx

11
growth/virus.tscn Normal file
View File

@@ -0,0 +1,11 @@
[gd_scene format=3 uid="uid://bsv3h2lpv7h77"]
[node name="Virus" type="Node2D"]
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
[node name="Area2D" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
[node name="RayCast2D" type="RayCast2D" parent="."]