Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class_name Snake
- extends Node2D
- const AXOLOTL = 0
- const FISH = 1
- var fish_pos
- var axolotl_body = [Vector2(5, 5), Vector2(4, 5), Vector2(3, 5)]
- @onready var axolotl_texture = $AxolotlTextures
- func _ready():
- fish_pos = place_fish()
- draw_fish()
- draw_axolotl()
- #move_ctr()
- func place_fish():
- randomize()
- var x = randi() % 20
- var y = randi() % 20
- return Vector2(x, y)
- func draw_fish():
- axolotl_texture.set_cell(0, fish_pos, FISH, Vector2(0, 0), 0)
- func move_axolotl(move_direction):
- var body_copy = axolotl_body.slice(0, axolotl_body.size() - 2)
- var new_head = body_copy[0] + move_direction
- axolotl_body = body_copy.insert(0, new_head)
- func draw_axolotl():
- for block in axolotl_body:
- axolotl_texture.set_cell(0, Vector2(block.x, block.y), AXOLOTL, Vector2(3,0), 0)
- func _on_axolotl_tick_timeout():
- move_axolotl(Vector2(1,0))
- draw_fish()
- draw_axolotl()
Advertisement
Add Comment
Please, Sign In to add comment