Ok, this is the platform code:
extends RigidBody2D
func _integrate_forces(state):
if position.y >= 480:
linear_velocity = linear_velocity * (-1)
elif position.y <= 80:
linear_velocity = linear_velocity * (-1)
And this is the player code:
extends KinematicBody2D
signal addScore
const FLOOR = Vector2(0, -1)
var motion = Vector2()
var on_ground = false
func _physics_process(delta):
motion.y += 10
move_and_slide(motion)
if Input.is_action_pressed("ui_right"):
$AnimatedSprite.set_flip_h(false)
motion.x = 300
move_and_slide(motion)
elif Input.is_action_pressed("ui_left"):
$AnimatedSprite.set_flip_h(true)
motion.x = -300
move_and_slide(motion)
if Input.is_action_pressed("ui_up"):
$Jump.play()
if on_ground == true:
motion.y = -300
on_ground = false
motion = move_and_slide(motion, FLOOR)
if is_on_floor():
on_ground = true
else:
on_ground = false
position.y = clamp(position.y, -256, 1600)
if position.y >= 1500:
$wrong.play()
position.x = 900
position.y = 100