fastRunner/TileMap.gd

57 lines
1.7 KiB
GDScript
Raw Normal View History

2024-02-22 20:33:20 -05:00
extends TileMap
2024-03-04 20:35:09 -05:00
@export var playerPos :Vector2 = Vector2.ZERO
2024-02-28 20:21:50 -05:00
2024-03-04 20:35:09 -05:00
@onready var player :CharacterBody2D =$"../CharacterBody2D"
2024-02-22 20:33:20 -05:00
var rng = RandomNumberGenerator.new()
# Called when the node enters the scene tree for the first time.
func _ready():
pass
2024-02-28 20:21:50 -05:00
#return random int
2024-02-22 20:33:20 -05:00
func roller():
2024-03-04 20:35:09 -05:00
var rum :int = rng.randi_range(0, 200)
var randomHouse :int = rng.randi_range(5,10)
var randomPower :int = rng.randi_range(2,8)
var randomGap :int = rng.randi_range(1,15)
var randomSet :Array = [rum, randomHouse,randomPower,randomGap]
2024-02-28 20:21:50 -05:00
return randomSet
#draws the ground, houses and powerups
2024-03-04 20:35:09 -05:00
func drawPat(playerPost :Vector2):
var tilePos = Vector2(playerPost.x+(36),11)
var tileCheck = tilePos + Vector2(1,1)
2024-02-28 20:21:50 -05:00
var rum = roller()
2024-02-22 20:33:20 -05:00
2024-02-28 20:21:50 -05:00
if get_cell_tile_data(0,tileCheck,false) == null:
2024-03-04 20:35:09 -05:00
set_pattern(0,tilePos +Vector2(rum[3],0),tile_set.get_pattern(1))
2024-02-28 20:21:50 -05:00
if int(playerPos.x) % 3 == 0:
if rum[0] > 180:
2024-03-04 20:35:09 -05:00
set_pattern(1,tilePos-Vector2(-8,rum[1]),tile_set.get_pattern(4))
2024-02-28 20:21:50 -05:00
if int(playerPos.x) % 7 == 0:
if rum[0] > 180:
2024-03-04 20:35:09 -05:00
set_pattern(1,tilePos-Vector2(-8,rum[2]),tile_set.get_pattern(5))
2024-02-28 20:21:50 -05:00
#removes old tiles
2024-03-04 20:35:09 -05:00
func garbageCollect(playerPost :Vector2):
2024-02-28 20:21:50 -05:00
for dist in get_used_cells(0):
2024-03-04 20:35:09 -05:00
if playerPost.x-dist.x > 100:
erase_cell(0, dist)
2024-02-28 20:21:50 -05:00
for dist in get_used_cells(1):
2024-03-04 20:35:09 -05:00
if playerPost.x-dist.x > 100:
erase_cell(1, dist)
2024-02-22 20:33:20 -05:00
# Called every frame. 'delta' is the elapsed time since the previous frame.
2024-03-04 20:35:09 -05:00
func _process(_delta):
2024-02-28 20:21:50 -05:00
playerPos = self.local_to_map(player.position)
if playerPos.y > 15:
NewScript.playerDeath()
get_tree().change_scene_to_file("res://mainMenu.tscn")
var data = get_cell_tile_data(1,playerPos)
if data:
NewScript.hit(data.get_custom_data_by_layer_id(0))
drawPat(playerPos)
garbageCollect(playerPos)
2024-02-22 20:33:20 -05:00
2024-02-28 20:21:50 -05:00
NewScript.playerPoScore()