From 7ce69fb9607ee728049daa9877241d71829957e0 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Wed, 23 May 2018 03:57:15 -0400 Subject: [PATCH] Much more modular upgrades. Renamed laserr to laser. Health and spawns still completely without balance --- Bad1.gd | 8 ++-- Bad1.tscn | 6 ++- Bloob.gd | 4 +- Bloob.tscn | 5 ++- Laser.gd | 55 +++++++++++++++++++++++++ Laser.tscn | 56 ++++++++++++++++++++++++++ Main.gd | 59 +++++++++++++++------------ Main.tscn | 10 ++--- Mothership.tscn | 4 +- Player.gd | 103 ++++++++++++++++++++++++++++++----------------- Player.tscn | 4 +- UpgradeMenu.gd | 12 ++++++ UpgradeMenu.tscn | 33 +++++++++++++-- 13 files changed, 275 insertions(+), 84 deletions(-) create mode 100644 Laser.gd create mode 100644 Laser.tscn diff --git a/Bad1.gd b/Bad1.gd index 41d7bb0..f254519 100644 --- a/Bad1.gd +++ b/Bad1.gd @@ -8,7 +8,7 @@ var screensize # class member variables go here, for example: # var a = 2 # var b = "textvar" -var health = 100 +var health = 50 var hit_timer = 1000 func _ready(): @@ -17,7 +17,7 @@ func _ready(): func hit(who): - health -= 20 + health -= 10 $AnimatedSprite.frame = 1 hit_timer = 0 @@ -25,7 +25,7 @@ var velocity = Vector2() func _process(delta): if health <= 0: - emit_signal("dead") + emit_signal("dead", 150) queue_free() if hit_timer < 0.15: @@ -42,7 +42,7 @@ func _process(delta): if velocity.length() > 0: velocity = velocity.normalized() * SPEED - var health_bar = Vector2(((health * 3) - 157), -273) + var health_bar = Vector2(((health * 6) - 157), -273) $Line2D.set_point_position( 1, health_bar ) position += velocity * delta \ No newline at end of file diff --git a/Bad1.tscn b/Bad1.tscn index 08dd934..c5f264b 100644 --- a/Bad1.tscn +++ b/Bad1.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=7 format=2] [ext_resource path="res://Bad1.gd" type="Script" id=1] -[ext_resource path="res://Laserr.tscn" type="PackedScene" id=2] +[ext_resource path="res://Laser.tscn" type="PackedScene" id=2] [ext_resource path="res://art/bad/bad1/bad1.png" type="Texture" id=3] [ext_resource path="res://art/bad/bad1/bad1_hit.png" type="Texture" id=4] @@ -28,10 +28,12 @@ gravity_vec = Vector2( 0, 1 ) gravity = 98.0 linear_damp = 0.1 angular_damp = 1.0 +collision_layer = 2 +collision_mask = 0 audio_bus_override = false audio_bus_name = "Master" script = ExtResource( 1 ) -_sections_unfolded = [ "Transform" ] +_sections_unfolded = [ "Collision", "Transform" ] SPEED = 50 Laser = ExtResource( 2 ) diff --git a/Bloob.gd b/Bloob.gd index 08c3b1d..402e626 100644 --- a/Bloob.gd +++ b/Bloob.gd @@ -7,7 +7,7 @@ var screensize # class member variables go here, for example: # var a = 2 # var b = "textvar" -var health = 200 +var health = 150 var hit_timer = 1000 func _ready(): @@ -24,7 +24,7 @@ var velocity = Vector2() func _process(delta): if health <= 0: - emit_signal("dead") + emit_signal("dead", 300) queue_free() if hit_timer < 0.15: diff --git a/Bloob.tscn b/Bloob.tscn index c4cbdf6..eaa41b0 100644 --- a/Bloob.tscn +++ b/Bloob.tscn @@ -18,7 +18,7 @@ animations = [ { "speed": 5.0 } ] -[node name="Area2D" type="Area2D"] +[node name="Area2D" type="Area2D" index="0"] scale = Vector2( 0.25, 0.25 ) input_pickable = true @@ -26,10 +26,11 @@ gravity_vec = Vector2( 0, 1 ) gravity = 98.0 linear_damp = 0.1 angular_damp = 1.0 +collision_mask = 0 audio_bus_override = false audio_bus_name = "Master" script = ExtResource( 1 ) -_sections_unfolded = [ "Transform" ] +_sections_unfolded = [ "Collision", "Transform" ] SPEED = 40 [node name="CollisionShape2D" type="CollisionShape2D" parent="." index="0"] diff --git a/Laser.gd b/Laser.gd new file mode 100644 index 0000000..98d8969 --- /dev/null +++ b/Laser.gd @@ -0,0 +1,55 @@ +extends Area2D + +signal hit + +export (int) var SPEED +export (int) var DAMAGE +var plasma = false +var current_pen = 0 + +# class member variables go here, for example: +# var a = 2 +# var b = "textvar" + +func _on_Visibility_screen_exited(): + queue_free() + +func _ready(): + # Called every time the node is added to the scene. + # Initialization here + $AnimatedSprite.play() + connect("area_entered", self, "hit") + pass + +func hit(who): + #if plasma == false: + # hide() + # queue_free() + if current_pen > 0: + current_pen -= 1 + else: + hide() + queue_free() + +func _process(delta): + var velocity = Vector2() + velocity.x += 1 + velocity = velocity.normalized() * SPEED + position += velocity * delta + +func _on_Laser_body_entered(body): + emit_signal("hit") + if plasma == false: + $CollisionShape2D.disabled = true + queue_free() + else: + var timer = null + timer = Timer.new() + timer.set_one_shot(true) + timer.set_wait_time(0.1) + timer.connect("timeout", self, "on_timeout_complete") + add_child(timer) + $CollisionShape2D.disabled = true + +func on_timeout_complete(): + $CollisionShape2D.disabled = false \ No newline at end of file diff --git a/Laser.tscn b/Laser.tscn new file mode 100644 index 0000000..22f07da --- /dev/null +++ b/Laser.tscn @@ -0,0 +1,56 @@ +[gd_scene load_steps=6 format=2] + +[ext_resource path="res://Laser.gd" type="Script" id=1] +[ext_resource path="res://art/laser/laser1.png" type="Texture" id=2] +[ext_resource path="res://art/laser/laser2.png" type="Texture" id=3] + +[sub_resource type="CapsuleShape2D" id=1] + +custom_solver_bias = 0.0 +radius = 5.39465 +height = 0.325962 + +[sub_resource type="SpriteFrames" id=2] + +animations = [ { +"frames": [ ExtResource( 2 ), ExtResource( 3 ) ], +"loop": true, +"name": "default", +"speed": 20.0 +} ] + +[node name="Laser" type="Area2D"] + +input_pickable = true +gravity_vec = Vector2( 0, 1 ) +gravity = 98.0 +linear_damp = 0.1 +angular_damp = 1.0 +collision_layer = 3 +collision_mask = 3 +audio_bus_override = false +audio_bus_name = "Master" +script = ExtResource( 1 ) +_sections_unfolded = [ "Collision" ] +SPEED = 1200 +DAMAGE = 10 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="." index="0"] + +position = Vector2( 28, -5 ) +rotation = 1.5708 +shape = SubResource( 1 ) +_sections_unfolded = [ "Transform" ] +__meta__ = { +"_edit_group_": true +} + +[node name="AnimatedSprite" type="AnimatedSprite" parent="." index="1"] + +position = Vector2( -1.90735e-06, 0 ) +scale = Vector2( 0.1, 0.2 ) +frames = SubResource( 2 ) +animation = "default" +_sections_unfolded = [ "Transform" ] + + diff --git a/Main.gd b/Main.gd index b76860c..0c97a4a 100644 --- a/Main.gd +++ b/Main.gd @@ -1,19 +1,17 @@ extends Node + export (PackedScene) var FirstBad -export (PackedScene) var BadBlob +export (PackedScene) var BlobBad export (PackedScene) var UpgradeMenu -# class member variables go here, for example: -# var a = 2 -# var b = "textvar" + var position = Vector2(200, 200) -var kill_money = 10 var total_bads_spawned = 0 var upgrade_cost = 50 func _ready(): $BaddieTimer.start() randomize() - $MoneyDisplay.text = str($Player.money, " points") + updatePoints() func _process(delta): if (Input.is_action_pressed("ctlr_l")): @@ -23,48 +21,59 @@ func _process(delta): get_tree().quit() if (Input.is_action_pressed("ui_quit")): get_tree().quit() - $MoneyDisplay.text = str($Player.money, " points") + updatePoints() -func _on_bad1_death(): +func _on_bad_death(kill_money): $Player.money += kill_money - $MoneyDisplay.text = str($Player.money, " points") - -func _on_badblob_death(): - $Player.money += kill_money*2 - $MoneyDisplay.text = str($Player.money, " points") + updatePoints() var sendblob = 0 func BaddieTimer(): - prints ("baddie boi") if total_bads_spawned < 11: var bad + if sendblob == 5: sendblob = 0 - bad = BadBlob.instance() - add_child(bad) - bad.connect("dead", self, "_on_badblob_death") + bad = BlobBad.instance() else: bad = FirstBad.instance() - add_child(bad) sendblob += 1 - bad.connect("dead", self, "_on_bad1_death") - total_bads_spawned += 1 - $BaddieTimer.wait_time = $BaddieTimer.wait_time * 0.99 - $MoneyDisplay.text = str($Player.money, " points") + add_child(bad) + bad.connect("dead", self, "_on_bad_death") + total_bads_spawned += 1 + $BaddieTimer.wait_time = $BaddieTimer.wait_time * 0.97 + + updatePoints() bad.position.x = 1200 bad.position.y = randi()%500 + 25 else: - $Player.money += 200 total_bads_spawned = 0 func _on_Player_shooting_speed_upgrade(): - #$MoneyDisplay.text = str($Player.money, " points") + updatePoints() pass func _on_PauseButton_pressed(): var upgmenu upgmenu = UpgradeMenu.instance() add_child(upgmenu) - get_tree().paused = true # replace with function body + upgmenu.connect("refund", self, "_refund_button") + get_tree().paused = true + +func updatePoints(): + $MoneyDisplay.text = str($Player.money, " points") + +#When refund signal from upgrade menu comes in, +# tell Player to refund upgrades +func _refund_button(): + $Player.refund() + +#When refund comes back successfully from Player, +# pause game again +func _on_Player_refund(ship_value): + prints("Refunded for ", ship_value) + updatePoints() + get_tree().paused = true + pass # replace with function body diff --git a/Main.tscn b/Main.tscn index 9cc4cd7..c91489d 100644 --- a/Main.tscn +++ b/Main.tscn @@ -24,12 +24,12 @@ lossy_quality = 0.7 flags = 7 size = Vector2( 0, 0 ) -[node name="Main" type="Node"] +[node name="Main" type="Node" index="0"] script = ExtResource( 1 ) _sections_unfolded = [ "Pause" ] FirstBad = ExtResource( 2 ) -BadBlob = ExtResource( 3 ) +BlobBad = ExtResource( 3 ) UpgradeMenu = ExtResource( 4 ) [node name="Sprite2" type="Sprite" parent="." index="0"] @@ -50,14 +50,12 @@ texture = ExtResource( 5 ) [node name="BaddieTimer" type="Timer" parent="." index="3"] process_mode = 1 -wait_time = 5.0 +wait_time = 4.0 one_shot = false autostart = false [node name="Mothership" parent="." index="4" instance=ExtResource( 7 )] -Laser = null - [node name="MoneyDisplay" type="Label" parent="." index="5"] anchor_left = 0.0 @@ -181,6 +179,8 @@ align = 1 [connection signal="body_entered" from="Player" to="Player" method="_on_Player_body_entered"] +[connection signal="refund" from="Player" to="." method="_on_Player_refund"] + [connection signal="shooting_speed_upgrade" from="Player" to="." method="_on_Player_shooting_speed_upgrade"] [connection signal="timeout" from="BaddieTimer" to="." method="BaddieTimer"] diff --git a/Mothership.tscn b/Mothership.tscn index c128806..ed9f089 100644 --- a/Mothership.tscn +++ b/Mothership.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=7 format=2] [ext_resource path="res://Mothership.gd" type="Script" id=1] -[ext_resource path="res://Laserr.tscn" type="PackedScene" id=2] +[ext_resource path="res://Laser.tscn" type="PackedScene" id=2] [ext_resource path="res://art/mothership/mothership.png" type="Texture" id=3] [sub_resource type="CapsuleShape2D" id=1] @@ -24,7 +24,7 @@ animations = [ { custom_solver_bias = 0.0 extents = Vector2( 135.733, 138.728 ) -[node name="Mothership" type="Area2D"] +[node name="Mothership" type="Area2D" index="0"] position = Vector2( 23.327, 304.835 ) scale = Vector2( 0.3, 0.3 ) diff --git a/Player.gd b/Player.gd index d77a11e..de8bf52 100644 --- a/Player.gd +++ b/Player.gd @@ -1,24 +1,48 @@ extends Area2D +signal refund signal shooting_speed_upgrade export (PackedScene) var Laser -#Constants -const BULLET_DELAY_DEFAULT = 0.9 -const SHOOTING_SPEED_UPGRADE_DEFAULT = 50 -const SHIP_SPEED_DEFAULT = 400 +#Default ship strengths and costs +const SHOOTING_SPEED_UPGRADE_TIER1 = 50 #To be replaced +const BULLET_DELAY_TIER1 = 0.8 +const BULLET_DELAY_TIER2 = 0.5 +const BULLET_DELAY_TIER3 = 0.2 +const BULLET_DELAY_TIER4 = 0.1 +const BULLET_DELAY_TIER5 = 0.05 +const BULLET_DELAY_TIER2_COST = 100 +const BULLET_DELAY_TIER3_COST = 200 +const BULLET_DELAY_TIER4_COST = 400 +const BULLET_DELAY_TIER5_COST = 1000 + +const SHIP_SPEED_TIER1 = 150 +const SHIP_SPEED_TIER2 = 200 +const SHIP_SPEED_TIER3 = 300 +const SHIP_SPEED_TIER4 = 500 +const SHIP_SPEED_TIER5 = 800 + +#func upgradeBulletDelay(): +# if (bullet_delay_tier == 1 && money >= BULLET_DELAY_TIER2_COST): +# bullet_delay = BULLET_DELAY_TIER2 +# money -= BULLET_DELAY_TIER2_COST +# ship_value += BULLET_DELAY_TIER2_COST +# + +var screensize + +var ship_speed = SHIP_SPEED_TIER1 + +var bullet_delay = BULLET_DELAY_TIER1 +var bullet_delay_tier = 1 +var laser_penetration = 0 +var double_laser = false var ship_value = 0 -var ship_speed = SHIP_SPEED_DEFAULT -var bullet_delay = BULLET_DELAY_DEFAULT -var screensize +var refund_percentage = 1 var money = 100 -var shooting_speed_upgrade = 50 -var double_laser = true -# class member variables go here, for example: -# var a = 2 -# var b = "textvar" +var shooting_speed_upgrade = 50 func _ready(): timer = Timer.new() @@ -36,22 +60,23 @@ func _ready(): pass func refund(): - bullet_delay = BULLET_DELAY_DEFAULT - ship_speed = SHIP_SPEED_DEFAULT - money += ship_value + bullet_delay = BULLET_DELAY_TIER1 + ship_speed = SHIP_SPEED_TIER1 + shooting_speed_upgrade = SHOOTING_SPEED_UPGRADE_TIER1 + money += ship_value*refund_percentage + emit_signal("refund", ship_value*refund_percentage) ship_value = 0 var timer = null var can_shoot = true - -func on_timeout_complete(): - can_shoot = true - var going_up = false var going_down = false var shoot_down = false +func on_timeout_complete(): + can_shoot = true + func _process(delta): var velocity = Vector2() # the player's movement vector if (Input.is_action_pressed("ui_right")): @@ -81,25 +106,10 @@ func _process(delta): timer.start() if ((Input.is_action_pressed("ui_accept") || shoot_down == true) && can_shoot == true): - var laser = Laser.instance() - get_node("../").add_child(laser) - laser.position.y = position.y - 27 - laser.position.x = position.x + 46 - - #MAYBE THE SECOND LASER SHOULD BE IT'S OWN NODE - if double_laser == true: - var laser2 = Laser.instance() - get_node("../").add_child(laser2) - laser2.position.y = position.y + 28 - laser2.position.x = position.x + 46 - can_shoot = false - timer.start() - - + shoot() func _on_Player_body_entered(body): prints("hit") - pass # replace with function body func upPressed(): going_up = true @@ -112,6 +122,25 @@ func downDepressed(): going_down = false func shootDown(): - shoot_down = true # replace with function body + shoot_down = true func shootUp(): - shoot_down = false # replace with function body + shoot_down = false + +func shoot(): + var laser = Laser.instance() + get_node("../").add_child(laser) + laser.current_pen = laser_penetration + laser.position.y = position.y - 27 + laser.position.x = position.x + 46 + + #MAYBE THE LASERS SHOULD BE THEIR OWN NODES + #Would allow for more simple additions in the future + if double_laser == true: + var laser2 = Laser.instance() + get_node("../").add_child(laser2) + laser2.position.y = position.y + 28 + laser2.position.x = position.x + 46 + laser2.current_pen = laser_penetration + + can_shoot = false + timer.start() \ No newline at end of file diff --git a/Player.tscn b/Player.tscn index 680705c..84112a8 100644 --- a/Player.tscn +++ b/Player.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=7 format=2] [ext_resource path="res://Player.gd" type="Script" id=1] -[ext_resource path="res://Laserr.tscn" type="PackedScene" id=2] +[ext_resource path="res://Laser.tscn" type="PackedScene" id=2] [ext_resource path="res://art/player/Rocket1.png" type="Texture" id=3] [ext_resource path="res://art/player/Rocket2.png" type="Texture" id=4] @@ -20,7 +20,7 @@ custom_solver_bias = 0.0 radius = 19.3222 height = 76.5834 -[node name="Player" type="Area2D" index="0"] +[node name="Player" type="Area2D"] input_pickable = true gravity_vec = Vector2( 0, 1 ) diff --git a/UpgradeMenu.gd b/UpgradeMenu.gd index ea28313..c9c2d51 100644 --- a/UpgradeMenu.gd +++ b/UpgradeMenu.gd @@ -1,5 +1,11 @@ extends Node +signal refund +signal speed_upgrade +signal bullet_delay_upgrade +signal add_laser +signal plasma_lasers + # class member variables go here, for example: # var a = 2 # var b = "textvar" @@ -18,3 +24,9 @@ func _ready(): func _on_Button_pressed(): get_tree().paused = false queue_free() + + +func _on_Refund_pressed(): + get_tree().paused = false + emit_signal("refund") + pass # replace with function body diff --git a/UpgradeMenu.tscn b/UpgradeMenu.tscn index cb21af3..646492d 100644 --- a/UpgradeMenu.tscn +++ b/UpgradeMenu.tscn @@ -5,13 +5,13 @@ [sub_resource type="Theme" id=1] -[node name="UpgradeMenu" type="Node" index="0"] +[node name="UpgradeMenu" type="Node"] pause_mode = 2 script = ExtResource( 1 ) _sections_unfolded = [ "Pause" ] -[node name="Button" type="Button" parent="." index="0"] +[node name="Resume" type="Button" parent="." index="0"] anchor_left = 0.0 anchor_top = 0.0 @@ -38,6 +38,33 @@ flat = false align = 1 _sections_unfolded = [ "Theme" ] -[connection signal="pressed" from="Button" to="." method="_on_Button_pressed"] +[node name="Refund" type="Button" parent="." index="1"] + +anchor_left = 0.0 +anchor_top = 0.0 +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_left = 618.0 +margin_top = 174.0 +margin_right = 742.0 +margin_bottom = 277.0 +rect_pivot_offset = Vector2( 0, 0 ) +rect_clip_content = false +focus_mode = 2 +mouse_filter = 0 +mouse_default_cursor_shape = 0 +size_flags_horizontal = 1 +size_flags_vertical = 1 +toggle_mode = false +enabled_focus_mode = 2 +shortcut = null +group = null +text = "Refund" +flat = false +align = 1 + +[connection signal="pressed" from="Resume" to="." method="_on_Button_pressed"] + +[connection signal="pressed" from="Refund" to="." method="_on_Refund_pressed"]