Multiplayer now actually semi-funcitonal. Needs enemy spawning and
support for multiple allies, still
This commit is contained in:
parent
1de7da63ad
commit
4887754f6b
|
@ -0,0 +1,288 @@
|
||||||
|
extends Area2D
|
||||||
|
|
||||||
|
|
||||||
|
signal update_display # tells parent to update points display
|
||||||
|
signal refund # will tell parent a refund is occuring, for display
|
||||||
|
signal shooting_speed_upgrade # signals that a shooting speed upgrade has occured
|
||||||
|
signal ship_speed_upgrade
|
||||||
|
signal shooting_speed_fully_upgraded
|
||||||
|
signal ship_speed_fully_upgraded
|
||||||
|
signal restart_game
|
||||||
|
signal multiplayer_movement
|
||||||
|
|
||||||
|
export (PackedScene) var Laser
|
||||||
|
|
||||||
|
################################
|
||||||
|
#THINGS THAT MAY NEED ADJUSTING
|
||||||
|
#################################
|
||||||
|
#Default ship strengths and costs
|
||||||
|
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 SHOOTING_SPEED_UPGRADE_DEFAULT = 1500
|
||||||
|
const BULLET_DELAY_MINIMUM = 0.01
|
||||||
|
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
|
||||||
|
const SHIP_SPEED_UPGRADE_DEFAULT = 1500
|
||||||
|
const SHIP_SPEED_MAXIMUM = 1200
|
||||||
|
const SHIP_SPEED_TIER2_COST = 200
|
||||||
|
const SHIP_SPEED_TIER3_COST = 400
|
||||||
|
const SHIP_SPEED_TIER4_COST = 600
|
||||||
|
const SHIP_SPEED_TIER5_COST = 800
|
||||||
|
|
||||||
|
const STARTING_MONEY = 100
|
||||||
|
|
||||||
|
#################################
|
||||||
|
|
||||||
|
var screensize
|
||||||
|
|
||||||
|
var ship_speed = SHIP_SPEED_TIER1
|
||||||
|
var ship_speed_tier = 0
|
||||||
|
|
||||||
|
var bullet_delay = BULLET_DELAY_TIER1
|
||||||
|
var bullet_delay_tier = 0
|
||||||
|
var laser_penetration = 0
|
||||||
|
var double_laser = false
|
||||||
|
|
||||||
|
var ship_value = 0
|
||||||
|
var refund_percentage = 1
|
||||||
|
var money = STARTING_MONEY
|
||||||
|
|
||||||
|
var shooting_speed_upgrade = SHOOTING_SPEED_UPGRADE_DEFAULT
|
||||||
|
var ship_speed_upgrade = SHIP_SPEED_UPGRADE_DEFAULT
|
||||||
|
|
||||||
|
func upgradeMenu():
|
||||||
|
var upgmenu = preload("res://UpgradeMenu.tscn").instance()
|
||||||
|
add_child(upgmenu)
|
||||||
|
upgmenu.connect("refund", self, "_refund_button")
|
||||||
|
upgmenu.connect("bullet_delay_upgrade", self, "upgradeBulletDelay_button")
|
||||||
|
upgmenu.connect("ship_speed_upgrade", self, "upgradeShipSpeed_button")
|
||||||
|
upgmenu.bullet_delay_tier = bullet_delay_tier
|
||||||
|
upgmenu.ship_speed_tier = ship_speed_tier
|
||||||
|
get_tree().paused = true
|
||||||
|
|
||||||
|
func upgradeShipSpeed_button():
|
||||||
|
upgradeShipSpeed()
|
||||||
|
emit_signal("update_display")
|
||||||
|
get_tree().paused = true
|
||||||
|
|
||||||
|
func upgradeBulletDelay_button():
|
||||||
|
upgradeBulletDelay()
|
||||||
|
emit_signal("update_display")
|
||||||
|
get_tree().paused = true
|
||||||
|
|
||||||
|
func upgradeBulletDelay():
|
||||||
|
if (bullet_delay == BULLET_DELAY_TIER1 && money >= BULLET_DELAY_TIER2_COST):
|
||||||
|
bullet_delay = BULLET_DELAY_TIER2
|
||||||
|
money -= BULLET_DELAY_TIER2_COST
|
||||||
|
ship_value += BULLET_DELAY_TIER2_COST
|
||||||
|
bullet_delay_tier = 1
|
||||||
|
elif (bullet_delay == BULLET_DELAY_TIER2 && money >= BULLET_DELAY_TIER3_COST):
|
||||||
|
bullet_delay = BULLET_DELAY_TIER3
|
||||||
|
money -= BULLET_DELAY_TIER3_COST
|
||||||
|
ship_value += BULLET_DELAY_TIER3_COST
|
||||||
|
bullet_delay_tier = 2
|
||||||
|
elif (bullet_delay == BULLET_DELAY_TIER3 && money >= BULLET_DELAY_TIER4_COST):
|
||||||
|
bullet_delay = BULLET_DELAY_TIER4
|
||||||
|
money -= BULLET_DELAY_TIER4_COST
|
||||||
|
ship_value += BULLET_DELAY_TIER4_COST
|
||||||
|
bullet_delay_tier = 3
|
||||||
|
elif (bullet_delay == BULLET_DELAY_TIER4 && money >= BULLET_DELAY_TIER5_COST):
|
||||||
|
bullet_delay = BULLET_DELAY_TIER5
|
||||||
|
money -= BULLET_DELAY_TIER5_COST
|
||||||
|
ship_value += BULLET_DELAY_TIER5_COST
|
||||||
|
bullet_delay_tier = 4
|
||||||
|
elif (bullet_delay <= BULLET_DELAY_MINIMUM):
|
||||||
|
emit_signal("bullet_delay_fully_upgraded")
|
||||||
|
elif (bullet_delay <= BULLET_DELAY_TIER5 && money >= shooting_speed_upgrade):
|
||||||
|
bullet_delay = bullet_delay*0.95
|
||||||
|
money -= shooting_speed_upgrade
|
||||||
|
ship_value += shooting_speed_upgrade
|
||||||
|
shooting_speed_upgrade *= 1.1
|
||||||
|
bullet_delay_tier += 1
|
||||||
|
timer.set_wait_time(bullet_delay)
|
||||||
|
prints(bullet_delay)
|
||||||
|
|
||||||
|
func upgradeShipSpeed():
|
||||||
|
prints("func upgradeShipSpeed():")
|
||||||
|
if (ship_speed == SHIP_SPEED_TIER1 && money >= SHIP_SPEED_TIER2_COST):
|
||||||
|
ship_speed = SHIP_SPEED_TIER2
|
||||||
|
money -= SHIP_SPEED_TIER2_COST
|
||||||
|
ship_value += SHIP_SPEED_TIER2_COST
|
||||||
|
ship_speed_tier = 1
|
||||||
|
elif (ship_speed == SHIP_SPEED_TIER2 && money >= SHIP_SPEED_TIER3_COST):
|
||||||
|
ship_speed = SHIP_SPEED_TIER3
|
||||||
|
money -= SHIP_SPEED_TIER3_COST
|
||||||
|
ship_value += SHIP_SPEED_TIER3_COST
|
||||||
|
ship_speed_tier = 2
|
||||||
|
elif (ship_speed == SHIP_SPEED_TIER3 && money >= SHIP_SPEED_TIER4_COST):
|
||||||
|
ship_speed = SHIP_SPEED_TIER4
|
||||||
|
money -= SHIP_SPEED_TIER4_COST
|
||||||
|
ship_value += SHIP_SPEED_TIER4_COST
|
||||||
|
ship_speed_tier = 3
|
||||||
|
elif (ship_speed == SHIP_SPEED_TIER4 && money >= SHIP_SPEED_TIER5_COST):
|
||||||
|
ship_speed = SHIP_SPEED_TIER5
|
||||||
|
money -= SHIP_SPEED_TIER5_COST
|
||||||
|
ship_value += SHIP_SPEED_TIER5_COST
|
||||||
|
ship_speed_tier = 4
|
||||||
|
elif (ship_speed >= SHIP_SPEED_MAXIMUM):
|
||||||
|
emit_signal("ship_speed_fully_upgraded")
|
||||||
|
elif (ship_speed >= SHIP_SPEED_TIER5 && money >= ship_speed_upgrade):
|
||||||
|
ship_speed = ship_speed*1.05
|
||||||
|
money -= ship_speed_upgrade
|
||||||
|
ship_value += ship_speed_upgrade
|
||||||
|
ship_speed_upgrade *= 1.1
|
||||||
|
prints(ship_speed)
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
timer = Timer.new()
|
||||||
|
timer.set_one_shot(true)
|
||||||
|
timer.set_wait_time(bullet_delay)
|
||||||
|
timer.connect("timeout", self, "on_timeout_complete")
|
||||||
|
add_child(timer)
|
||||||
|
timer.start()
|
||||||
|
|
||||||
|
position.x = 100
|
||||||
|
position.y = 250
|
||||||
|
|
||||||
|
screensize = get_viewport_rect().size
|
||||||
|
$AnimatedSprite.play()
|
||||||
|
|
||||||
|
func _refund_button():
|
||||||
|
bullet_delay = BULLET_DELAY_TIER1
|
||||||
|
bullet_delay_tier = 0
|
||||||
|
timer.set_wait_time(bullet_delay)
|
||||||
|
ship_speed = SHIP_SPEED_TIER1
|
||||||
|
shooting_speed_upgrade = SHOOTING_SPEED_UPGRADE_DEFAULT
|
||||||
|
money += ship_value*refund_percentage
|
||||||
|
prints("Refunded ", ship_value*refund_percentage)
|
||||||
|
ship_value = 0
|
||||||
|
emit_signal("update_display")
|
||||||
|
get_tree().paused = true
|
||||||
|
|
||||||
|
var timer = null
|
||||||
|
|
||||||
|
var can_shoot = false
|
||||||
|
var shoot_down = false
|
||||||
|
|
||||||
|
func on_timeout_complete():
|
||||||
|
can_shoot = true
|
||||||
|
|
||||||
|
#func _unhandled_input(event):
|
||||||
|
# if (event is InputEventScreenTouch):
|
||||||
|
# gravity_point = true
|
||||||
|
# gravity_vec = Vector2(0.5, 0.5)
|
||||||
|
|
||||||
|
var x_up = false
|
||||||
|
var y_up = false
|
||||||
|
var x_down = false
|
||||||
|
var y_down = false
|
||||||
|
|
||||||
|
func moveto(finger_position):
|
||||||
|
if (finger_position.x > position.x && finger_position.x < 800):
|
||||||
|
velocity.x += 1
|
||||||
|
x_up = true
|
||||||
|
if position.x > finger_position.x:
|
||||||
|
velocity.x -= 1
|
||||||
|
x_down = true
|
||||||
|
if (finger_position.y - 100 > position.y && finger_position.x < 800):
|
||||||
|
velocity.y += 1
|
||||||
|
y_up = true
|
||||||
|
if (position.y > finger_position.y - 100 && finger_position.x < 800):
|
||||||
|
velocity.y -= 1
|
||||||
|
y_down = true
|
||||||
|
# if (finger_position.x >= 800 && can_shoot):
|
||||||
|
# shoot()
|
||||||
|
if get_tree().has_network_peer():
|
||||||
|
rpc("move_player", get_tree().get_network_unique_id(), position)
|
||||||
|
|
||||||
|
remote func move_player(id, position):
|
||||||
|
prints("PLAYER SAYS:", id, position)
|
||||||
|
emit_signal("multiplayer_movement", id, position)
|
||||||
|
|
||||||
|
var velocity = Vector2() # the player's movement vector
|
||||||
|
|
||||||
|
func _process(delta):
|
||||||
|
velocity = Vector2()
|
||||||
|
if (Input.is_action_pressed("ui_right") || x_up):
|
||||||
|
velocity.x += 1
|
||||||
|
x_up = false
|
||||||
|
if (Input.is_action_pressed("ui_left") || x_down):
|
||||||
|
velocity.x -= 1
|
||||||
|
x_down = false
|
||||||
|
if (Input.is_action_pressed("ui_down") || y_up):
|
||||||
|
velocity.y += 1
|
||||||
|
y_up = false
|
||||||
|
if (Input.is_action_pressed("ui_up") || y_down):
|
||||||
|
velocity.y -= 1
|
||||||
|
y_down = false
|
||||||
|
if (velocity.length() > 0):
|
||||||
|
velocity = velocity.normalized() * ship_speed
|
||||||
|
|
||||||
|
position += velocity * delta
|
||||||
|
position.x = clamp(position.x, 0, screensize.x)
|
||||||
|
position.y = clamp(position.y, 0, screensize.y)
|
||||||
|
if get_tree().has_network_peer():
|
||||||
|
rpc("move_player", get_tree().get_network_unique_id(), position)
|
||||||
|
|
||||||
|
if ((Input.is_action_pressed("ui_accept") || shoot_down == true) && can_shoot == true):
|
||||||
|
shoot()
|
||||||
|
|
||||||
|
if (Input.is_action_pressed("ui_reset") && can_shoot == true):
|
||||||
|
upgradeMenu()
|
||||||
|
|
||||||
|
var x_up = false
|
||||||
|
var y_up = false
|
||||||
|
var x_down = false
|
||||||
|
var y_down = false
|
||||||
|
|
||||||
|
func _on_Player_body_entered(body):
|
||||||
|
prints("hit")
|
||||||
|
|
||||||
|
func shootDown():
|
||||||
|
shoot_down = true
|
||||||
|
func shootUp():
|
||||||
|
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()
|
||||||
|
|
||||||
|
func gameOver():
|
||||||
|
var gameover = preload("res://GameOver.tscn").instance()
|
||||||
|
add_child(gameover)
|
||||||
|
gameover.connect("restart", self, "restart_game")
|
||||||
|
# gameover.connect("bullet_delay_upgrade", self, "upgradeBulletDelay_button")
|
||||||
|
get_tree().paused = true
|
||||||
|
|
||||||
|
func restart_game():
|
||||||
|
_refund_button()
|
||||||
|
get_tree().paused = false
|
||||||
|
money = STARTING_MONEY
|
||||||
|
emit_signal("restart_game")
|
13
Main.gd
13
Main.gd
|
@ -43,6 +43,10 @@ func _process(delta):
|
||||||
get_tree().quit()
|
get_tree().quit()
|
||||||
updatePoints()
|
updatePoints()
|
||||||
|
|
||||||
|
if get_tree().has_network_peer():
|
||||||
|
if !get_tree().is_network_server():
|
||||||
|
$BaddieTimer.stop()
|
||||||
|
|
||||||
if (touchy_feely && (abs(touchy_feely.position.x - $Player.position.x) > 1)):
|
if (touchy_feely && (abs(touchy_feely.position.x - $Player.position.x) > 1)):
|
||||||
if (touchy_feely.position.x < 800):
|
if (touchy_feely.position.x < 800):
|
||||||
$Player.moveto(touchy_feely.position)
|
$Player.moveto(touchy_feely.position)
|
||||||
|
@ -135,4 +139,11 @@ func _input(event):
|
||||||
$Player.position.y = event.position.y - 100
|
$Player.position.y = event.position.y - 100
|
||||||
prints(event.index)
|
prints(event.index)
|
||||||
else:
|
else:
|
||||||
touchy_shooty = true
|
touchy_shooty = true
|
||||||
|
|
||||||
|
func _on_Player_multiplayer_movement(id, position, is_shooting):
|
||||||
|
prints("Multiplayer movement for", id, "to", position)
|
||||||
|
$OtherPlayer.visible = true
|
||||||
|
$OtherPlayer.position = position
|
||||||
|
if is_shooting:
|
||||||
|
$OtherPlayer.shoot()
|
||||||
|
|
10
Main.tscn
10
Main.tscn
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=11 format=2]
|
[gd_scene load_steps=12 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://Main.gd" type="Script" id=1]
|
[ext_resource path="res://Main.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://Bad1.tscn" type="PackedScene" id=2]
|
[ext_resource path="res://Bad1.tscn" type="PackedScene" id=2]
|
||||||
|
@ -8,6 +8,7 @@
|
||||||
[ext_resource path="res://Player.tscn" type="PackedScene" id=6]
|
[ext_resource path="res://Player.tscn" type="PackedScene" id=6]
|
||||||
[ext_resource path="res://Mothership.tscn" type="PackedScene" id=7]
|
[ext_resource path="res://Mothership.tscn" type="PackedScene" id=7]
|
||||||
[ext_resource path="res://art/interface/pause.png" type="Texture" id=8]
|
[ext_resource path="res://art/interface/pause.png" type="Texture" id=8]
|
||||||
|
[ext_resource path="res://OtherPlayer.tscn" type="PackedScene" id=9]
|
||||||
|
|
||||||
[sub_resource type="ImageTexture" id=1]
|
[sub_resource type="ImageTexture" id=1]
|
||||||
|
|
||||||
|
@ -166,8 +167,15 @@ scale = Vector2( 0.199771, 0.199771 )
|
||||||
frames = SubResource( 2 )
|
frames = SubResource( 2 )
|
||||||
animation = "default"
|
animation = "default"
|
||||||
|
|
||||||
|
[node name="OtherPlayer" parent="." index="9" instance=ExtResource( 9 )]
|
||||||
|
|
||||||
|
visible = false
|
||||||
|
_sections_unfolded = [ "Transform", "Visibility" ]
|
||||||
|
|
||||||
[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="multiplayer_movement" from="Player" to="." method="_on_Player_multiplayer_movement"]
|
||||||
|
|
||||||
[connection signal="restart_game" from="Player" to="Mothership" method="_on_Player_restart_game"]
|
[connection signal="restart_game" from="Player" to="Mothership" method="_on_Player_restart_game"]
|
||||||
|
|
||||||
[connection signal="restart_game" from="Player" to="." method="_on_Player_restart_game"]
|
[connection signal="restart_game" from="Player" to="." method="_on_Player_restart_game"]
|
||||||
|
|
|
@ -20,7 +20,7 @@ height = 1.0
|
||||||
ascent = 0.0
|
ascent = 0.0
|
||||||
distance_field = false
|
distance_field = false
|
||||||
|
|
||||||
[node name="Networking" type="Node" index="0"]
|
[node name="Networking" type="Node"]
|
||||||
|
|
||||||
pause_mode = 2
|
pause_mode = 2
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
|
|
@ -0,0 +1,180 @@
|
||||||
|
extends Area2D
|
||||||
|
|
||||||
|
|
||||||
|
signal update_display # tells parent to update points display
|
||||||
|
signal refund # will tell parent a refund is occuring, for display
|
||||||
|
signal shooting_speed_upgrade # signals that a shooting speed upgrade has occured
|
||||||
|
signal ship_speed_upgrade
|
||||||
|
signal shooting_speed_fully_upgraded
|
||||||
|
signal ship_speed_fully_upgraded
|
||||||
|
signal restart_game
|
||||||
|
signal multiplayer_movement
|
||||||
|
|
||||||
|
export (PackedScene) var Laser
|
||||||
|
|
||||||
|
################################
|
||||||
|
#THINGS THAT MAY NEED ADJUSTING
|
||||||
|
#################################
|
||||||
|
#Default ship strengths and costs
|
||||||
|
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 SHOOTING_SPEED_UPGRADE_DEFAULT = 1500
|
||||||
|
const BULLET_DELAY_MINIMUM = 0.01
|
||||||
|
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
|
||||||
|
const SHIP_SPEED_UPGRADE_DEFAULT = 1500
|
||||||
|
const SHIP_SPEED_MAXIMUM = 1200
|
||||||
|
const SHIP_SPEED_TIER2_COST = 200
|
||||||
|
const SHIP_SPEED_TIER3_COST = 400
|
||||||
|
const SHIP_SPEED_TIER4_COST = 600
|
||||||
|
const SHIP_SPEED_TIER5_COST = 800
|
||||||
|
|
||||||
|
const STARTING_MONEY = 100
|
||||||
|
|
||||||
|
#################################
|
||||||
|
|
||||||
|
var screensize
|
||||||
|
|
||||||
|
var ship_speed = SHIP_SPEED_TIER1
|
||||||
|
var ship_speed_tier = 0
|
||||||
|
|
||||||
|
var bullet_delay = BULLET_DELAY_TIER1
|
||||||
|
var bullet_delay_tier = 0
|
||||||
|
var laser_penetration = 0
|
||||||
|
var double_laser = false
|
||||||
|
|
||||||
|
var ship_value = 0
|
||||||
|
var refund_percentage = 1
|
||||||
|
var money = STARTING_MONEY
|
||||||
|
|
||||||
|
var shooting_speed_upgrade = SHOOTING_SPEED_UPGRADE_DEFAULT
|
||||||
|
var ship_speed_upgrade = SHIP_SPEED_UPGRADE_DEFAULT
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
timer = Timer.new()
|
||||||
|
timer.set_one_shot(true)
|
||||||
|
timer.set_wait_time(bullet_delay)
|
||||||
|
timer.connect("timeout", self, "on_timeout_complete")
|
||||||
|
add_child(timer)
|
||||||
|
timer.start()
|
||||||
|
|
||||||
|
position.x = 100
|
||||||
|
position.y = 250
|
||||||
|
|
||||||
|
screensize = get_viewport_rect().size
|
||||||
|
$AnimatedSprite.play()
|
||||||
|
|
||||||
|
var timer = null
|
||||||
|
|
||||||
|
var can_shoot = false
|
||||||
|
var shoot_down = false
|
||||||
|
|
||||||
|
func on_timeout_complete():
|
||||||
|
can_shoot = true
|
||||||
|
|
||||||
|
#func _unhandled_input(event):
|
||||||
|
# if (event is InputEventScreenTouch):
|
||||||
|
# gravity_point = true
|
||||||
|
# gravity_vec = Vector2(0.5, 0.5)
|
||||||
|
|
||||||
|
var x_up = false
|
||||||
|
var y_up = false
|
||||||
|
var x_down = false
|
||||||
|
var y_down = false
|
||||||
|
|
||||||
|
func moveto(finger_position):
|
||||||
|
if (finger_position.x > position.x && finger_position.x < 800):
|
||||||
|
velocity.x += 1
|
||||||
|
x_up = true
|
||||||
|
if position.x > finger_position.x:
|
||||||
|
velocity.x -= 1
|
||||||
|
x_down = true
|
||||||
|
if (finger_position.y - 100 > position.y && finger_position.x < 800):
|
||||||
|
velocity.y += 1
|
||||||
|
y_up = true
|
||||||
|
if (position.y > finger_position.y - 100 && finger_position.x < 800):
|
||||||
|
velocity.y -= 1
|
||||||
|
y_down = true
|
||||||
|
# if (finger_position.x >= 800 && can_shoot):
|
||||||
|
# shoot()
|
||||||
|
if get_tree().has_network_peer():
|
||||||
|
rpc("move_player", get_tree().get_network_unique_id(), position)
|
||||||
|
|
||||||
|
remote func move_player(id, position):
|
||||||
|
prints("PLAYER SAYS:", id, position)
|
||||||
|
emit_signal("multiplayer_movement", id, position)
|
||||||
|
|
||||||
|
var velocity = Vector2() # the player's movement vector
|
||||||
|
|
||||||
|
func _process(delta):
|
||||||
|
velocity = Vector2()
|
||||||
|
if (Input.is_action_pressed("ui_right") || x_up):
|
||||||
|
velocity.x += 1
|
||||||
|
x_up = false
|
||||||
|
if (Input.is_action_pressed("ui_left") || x_down):
|
||||||
|
velocity.x -= 1
|
||||||
|
x_down = false
|
||||||
|
if (Input.is_action_pressed("ui_down") || y_up):
|
||||||
|
velocity.y += 1
|
||||||
|
y_up = false
|
||||||
|
if (Input.is_action_pressed("ui_up") || y_down):
|
||||||
|
velocity.y -= 1
|
||||||
|
y_down = false
|
||||||
|
if (velocity.length() > 0):
|
||||||
|
velocity = velocity.normalized() * ship_speed
|
||||||
|
|
||||||
|
position += velocity * delta
|
||||||
|
position.x = clamp(position.x, 0, screensize.x)
|
||||||
|
position.y = clamp(position.y, 0, screensize.y)
|
||||||
|
if get_tree().has_network_peer():
|
||||||
|
rpc("move_player", get_tree().get_network_unique_id(), position)
|
||||||
|
|
||||||
|
if ((Input.is_action_pressed("ui_accept") || shoot_down == true) && can_shoot == true):
|
||||||
|
shoot()
|
||||||
|
|
||||||
|
if (Input.is_action_pressed("ui_reset") && can_shoot == true):
|
||||||
|
upgradeMenu()
|
||||||
|
|
||||||
|
var x_up = false
|
||||||
|
var y_up = false
|
||||||
|
var x_down = false
|
||||||
|
var y_down = false
|
||||||
|
|
||||||
|
func _on_Player_body_entered(body):
|
||||||
|
prints("hit")
|
||||||
|
|
||||||
|
func shootDown():
|
||||||
|
shoot_down = true
|
||||||
|
func shootUp():
|
||||||
|
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()
|
|
@ -0,0 +1,171 @@
|
||||||
|
[gd_scene load_steps=7 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://Laser.tscn" type="PackedScene" id=1]
|
||||||
|
[ext_resource path="res://art/player/Rocket1.png" type="Texture" id=2]
|
||||||
|
[ext_resource path="res://art/player/Rocket2.png" type="Texture" id=3]
|
||||||
|
|
||||||
|
[sub_resource type="GDScript" id=3]
|
||||||
|
|
||||||
|
script/source = "extends Area2D
|
||||||
|
|
||||||
|
|
||||||
|
signal update_display # tells parent to update points display
|
||||||
|
signal refund # will tell parent a refund is occuring, for display
|
||||||
|
signal shooting_speed_upgrade # signals that a shooting speed upgrade has occured
|
||||||
|
signal ship_speed_upgrade
|
||||||
|
signal shooting_speed_fully_upgraded
|
||||||
|
signal ship_speed_fully_upgraded
|
||||||
|
signal restart_game
|
||||||
|
signal multiplayer_movement
|
||||||
|
|
||||||
|
export (PackedScene) var Laser
|
||||||
|
|
||||||
|
################################
|
||||||
|
#THINGS THAT MAY NEED ADJUSTING
|
||||||
|
#################################
|
||||||
|
#Default ship strengths and costs
|
||||||
|
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 SHOOTING_SPEED_UPGRADE_DEFAULT = 1500
|
||||||
|
const BULLET_DELAY_MINIMUM = 0.01
|
||||||
|
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
|
||||||
|
const SHIP_SPEED_UPGRADE_DEFAULT = 1500
|
||||||
|
const SHIP_SPEED_MAXIMUM = 1200
|
||||||
|
const SHIP_SPEED_TIER2_COST = 200
|
||||||
|
const SHIP_SPEED_TIER3_COST = 400
|
||||||
|
const SHIP_SPEED_TIER4_COST = 600
|
||||||
|
const SHIP_SPEED_TIER5_COST = 800
|
||||||
|
|
||||||
|
const STARTING_MONEY = 100
|
||||||
|
|
||||||
|
#################################
|
||||||
|
|
||||||
|
var screensize
|
||||||
|
|
||||||
|
var ship_speed = SHIP_SPEED_TIER1
|
||||||
|
var ship_speed_tier = 0
|
||||||
|
|
||||||
|
var bullet_delay = BULLET_DELAY_TIER1
|
||||||
|
var bullet_delay_tier = 0
|
||||||
|
var laser_penetration = 0
|
||||||
|
var double_laser = false
|
||||||
|
|
||||||
|
var ship_value = 0
|
||||||
|
var refund_percentage = 1
|
||||||
|
var money = STARTING_MONEY
|
||||||
|
|
||||||
|
var shooting_speed_upgrade = SHOOTING_SPEED_UPGRADE_DEFAULT
|
||||||
|
var ship_speed_upgrade = SHIP_SPEED_UPGRADE_DEFAULT
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
timer = Timer.new()
|
||||||
|
timer.set_one_shot(true)
|
||||||
|
timer.set_wait_time(bullet_delay)
|
||||||
|
timer.connect(\"timeout\", self, \"on_timeout_complete\")
|
||||||
|
add_child(timer)
|
||||||
|
timer.start()
|
||||||
|
|
||||||
|
position.x = 100
|
||||||
|
position.y = 250
|
||||||
|
|
||||||
|
screensize = get_viewport_rect().size
|
||||||
|
$AnimatedSprite.play()
|
||||||
|
|
||||||
|
var timer = null
|
||||||
|
|
||||||
|
var can_shoot = false
|
||||||
|
var shoot_down = false
|
||||||
|
|
||||||
|
func on_timeout_complete():
|
||||||
|
can_shoot = true
|
||||||
|
|
||||||
|
#func _unhandled_input(event):
|
||||||
|
# if (event is InputEventScreenTouch):
|
||||||
|
# gravity_point = true
|
||||||
|
# gravity_vec = Vector2(0.5, 0.5)
|
||||||
|
|
||||||
|
var x_up = false
|
||||||
|
var y_up = false
|
||||||
|
var x_down = false
|
||||||
|
var y_down = false
|
||||||
|
|
||||||
|
func _process(delta):
|
||||||
|
pass
|
||||||
|
|
||||||
|
func shoot():
|
||||||
|
if can_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()"
|
||||||
|
_sections_unfolded = [ "Resource" ]
|
||||||
|
|
||||||
|
[sub_resource type="SpriteFrames" id=1]
|
||||||
|
|
||||||
|
animations = [ {
|
||||||
|
"frames": [ ExtResource( 2 ), ExtResource( 3 ) ],
|
||||||
|
"loop": true,
|
||||||
|
"name": "default",
|
||||||
|
"speed": 15.0
|
||||||
|
} ]
|
||||||
|
|
||||||
|
[sub_resource type="CapsuleShape2D" id=2]
|
||||||
|
|
||||||
|
custom_solver_bias = 0.0
|
||||||
|
radius = 12.8998
|
||||||
|
height = 40.4125
|
||||||
|
|
||||||
|
[node name="OtherPlayer" type="Area2D"]
|
||||||
|
|
||||||
|
input_pickable = true
|
||||||
|
gravity_point = true
|
||||||
|
gravity_vec = Vector2( 10, 10 )
|
||||||
|
gravity = 1000.0
|
||||||
|
linear_damp = 0.1
|
||||||
|
angular_damp = 1.0
|
||||||
|
collision_layer = 29
|
||||||
|
collision_mask = 29
|
||||||
|
audio_bus_override = false
|
||||||
|
audio_bus_name = "Master"
|
||||||
|
script = SubResource( 3 )
|
||||||
|
Laser = ExtResource( 1 )
|
||||||
|
|
||||||
|
[node name="AnimatedSprite" type="AnimatedSprite" parent="." index="0"]
|
||||||
|
|
||||||
|
position = Vector2( 1.01175, 7.07602 )
|
||||||
|
scale = Vector2( 0.2, 0.2 )
|
||||||
|
frames = SubResource( 1 )
|
||||||
|
animation = "default"
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="." index="1"]
|
||||||
|
|
||||||
|
position = Vector2( 45.5518, -3.09424 )
|
||||||
|
shape = SubResource( 2 )
|
||||||
|
|
||||||
|
|
57
Player.gd
57
Player.gd
|
@ -8,6 +8,7 @@ signal ship_speed_upgrade
|
||||||
signal shooting_speed_fully_upgraded
|
signal shooting_speed_fully_upgraded
|
||||||
signal ship_speed_fully_upgraded
|
signal ship_speed_fully_upgraded
|
||||||
signal restart_game
|
signal restart_game
|
||||||
|
signal multiplayer_movement
|
||||||
|
|
||||||
export (PackedScene) var Laser
|
export (PackedScene) var Laser
|
||||||
|
|
||||||
|
@ -187,6 +188,8 @@ var y_up = false
|
||||||
var x_down = false
|
var x_down = false
|
||||||
var y_down = false
|
var y_down = false
|
||||||
|
|
||||||
|
var is_shooting
|
||||||
|
|
||||||
func moveto(finger_position):
|
func moveto(finger_position):
|
||||||
if (finger_position.x > position.x && finger_position.x < 800):
|
if (finger_position.x > position.x && finger_position.x < 800):
|
||||||
velocity.x += 1
|
velocity.x += 1
|
||||||
|
@ -202,12 +205,11 @@ func moveto(finger_position):
|
||||||
y_down = true
|
y_down = true
|
||||||
# if (finger_position.x >= 800 && can_shoot):
|
# if (finger_position.x >= 800 && can_shoot):
|
||||||
# shoot()
|
# shoot()
|
||||||
if get_tree().has_network_peer():
|
# if get_tree().has_network_peer():
|
||||||
rpc("move_player", get_tree().get_network_unique_id(), position)
|
# rpc("move_player", get_tree().get_network_unique_id(), position, ~can_shoot)
|
||||||
|
|
||||||
#remote func move_player(id, position):
|
remote func move_player(id, position, is_shooting):
|
||||||
# prints("PLAYER SAYS:", id, position)
|
emit_signal("multiplayer_movement", id, position, is_shooting)
|
||||||
# pass
|
|
||||||
|
|
||||||
var velocity = Vector2() # the player's movement vector
|
var velocity = Vector2() # the player's movement vector
|
||||||
|
|
||||||
|
@ -231,8 +233,14 @@ func _process(delta):
|
||||||
position += velocity * delta
|
position += velocity * delta
|
||||||
position.x = clamp(position.x, 0, screensize.x)
|
position.x = clamp(position.x, 0, screensize.x)
|
||||||
position.y = clamp(position.y, 0, screensize.y)
|
position.y = clamp(position.y, 0, screensize.y)
|
||||||
|
|
||||||
|
if can_shoot:
|
||||||
|
is_shooting = false
|
||||||
|
else:
|
||||||
|
is_shooting = true
|
||||||
|
|
||||||
if get_tree().has_network_peer():
|
if get_tree().has_network_peer():
|
||||||
rpc("move_player", get_tree().get_network_unique_id(), position)
|
rpc("move_player", get_tree().get_network_unique_id(), position, is_shooting)
|
||||||
|
|
||||||
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):
|
||||||
shoot()
|
shoot()
|
||||||
|
@ -254,25 +262,26 @@ func shootUp():
|
||||||
shoot_down = false
|
shoot_down = false
|
||||||
|
|
||||||
func shoot():
|
func shoot():
|
||||||
var laser = Laser.instance()
|
if can_shoot:
|
||||||
get_node("../").add_child(laser)
|
var laser = Laser.instance()
|
||||||
laser.current_pen = laser_penetration
|
get_node("../").add_child(laser)
|
||||||
laser.position.y = position.y - 27
|
laser.current_pen = laser_penetration
|
||||||
laser.position.x = position.x + 46
|
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
|
|
||||||
|
|
||||||
|
#MAYBE THE LASERS SHOULD BE THEIR OWN NODES
|
||||||
can_shoot = false
|
#Would allow for more simple additions in the future
|
||||||
timer.start()
|
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()
|
||||||
|
|
||||||
func gameOver():
|
func gameOver():
|
||||||
var gameover = preload("res://GameOver.tscn").instance()
|
var gameover = preload("res://GameOver.tscn").instance()
|
||||||
add_child(gameover)
|
add_child(gameover)
|
||||||
|
|
|
@ -20,7 +20,7 @@ custom_solver_bias = 0.0
|
||||||
radius = 12.8998
|
radius = 12.8998
|
||||||
height = 40.4125
|
height = 40.4125
|
||||||
|
|
||||||
[node name="Player" type="Area2D"]
|
[node name="Player" type="Area2D" index="0"]
|
||||||
|
|
||||||
input_pickable = true
|
input_pickable = true
|
||||||
gravity_point = true
|
gravity_point = true
|
||||||
|
|
Loading…
Reference in New Issue