Advertisement
Guest User

GAMEBOX 1: SOURCE CODE shape.gd

a guest
Sep 16th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. extends Node2D
  2.  
  3. var textures = [
  4.     "res://Graphics/o.png",
  5.     "res://Graphics/tri.png",
  6.     "res://Graphics/x.png"
  7. ]
  8.  
  9. var movement_vector = Vector2(0, 0)
  10. var SPEED = 400
  11.  
  12. var destination = Vector2(0, 0)
  13.  
  14. func _ready():
  15.     randomize()
  16.     set_random_texture()
  17.     set_random_destination()
  18.     calculate_movement_vector()
  19.    
  20.     add_to_group("shapes")
  21.  
  22. func _process(delta):
  23.     position += movement_vector*SPEED*delta
  24.  
  25. func set_random_texture() -> void:
  26.     var selection = textures[randi()%textures.size()]
  27.     $Sprite.texture = load(selection)
  28.    
  29. func set_random_destination() -> void:
  30.     var viewport_rect = get_viewport_rect()
  31.    
  32.     destination.x = randf()*viewport_rect.size.x
  33.     destination.y = randf()*viewport_rect.size.y
  34.    
  35. # FUCK YOU.
  36. func calculate_movement_vector() -> void:
  37.     movement_vector = Vector2(-1, 0).rotated(global_position.angle_to_point(destination))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement