Obstacles and Collisions

Add obstacles and collions in Godot using graphics from the Obstacles and Enemies lab.

1. Setting up the Godot project

2. Add collision layers and masks

3. Add a static obstacle

4. Add a second obstacle scene

5. Documentation

Updates to PlayerController.gd script

func obstacle_collision():
	is_alive = false # player movement suspended before determining state
	$AnimatedSprite.play('Hit')


# after hit animation, test if player is still alive
func _on_AnimatedSprite_animation_finished():
	if $AnimatedSprite.animation == 'Hit':
		is_alive = true
		emit_signal("player_hit", is_alive) # don't know if player should die yet

Updates to SceneManager.gd script

func _on_player_hit(is_alive):
	
	if is_alive and Global.player_lives > 0:
		Global.player_lives = Global.player_lives - 1
		
	if not is_alive or Global.player_lives <= 0:
		player.dies()

Full ObstacleSimple.gd script

extends Area2D

# choose frame from sprite sheet
export var frame_number = 0 

func _ready():
	$Sprite.frame = frame_number

func _on_Obstacle_body_entered(body):
	body.enemy_collision() # call enemy collision func in player
	$HitSound.play()