Add bottom area limits

This commit is contained in:
Mathilde Grapin 2023-07-02 17:23:23 +02:00
parent 40525022d7
commit 200ae7f262
22 changed files with 300 additions and 40 deletions

View file

@ -6,8 +6,6 @@ signal hit_ball
signal ball_starts_colliding
signal ball_stops_colliding
@export var speed = 120
@onready var animation_player = $AnimationPlayer
@onready var sprite = $Sprite2D
@onready var tile_map: TileMap = get_parent()
func _ready():
@ -19,21 +17,21 @@ func get_input_direction():
func flip_sprite():
if Input.is_action_pressed("move_left"):
sprite.flip_h = true
$Sprite2D.flip_h = true
elif Input.is_action_pressed("move_right"):
sprite.flip_h = false
$Sprite2D.flip_h = false
func play_idle_animation():
animation_player.play("idle")
$AnimationPlayer.play("idle")
func play_walk_animation():
animation_player.play("walk")
$AnimationPlayer.play("walk")
func play_hit_ball_animation():
animation_player.speed_scale = 0.8
animation_player.play("hit_ball")
await animation_player.animation_finished
animation_player.speed_scale = 1
$AnimationPlayer.speed_scale = 0.8
$AnimationPlayer.play("hit_ball")
await $AnimationPlayer.animation_finished
$AnimationPlayer.speed_scale = 1
func _on_area_2d_body_entered(_body):
# As players Area2D only collide with balls

View file

@ -4,6 +4,11 @@ extends TileMap
@export var wall_tile_source_id = 1
@export var destination_tile_source_id = 2
@export var target_tile_source_id = 3
@export var ground_left_tile_source_id = 4
@export var ground_right_tile_source_id = 5
@export var ground_bottom_tile_source_id = 6
@export var ground_left_bottom_tile_source_id = 7
@export var ground_right_bottom_tile_source_id = 8
@export var map_width = 13 # keep to a odd value
@export var map_height = 19 # keep to a odd value
# Debug variables
@ -22,9 +27,23 @@ func draw_map():
draw_wall()
func draw_ground():
var tile_source_id = ground_tile_source_id
var height = get_bottom_area_height()
for x in range(map_width):
for y in range(map_height):
set_cell(0, Vector2i(x, y), ground_tile_source_id, Vector2i(0, 0), 0)
if x == 0 && y == map_height - 1:
tile_source_id = ground_left_bottom_tile_source_id
elif x == map_width - 1 && y == map_height - 1:
tile_source_id = ground_right_bottom_tile_source_id
elif x == 0 && y >= height.x:
tile_source_id = ground_left_tile_source_id
elif x == map_width - 1 && y >= height.x:
tile_source_id = ground_right_tile_source_id
elif y == height.y:
tile_source_id = ground_bottom_tile_source_id
else:
tile_source_id = ground_tile_source_id
set_cell(0, Vector2i(x, y), tile_source_id, Vector2i(0, 0), 0)
func draw_wall():
var middle_height = floor(map_height / 2.0)