Added fall zones
This commit is contained in:
parent
d02d369c13
commit
c257f9c1ad
8 changed files with 64 additions and 7 deletions
|
@ -56,6 +56,7 @@ enum MapElemType {
|
|||
SMALL_SLOPE_RIGHT_1,
|
||||
SMALL_SLOPE_RIGHT_2,
|
||||
LEDGE,
|
||||
OOB_LOWER,
|
||||
}
|
||||
|
||||
enum SpriteClass {
|
||||
|
@ -162,6 +163,7 @@ const TILE_SET_MAP_ELEMS = {
|
|||
MapElemType.SMALL_SLOPE_RIGHT_1: [12],
|
||||
MapElemType.SMALL_SLOPE_RIGHT_2: [13, 14],
|
||||
MapElemType.LEDGE: [19, 20, 21, 22],
|
||||
MapElemType.OOB_LOWER: [23],
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,8 @@ func init_stage_grid(tilemap : TileMap):
|
|||
Constants.MapElemType.SMALL_SLOPE_LEFT_2,
|
||||
Constants.MapElemType.SMALL_SLOPE_RIGHT_1,
|
||||
Constants.MapElemType.SMALL_SLOPE_RIGHT_2,
|
||||
Constants.MapElemType.LEDGE]:
|
||||
Constants.MapElemType.LEDGE,
|
||||
Constants.MapElemType.OOB_LOWER]:
|
||||
for test_cell_v in Constants.TILE_SET_MAP_ELEMS[scene.tile_set_name][test_map_elem_type]:
|
||||
if test_cell_v == cellv:
|
||||
map_elem_type = test_map_elem_type
|
||||
|
@ -131,6 +132,8 @@ func init_stage_grid(tilemap : TileMap):
|
|||
insert_grid_collider(stage_x, stage_y, Constants.Direction.UP, 1, map_elem_type)
|
||||
Constants.MapElemType.LEDGE:
|
||||
insert_grid_collider(stage_x, stage_y, Constants.Direction.DOWN, 1, map_elem_type)
|
||||
Constants.MapElemType.OOB_LOWER:
|
||||
insert_grid_collider(stage_x, stage_y, Constants.Direction.DOWN, 1, map_elem_type)
|
||||
|
||||
func insert_grid_collider(stage_x, stage_y, direction : int, fractional_height : float, map_elem_type : int):
|
||||
var check_colliders = []
|
||||
|
|
|
@ -51,7 +51,7 @@ func _ready():
|
|||
for node_name in Constants.UNIT_SPRITES[unit_type][sprite_class][1]:
|
||||
sprite_class_nodes[sprite_class].append(get_node(node_name))
|
||||
|
||||
pos = Vector2(position.x / Constants.GRID_SIZE, -1 * position.y / Constants.GRID_SIZE)
|
||||
pos = Vector2(position.x / Constants.GRID_SIZE, position.y / -Constants.GRID_SIZE)
|
||||
position.x = position.x * Constants.SCALE_FACTOR
|
||||
position.y = position.y * Constants.SCALE_FACTOR
|
||||
scale.x = Constants.SCALE_FACTOR
|
||||
|
@ -266,7 +266,7 @@ func react(delta):
|
|||
pos.x = pos.x + h_speed * delta
|
||||
pos.y = pos.y + v_speed * delta
|
||||
position.x = pos.x * Constants.GRID_SIZE * Constants.SCALE_FACTOR
|
||||
position.y = -1 * pos.y * Constants.GRID_SIZE * Constants.SCALE_FACTOR
|
||||
position.y = pos.y * Constants.GRID_SIZE *-Constants.SCALE_FACTOR
|
||||
|
||||
func hit(dir : int):
|
||||
# implemented in subclass
|
||||
|
|
|
@ -46,6 +46,10 @@ func process_unit(delta, time_elapsed : float):
|
|||
facing = Constants.Direction.RIGHT
|
||||
actions[Constants.ActionType.MOVE] = true
|
||||
|
||||
# Check if fallen off
|
||||
if last_contacted_map_elem_type == Constants.MapElemType.OOB_LOWER:
|
||||
oob_lower()
|
||||
|
||||
# Fine tune the player's speed
|
||||
|
||||
if get_current_action() == Constants.UnitCurrentAction.RECOILING:
|
||||
|
@ -140,3 +144,25 @@ func landed():
|
|||
return
|
||||
target_move_speed += boost
|
||||
boost = 0
|
||||
|
||||
func oob_lower():
|
||||
# Called when the player falls in a hole
|
||||
|
||||
# Calculate respawn point
|
||||
var tilemap : TileMap = get_node("../Stage")
|
||||
var tile : Vector2 = pos.floor()
|
||||
tile.y *= -1
|
||||
while tilemap.get_cellv(tile) == 23 or tilemap.get_cellv(tile) < 0:
|
||||
tile += Vector2.RIGHT
|
||||
while tilemap.get_cellv(tile) >= 0:
|
||||
tile += Vector2.UP
|
||||
pos = tile
|
||||
pos.x += 0.5
|
||||
pos.y *= -1
|
||||
last_contacted_map_elem_type = Constants.MapElemType.SLOPE_LEFT
|
||||
# =======================
|
||||
|
||||
# reset speed
|
||||
# should other things be done here?
|
||||
h_speed = 0
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue