Player code:
`extends KinematicBody2D
const UP = Vector2(0, -1)
const GRAVITY = 35
const SPEED = 550
const JUMP_HEIGHT = -1200
const MAX_HP = 100
const MAX_POWER = 200
onready var sprite = get_node("Sprite")
onready var collision = get_node("CollisionShape2D")
onready var CastR = get_node("CastR")
onready var CastL = get_node("CastL")
onready var CastD = get_node("CastD")
var dash = 0
var HP = 100
var power = 50
var jump_time = 0
var motion = Vector2()
var jumping = false
var anim = "Still"
var coll = null
var plat = null
var plat_vel = Vector2()
func _ready():
pass
func _process(delta):
if motion.x == 0:
anim = "Still"
if jumping:
anim = "Jump"
sprite.play(anim)
if HP < 1:
get_tree().reload_current_scene()
if power > MAX_POWER:
power = MAX_POWER
if power < 0:
power = 0
if Input.is_action_just_pressed("block_break"):
if sprite.flip_h == false:
if CastR.is_colliding():
var posx = CastR.get_collision_point().x+32
var posy = CastR.get_collision_point().y
var cellx = int(posx/64)
var celly = int(posy/64)
if( sign(posx) == -1):
cellx -= 1
if( sign(posy) == -1):
celly -= 1
_delete_cell(Vector2(cellx,celly))
if sprite.flip_h == true:
if CastL.is_colliding():
var posx = CastL.get_collision_point().x-32
var posy = CastL.get_collision_point().y
var cellx = int(posx/64)
var celly = int(posy/64)
if( sign(posx) == -1):
cellx -= 1
if( sign(posy) == -1):
celly -= 1
_delete_cell(Vector2(cellx,celly))
func _physics_process(delta):
motion.y += GRAVITY
if Input.is_action_pressed("ui_right"):
motion.x = SPEED
anim = "Running"
elif Input.is_action_pressed("ui_left"):
motion.x = -SPEED
anim = "Running"
else:
motion.x = 0
if is_on_floor():
jumping = false
if Input.is_action_just_pressed("ui_select"):
motion.y += JUMP_HEIGHT
jumping = true
if Input.is_action_pressed("dash") && power > 0:
if (sprite.flip_h == true):
motion.x = -SPEED*3
power -= 3
dash = 1
get_node("Poof").emitting = 1
get_node("Poof").rotation_degrees = 0
if (sprite.flip_h == false):
motion.x = SPEED*3
power -= 3
dash = 1
get_node("Poof").emitting = 1
get_node("Poof").rotation_degrees = 180
if Input.is_action_just_released("dash"):
dash = 0
get_node("Poof").emitting = 0
if Input.is_action_just_pressed("super_jump"):
motion.y += JUMP_HEIGHT*1.5
motion = move_and_slide(motion, UP)
func on_snake_fox_hit():
fox_hurt(10)
func _fox_hurt(amnt):
motion.y = JUMP_HEIGHT*0.6
HP -= amnt
func _delete_cell( location ):
get_node("../TileMap").set_cellv(location, -1)
`
Moving platform code:
`
extends KinematicBody2D
onready var timer = get_node("Timer")
onready var anim = get_node("AnimationPlayer")
onready var top = get_node("Top")
var motion = Vector2()
var top_obj = null
export var dir = 0
export var speed = 1
export var dim = 0
export var chosen_anim = ""
func physics_process(delta):
if dim == 1:
h_move()
if dim == 0:
_v_move()
global_translate(motion)
func _h_move():
motion.x = speed*dir
func _v_move():
motion.y = speed*dir
func _on_Timer_timeout():
if dir == 1:
dir = -1
else:
dir = 1
timer.start()
`
And a link to my project if anyone wants to poke around:
https://www.sendspace.com/file/t5obhd