0 votes

sorry for my bad english
i want to ask why i got error, i am super newbie at this game dev even progammer

i try to make flappy bird tutorial from youtube, and then got error when extends class i dunno why i got error
here code

extends RigidBody2D

onready var state = FlappingState.new(self)

const STATEFLYING = 0
const STATE
FLAPPING = 1
const STATEHIT = 2
const STATE
GROUNDED = 3

func ready():
#$anim
sprite.play("flying")
setprocessinput(true)

func physicsprocess(delta):
state.update(delta)
print(linear_velocity)
pass

func _input(event):
state.input(event)

func setstate(newstate):
state.exit()

if new_state == STATE_FLYING:
    state = FlyingState.new(self)
elif new_state == STATE_FLAPPING:
    state = FlappingState.new(self)
elif new_state == STATE_HIT:
    state = HitState.new(self)
elif new_state == STATE_GROUNDED:
    state = GroundedState.new(self)
pass

func getstate():
if state extends FlyingState:
return STATE
FLYING
if state extends FlappingState:
return STATEFLAPPING
if state extends HitState:
return STATE
HIT
if state extends GroundedState:
return STATE_GROUNDED
pass

Flying State ------------------------------------------------

class FlyingState:
var bird

func _init(bird):
    self.bird = bird

func update(delta):
    pass

func input(event):
    pass

func exit():
    pass

Flaping State ------------------------------------------------

class FlappingState:
var bird

func _init(bird):
    self.bird = bird

    bird.set_linear_velocity(Vector2(50, bird.get_linear_velocity().y))
    pass

func update(delta):

    if rad2deg(bird.get_rotation()) < -30:
        bird.set_rotation(deg2rad(-30))
        bird.set_angular_velocity(0)

    if bird.linear_velocity.y > 0:
        bird.set_angular_velocity(1.5)
    pass

func input(event):
    if Input.is_action_just_pressed("klik_kiri"):
        flap()

    pass

func flap():
    bird.set_linear_velocity(Vector2(bird.get_linear_velocity().x, -150))
    bird.set_angular_velocity(-3)
    pass

func exit():
    pass

Hit State ------------------------------------------------

class HitState:
var bird

func _init(bird):
    self.bird = bird

func update(delta):
    pass

func input(event):
    pass

func exit():
    pass

Grounded State ------------------------------------------------

class GroundedState:
var bird

func _init(bird):
    self.bird = bird

func update(delta):
    pass

func input(event):
    pass

func exit():
    pass

error

asked Jul 19, 2018 in Engine by roxas4sora (15 points)

1 Answer

0 votes
Best answer

Maybe you should replace 'extends' with 'is' ?

answered Jul 20, 2018 by curiousdev (46 points)
selected Jul 20, 2018 by roxas4sora

wow, is works thank >_<

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.