Much more modular upgrades. Renamed laserr to laser.

Health and spawns still completely without balance
This commit is contained in:
Sage Vaillancourt 2018-05-23 03:57:15 -04:00
parent 0713f7ae60
commit 7ce69fb960
13 changed files with 275 additions and 84 deletions

View File

@ -8,7 +8,7 @@ var screensize
# class member variables go here, for example: # class member variables go here, for example:
# var a = 2 # var a = 2
# var b = "textvar" # var b = "textvar"
var health = 100 var health = 50
var hit_timer = 1000 var hit_timer = 1000
func _ready(): func _ready():
@ -17,7 +17,7 @@ func _ready():
func hit(who): func hit(who):
health -= 20 health -= 10
$AnimatedSprite.frame = 1 $AnimatedSprite.frame = 1
hit_timer = 0 hit_timer = 0
@ -25,7 +25,7 @@ var velocity = Vector2()
func _process(delta): func _process(delta):
if health <= 0: if health <= 0:
emit_signal("dead") emit_signal("dead", 150)
queue_free() queue_free()
if hit_timer < 0.15: if hit_timer < 0.15:
@ -42,7 +42,7 @@ func _process(delta):
if velocity.length() > 0: if velocity.length() > 0:
velocity = velocity.normalized() * SPEED 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 ) $Line2D.set_point_position( 1, health_bar )
position += velocity * delta position += velocity * delta

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=7 format=2] [gd_scene load_steps=7 format=2]
[ext_resource path="res://Bad1.gd" type="Script" id=1] [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.png" type="Texture" id=3]
[ext_resource path="res://art/bad/bad1/bad1_hit.png" type="Texture" id=4] [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 gravity = 98.0
linear_damp = 0.1 linear_damp = 0.1
angular_damp = 1.0 angular_damp = 1.0
collision_layer = 2
collision_mask = 0
audio_bus_override = false audio_bus_override = false
audio_bus_name = "Master" audio_bus_name = "Master"
script = ExtResource( 1 ) script = ExtResource( 1 )
_sections_unfolded = [ "Transform" ] _sections_unfolded = [ "Collision", "Transform" ]
SPEED = 50 SPEED = 50
Laser = ExtResource( 2 ) Laser = ExtResource( 2 )

View File

@ -7,7 +7,7 @@ var screensize
# class member variables go here, for example: # class member variables go here, for example:
# var a = 2 # var a = 2
# var b = "textvar" # var b = "textvar"
var health = 200 var health = 150
var hit_timer = 1000 var hit_timer = 1000
func _ready(): func _ready():
@ -24,7 +24,7 @@ var velocity = Vector2()
func _process(delta): func _process(delta):
if health <= 0: if health <= 0:
emit_signal("dead") emit_signal("dead", 300)
queue_free() queue_free()
if hit_timer < 0.15: if hit_timer < 0.15:

View File

@ -18,7 +18,7 @@ animations = [ {
"speed": 5.0 "speed": 5.0
} ] } ]
[node name="Area2D" type="Area2D"] [node name="Area2D" type="Area2D" index="0"]
scale = Vector2( 0.25, 0.25 ) scale = Vector2( 0.25, 0.25 )
input_pickable = true input_pickable = true
@ -26,10 +26,11 @@ gravity_vec = Vector2( 0, 1 )
gravity = 98.0 gravity = 98.0
linear_damp = 0.1 linear_damp = 0.1
angular_damp = 1.0 angular_damp = 1.0
collision_mask = 0
audio_bus_override = false audio_bus_override = false
audio_bus_name = "Master" audio_bus_name = "Master"
script = ExtResource( 1 ) script = ExtResource( 1 )
_sections_unfolded = [ "Transform" ] _sections_unfolded = [ "Collision", "Transform" ]
SPEED = 40 SPEED = 40
[node name="CollisionShape2D" type="CollisionShape2D" parent="." index="0"] [node name="CollisionShape2D" type="CollisionShape2D" parent="." index="0"]

55
Laser.gd Normal file
View File

@ -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

56
Laser.tscn Normal file
View File

@ -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" ]

59
Main.gd
View File

@ -1,19 +1,17 @@
extends Node extends Node
export (PackedScene) var FirstBad export (PackedScene) var FirstBad
export (PackedScene) var BadBlob export (PackedScene) var BlobBad
export (PackedScene) var UpgradeMenu export (PackedScene) var UpgradeMenu
# class member variables go here, for example:
# var a = 2
# var b = "textvar"
var position = Vector2(200, 200) var position = Vector2(200, 200)
var kill_money = 10
var total_bads_spawned = 0 var total_bads_spawned = 0
var upgrade_cost = 50 var upgrade_cost = 50
func _ready(): func _ready():
$BaddieTimer.start() $BaddieTimer.start()
randomize() randomize()
$MoneyDisplay.text = str($Player.money, " points") updatePoints()
func _process(delta): func _process(delta):
if (Input.is_action_pressed("ctlr_l")): if (Input.is_action_pressed("ctlr_l")):
@ -23,48 +21,59 @@ func _process(delta):
get_tree().quit() get_tree().quit()
if (Input.is_action_pressed("ui_quit")): if (Input.is_action_pressed("ui_quit")):
get_tree().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 $Player.money += kill_money
$MoneyDisplay.text = str($Player.money, " points") updatePoints()
func _on_badblob_death():
$Player.money += kill_money*2
$MoneyDisplay.text = str($Player.money, " points")
var sendblob = 0 var sendblob = 0
func BaddieTimer(): func BaddieTimer():
prints ("baddie boi")
if total_bads_spawned < 11: if total_bads_spawned < 11:
var bad var bad
if sendblob == 5: if sendblob == 5:
sendblob = 0 sendblob = 0
bad = BadBlob.instance() bad = BlobBad.instance()
add_child(bad)
bad.connect("dead", self, "_on_badblob_death")
else: else:
bad = FirstBad.instance() bad = FirstBad.instance()
add_child(bad)
sendblob += 1 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.x = 1200
bad.position.y = randi()%500 + 25 bad.position.y = randi()%500 + 25
else: else:
$Player.money += 200
total_bads_spawned = 0 total_bads_spawned = 0
func _on_Player_shooting_speed_upgrade(): func _on_Player_shooting_speed_upgrade():
#$MoneyDisplay.text = str($Player.money, " points") updatePoints()
pass pass
func _on_PauseButton_pressed(): func _on_PauseButton_pressed():
var upgmenu var upgmenu
upgmenu = UpgradeMenu.instance() upgmenu = UpgradeMenu.instance()
add_child(upgmenu) 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

View File

@ -24,12 +24,12 @@ lossy_quality = 0.7
flags = 7 flags = 7
size = Vector2( 0, 0 ) size = Vector2( 0, 0 )
[node name="Main" type="Node"] [node name="Main" type="Node" index="0"]
script = ExtResource( 1 ) script = ExtResource( 1 )
_sections_unfolded = [ "Pause" ] _sections_unfolded = [ "Pause" ]
FirstBad = ExtResource( 2 ) FirstBad = ExtResource( 2 )
BadBlob = ExtResource( 3 ) BlobBad = ExtResource( 3 )
UpgradeMenu = ExtResource( 4 ) UpgradeMenu = ExtResource( 4 )
[node name="Sprite2" type="Sprite" parent="." index="0"] [node name="Sprite2" type="Sprite" parent="." index="0"]
@ -50,14 +50,12 @@ texture = ExtResource( 5 )
[node name="BaddieTimer" type="Timer" parent="." index="3"] [node name="BaddieTimer" type="Timer" parent="." index="3"]
process_mode = 1 process_mode = 1
wait_time = 5.0 wait_time = 4.0
one_shot = false one_shot = false
autostart = false autostart = false
[node name="Mothership" parent="." index="4" instance=ExtResource( 7 )] [node name="Mothership" parent="." index="4" instance=ExtResource( 7 )]
Laser = null
[node name="MoneyDisplay" type="Label" parent="." index="5"] [node name="MoneyDisplay" type="Label" parent="." index="5"]
anchor_left = 0.0 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="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="shooting_speed_upgrade" from="Player" to="." method="_on_Player_shooting_speed_upgrade"]
[connection signal="timeout" from="BaddieTimer" to="." method="BaddieTimer"] [connection signal="timeout" from="BaddieTimer" to="." method="BaddieTimer"]

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=7 format=2] [gd_scene load_steps=7 format=2]
[ext_resource path="res://Mothership.gd" type="Script" id=1] [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] [ext_resource path="res://art/mothership/mothership.png" type="Texture" id=3]
[sub_resource type="CapsuleShape2D" id=1] [sub_resource type="CapsuleShape2D" id=1]
@ -24,7 +24,7 @@ animations = [ {
custom_solver_bias = 0.0 custom_solver_bias = 0.0
extents = Vector2( 135.733, 138.728 ) extents = Vector2( 135.733, 138.728 )
[node name="Mothership" type="Area2D"] [node name="Mothership" type="Area2D" index="0"]
position = Vector2( 23.327, 304.835 ) position = Vector2( 23.327, 304.835 )
scale = Vector2( 0.3, 0.3 ) scale = Vector2( 0.3, 0.3 )

103
Player.gd
View File

@ -1,24 +1,48 @@
extends Area2D extends Area2D
signal refund
signal shooting_speed_upgrade signal shooting_speed_upgrade
export (PackedScene) var Laser export (PackedScene) var Laser
#Constants #Default ship strengths and costs
const BULLET_DELAY_DEFAULT = 0.9 const SHOOTING_SPEED_UPGRADE_TIER1 = 50 #To be replaced
const SHOOTING_SPEED_UPGRADE_DEFAULT = 50 const BULLET_DELAY_TIER1 = 0.8
const SHIP_SPEED_DEFAULT = 400 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_value = 0
var ship_speed = SHIP_SPEED_DEFAULT var refund_percentage = 1
var bullet_delay = BULLET_DELAY_DEFAULT
var screensize
var money = 100 var money = 100
var shooting_speed_upgrade = 50
var double_laser = true
# class member variables go here, for example: var shooting_speed_upgrade = 50
# var a = 2
# var b = "textvar"
func _ready(): func _ready():
timer = Timer.new() timer = Timer.new()
@ -36,22 +60,23 @@ func _ready():
pass pass
func refund(): func refund():
bullet_delay = BULLET_DELAY_DEFAULT bullet_delay = BULLET_DELAY_TIER1
ship_speed = SHIP_SPEED_DEFAULT ship_speed = SHIP_SPEED_TIER1
money += ship_value shooting_speed_upgrade = SHOOTING_SPEED_UPGRADE_TIER1
money += ship_value*refund_percentage
emit_signal("refund", ship_value*refund_percentage)
ship_value = 0 ship_value = 0
var timer = null var timer = null
var can_shoot = true var can_shoot = true
func on_timeout_complete():
can_shoot = true
var going_up = false var going_up = false
var going_down = false var going_down = false
var shoot_down = false var shoot_down = false
func on_timeout_complete():
can_shoot = true
func _process(delta): func _process(delta):
var velocity = Vector2() # the player's movement vector var velocity = Vector2() # the player's movement vector
if (Input.is_action_pressed("ui_right")): if (Input.is_action_pressed("ui_right")):
@ -81,25 +106,10 @@ func _process(delta):
timer.start() timer.start()
if ((Input.is_action_pressed("ui_accept") || shoot_down == true) && can_shoot == true): if ((Input.is_action_pressed("ui_accept") || shoot_down == true) && can_shoot == true):
var laser = Laser.instance() shoot()
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()
func _on_Player_body_entered(body): func _on_Player_body_entered(body):
prints("hit") prints("hit")
pass # replace with function body
func upPressed(): func upPressed():
going_up = true going_up = true
@ -112,6 +122,25 @@ func downDepressed():
going_down = false going_down = false
func shootDown(): func shootDown():
shoot_down = true # replace with function body shoot_down = true
func shootUp(): 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()

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=7 format=2] [gd_scene load_steps=7 format=2]
[ext_resource path="res://Player.gd" type="Script" id=1] [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/Rocket1.png" type="Texture" id=3]
[ext_resource path="res://art/player/Rocket2.png" type="Texture" id=4] [ext_resource path="res://art/player/Rocket2.png" type="Texture" id=4]
@ -20,7 +20,7 @@ custom_solver_bias = 0.0
radius = 19.3222 radius = 19.3222
height = 76.5834 height = 76.5834
[node name="Player" type="Area2D" index="0"] [node name="Player" type="Area2D"]
input_pickable = true input_pickable = true
gravity_vec = Vector2( 0, 1 ) gravity_vec = Vector2( 0, 1 )

View File

@ -1,5 +1,11 @@
extends Node extends Node
signal refund
signal speed_upgrade
signal bullet_delay_upgrade
signal add_laser
signal plasma_lasers
# class member variables go here, for example: # class member variables go here, for example:
# var a = 2 # var a = 2
# var b = "textvar" # var b = "textvar"
@ -18,3 +24,9 @@ func _ready():
func _on_Button_pressed(): func _on_Button_pressed():
get_tree().paused = false get_tree().paused = false
queue_free() queue_free()
func _on_Refund_pressed():
get_tree().paused = false
emit_signal("refund")
pass # replace with function body

View File

@ -5,13 +5,13 @@
[sub_resource type="Theme" id=1] [sub_resource type="Theme" id=1]
[node name="UpgradeMenu" type="Node" index="0"] [node name="UpgradeMenu" type="Node"]
pause_mode = 2 pause_mode = 2
script = ExtResource( 1 ) script = ExtResource( 1 )
_sections_unfolded = [ "Pause" ] _sections_unfolded = [ "Pause" ]
[node name="Button" type="Button" parent="." index="0"] [node name="Resume" type="Button" parent="." index="0"]
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
@ -38,6 +38,33 @@ flat = false
align = 1 align = 1
_sections_unfolded = [ "Theme" ] _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"]