RoofTop Ninja Programming (BETA)

 #PLAYER CODE

extends KinematicBody2D

signal grounded_updated(is_grounded)

var score : int = 0

var is_attacking = false

var speed : int = 600

var jumpforce : int = 800

var Gravity : int = 1500

var is_grounded 

var vel : Vector2 = Vector2()

var facing = 1

onready var sprite : AnimatedSprite = get_node("sprite")


func _process(delta):

vel.x = 0

var was_grounded = is_grounded

is_grounded = is_on_floor()

if is_on_floor():

Gravity = 1500


if was_grounded == null || is_grounded != was_grounded:

emit_signal("grounded_updated", is_grounded)

if Input.is_key_pressed(KEY_SHIFT):

speed += 0

if Input.is_action_pressed("move_left"):

is_attacking = false

sprite.flip_h = true

vel.x -= speed

facing = -1

if is_on_floor():

$sprite.play("RUN")

if Input.is_action_pressed("move_right"):

is_attacking = false

vel.x += speed

sprite.flip_h = false

facing = 1

if is_on_floor():

$sprite.play("RUN")

if Input.is_action_just_pressed("attack_sword"):

if is_on_floor():

if vel.x == 0:

if facing == 1:

move_local_x(+30)

$sprite.play("ATTACK")

is_attacking = true

if facing == -1:

move_local_x(-30)

$sprite.play("ATTACK")

is_attacking = true


else:

pass

else:

pass


else:

pass



if vel.x == 0 and is_on_floor():

if is_attacking == false:

$sprite.play("IDLE")

else:

pass



vel = move_and_slide(vel, Vector2.UP)



vel.y += Gravity*delta


if Input.is_action_just_pressed("jump") and is_on_floor():

is_attacking = false

vel.y -= jumpforce

if is_on_floor() == false:

$sprite.play("JUMP")

if Input.is_action_pressed("glide_a"):

if is_on_floor() == false:

if vel.y > 0:

Gravity = 200

speed = 700

$sprite.play("GLIDE")

else:

pass

else:

pass

if Input.is_action_just_released("glide_a"):

Gravity = 1500

speed = 600

#if vel.x < 0:

# sprite.flip_h = true

#elif vel.x > 0:

# sprite.flip_h = false



func _on_sprite_animation_finished():

if $sprite.animation == "ATTACK":

is_attacking = false

if facing == 1:

move_local_x(-30)

if facing == -1:

move_local_x(30)

#ENEMY CODE STARTS HERE
extends KinematicBody2D

var velocity = Vector2()
export var direction = 1

func _ready():
if direction == -1:
$AnimatedSprite.flip_h = true
$floor_checker.position.x = $CollisionShape2D.shape.get_extents().x * direction

func _physics_process(delta):
if is_on_wall() or not $floor_checker.is_colliding():
direction = direction*-1
$AnimatedSprite.flip_h = not $AnimatedSprite.flip_h
$floor_checker.position.x = $CollisionShape2D.shape.get_extents().x * direction
if not $AnimatedSprite.animation == 'ATTACK':
#$AnimatedSprite.play("RUN")
pass
velocity.y += 20
velocity.x = 150 * direction
velocity = move_and_slide(velocity,Vector2.UP)




func _on_player_attacker_body_entered(body):
get_tree().reload_current_scene()


func _on_player_detector_body_entered(body):
$AnimatedSprite.play("ATTACK")

#CAMERA 2D CODE STARTS HERE
extends Camera2D
var facing = 0
const look_ahead_factor = 0.2
const shift_trans = Tween.TRANS_SINE
const shift_ease = Tween.EASE_OUT
const shift_duration = 1.0

onready var prev_camera_pos = get_camera_position()
onready var tween = $shift_tween
func _process(delta):
_check_facing()
prev_camera_pos = get_camera_position()
func _check_facing():
var new_facing = sign(get_camera_position().x - prev_camera_pos.x)
if new_facing != 0 && facing != new_facing:
facing = new_facing
var target_offset = get_viewport_rect().size.x * look_ahead_factor* facing
tween.interpolate_property(self, "position:x", position.x, target_offset, shift_duration, shift_trans, shift_ease)
tween.start()
#position.x = target_offset
func _on_PLAYER_grounded_updated(is_grounded):
drag_margin_v_enabled = !is_grounded

Comments