Guest User

Untitled

a guest
Feb 23rd, 2024
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class_name Snake
  2. extends Node2D
  3.  
  4. const AXOLOTL = 0
  5. const FISH = 1
  6. var fish_pos
  7. var axolotl_body = [Vector2(5, 5), Vector2(4, 5), Vector2(3, 5)]
  8.  
  9. @onready var axolotl_texture = $AxolotlTextures
  10.  
  11. func _ready():
  12.     fish_pos = place_fish()
  13.     draw_fish()
  14.     draw_axolotl()
  15.     #move_ctr()
  16.    
  17. func place_fish():
  18.     randomize()
  19.     var x = randi() % 20
  20.     var y = randi() % 20
  21.     return Vector2(x, y)
  22.    
  23. func draw_fish():
  24.     axolotl_texture.set_cell(0, fish_pos, FISH, Vector2(0, 0), 0)
  25.    
  26. func move_axolotl(move_direction):
  27.     var body_copy = axolotl_body.slice(0, axolotl_body.size() - 2)
  28.     var new_head = body_copy[0] + move_direction
  29.     axolotl_body = body_copy.insert(0, new_head)
  30.    
  31. func draw_axolotl():
  32.     for block in axolotl_body:
  33.         axolotl_texture.set_cell(0, Vector2(block.x, block.y), AXOLOTL, Vector2(3,0), 0)
  34.  
  35.  
  36. func _on_axolotl_tick_timeout():
  37.     move_axolotl(Vector2(1,0))
  38.     draw_fish()
  39.     draw_axolotl()
  40.  
Advertisement
Add Comment
Please, Sign In to add comment