The beginning of public history

This commit is contained in:
2019-09-16 02:07:41 -04:00
commit 64a2ffbc89
1104 changed files with 7534 additions and 0 deletions

41
Scripts/BaddieManager.gd Normal file
View File

@ -0,0 +1,41 @@
extends Node2D
export var HP = 8
export var color = "ffff00"
func _ready():
pass
func take_damage(dmg):
playAudio("Bomb_Drop.wav")
modulate = Color(255,0,0)
$KinematicBody2D/Light2D.color = Color(255,0,0)
HP -= dmg
reset_color()
var color_timer
func reset_color():
if !color_timer:
color_timer = Timer.new()
add_child(color_timer)
color_timer.connect("timeout", self, "color_timeout")
color_timer.start(0.125)
func color_timeout():
modulate = Color(color)
$KinematicBody2D/Light2D.color = Color(color)
func _process(delta):
if(HP <= 0):
queue_free()
var audioPlayer
func playAudio(track):
if !audioPlayer:
audioPlayer = AudioStreamPlayer.new()
get_parent().add_child(audioPlayer)
audioPlayer.stream = load("res://Sound/" + track)
audioPlayer.volume_db = -30
audioPlayer.play()

271
Scripts/Console.gd Normal file
View File

@ -0,0 +1,271 @@
extends Control
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
const CHANGE_TIME = 0.0125
const ACTION_TIME = 0.25
var actionTimer
var changeChar
var queuedAction
var charCount = 0
var visableChars = 0
var tempValue = ""
const MAIN_MENU = ['Next Level', 'Upgrades', 'Main Menu']
const ALL_EQUIPMENT = {
#"pistol" : 4,
#"smg" : 8
}
const BASE_UNLOCK = {
#"stealth" : 1000,
"jump" : 1
}
func _ready():
actionTimer = Timer.new()
actionTimer.connect("timeout", self, "RunQueuedAction")
add_child(actionTimer)
$Display.text = $Display.text + "\nGood job Unit " + String(SaveManager.get_run()) + "!"
addLine("\nAwaiting input...")
changeChar = CHANGE_TIME
$Display.visible_characters = 18
visableChars = 18
updateCharCount()
GenerateInputs(MAIN_MENU)
pass # Replace with function body.
func GenerateInputs(options):
for child in $Buttons.get_children():
child.queue_free()
for option in options:
var button = Button.new()
button.text = " [" + option + "] "
button.connect("button_down", self, "ButtonInput", [option])
$Buttons.add_child(button)
func ButtonInput(input):
if input == "Main Menu":
addLine("gis exit\nExiting environment...")
if !queuedAction:
queuedAction = input
elif input == "Next Level":
addLine("gis run unit " + String(SaveManager.get_run()))
if !queuedAction:
queuedAction = input
elif input == "Upgrades":
addLine("gis config unit " + String(SaveManager.get_run()))
if !queuedAction:
queuedAction = input
elif input == "Back":
addLine("X")
if !queuedAction:
queuedAction = input
elif input == "Equipment":
addLine("2")
if !queuedAction:
queuedAction = input
elif input == "Abilities":
addLine("1")
if !queuedAction:
queuedAction = input
elif input.to_lower() in SaveManager.get_equipment():
addLine("gis access equipment " + input.to_lower())
if !queuedAction:
queuedAction = input
elif input.to_lower() in SaveManager.get_actions():
addLine("gis access upgrade " + input.to_lower())
if !queuedAction:
queuedAction = input
elif input == "Equip":
addLine("1")
if !queuedAction:
queuedAction = input
elif input == "Upgrade":
addLine("1")
if !queuedAction:
queuedAction = input
elif input == "Unequip":
addLine("1")
if !queuedAction:
queuedAction = input
elif input == "Buy Equipment":
addLine("3")
if !queuedAction:
queuedAction = input
elif input.to_lower() in ALL_EQUIPMENT:
addLine("gis equipment purchase " + input.to_lower())
if !queuedAction:
queuedAction = input
else:
addLine("Error 404! Command `button:" + input + "` not found!")
func capFirst(inputVal):
return inputVal.capitalize()[0] + inputVal.substr(1, len(inputVal))
func RunQueuedAction():
if queuedAction == "Main Menu":
get_tree().change_scene("res://Nodes/Title.tscn")
elif queuedAction == "Next Level":
get_tree().change_scene("res://Nodes/Game.tscn")
elif queuedAction == "Upgrades":
clearConsole()
addLine("Upgrade Chips: " + String(SaveManager.get_upgrade_points()) + "\n\n")
addLine("Select upgrade category:")
addLine("1. Abilities")
addLine("2. Equipment")
addLine("3. Buy Equipment")
addLine("\nX. Back")
GenerateInputs(['Abilities', 'Equipment', 'Buy Equipment', 'Back'])
elif queuedAction == "Buy Equipment":
clearConsole()
addLine("Upgrade Chips: " + String(SaveManager.get_upgrade_points()) + "\n\n")
addLine("Equipment:")
var i = 1
var tempInputs = []
for equipment in ALL_EQUIPMENT:
if !(equipment in SaveManager.get_equipment()):
tempInputs.append(capFirst(equipment))
addLine(String(i) + ". " + capFirst(equipment) + " (COST " + String(ALL_EQUIPMENT[equipment]) + ")")
i += 1
GenerateInputs(tempInputs + ['Upgrades'])
elif queuedAction == "Back":
GenerateInputs(MAIN_MENU)
clearConsole()
elif queuedAction == "Equipment":
clearConsole()
addLine("Upgrade Chips: " + String(SaveManager.get_upgrade_points()) + "\n\n")
addLine("Equipment:")
var i = 1
var tempInputs = []
for equip in SaveManager.get_equipment():
var suffix = ""
if equip == SaveManager.get_equiped():
suffix = " (EQUIPED)"
addLine(String(i) + ". " + equip.capitalize()[0] + equip.substr(1, len(equip)) + suffix)
tempInputs.append(equip.capitalize()[0] + equip.substr(1, len(equip)))
i += 1
addLine('\nX. Back')
GenerateInputs(tempInputs + ["Upgrades"])
elif queuedAction == "Abilities":
clearConsole()
addLine("Upgrade Chips: " + String(SaveManager.get_upgrade_points()) + "\n\n")
addLine("Abilities:")
var i = 1
var tempInputs = []
for action in SaveManager.get_actions():
addLine(String(i) + ". " + action.capitalize()[0] + action.substr(1, len(action)))
tempInputs.append(action.capitalize()[0] + action.substr(1, len(action)))
i += 1
addLine('\nX. Back')
GenerateInputs(tempInputs + ["Upgrades"])
elif queuedAction.to_lower() in SaveManager.get_equipment():
clearConsole()
addLine("Equipment: " + queuedAction)
addLine("")
var tempInputs = []
if(queuedAction.to_lower() == SaveManager.get_equiped()):
tempInputs.append("Unequip")
addLine("1. Unequip")
else:
tempInputs.append("Equip")
addLine("1. Equip")
addLine("\nX. Back")
tempValue = queuedAction.to_lower()
GenerateInputs(tempInputs + ["Equipment"])
elif queuedAction.to_lower() in SaveManager.get_actions():
clearConsole()
addLine("Upgrade Chips: " + String(SaveManager.get_upgrade_points()) + "\n\n")
addLine("Ability: " + queuedAction)
addLine("Level: " + String(SaveManager.get_action_value(queuedAction.to_lower())))
addLine("")
var pointsToUpgrade = 1 * int(SaveManager.get_action_value(queuedAction.to_lower()))
if queuedAction.to_lower() in BASE_UNLOCK:
pointsToUpgrade += BASE_UNLOCK[queuedAction.to_lower()]
var tempInputs = []
tempInputs.append("Upgrade")
addLine("1. Upgrade (" + String(pointsToUpgrade) + " Points)")
addLine("\nX. Back")
tempValue = queuedAction.to_lower()
GenerateInputs(tempInputs + ["Abilities"])
elif queuedAction == "Equip":
SaveManager.set_equiped(tempValue)
addLine("\nEquiped: " + tempValue.capitalize()[0] + tempValue.substr(1, len(tempValue)))
queuedAction = "Equipment"
actionTimer.stop()
return
elif queuedAction == "Upgrade":
var UPGRADE_COST = 1 * int(SaveManager.get_action_value(tempValue.to_lower()))
if tempValue.to_lower() in BASE_UNLOCK:
UPGRADE_COST += BASE_UNLOCK[tempValue.to_lower()]
if (SaveManager.get_upgrade_points() >= UPGRADE_COST):
SaveManager.change_upgrade_points(-1 * UPGRADE_COST)
SaveManager.set_action_value(tempValue, SaveManager.get_action_value(tempValue) + 1)
addLine("\nUpgraded: " + tempValue.capitalize()[0] + tempValue.substr(1, len(tempValue)))
else:
addLine("\nNot enough upgrade chips!")
queuedAction = tempValue
actionTimer.stop()
return
elif queuedAction == "Unequip":
SaveManager.set_equiped("none")
addLine("\nUnequiped: " + tempValue.capitalize()[0] + tempValue.substr(1, len(tempValue)))
queuedAction = "Equipment"
actionTimer.stop()
return
elif queuedAction.to_lower() in ALL_EQUIPMENT:
var cost = ALL_EQUIPMENT[queuedAction.to_lower()]
if (SaveManager.get_upgrade_points() >= cost):
SaveManager.change_upgrade_points(-1 * cost)
addLine("Purchased: " + queuedAction)
SaveManager.unlock_equipment(queuedAction.to_lower())
else:
addLine("\nNot enough upgrade chips!")
queuedAction = "Buy Equipment"
return
else:
addLine("Error 404! Command `action:" + queuedAction + "` not found!")
queuedAction = null
addLine("\nAwaiting input...")
actionTimer.stop()
func _process(delta):
if(visableChars < charCount):
if(changeChar <= 0):
visableChars += 4
$Display.visible_characters = visableChars
changeChar = CHANGE_TIME
else:
changeChar -= delta
else:
changeChar = CHANGE_TIME
if queuedAction && actionTimer.is_stopped():
actionTimer.start(ACTION_TIME)
func addLine(line):
$Display.text = $Display.text + "\n" + line
updateCharCount()
func clearConsole():
$Display.visible_characters = 0
$Display.text = ""
visableChars = 0
updateCharCount()
func updateCharCount():
charCount = $Display.get_total_character_count()

View File

@ -0,0 +1,90 @@
extends Node2D
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
const DASH_SPEED = 300
const UP = Vector2(0, -1)
const RADperDEGREE = 57.2957795
const SLASH_ANIMATION = preload("res://Nodes/Animations/SlashAnimation.tscn")
var player
var colliderShape
func _ready():
colliderShape = $AnimatedSprite/Area2D/CollisionShape2D.get_shape()
get_child(0).get_child(0).hide()
player = get_parent().get_parent()
player.connect("unequip", self, "on_unequip")
$AnimatedSprite.connect("animation_finished", self, "on_animation_finished")
$AnimatedSprite/Area2D.connect("body_entered", self, "on_collide")
$AnimatedSprite.play("Spawn")
pass # Replace with function body.
var audioPlayer
func playAudio(track):
if !audioPlayer:
audioPlayer = AudioStreamPlayer.new()
self.add_child(audioPlayer)
audioPlayer.stream = load("res://Sound/" + track)
audioPlayer.volume_db = -30
audioPlayer.play()
func on_unequip():
$AnimatedSprite.play("Spawn", true)
func on_collide(body):
if(body.has_method("take_damage")):
print(body)
if($AnimatedSprite.animation == "Attack"):
print("ATTACK")
body.take_damage(1)
pass
var pos
func _physics_process(delta):
$AnimatedSprite.flip_h = get_global_mouse_position().x < global_position.x
if(get_global_mouse_position().x < global_position.x):
$AnimatedSprite/Area2D.rotation = PI
else:
$AnimatedSprite/Area2D.rotation = 0
if($AnimatedSprite.animation == "Attack"):
$AnimatedSprite/Area2D/CollisionShape2D.shape = colliderShape
else:
$AnimatedSprite/Area2D/CollisionShape2D.shape = null
if($AnimatedSprite.animation != "Spawn"):
if(Input.is_action_just_pressed("attack")):
if($AnimatedSprite.animation != "Attack"):
playAudio("Charge2.wav")
get_child(0).get_child(0).show()
$AnimatedSprite.play("Attack")
pos = player.global_position - get_global_mouse_position()
var angle = atan(pos.y/pos.x)
var goUp = -1
var goRight = -1
if(pos.y < 0):
goUp = 1
if(pos.x < 0):
goRight = 1
var xVar = cos(abs(angle)) * DASH_SPEED * goRight
var yVar = sin(abs(angle)) * DASH_SPEED
yVar = (yVar) * goUp - 20
pos = Vector2(xVar, yVar)
if($AnimatedSprite.animation == "Attack"):
player.move_and_slide(pos, UP)
func on_animation_finished():
if($AnimatedSprite.animation != "idle"):
get_child(0).get_child(0).hide()
$AnimatedSprite.play("idle")

14
Scripts/Exit.gd Normal file
View File

@ -0,0 +1,14 @@
extends Node2D
func _ready():
$Area2D.connect("body_entered", self, "on_collide")
func on_collide(body):
if body.has_method("victoryCondition"):
MusicPlayer.stop()
MusicPlayer.stream = load("res://Music/DOS-88/Smooth Sailing.ogg")
MusicPlayer.volume_db = 0
MusicPlayer.play()
body.victoryCondition()

64
Scripts/MangeIntro.gd Normal file
View File

@ -0,0 +1,64 @@
extends Label
#Hide all charafcters on start
func _ready():
show_text(2)
visible_characters = 0
var timePassed = 0 #Current amount of time spend displaying te
const CHECK_LENGTH = 0.05 #Interval to check for updates
var timeNeeded = 0 #Time that it takes to display the text
var timer #Timer object
var fadeTimer #Timer object
func show_text(seconds):
timeNeeded = seconds
timePassed = 0
if(!timer):
timer = Timer.new()
add_child(timer)
timer.connect("timeout", self, "on_timeout")
timer.start(CHECK_LENGTH)
func fade_text(seconds):
timeNeeded = seconds
timePassed = 0
if(!fadeTimer):
fadeTimer = Timer.new()
add_child(fadeTimer)
fadeTimer.connect("timeout", self, "on_fade_timeout")
fadeTimer.start(CHECK_LENGTH)
func on_fade_timeout():
timePassed += CHECK_LENGTH
modulate.a = 1 - (timePassed/timeNeeded)
if(timePassed >= timeNeeded):
fadeTimer.stop()
checkIfDone()
else:
fadeTimer.start(CHECK_LENGTH)
pass
var done = false
func checkIfDone():
if(done):
fadeTimer.queue_free()
timer.queue_free()
get_tree().change_scene("res://Nodes/Title.tscn")
else:
visible_characters = 0
modulate.a = 1
text = "Welcome Unit " + String($"/root/SaveManager".get_run() + 1) + "."
done = true
show_text(3)
func on_timeout():
timePassed += CHECK_LENGTH
visible_characters = (timePassed/timeNeeded) * get_total_character_count()
if(timePassed >= timeNeeded):
timer.stop()
fade_text(2)
else:
timer.start(CHECK_LENGTH)
pass

292
Scripts/MapGeneration.gd Normal file
View File

@ -0,0 +1,292 @@
extends Node
export var mapSize = 128
var playerSpawn = Vector2()
var PLAYER_OBJ = preload("res://Nodes/Player.tscn")
const PATH_SIZE = 2
func _ready():
MusicPlayer.stop()
MusicPlayer.stream = load("res://Music/DOS-88/Checking Manifest.ogg")
MusicPlayer.volume_db = 0
MusicPlayer.play()
UpdateProgress("Loading generation libraries...")
randomize()
func UpdateProgress(message):
print(message)
$LoadingScreen.get_child(2).text = message
func setTile(x,y, value):
var tileValue = -1
if(value == "block"):
tileValue = 0
elif(value == "safe_block"):
tileValue = 2
elif(value == "player"):
playerSpawn = Vector2(x,y)
elif(value == "ladder"):
tileValue = 1
elif(value == "light"):
createObject(x,y, "res://Nodes/Light.tscn")
elif(value == "coin"):
createObject(x,y, "res://Nodes/Pickup.tscn")
elif(value == "enemy"):
createObject(x,y, "res://Nodes/Enemies/Basic.tscn")
elif(value == "exit"):
createObject(x,y, "res://Nodes/Exit.tscn")
$TileMap.set_cell(x, y, tileValue)
func createObject(x,y,objectPath):
var obj = load(objectPath).instance()
add_child(obj)
var pos = $TileMap.map_to_world(Vector2(x,y))
obj.position = Vector2(pos.x + 8, pos.y + 8)
func generateStructure(x,y, structure):
var symbolDictionary = {
"x" : "safe_block",
"p" : "player",
"l" : "ladder",
"c" : "coin",
"e" : "enemy",
"#" : "exit",
"?": "light"
}
var largestX = 0
var largestY = structure.size()
for structY in range(0, structure.size()):
for structX in range(0, structure[structY].size()):
if structX > largestX:
largestX = structX
var symbol = structure[structY][structX]
setTile(x + structX, y + structY, symbolDictionary.get(symbol))
var rect = Rect2(Vector2(x-1,y-1),Vector2(largestX+1,largestY+1))
return rect
func fillMap(value="block"):
for x in range(0, mapSize):
for y in range(0, mapSize):
setTile(x,y,value)
func spawnPlayer():
var tempVector = Vector2(playerSpawn.x * $TileMap.cell_size.x, playerSpawn.y * $TileMap.cell_size.y)
var player = PLAYER_OBJ.instance()
add_child(player)
player.position = tempVector
player.get_child(0).current = true
var welcome = load("res://Nodes/PlayerGreetings.tscn").instance()
add_child(welcome)
welcome.position = Vector2(tempVector.x - 16, tempVector.y - 16)
$TileMap.set_cell(playerSpawn.x, playerSpawn.y, -1)
$LoadingScreen.hideSelf()
var rooms = Array()
func createConnections():
var graph = AStar.new()
var point_id = 0
for x in range(mapSize):
for y in range(mapSize):
if $TileMap.get_cell(x,y) == 0:
graph.add_point(point_id, Vector3(x,y,0))
if x > 0 && $TileMap.get_cell(x - 1, y) == 0:
var left_point = graph.get_closest_point(Vector3(x - 1, y, 0))
graph.connect_points(point_id, left_point)
if y > 0 && $TileMap.get_cell(x, y - 1) == 0:
var above_point = graph.get_closest_point(Vector3(x, y - 1, 0))
graph.connect_points(point_id, above_point)
point_id += 1
var room_graph = AStar.new()
point_id = 0
for room in rooms:
var room_center = room.position + room.size / 2
room_graph.add_point(point_id, Vector3(room_center.x, room_center.y, 0))
point_id += 1
while !is_everything_connected(room_graph):
add_random_connection(graph, room_graph)
func is_everything_connected(graph):
var points = graph.get_points()
var start = points.pop_back()
for point in points:
var path = graph.get_point_path(start, point)
if !path:
return false
return true
func add_random_connection(stone_graph, room_graph):
var start_room_id = get_least_connected_point(room_graph)
var end_room_id = get_nearest_unconnected_point(room_graph, start_room_id)
var start_position = pick_random_door_location(rooms[start_room_id])
var end_position = pick_random_door_location(rooms[end_room_id])
var closet_start_point = stone_graph.get_closest_point(start_position)
var closet_end_point = stone_graph.get_closest_point(end_position)
var path = stone_graph.get_point_path(closet_start_point, closet_end_point)
for pos in path:
for i in range(PATH_SIZE):
if($TileMap.get_cell(pos.x+i, pos.y+i) == 0):
setTile(pos.x+i, pos.y+i, "-1")
if($TileMap.get_cell(pos.x+i, pos.y-i) == 0):
setTile(pos.x+i, pos.y-i, "-1")
if($TileMap.get_cell(pos.x-i, pos.y+i) == 0):
setTile(pos.x-i, pos.y+i, "-1")
if($TileMap.get_cell(pos.x-i, pos.y-i) == 0):
setTile(pos.x-i, pos.y-i, "-1")
if $TileMap.get_cell(pos.x, pos.y - 2) == -1:
if $TileMap.get_cell(pos.x, pos.y - 1) == -1:
if $TileMap.get_cell(pos.x, pos.y) == -1:
if !isNextToCell(pos.x, pos.y, 1):
setTile(pos.x, pos.y, "ladder")
#elif(rand_range(0,1) > 0.666):
# setTile(pos.x, pos.y, "light")
elif $TileMap.get_cell(pos.x, pos.y + 2) == -1:
if $TileMap.get_cell(pos.x, pos.y + 1) == -1:
if $TileMap.get_cell(pos.x, pos.y) == -1:
if !isNextToCell(pos.x, pos.y, 1):
setTile(pos.x, pos.y, "ladder")
room_graph.connect_points(start_room_id, end_room_id)
func isNextToCell(x, y, tileId):
return $TileMap.get_cell(x-1, y) == tileId or $TileMap.get_cell(x+1, y) == tileId or $TileMap.get_cell(x, y-1) == tileId or $TileMap.get_cell(x, y+1) == tileId
func get_least_connected_point(graph):
var point_ids = graph.get_points()
var least
var tied_for_least
for point in point_ids:
var count = graph.get_point_connections(point).size()
if !least or count < least:
least = count
tied_for_least = [point]
elif count == least:
tied_for_least.append(point)
return tied_for_least[randi() % tied_for_least.size()]
func get_nearest_unconnected_point(graph, target_point):
var target_position = graph.get_point_position(target_point)
var point_ids = graph.get_points()
var nearest
var tied_for_nearest = []
for point in point_ids:
if point == target_point:
continue
var path = graph.get_point_path(point, target_point)
if path:
continue
var dist = (graph.get_point_position(point) - target_position).length()
if !nearest || dist < nearest:
nearest = dist
tied_for_nearest = [point]
elif dist == nearest:
tied_for_nearest.append(point)
return tied_for_nearest[randi() % tied_for_nearest.size()]
func pick_random_door_location(room):
var options = []
for x in range(room.position.x + 1, room.end.x - 2):
if $TileMap.get_cell(x, room.position.y) == -1:
options.append(Vector3(x, room.position.y, 0))
if $TileMap.get_cell(x, room.end.y) == -1:
options.append(Vector3(x, room.end.y - 1, 0))
for y in range(room.position.y + 1, room.end.y - 2):
if $TileMap.get_cell(room.position.x, y) == -1:
options.append(Vector3(room.position.x, y, 0))
if $TileMap.get_cell(room.end.x - 1, y) == -1:
options.append(Vector3(room.end.x - 1, y, 0))
return options[randi() % options.size()]
func defaultGenerator(padding = 16):
UpdateProgress("Running default generator with map size " + String(mapSize) + "x" + String(mapSize))
fillMap()
var randomStructures = [
[
['x','x','x','x','x','x','x','x','x','x','x','x'],
[' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '],
[' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '],
[' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '],
['x','x',' ',' ','x',' ',' ','x',' ',' ','x','x'],
['x',' ',' ',' ','x',' ',' ','x',' ',' ',' ','x'],
['x',' ',' ',' ','x',' ','e','x',' ','e',' ','x'],
['x','x','x','x','x','x','x','x','x','x','x','x']
],
[
['x','x','x','x','x','x','x','x','x','x','x','x'],
[' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '],
[' ',' ',' ',' ','x','l',' ','x',' ',' ',' ',' '],
[' ','e',' ',' ','x',' ',' ','x',' ',' ',' ',' '],
['x','x','x','x','x','l',' ','x','x','x','x','x'],
['x',' ',' ',' ','x',' ',' ','x',' ',' ',' ','x'],
['x','c',' ',' ',' ',' ','e',' ',' ',' ','c','x'],
['x','x','x','x','x','x','x','x','x','x','x','x']
],
]
for i in range(rand_range(mapSize/32, mapSize/8)):
rooms.append(generateStructure(rand_range(padding, mapSize - padding),rand_range(padding, mapSize - padding), randomStructures[rand_range(0, randomStructures.size())]))
#Create spawn point
UpdateProgress("Creating client connection port...")
var spawnStructure = [
['x','x','x','x','x','x','x','x','x'],
['x',' ','?',' ',' ',' ','?',' ','x'],
['x',' ',' ',' ',' ',' ',' ',' ',' '],
['x',' ','p',' ',' ',' ',' ',' ',' '],
['x','x','x','x','x','x','x','x','x']]
rooms.append(generateStructure(rand_range(padding, mapSize/3),rand_range(padding, mapSize/3), spawnStructure))
var exitStructure = [
['x','x','x','x','x','x','x'],
['x',' ',' ',' ',' ',' ','x'],
['x',' ',' ',' ',' ',' ','x'],
[' ',' ',' ','#',' ',' ',' '],
[' ',' ','x','x','x',' ',' '],
[' ',' ','x','x','x',' ',' ']]
rooms.append(generateStructure(rand_range(padding, mapSize - padding),rand_range(padding, mapSize - padding*3), exitStructure))
createConnections()
$TileMap.set_cell(playerSpawn.x, playerSpawn.y, 0)
UpdateProgress("Removing all possible escapes...")
for x in range(0, mapSize):
for y in range(0, mapSize):
if x < padding or y < padding or x >= mapSize - padding or y >= mapSize - padding:
setTile(x,y,"block")
spawnPlayer()

193
Scripts/PlayerManager.gd Normal file
View File

@ -0,0 +1,193 @@
extends KinematicBody2D
#----------- Equipment
var currentlyEquiped = "none"
var sheathed = "saber"
#----------- misc movement
const UP = Vector2(0, -1)
const BASE_GRAVITY = 20
const BASE_SPEED = 150
var motion = Vector2()
#----------- Jumping related variables
const BASE_JUMP = -250 #Motion added for a jump
var extra_jumps = 0 #Number of double jumps a player has
var current_jumps = 0 #Number of jumps a player has left
var jumpHeight = 0
var coins = 0
var GAMEOVER = false
const JUMP_PLATFORM = preload("res://Nodes/jump_platform.tscn")
func _ready():
extra_jumps = SaveManager.get_action_value('jump')/4
jumpHeight = SaveManager.get_action_value('jump') * -2
sheathed = SaveManager.get_equiped()
updateEquipment()
func victoryCondition():
SaveManager.change_upgrade_points(coins)
slide_out()
const VICTORY_SCREEN = "res://Nodes/Victory.tscn"
var slide_progress = 0
var slide_timer
const SLIDE_SPEED = 0.0125
const PIXELS_PER = 32
func slide_out():
$CanvasLayer/GUI/SlideRect.rect_size.y = slide_progress
if slide_progress < 600:
slide_progress += PIXELS_PER
if(!slide_timer):
slide_timer = Timer.new()
add_child(slide_timer)
slide_timer.connect("timeout", self, "slide_out")
slide_timer.start(SLIDE_SPEED)
else:
get_tree().change_scene(VICTORY_SCREEN)
func done_sliding():
return slide_progress >= 600
signal unequip
var waitingToUpdate = 0
func _process(delta):
if(Input.is_action_just_pressed("sheath")):
switch_sheath()
if(Input.is_action_pressed("attack") and currentlyEquiped == "none"):
switch_sheath()
func deal_damage(dmg = 1):
playAudio("Hero_Hurt.wav")
updateHealth(-dmg)
print(getHealth())
func switch_sheath():
if(sheathed == "none"):
sheathed = currentlyEquiped
currentlyEquiped = "none"
else:
currentlyEquiped = sheathed
sheathed = "none"
emit_signal("unequip")
updateEquipment()
var audioPlayer
func playAudio(track):
if !audioPlayer:
audioPlayer = AudioStreamPlayer.new()
self.add_child(audioPlayer)
audioPlayer.stream = load("res://Sound/" + track)
audioPlayer.volume_db = -30
audioPlayer.play()
func pickupCoin():
coins += 1
$CanvasLayer/GUI/Label.text = String(coins)
var maxHP = 25
var health
func updateHealth(val):
if !health:
health = maxHP
$CanvasLayer/GUI/Healthbar.max_value = maxHP
health += val
$CanvasLayer/GUI/Healthbar.value = health
if(health <= 0):
game_over()
func getHealth():
if !health:
health = maxHP
return health
func game_over():
GAMEOVER = true
$CanvasLayer/GUI.hide()
$CanvasLayer/GameOver.show()
var tileMap
func _physics_process(delta):
if GAMEOVER:
hide()
else:
#Implement the force of gravity!
motion.y += BASE_GRAVITY
#Moves the player left & right
if(Input.is_action_pressed("right")):
motion.x = BASE_SPEED
elif (Input.is_action_pressed("left")):
motion.x = -BASE_SPEED
else:
motion.x = 0
if is_on_floor():
motion.y = 0
if !tileMap:
var childs = get_parent().get_children()
for child in childs:
if typeof(child) == typeof(TileMap):
tileMap = child
break
#Handle the jumpings
if (Input.is_action_just_pressed("up")):
if is_on_floor():
if(Input.is_action_pressed("down")):
var tilePos = tileMap.world_to_map(position)
tilePos.y += 1
if(tileMap.get_cell(tilePos.x, tilePos.y) == 1):
position.y += 4
else:
motion.y = BASE_JUMP + jumpHeight
#Reset number of jumps
current_jumps = extra_jumps
elif current_jumps > 0:
motion.y = BASE_JUMP + jumpHeight
playAudio("Sword.wav")
spawn_jump_platform()
current_jumps -= 1
#Do animations
$AnimatedSprite.flip_h = get_global_mouse_position().x < position.x
if is_on_floor():
if($AnimatedSprite.animation == "jump"):
playAudio("Sword2.wav")
if abs(motion.x) > 0:
if(motion.x > 0):
$AnimatedSprite.play("walk", true)
else:
$AnimatedSprite.play("walk", false)
else:
$AnimatedSprite.play("idle")
else:
$AnimatedSprite.play("jump")
motion = move_and_slide(motion, UP)
func spawn_jump_platform():
var platform = JUMP_PLATFORM.instance()
get_parent().add_child(platform)
platform.position = Vector2(position.x, position.y + 4)
pass
func updateEquipment():
var equipmentNode = get_child(3)
if(equipmentNode.get_children().size() + 1 > 0):
for enode in equipmentNode.get_children():
enode.queue_free()
var equipment = load("res://Nodes/Equipment/" + currentlyEquiped + ".tscn").instance()
equipmentNode.add_child(equipment)

51
Scripts/RunLabel.gd Normal file
View File

@ -0,0 +1,51 @@
extends Label
#Hide all charafcters on start
func _ready():
text = "Authorization Granted: Unit " + String($"/root/SaveManager".get_run())
show_text(2)
visible_characters = 0
var timePassed = 0 #Current amount of time spend displaying te
const CHECK_LENGTH = 0.05 #Interval to check for updates
var timeNeeded = 0 #Time that it takes to display the text
var timer #Timer object
var fadeTimer #Timer object
func show_text(seconds):
timeNeeded = seconds
timePassed = 0
if(!timer):
timer = Timer.new()
add_child(timer)
timer.connect("timeout", self, "on_timeout")
timer.start(CHECK_LENGTH)
func fade_text(seconds):
timeNeeded = seconds
timePassed = 0
if(!fadeTimer):
fadeTimer = Timer.new()
add_child(fadeTimer)
fadeTimer.connect("timeout", self, "on_fade_timeout")
fadeTimer.start(CHECK_LENGTH)
func on_fade_timeout():
timePassed += CHECK_LENGTH
modulate.a = 1 - (timePassed/timeNeeded)
if(timePassed >= timeNeeded):
fadeTimer.queue_free()
else:
fadeTimer.start(CHECK_LENGTH)
pass
func on_timeout():
timePassed += CHECK_LENGTH
visible_characters = (timePassed/timeNeeded) * get_total_character_count()
if(timePassed >= timeNeeded):
timer.queue_free()
fade_text(2)
else:
timer.start(CHECK_LENGTH)
pass

59
Scripts/Title.gd Normal file
View File

@ -0,0 +1,59 @@
extends Control
var fadeTo
func _ready():
MusicPlayer.stop()
MusicPlayer.stream = load("res://Music/DOS-88/Race to Mars.ogg")
MusicPlayer.volume_db = 0
MusicPlayer.play()
$Fader.modulate.a = 1
$CreditsMenu.hide()
$"New Game".connect("button_down", self, "new_game")
$Credits.connect("button_down", self, "show_credits")
$Quit.connect("button_down", self, "on_quit_down")
fade_out(3, 1, -1)
func new_game():
SaveManager.add_run()
fadeTo = "res://Nodes/Game.tscn"
fade_out(3, -80)
func show_credits():
$CreditsMenu.show()
func on_quit_down():
get_tree().quit()
var timePassed = 0 #Current amount of time spend displaying te
const CHECK_LENGTH = 0.05 #Interval to check for updates
var timeNeeded = 0 #Time that it takes to display the text
var fadeTimer #Timer object
var multiplier = 1
var adder = 0
func fade_out(seconds, multi = 1, add = 0):
multiplier = multi
adder = add
timeNeeded = seconds
timePassed = 0
if(!fadeTimer):
fadeTimer = Timer.new()
add_child(fadeTimer)
fadeTimer.connect("timeout", self, "on_fade_timeout")
fadeTimer.start(CHECK_LENGTH)
func on_fade_timeout():
timePassed += CHECK_LENGTH
MusicPlayer.volume_db = multiplier * (timePassed/timeNeeded)
$Fader.modulate.a = abs(timePassed/timeNeeded + adder)
if(timePassed >= timeNeeded):
fadeTimer.stop()
if($Fader.modulate.a > 0.5):
get_tree().change_scene(fadeTo)
else:
fadeTimer.start(CHECK_LENGTH)
pass

53
Scripts/TypeLabel.gd Normal file
View File

@ -0,0 +1,53 @@
extends Label
export var time_to_show = 4.0
export var fade_after_show = true
#Hide all charafcters on start
func _ready():
show_text(time_to_show)
visible_characters = 0
var timePassed = 0 #Current amount of time spend displaying te
const CHECK_LENGTH = 0.05 #Interval to check for updates
var timeNeeded = 0 #Time that it takes to display the text
var timer #Timer object
var fadeTimer #Timer object
func show_text(seconds):
timeNeeded = seconds
timePassed = 0
if(!timer):
timer = Timer.new()
add_child(timer)
timer.connect("timeout", self, "on_timeout")
timer.start(CHECK_LENGTH)
func fade_text(seconds):
timeNeeded = seconds
timePassed = 0
if(!fadeTimer):
fadeTimer = Timer.new()
add_child(fadeTimer)
fadeTimer.connect("timeout", self, "on_fade_timeout")
fadeTimer.start(CHECK_LENGTH)
func on_fade_timeout():
timePassed += CHECK_LENGTH
modulate.a = 1 - (timePassed/timeNeeded)
if(timePassed >= timeNeeded):
fadeTimer.queue_free()
else:
fadeTimer.start(CHECK_LENGTH)
pass
func on_timeout():
timePassed += CHECK_LENGTH
visible_characters = (timePassed/timeNeeded) * get_total_character_count()
if(timePassed >= timeNeeded):
timer.queue_free()
if(fade_after_show):
fade_text(2)
else:
timer.start(CHECK_LENGTH)
pass

View File

@ -0,0 +1,12 @@
extends AnimatedSprite
func _ready():
play("spawn")
connect("animation_finished", self, "on_animation_finished")
func on_animation_finished():
if(animation == "spawn"):
play("destroy")
else:
get_parent().queue_free()

127
Scripts/saving.gd Normal file
View File

@ -0,0 +1,127 @@
extends Node
const SAVE_PATH = "res://save_raw.yaml"
const CONFIG_PATH = "res://config.cfg"
var _config_file = ConfigFile.new()
const RUN_PATH = "user://run.save"
var _run_file = File.new()
const SAVE_PROGRESS = "user://progress.save"
var _settings = {
"audio": {
"mute": "false"
}
}
var _game_progress = {
"upgrade_points" : "0",
"equipment" : ["saber"],
"equiped" : "saber",
"actions" :
{
"jump" : 1
}
}
func _ready():
var SaveFile = File.new()
if !SaveFile.file_exists(SAVE_PROGRESS):
save_settings()
else:
load_settings()
func load_json(path):
var file = File.new()
file.open(path, file.READ)
var tmp_text = file.get_as_text()
file.close()
var data = parse_json(tmp_text)
return data
func write_json(path, data):
var file = File.new()
file.open(path, file.WRITE)
file.store_string(to_json(data))
file.close()
func get_run():
if(_run_file.file_exists(RUN_PATH)):
_run_file.open(RUN_PATH, File.READ)
var run_value = _run_file.get_64()
_run_file.close()
return run_value
else:
return 0
func add_run():
var currentRun = get_run()
currentRun += 1
_run_file.open(RUN_PATH, File.WRITE)
_run_file.store_64(currentRun)
_run_file.close()
return currentRun
func save_progress():
write_json(SAVE_PROGRESS, _game_progress)
func get_upgrade_points():
if "upgrade_points" in _game_progress:
return int(_game_progress["upgrade_points"])
else:
return 0
func change_upgrade_points(pts):
_game_progress["upgrade_points"] = int(_game_progress["upgrade_points"]) + pts
func get_equipment():
return _game_progress['equipment']
func get_equiped():
return _game_progress['equiped']
func set_equiped(equip):
_game_progress['equiped'] = equip
save_progress()
func unlock_equipment(equip):
_game_progress['equipment'].append(equip)
save_progress()
func get_actions():
var actions = []
for action in _game_progress['actions']:
actions.append(action)
return actions
func get_action_value(action):
return _game_progress['actions'][action]
func set_action_value(action, value):
_game_progress['actions'][action] = value
save_progress()
func save_settings():
for section in _settings.keys():
for key in _settings[section]:
_config_file.set_value(section, key, _settings[section][key])
_config_file.save(CONFIG_PATH)
func load_settings():
var error = _config_file.load(CONFIG_PATH)
if error != OK:
print("Failed to load config file. Error: %s" % error)
return -1
for section in _settings.keys():
for key in _settings[section]:
var val = _config_file.get_value(section, key, null)
_settings[section][key] = val
pass