2025-05-14 13:30:27 +10:00
|
|
|
extends Control
|
|
|
|
|
|
|
|
|
|
enum Gamemode{
|
|
|
|
|
Story,
|
|
|
|
|
Endless
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#mode settings
|
2025-05-16 15:56:55 +10:00
|
|
|
|
2025-05-16 22:13:34 +10:00
|
|
|
signal game_over(score : int)
|
|
|
|
|
|
2025-05-14 13:30:27 +10:00
|
|
|
@export var max_lives = 3
|
2025-05-18 10:32:25 +10:00
|
|
|
@export var lives = 3 #debug
|
2025-05-14 13:30:27 +10:00
|
|
|
@export var platformer_game : PackedScene
|
|
|
|
|
@export var games : Array[PackedScene]
|
2025-05-15 15:28:16 +10:00
|
|
|
@export var zoom_speed : float = 0.5
|
2025-05-16 15:56:55 +10:00
|
|
|
@export_group("Channel Rules")
|
2025-05-17 17:26:28 +10:00
|
|
|
@export var target_channels : float = 1
|
|
|
|
|
@export var channel_growth_per_min : float = 0.8
|
2025-05-16 15:56:55 +10:00
|
|
|
|
2025-05-14 13:30:27 +10:00
|
|
|
@export_group("Node References")
|
|
|
|
|
@export var main_camera : Camera2D
|
|
|
|
|
@export var outer_channels : Array[Channel]
|
|
|
|
|
@export var main_channel : Channel
|
2025-05-17 16:24:38 +10:00
|
|
|
@export var game_over_screen : CanvasLayer
|
|
|
|
|
@export var game_over_score : Label
|
|
|
|
|
|
2025-05-14 13:30:27 +10:00
|
|
|
var gamemode : Gamemode = Gamemode.Story #will be set by manager/menu option
|
2025-05-15 14:35:32 +10:00
|
|
|
var zooming_out : bool = false
|
2025-05-16 15:56:55 +10:00
|
|
|
var gameplay : bool = false # becomes true when the game starts
|
2025-05-16 22:13:34 +10:00
|
|
|
var score : int = 0
|
2025-05-14 13:30:27 +10:00
|
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
|
func _ready() -> void:
|
2025-05-15 14:35:32 +10:00
|
|
|
GameManager.zoom_out_signal.connect(zoom_out)
|
2025-05-16 01:29:12 +10:00
|
|
|
GameManager.prepare.connect(get_ready)
|
2025-05-16 15:56:55 +10:00
|
|
|
GameManager.gaming.connect(start_game)
|
2025-05-16 22:13:34 +10:00
|
|
|
GameManager.channel_win.connect(rec_channel_win)
|
|
|
|
|
GameManager.channel_lose.connect(rec_channel_lose)
|
2025-05-14 13:30:27 +10:00
|
|
|
if(gamemode == Gamemode.Story):
|
2025-05-17 14:21:38 +10:00
|
|
|
|
2025-05-14 13:30:27 +10:00
|
|
|
main_camera.zoom = Vector2(3.1,3.1)
|
2025-05-16 15:56:55 +10:00
|
|
|
main_channel.start_specific_channel(platformer_game)
|
2025-05-16 22:13:34 +10:00
|
|
|
if(GameManager.are_we_skipping_intro):
|
2025-05-17 14:21:38 +10:00
|
|
|
zooming_out = true
|
2025-05-16 22:13:34 +10:00
|
|
|
main_camera.zoom = Vector2(1,1)
|
|
|
|
|
GameManager.skip_intro.emit()
|
2025-05-14 13:30:27 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
|
func _process(delta: float) -> void:
|
2025-05-15 14:35:32 +10:00
|
|
|
#if(Input.is_action_just_pressed("ui_down")):
|
2025-05-17 13:05:08 +10:00
|
|
|
#main_channel.start_channel() #so this works
|
2025-05-15 14:35:32 +10:00
|
|
|
if(zooming_out):
|
2025-05-17 14:21:38 +10:00
|
|
|
var zoom_amount : float = clampf(main_camera.zoom.x - delta * zoom_speed,1, 3.1 ) #was 4?
|
|
|
|
|
main_camera.zoom = Vector2(zoom_amount,zoom_amount)
|
|
|
|
|
else:
|
|
|
|
|
var zoom_amount : float = clampf(main_camera.zoom.x + delta * zoom_speed,1, 3.1 ) #was 4?
|
2025-05-15 14:35:32 +10:00
|
|
|
main_camera.zoom = Vector2(zoom_amount,zoom_amount)
|
2025-05-16 15:56:55 +10:00
|
|
|
if(gameplay):
|
|
|
|
|
game_loop(delta)
|
2025-05-15 14:35:32 +10:00
|
|
|
|
|
|
|
|
func zoom_out():
|
|
|
|
|
zooming_out = true
|
2025-05-16 01:29:12 +10:00
|
|
|
|
2025-05-17 14:21:38 +10:00
|
|
|
func zoom_in():
|
|
|
|
|
zooming_out = false
|
|
|
|
|
|
2025-05-16 01:29:12 +10:00
|
|
|
func get_ready():
|
|
|
|
|
for channel in outer_channels:
|
|
|
|
|
channel.channel_mode = channel.Mode.Static
|
2025-05-16 15:56:55 +10:00
|
|
|
|
|
|
|
|
func start_game():
|
|
|
|
|
gameplay = true
|
2025-05-16 22:57:02 +10:00
|
|
|
main_channel.start_channel()
|
2025-05-16 15:56:55 +10:00
|
|
|
|
|
|
|
|
func game_loop(delta : float):
|
|
|
|
|
target_channels += channel_growth_per_min * (delta/60)
|
|
|
|
|
var online_channels : Array[Channel]
|
|
|
|
|
var offline_channels : Array[Channel]
|
|
|
|
|
# sort all the channels into online and offline
|
2025-05-17 13:05:08 +10:00
|
|
|
#if main_channel.channel_mode == Channel.Mode.Online:
|
|
|
|
|
if main_channel.platformer_online:
|
2025-05-16 15:56:55 +10:00
|
|
|
online_channels.append(main_channel)
|
|
|
|
|
else:
|
2025-05-17 13:05:08 +10:00
|
|
|
offline_channels.append(main_channel)
|
2025-05-16 15:56:55 +10:00
|
|
|
for channel in outer_channels:
|
|
|
|
|
if(channel.channel_mode == Channel.Mode.Online):
|
|
|
|
|
online_channels.append(channel)
|
2025-05-16 23:16:29 +10:00
|
|
|
elif(!channel.dead_channel):
|
2025-05-16 15:56:55 +10:00
|
|
|
offline_channels.append(channel)
|
|
|
|
|
# if i need to switch a channel online, then pick one and run tis start channel method
|
2025-05-16 22:13:34 +10:00
|
|
|
#print("Online Channels: " + str(online_channels.size()))
|
2025-05-16 15:56:55 +10:00
|
|
|
if(online_channels.size() < target_channels and offline_channels.size() > 0):
|
|
|
|
|
var random_channel_number = randi_range(0, offline_channels.size()-1)
|
2025-05-16 22:13:34 +10:00
|
|
|
var random_game = randi_range(0, games.size()-1)
|
2025-05-17 13:05:08 +10:00
|
|
|
offline_channels[random_channel_number].start_channel()
|
|
|
|
|
#if(offline_channels[random_channel_number] != main_channel):
|
|
|
|
|
#offline_channels[random_channel_number].start_channel()
|
2025-05-16 23:16:29 +10:00
|
|
|
#picking a random game is cool but we cant have two of the same!
|
|
|
|
|
#offline_channels[random_channel_number].start_specific_channel(games[random_game])
|
2025-05-17 13:05:08 +10:00
|
|
|
#else:
|
|
|
|
|
#main_channel.start_channel()
|
2025-05-16 22:13:34 +10:00
|
|
|
|
|
|
|
|
func rec_channel_win():
|
|
|
|
|
score += 1
|
|
|
|
|
GameManager.send_update_data(score, lives)
|
|
|
|
|
|
|
|
|
|
func rec_channel_lose():
|
|
|
|
|
lives -= 1
|
|
|
|
|
GameManager.send_update_data(score, lives)
|
|
|
|
|
if(lives <= 0):
|
2025-05-17 14:21:38 +10:00
|
|
|
game_over_gg()
|
|
|
|
|
|
|
|
|
|
func game_over_gg():
|
|
|
|
|
zoom_in()
|
2025-05-17 16:24:38 +10:00
|
|
|
GameManager.send_game_over()
|
2025-05-23 21:36:52 +10:00
|
|
|
if gameplay:
|
|
|
|
|
game_over_score.text = str(score)
|
2025-05-17 14:21:38 +10:00
|
|
|
gameplay = false
|
|
|
|
|
main_channel.end_channel()
|
|
|
|
|
for channel in outer_channels:
|
|
|
|
|
channel.make_offline()
|
2025-05-17 16:24:38 +10:00
|
|
|
game_over_screen.show()
|
2025-05-23 21:36:52 +10:00
|
|
|
|
2025-05-17 16:24:38 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_play_again_button_pressed() -> void:
|
|
|
|
|
GameManager.are_we_skipping_intro = true
|
|
|
|
|
get_tree().change_scene_to_file("res://game_scene.tscn")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_return_to_menu_pressed() -> void:
|
|
|
|
|
get_tree().change_scene_to_file("res://menu/menu.tscn")
|