2024-01-27 21:10:58 +01:00
|
|
|
extends CharacterBody2D
|
|
|
|
|
|
|
|
|
|
|
|
const SPEED = 300.0
|
|
|
|
const JUMP_VELOCITY = -400.0
|
|
|
|
var angle = 2
|
|
|
|
var sprite
|
|
|
|
var anim
|
|
|
|
var csprite
|
2024-01-29 01:52:01 +01:00
|
|
|
var bpress = false
|
2024-01-27 21:10:58 +01:00
|
|
|
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
|
|
|
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
|
|
|
|
|
|
|
|
func _ready():
|
2024-01-29 01:52:01 +01:00
|
|
|
add_to_group("players")
|
2024-01-27 21:10:58 +01:00
|
|
|
anim = $AnimationPlayer
|
|
|
|
sprite = $Sprite2D
|
|
|
|
if Global.debug:
|
|
|
|
csprite = Global.dcpchar
|
|
|
|
sprite.texture = load(Global.pchars[Global.dparty[Global.dcpchar]])
|
|
|
|
else:
|
|
|
|
csprite = Global.cpchar
|
|
|
|
sprite.texture = load(Global.pchars[Global.party[Global.cpchar]])
|
|
|
|
|
|
|
|
func _physics_process(delta):
|
|
|
|
# Add the gravity.
|
|
|
|
#var velocity = Vector2.ZERO
|
|
|
|
if Global.live == 1:
|
|
|
|
velocity = (Vector2.RIGHT.rotated(rotation) * 500 * Global.xm * delta)-Vector2.UP.rotated(rotation) * 500 * Global.ym * delta
|
|
|
|
if Global.debug:
|
|
|
|
if Global.dcpchar != csprite:
|
|
|
|
csprite = Global.dcpchar
|
|
|
|
sprite.texture = load(Global.pchars[Global.dparty[Global.dcpchar]])
|
|
|
|
else:
|
|
|
|
if Global.cpchar != csprite:
|
|
|
|
csprite = Global.cpchar
|
|
|
|
sprite.texture = load(Global.pchars[Global.party[Global.cpchar]])
|
|
|
|
#origmpos = get_viewport().get_mouse_position()
|
|
|
|
#if Input.get_joy_axis(0,JOY_AXIS_LEFT_Y) != 0:
|
|
|
|
# velocity = Vector2.UP.rotated(rotation) * -400 * Input.get_joy_axis(0,JOY_AXIS_LEFT_Y)
|
|
|
|
position += velocity
|
|
|
|
if Global.ym > 0.3:
|
|
|
|
angle = 2
|
|
|
|
elif Global.ym < -0.3:
|
|
|
|
angle = 0
|
|
|
|
elif Global.xm > 0.3:
|
|
|
|
angle = 1
|
|
|
|
elif Global.xm < -0.3:
|
|
|
|
angle = 3
|
|
|
|
if velocity.y != 0 || velocity.x != 0:
|
|
|
|
if angle == 0:
|
|
|
|
anim.play("nwalk")
|
|
|
|
elif angle == 1:
|
|
|
|
anim.play("ewalk")
|
|
|
|
elif angle == 3:
|
|
|
|
anim.play("wwalk")
|
|
|
|
else:
|
|
|
|
anim.play("swalk")
|
|
|
|
else:
|
|
|
|
if angle == 0:
|
|
|
|
anim.play("nidle")
|
|
|
|
elif angle == 1:
|
|
|
|
anim.play("eidle")
|
|
|
|
elif angle == 3:
|
|
|
|
anim.play("widle")
|
|
|
|
else:
|
|
|
|
anim.play("sidle")
|
|
|
|
move_and_slide()
|
2024-01-29 01:52:01 +01:00
|
|
|
|
|
|
|
func _input(event):
|
|
|
|
if Global.live == 1:
|
|
|
|
if Input.is_action_just_pressed("shoot") && !bpress && Global.live == 1:
|
|
|
|
bpress = true
|
|
|
|
var bullet
|
|
|
|
if Global.debug:
|
|
|
|
bullet = load(Global.pbbullets[Global.dparty[Global.dcpchar]])
|
|
|
|
else:
|
|
|
|
bullet = load(Global.pbbullets[Global.party[Global.cpchar]])
|
|
|
|
var new_bullet = bullet.instantiate()
|
|
|
|
new_bullet.velocity = Vector2(0, -500).rotated(deg_to_rad(angle * 90))
|
|
|
|
var rposition = Vector2(0, -96).rotated(deg_to_rad(angle * 90))
|
|
|
|
if angle == 2:
|
|
|
|
new_bullet.position = Vector2(position.x + rposition.x, position.y + rposition.y + 98)
|
|
|
|
else:
|
|
|
|
new_bullet.position = Vector2(position.x + rposition.x, position.y + rposition.y)
|
|
|
|
if new_bullet.position.x > 0 && new_bullet.position.y > 0 && new_bullet.position.x < 1280 && new_bullet.position.y < 720:
|
|
|
|
get_parent().add_child(new_bullet)
|
|
|
|
elif Input.is_action_just_released("shoot") && bpress:
|
|
|
|
bpress = false
|