clegg
This commit is contained in:
commit
6a269eb236
97 changed files with 2137 additions and 0 deletions
139
objects/player/player.gd
Normal file
139
objects/player/player.gd
Normal file
|
@ -0,0 +1,139 @@
|
|||
extends CharacterBody2D
|
||||
|
||||
const WALK_ACCEL = 50.0
|
||||
const WALK_TOPSPEED = 160.0
|
||||
|
||||
const FLY_ACCEL = 50.0
|
||||
const FLY_TOPSPEED = 200.0
|
||||
|
||||
const GRAVITY = 15.0
|
||||
const FAST_FALL_VELOCITY = 500.0
|
||||
|
||||
var downward_velocity = 0.0
|
||||
var max_downward_velocity = 1200.0
|
||||
var fast_fall_max_downward_velocity = 1500.0
|
||||
|
||||
var fuel = 100.0
|
||||
const jetpack_velocity = 10.0
|
||||
|
||||
var score = 0
|
||||
|
||||
var aim_direction = 1
|
||||
|
||||
const BULLET = preload("res://weapons/spreadshot/spread_shot.tscn")
|
||||
const GRAZE_PARTICLES = preload("res://sprites/Player/graze_particles.tscn")
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
var axis = Input.get_axis("ui_left","ui_right")
|
||||
if axis != 0: aim_direction = axis
|
||||
#region ground movement
|
||||
if axis != 0:
|
||||
if velocity.y < 0:
|
||||
move(FLY_ACCEL,FLY_TOPSPEED)
|
||||
else:
|
||||
move(WALK_ACCEL,WALK_TOPSPEED)
|
||||
if is_on_floor():
|
||||
%Sprite.play("walk")
|
||||
else:
|
||||
%Sprite.play("fly")
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, WALK_ACCEL)
|
||||
%Sprite.play("idle")
|
||||
#endregion
|
||||
#region gun
|
||||
if Input.is_action_just_pressed("shoot"):
|
||||
%ShootSound.play()
|
||||
var bullet = BULLET.instantiate()
|
||||
bullet.global_position = global_position
|
||||
get_parent().add_child(bullet)
|
||||
#endregion
|
||||
#region jetpack flight
|
||||
if Input.is_action_pressed("fly"):
|
||||
if fuel > 0.0:
|
||||
%Sprite.play("fly")
|
||||
fuel -= 40.0 * delta
|
||||
downward_velocity = 0.0
|
||||
if %JetpackSound.is_playing() == false: %JetpackSound.play()
|
||||
if %JetpackSound.pitch_scale < 1.25:
|
||||
%JetpackSound.pitch_scale += 0.4 * delta
|
||||
velocity.y -= jetpack_velocity
|
||||
emit_fire(true)
|
||||
|
||||
else:
|
||||
emit_fire(false)
|
||||
else:
|
||||
if %JetpackSound.pitch_scale > 0.4:
|
||||
%JetpackSound.pitch_scale -= 0.1 * delta
|
||||
emit_fire(false)
|
||||
|
||||
#endregion
|
||||
if is_on_floor():
|
||||
downward_velocity = 0.0
|
||||
GlobalFunctions.append_score()
|
||||
fuel = 100.0
|
||||
silence_jetpack(delta)
|
||||
else:
|
||||
if Input.is_action_pressed("fast_fall"):
|
||||
silence_jetpack(delta)
|
||||
else:
|
||||
%JetpackSound.volume_db = 0.0
|
||||
|
||||
if Input.is_action_pressed("fast_fall"):
|
||||
downward_velocity += FAST_FALL_VELOCITY
|
||||
downward_velocity = clamp(downward_velocity,0.0,fast_fall_max_downward_velocity)
|
||||
velocity.y = clamp(velocity.y,velocity.y,fast_fall_max_downward_velocity)
|
||||
else:
|
||||
downward_velocity += GRAVITY
|
||||
downward_velocity = clamp(downward_velocity,0.0,max_downward_velocity)
|
||||
velocity.y = clamp(velocity.y,velocity.y,max_downward_velocity)
|
||||
fuel -= 1 * delta
|
||||
|
||||
|
||||
|
||||
#jetpack pitch
|
||||
|
||||
velocity.y += downward_velocity * delta
|
||||
move_and_slide()
|
||||
#if event.is_action_pressed()
|
||||
#endregion
|
||||
|
||||
|
||||
func move(acceleration,topspeed):
|
||||
var axis = Input.get_axis("ui_left","ui_right")
|
||||
velocity.x += (axis * acceleration)
|
||||
%Sprite.scale.x = axis
|
||||
velocity.x = clamp(velocity.x,-topspeed,topspeed)
|
||||
|
||||
func silence_jetpack(delta):
|
||||
%JetpackSound.pitch_scale = 1.0
|
||||
%JetpackSound.volume_db -= 50 * delta
|
||||
|
||||
func emit_fire(emit:bool=true,lifetime:float=0.24):
|
||||
get_tree().get_nodes_in_group("fire_particles")[0].emitting = emit
|
||||
get_tree().get_nodes_in_group("fire_particles")[0].lifetime = lifetime
|
||||
get_tree().get_nodes_in_group("fire_particles")[1].emitting = emit
|
||||
get_tree().get_nodes_in_group("fire_particles")[1].lifetime = lifetime
|
||||
|
||||
func _on_area_2d_body_entered(body: Node2D) -> void:
|
||||
if body.is_in_group("death"):
|
||||
get_tree().reload_current_scene()
|
||||
|
||||
|
||||
func _on_area_2d_area_entered(area: Area2D) -> void:
|
||||
#if area.is_in_group("death") or area.is_in_group("hurt"):
|
||||
#get_tree().reload_current_scene()
|
||||
pass
|
||||
|
||||
|
||||
func _on_hurtbox_area_entered(area: Area2D) -> void:
|
||||
get_tree().reload_current_scene()
|
||||
|
||||
|
||||
func _on_graze_hitbox_area_entered(area: Area2D) -> void:
|
||||
if area.is_in_group("enemy_bullet"):
|
||||
if area.get_parent().grazed == false:
|
||||
GlobalFunctions.queue_score(0)
|
||||
var graze_particle = GRAZE_PARTICLES.instantiate()
|
||||
graze_particle.global_position = global_position
|
||||
get_parent().add_child(graze_particle)
|
||||
area.get_parent().grazed = true
|
Loading…
Add table
Add a link
Reference in a new issue