Skip to content

Commit

Permalink
Space Rocks - Part 11
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Bradfield committed May 22, 2017
1 parent b9ca312 commit ccfb539
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 13 deletions.
Binary file not shown.
Binary file not shown.
50 changes: 43 additions & 7 deletions Space_Rocks_tutorial/working/scenes/enemy.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[gd_scene load_steps=6 format=1]
[gd_scene load_steps=8 format=1]

[ext_resource path="res://scripts/enemy.gd" type="Script" id=1]
[ext_resource path="res://art/sheet.ufoGreen.atex" type="Texture" id=2]
[ext_resource path="res://scenes/enemy_paths.tscn" type="PackedScene" id=3]
[ext_resource path="res://audio/enemy_laser.wav" type="Sample" id=4]

[sub_resource type="CircleShape2D" id=1]

Expand All @@ -26,8 +27,18 @@ tracks/0/keys = {
"values": [ 0.0, 180.0, 360.0 ]
}

[sub_resource type="SampleLibrary" id=3]

samples/enemy_laser = {
"db": -3.0,
"pitch": 1.0,
"priority": 0,
"sample": ExtResource( 4 )
}

[node name="enemy" type="Area2D"]

transform/pos = Vector2( -47.6131, -51.6943 )
input/pickable = true
shapes/0/shape = SubResource( 1 )
shapes/0/transform = Matrix32( 1, 0, 0, 1, 0, 0 )
Expand All @@ -37,10 +48,13 @@ gravity = 98.0
linear_damp = 0.1
angular_damp = 1.0
script/script = ExtResource( 1 )
__meta__ = {
"_edit_group_": true
}

[node name="sprite" type="Sprite" parent="."]

transform/rot = 56.4122
transform/rot = 89.4901
transform/scale = Vector2( 0.8, 0.8 )
texture = ExtResource( 2 )

Expand All @@ -64,10 +78,32 @@ autoplay = "rotate"

[node name="enemy_paths" parent="." instance=ExtResource( 3 )]

[node name="visible" type="VisibilityNotifier2D" parent="."]

rect = Rect2( -10, -10, 20, 20 )

[connection signal="exit_screen" from="visible" to="." method="_on_visible_exit_screen"]
[node name="bullet_container" type="Node" parent="."]

[node name="shoot_timer" type="Timer" parent="."]

process_mode = 1
wait_time = 1.0
one_shot = false
autostart = false

[node name="sounds" type="SamplePlayer" parent="."]

config/polyphony = 1
config/samples = SubResource( 3 )
default/volume_db = 0.0
default/pitch_scale = 1.0
default/pan = 0.0
default/depth = 0.0
default/height = 0.0
default/filter/type = 0
default/filter/cutoff = 5000.0
default/filter/resonance = 1.0
default/filter/gain = 1.0
default/reverb_room = 2
default/reverb_send = 0.0
default/chorus_send = 0.0

[connection signal="timeout" from="shoot_timer" to="." method="_on_shoot_timer_timeout"]


48 changes: 48 additions & 0 deletions Space_Rocks_tutorial/working/scenes/enemy_bullet.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[gd_scene load_steps=4 format=1]

[ext_resource path="res://scripts/enemy_bullet.gd" type="Script" id=1]
[ext_resource path="res://art/beams.png" type="Texture" id=2]

[sub_resource type="CapsuleShape2D" id=1]

custom_solver_bias = 0.0
radius = 5.02902
height = 42.6393

[node name="enemy_bullet" type="Area2D"]

transform/pos = Vector2( 511.316, 242.307 )
input/pickable = true
shapes/0/shape = SubResource( 1 )
shapes/0/transform = Matrix32( 1, 0, 0, 1, 0, 0 )
shapes/0/trigger = false
gravity_vec = Vector2( 0, 1 )
gravity = 98.0
linear_damp = 0.1
angular_damp = 1.0
script/script = ExtResource( 1 )
__meta__ = {
"_edit_group_": true
}
speed = 700

[node name="bullet" type="Sprite" parent="."]

texture = ExtResource( 2 )
region = true
region_rect = Rect2( 8.125, 293.609, 62, 98.5296 )

[node name="collision" type="CollisionShape2D" parent="."]

visibility/visible = false
shape = SubResource( 1 )
trigger = false
_update_shape_index = 0

[node name="visible" type="VisibilityNotifier2D" parent="."]

rect = Rect2( -10, -10, 20, 20 )

[connection signal="exit_screen" from="visible" to="." method="_on_visible_exit_screen"]


9 changes: 9 additions & 0 deletions Space_Rocks_tutorial/working/scenes/main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ wait_time = 3.0
one_shot = true
autostart = false

[node name="enemy_timer" type="Timer" parent="."]

process_mode = 1
wait_time = 3.0
one_shot = true
autostart = false

[connection signal="timeout" from="restart_timer" to="." method="_on_restart_timer_timeout"]

[connection signal="timeout" from="enemy_timer" to="." method="_on_enemy_timer_timeout"]


1 change: 0 additions & 1 deletion Space_Rocks_tutorial/working/scenes/player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ texture = ExtResource( 6 )
transform/pos = Vector2( 0, 35 )
frames = SubResource( 3 )
animation = "default"
frame = 2
playing = true

[connection signal="body_enter" from="." to="." method="_on_player_body_enter"]
Expand Down
31 changes: 28 additions & 3 deletions Space_Rocks_tutorial/working/scripts/enemy.gd
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
extends Area2D

var bullet = preload("res://scenes/enemy_bullet.tscn")

onready var paths = get_node("enemy_paths")
onready var bullet_container = get_node("bullet_container")
onready var shoot_timer = get_node("shoot_timer")
onready var sounds = get_node("sounds")

var path
var follow
var remote
var speed = 250
var speed = 150
var target = null

func _ready():
set_process(true)
Expand All @@ -16,10 +22,29 @@ func _ready():
follow.set_loop(false)
remote = Node2D.new()
follow.add_child(remote)
shoot_timer.set_wait_time(1.5) # vary by level
shoot_timer.start()

func _process(delta):
follow.set_offset(follow.get_offset() + speed * delta)
set_pos(remote.get_global_pos())
if follow.get_unit_offset() > 1:
queue_free()

func shoot1():
sounds.play("enemy_laser")
var dir = get_global_pos() - target.get_global_pos()
var b = bullet.instance()
bullet_container.add_child(b)
b.start_at(dir.angle(), get_global_pos())

func shoot3():
var dir = get_global_pos() - target.get_global_pos()
for a in [-0.2, 0, 0.2]:
sounds.play("enemy_laser")
var b = bullet.instance()
bullet_container.add_child(b)
b.start_at(dir.angle() + a, get_global_pos())

func _on_visible_exit_screen():
queue_free()
func _on_shoot_timer_timeout():
shoot3()
18 changes: 18 additions & 0 deletions Space_Rocks_tutorial/working/scripts/enemy_bullet.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
extends Area2D

var vel = Vector2()
export var speed = 800

func _ready():
set_fixed_process(true)

func start_at(dir, pos):
set_rot(dir)
set_pos(pos)
vel = Vector2(speed, 0).rotated(dir + PI/2)

func _fixed_process(delta):
set_pos(get_pos() + vel * delta)

func _on_visible_exit_screen():
queue_free()
14 changes: 12 additions & 2 deletions Space_Rocks_tutorial/working/scripts/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ extends Node

var asteroid = preload("res://scenes/asteroid.tscn")
var explosion = preload("res://scenes/explosion.tscn")
var enemy = preload("res://scenes/enemy.tscn")
onready var spawns = get_node("spawn_locations")
onready var asteroid_container = get_node("asteroid_container")
onready var expl_sounds = get_node("expl_sounds")
onready var HUD = get_node("HUD")
onready var player = get_node("player")
onready var enemy_timer = get_node("enemy_timer")

func _ready():
set_process(true)
Expand All @@ -16,6 +18,9 @@ func _ready():

func begin_next_level():
global.level += 1
enemy_timer.stop()
enemy_timer.set_wait_time(rand_range(2, 4))
enemy_timer.start()
HUD.show_message("Wave %s" % global.level)
for i in range(global.level):
spawn_asteroid("big", spawns.get_child(i).get_pos(),
Expand Down Expand Up @@ -57,7 +62,12 @@ func explode_player():
HUD.show_message("Game Over")
get_node("restart_timer").start()



func _on_restart_timer_timeout():
global.new_game()

func _on_enemy_timer_timeout():
var e = enemy.instance()
add_child(e)
e.target = player
enemy_timer.set_wait_time(rand_range(20, 40))
enemy_timer.start()

0 comments on commit ccfb539

Please sign in to comment.