+1 vote
extends KinematicBody2D


export var ACCELERATION = 10
export var MAX_SPEED = 100
export var FRICTION = 400

signal slowtime
signal respawn

enum {
    MOVE,
    ROLL,
    ATTACK,
    SWIM
}

var state = SWIM
var velocity = Vector2.ZERO
var roll_vector = Vector2.LEFT
var stats = PlayerStats
var onwater = false

onready var joystick = get_parent().get_node("Joystick/Joystick_Button")
onready var animationPlayer = $AnimationPlayer
onready var animationTree = $AnimationTree
onready var animationstate = animationTree.get("parameters/playback")
onready var stampHitbox = $Hitbox
onready var hurtbox = $Hurtbox
onready var blinkAnimationPlayer = $BlinkAnimationPlayer


func _ready():
    randomize()
    stats.connect("no_health", self, "_on_Player_respawn")
    animationTree.active = true
    stampHitbox.knockback_vector = roll_vector

func _physics_process(delta):
    match state:
        MOVE:
            move_state(delta)

        ROLL:
            pass

        ATTACK:
            attack_state(delta)


        SWIM:
            swim_state(delta)


func turn_state(delta):
    pass

func move_state(delta):
    if onwater == true:
        state = SWIM

    else:


        var input_vector = Vector2.ZERO
        input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
        input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
        input_vector = input_vector.normalized()

        if input_vector != Vector2.ZERO:
            roll_vector = input_vector
            stampHitbox.knockback_vector = input_vector
            animationTree.set("parameters/Idle/blend_position", input_vector)
            animationTree.set("parameters/Run/blend_position", input_vector)
            animationTree.set("parameters/Attack/blend_position", input_vector)
            animationTree.set("parameters/Swim/blend_position", input_vector)
            animationTree.set("parameters/IdleSwim/blend_position", input_vector)
            animationstate.travel("Run")
            velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION + delta)
        else:
            animationstate.travel("Idle")
            velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)


        velocity = move_and_slide(velocity) 

        if Input.is_action_just_pressed("attack"):
            state = ATTACK

        if onwater == true:
            state = SWIM



func swim_state(delta):

    if onwater == false:
        state = MOVE
    else:

        var input_vector = Vector2.ZERO
        input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
        input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
        input_vector = input_vector.normalized()

        if input_vector != Vector2.ZERO:
            roll_vector = input_vector
            stampHitbox.knockback_vector = input_vector
            animationTree.set("parameters/Idle/blend_position", input_vector)
            animationTree.set("parameters/Run/blend_position", input_vector)
            animationTree.set("parameters/Attack/blend_position", input_vector)
            animationTree.set("parameters/Swim/blend_position", input_vector)
            animationTree.set("parameters/IdleSwim/blend_position", input_vector)
            animationstate.travel("Swim")
            velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION + delta)
        else:
            if onwater == true:
                animationstate.travel("IdleSwim")
                velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)

            else:
                animationstate.travel("Idle")
                velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)


        velocity = move_and_slide(velocity) 






func attack_state(delta):
    velocity = Vector2.ZERO
    animationstate.travel("Attack")

func attack_animation_finished():
    state = MOVE


func _on_Hurtbox_area_entered(area):
    stats.health -= 1
    emit_signal("slowtime")
    hurtbox.start_invincibility(0.5)
    hurtbox.create_hit_effect(area)


func _on_Hurtbox_invincibility_started():
    blinkAnimationPlayer.play("Start")


func _on_Hurtbox_invincibility_ended():
    blinkAnimationPlayer.play("Stop")





func _on_Player_respawn():
    position = Vector2(342, 130)
    stats.health = 6
    #emit_signal("respawn")







func _on_WaterArea_body_entered(body):
    var onwater = true
    print(onwater)


func _on_WaterArea_body_exited(body):
    var onwater = false
    print(onwater)

enter image description here

in Engine by (20 points)

1 Answer

0 votes
Best answer

Removing the var text solves the issue:

func onWaterAreabodyentered(body):
var onwater = true
print(onwater)

func onWaterAreabodyexited(body):
var onwater = false
print(onwater)

func _on_WaterArea_body_entered(body):
    onwater = true
    print(onwater)


func _on_WaterArea_body_exited(body):
    onwater = false
    print(onwater)

i really shouldn't code past midnight..

by (20 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.