Skip to content

Commit

Permalink
Add circle spawn demo project
Browse files Browse the repository at this point in the history
  • Loading branch information
Xrayez committed Oct 26, 2020
1 parent deeb1ff commit f072515
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 0 deletions.
59 changes: 59 additions & 0 deletions 2d/spawn/circle_spawn.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
extends Node2D

enum Type {
CIRCLE,
RING,
}
export(Type) var type = Type.CIRCLE setget set_type
export var count := 500 setget set_count
export var min_radius := 0.0 setget set_min_radius
export var max_radius := 0.0 setget set_max_radius


func set_type(p_type):
type = p_type
call_deferred("spawn")


func set_count(p_count):
count = p_count
call_deferred("spawn")


func set_min_radius(p_min_radius):
min_radius = p_min_radius
call_deferred("spawn")


func set_max_radius(p_max_radius):
max_radius = p_max_radius
call_deferred("spawn")


func _ready():
randomize()
if max_radius <= 0.0:
# Fit screen size.
max_radius = get_viewport().size.y / 2
# Make sure sprites are not clipped by viewport.
max_radius -= preload("res://icon.png").get_size().length()
if min_radius <= 0.0:
min_radius = max_radius / 2
spawn()


func spawn():
for child in get_children():
if child is Sprite:
child.queue_free()
for i in count:
var goost = preload("res://goost.tscn").instance()
add_child(goost)
# Spawn a sprite at random position within a circle radius.
var point = Vector2()
match type:
Type.CIRCLE:
point = GoostGeometry2D.rand_point_in_circle(max_radius)
Type.RING:
point = GoostGeometry2D.rand_point_in_ring(min_radius, max_radius)
goost.global_position = point
12 changes: 12 additions & 0 deletions 2d/spawn/circle_spawn.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[gd_scene load_steps=2 format=2]

[ext_resource path="res://circle_spawn.gd" type="Script" id=1]

[node name="circle_spawn" type="Node2D"]
script = ExtResource( 1 )

[node name="camera" type="Camera2D" parent="."]
current = true
__meta__ = {
"_editor_description_": "Displays sprites centered."
}
6 changes: 6 additions & 0 deletions 2d/spawn/goost.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]

[ext_resource path="res://icon.png" type="Texture" id=1]

[node name="goost" type="Sprite"]
texture = ExtResource( 1 )
Binary file added 2d/spawn/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions 2d/spawn/icon.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://icon.png"
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
17 changes: 17 additions & 0 deletions 2d/spawn/project.godot
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters

config_version=4

[application]

config/name="Goost Spawn"
run/main_scene="res://circle_spawn.tscn"
boot_splash/image="res://icon.png"
boot_splash/fullsize=false
config/icon="res://icon.png"

0 comments on commit f072515

Please sign in to comment.