forked from team-sg/hero-mark-2
created random spawner thing
This commit is contained in:
parent
a23ca5347d
commit
b379b5a213
2 changed files with 38 additions and 2 deletions
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=24 format=2]
|
[gd_scene load_steps=26 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://maps/map.gd" type="Script" id=1]
|
[ext_resource path="res://maps/map.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://objects/hud/hud.tscn" type="PackedScene" id=2]
|
[ext_resource path="res://objects/hud/hud.tscn" type="PackedScene" id=2]
|
||||||
|
@ -11,6 +11,8 @@
|
||||||
[ext_resource path="res://objects/environment/ladder/ladder.tscn" type="PackedScene" id=9]
|
[ext_resource path="res://objects/environment/ladder/ladder.tscn" type="PackedScene" id=9]
|
||||||
[ext_resource path="res://graphics/particles/bubble.png" type="Texture" id=10]
|
[ext_resource path="res://graphics/particles/bubble.png" type="Texture" id=10]
|
||||||
[ext_resource path="res://objects/enemy/mine.tscn" type="PackedScene" id=11]
|
[ext_resource path="res://objects/enemy/mine.tscn" type="PackedScene" id=11]
|
||||||
|
[ext_resource path="res://scripts/random_spawner.gd" type="Script" id=12]
|
||||||
|
[ext_resource path="res://objects/environment/bubble/bubble.tscn" type="PackedScene" id=13]
|
||||||
|
|
||||||
[sub_resource type="CanvasItemMaterial" id=12]
|
[sub_resource type="CanvasItemMaterial" id=12]
|
||||||
blend_mode = 3
|
blend_mode = 3
|
||||||
|
@ -34,10 +36,11 @@ float rand(float co){
|
||||||
|
|
||||||
void vertex() {
|
void vertex() {
|
||||||
VERTEX.x /= frames;
|
VERTEX.x /= frames;
|
||||||
|
VERTEX.y /= 2.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fragment() {
|
void fragment() {
|
||||||
COLOR = texture(TEXTURE, vec2(UV.x / frames + COLOR.r, UV.y));
|
COLOR = texture(TEXTURE, vec2(UV.x / frames + COLOR.r, UV.y / 2.0));
|
||||||
}"
|
}"
|
||||||
|
|
||||||
[sub_resource type="ShaderMaterial" id=10]
|
[sub_resource type="ShaderMaterial" id=10]
|
||||||
|
@ -163,6 +166,7 @@ margin_bottom = 384.0
|
||||||
color = Color( 0.054902, 0.0666667, 0.329412, 1 )
|
color = Color( 0.054902, 0.0666667, 0.329412, 1 )
|
||||||
|
|
||||||
[node name="Bubbles" type="CPUParticles2D" parent="EffectLayer"]
|
[node name="Bubbles" type="CPUParticles2D" parent="EffectLayer"]
|
||||||
|
visible = false
|
||||||
material = SubResource( 10 )
|
material = SubResource( 10 )
|
||||||
position = Vector2( 128, 200 )
|
position = Vector2( 128, 200 )
|
||||||
lifetime = 13.0
|
lifetime = 13.0
|
||||||
|
@ -228,3 +232,10 @@ position = Vector2( 144, 24 )
|
||||||
|
|
||||||
[node name="Mine4" parent="Enemies/Mines" instance=ExtResource( 11 )]
|
[node name="Mine4" parent="Enemies/Mines" instance=ExtResource( 11 )]
|
||||||
position = Vector2( 72, 48 )
|
position = Vector2( 72, 48 )
|
||||||
|
|
||||||
|
[node name="BubbleSpawner" type="Node2D" parent="."]
|
||||||
|
position = Vector2( 0, 584 )
|
||||||
|
script = ExtResource( 12 )
|
||||||
|
scene = ExtResource( 13 )
|
||||||
|
extents = Rect2( 0, 0, 256, 8 )
|
||||||
|
delay = 0.2
|
||||||
|
|
25
scripts/random_spawner.gd
Normal file
25
scripts/random_spawner.gd
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
tool
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
export (PackedScene) var scene
|
||||||
|
export (Rect2) var extents setget _set_extents
|
||||||
|
export var delay = 1.0
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
if !Engine.editor_hint:
|
||||||
|
get_tree().create_timer(delay, false).connect("timeout", self, "spawn")
|
||||||
|
|
||||||
|
func spawn():
|
||||||
|
var node = scene.instance()
|
||||||
|
node.position.x = rand_range(extents.position.x, extents.end.x)
|
||||||
|
node.position.y = rand_range(extents.position.y, extents.end.y)
|
||||||
|
add_child(node)
|
||||||
|
get_tree().create_timer(delay, false).connect("timeout", self, "spawn")
|
||||||
|
|
||||||
|
func _draw():
|
||||||
|
if Engine.editor_hint:
|
||||||
|
draw_rect(extents, Color.thistle, false, 1.0)
|
||||||
|
|
||||||
|
func _set_extents(value):
|
||||||
|
extents = value
|
||||||
|
update()
|
Loading…
Add table
Add a link
Reference in a new issue