Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | VivAZ |
Good day everyone!
For some reason I can find a solution for my problem and yet I think it’s something simple but can’t find in the Godot docs. The tutorial I’m following is written during the Godot 2 I assume so I’ve been learning Godot and the new docs at the same time. For some reason I get an error saying ‘:’ expected at end of line. Yet I clearly have a colon there. Here is my code.
# script: bird
extends RigidBody2D
onready var state = FlappingState.new(self)
const STATE_FLYING = 0
const STATE_FLAPPING = 1
const STATE_HIT = 2
const STATE_GROUNDED = 3
func _ready():
pass
func _integrate_forces(delta):
state.update(delta)
pass
func _input(event):
state.input(event)
pass
func set_state(new_state):
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 get_state():
if state extends FlyingState: #myproblem is here
return STATE_FLYING
elif state extends FlappingState:
return STATE_FLAPPING
pass
# class FlyingState --------------------------------------------------------------
class FlyingState:
var bird
func _init(bird):
self.bird = bird
func update(delta):
pass
func input(event):
pass
func exit():
pass
# class FlappingState --------------------------------------------------------------
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.get_linear_velocity().y > 0:
bird.set_angular_velocity(1.5)
pass
func input(event):
if event.is_action_pressed("ui_spacebar"):
flap()
pass
func flap():
bird.set_linear_velocity(Vector2(bird.get_linear_velocity().x, -150))
bird.set_angular_velocity(-3)
pass
func exit():
pass
# class HitState --------------------------------------------------------------
class HitState:
var bird
func _init(bird):
self.bird = bird
func update(delta):
pass
func input(event):
pass
func exit():
pass
# class GroundedState --------------------------------------------------------------
class GroundedState:
var bird
func _init(bird):
self.bird = bird
func update(delta):
pass
func input(event):
pass
func exit():
pass