[swift] Main
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- extends TileMap
- var rng = RandomNumberGenerator.new()
- var tail = Array()
- var headGap = $"Snake Head".position
- func onSnakeEat():
- #Set x and y coords within map coords
- var fruitX = 24 + rng.randi_range(0, 13) * 16
- var fruitY = 24 + rng.randi_range(0, 13) * 16
- var fruitVec = Vector2(fruitX, fruitY)
- #Move fruit to coords
- $Fruit.set_global_position(fruitVec)
- #Instance new tail
- var tailScene = load("res://Snake Tail.tscn")
- var tailClone = tailScene.instance()
- add_child(tailClone)
- #Add tail to array
- tail.push_front(tailClone)
- #Move tail where head used to be
- if tail.count > 0:
- print_debug("Tail added to array")
- #Move last tail to where head used to be
- tail.back().position = headGap
- #Add to front of list, remove from back
- tail.push_front(tail.back())
- tail.remove(tail.count - 1)
Editor
You can edit this paste and save as new: