Commit d998a3ad authored by Adam Gausmann's avatar Adam Gausmann
Browse files

Merge branch 'high-score' into master

parents 5dfcfaa2 009ee43d
source_md5="47313fa4c47a9963fddd764e1ec6e4a8"
dest_md5="2ded9e7f9060e2b530aab678b135fc5b"
dest_md5="101646a1a3679e130eebca96b0b56ae1"
source_md5="47313fa4c47a9963fddd764e1ec6e4a8"
dest_md5="2ded9e7f9060e2b530aab678b135fc5b"
dest_md5="101646a1a3679e130eebca96b0b56ae1"
......@@ -12,6 +12,7 @@ var direction = "right"
var texture_node = "player"
var previous_coord = null
var level = 1
var high_score = 0
func _ready():
position = Vector2.ONE * tile_size/2
......@@ -21,6 +22,9 @@ func _ready():
get_node("../../TileMap").update_map()
if high_score < get_high_score():
load_game()
# use this if you want to only move on keypress
func _unhandled_input(event):
for dir in inputs.keys():
......@@ -60,6 +64,12 @@ func move(dir: String):
if destination == null:
get_node("../../TileMap").update_map()
level += 1
if level > high_score:
high_score = level
if high_score > get_high_score():
save_game()
elif previous_coord != destination && previous_coord != get_coord(position):
var tele_direction = Vector2(destination.x - coord.x, coord.y - destination.y)
teleport(tele_direction.x, tele_direction.y)
......@@ -109,14 +119,15 @@ func life_update():
get_node("..").kill(name)
func _input(ev):
if Input.is_key_pressed(KEY_SPACE):
if dashCharges > 0:
if dashRange == 1:
dashRange = 2
else:
dashRange = 1
if Input.is_key_pressed(KEY_T):
teleport(3,3)
#if Input.is_key_pressed(KEY_SPACE):
# if dashCharges > 0:
# if dashRange == 1:
# dashRange = 2
# else:
# dashRange = 1
#if Input.is_key_pressed(KEY_T):
# teleport(3,3)
pass
func _draw():
var label = Label.new()
......@@ -125,6 +136,7 @@ func _draw():
draw_string(font, Vector2(OS.window_size.x/5.5, OS.window_size.y/6), 'Dashes: ' + str(dashCharges), Color(1.0, 1.0, 0.0, 1.0))
draw_string(font, Vector2(OS.window_size.x/5.5, OS.window_size.y/5), 'Health: ' + str(health) + ' / ' + str(max_health), Color(1.0, 1.0, 0.0, 1.0))
draw_string(font, Vector2(OS.window_size.x/5.5, OS.window_size.y/4), 'Level: ' + str(level),Color(1.0, 1.0, 0.0, 1.0))
draw_string(font, Vector2(OS.window_size.x/5.5, OS.window_size.y/8), 'High Score: ' + str(high_score),Color(1.0, 1.0, 0.0, 1.0))
# Calculates and returns the coordinate of the player in the map by taking its
# current position and dividing by the tile_size
......@@ -149,6 +161,58 @@ func _process(_delta):
# else:
# return "NULL"
func save():
var save_dict = {
"high_score" : level
}
return save_dict
func save_game():
var save_game = File.new()
save_game.open("user://savegame.save", File.WRITE)
# Store the save dictionary as a new line in the save file.
save_game.store_line(to_json(save()))
save_game.close()
func load_game():
var save_game = File.new()
if not save_game.file_exists("user://savegame.save"):
save_game()
save_game.open("user://savegame.save", File.READ)
var data = parse_json(save_game.get_line())
high_score = data["high_score"]
save_game.close()
func get_high_score():
var saved_high_score
var save_game = File.new()
if not save_game.file_exists("user://savegame.save"):
saved_high_score = -1
else:
save_game.open("user://savegame.save", File.READ)
var data = parse_json(save_game.get_line())
saved_high_score = data["high_score"]
save_game.close()
return saved_high_score
func delete_save():
var save_game = File.new()
if save_game.file_exists("user://savegame.save"):
var dir = Directory.new()
dir.remove("user://savegame.save")
save_game.close()
#Stats
var speed: float = 1 #Controls how frequently the player can act; increases the rate at which delay is gone through
var health: float = 12
......
......@@ -76,7 +76,7 @@ custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path="html/tdg.html"
export_path="../html/tdg.html"
patch_list=PoolStringArray( )
script_export_mode=1
script_encryption_key=""
......
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/favicon.png-05a5f25b7b35b567a640a7daf7751a8e.stex"
metadata={
"vram_texture": false
}
importer="image"
type="Image"
path="res://.import/favicon.png-05a5f25b7b35b567a640a7daf7751a8e.image"
[deps]
source_file="res://favicon.png"
dest_files=[ "res://.import/favicon.png-05a5f25b7b35b567a640a7daf7751a8e.stex" ]
dest_files=[ "res://.import/favicon.png-05a5f25b7b35b567a640a7daf7751a8e.image" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
metadata={
"vram_texture": false
}
importer="image"
type="Image"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.image"
[deps]
source_file="res://icon.png"
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.image" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
......@@ -2,7 +2,8 @@ const CELL = preload("res://src/Cell.gd")
const ROOM = preload("res://src/Room.gd")
# Percentage of cells in the map that should be enemy spawns
const ENEMY_FILL_PERCENT = 0.15
const ENEMY_FILL_PERCENT = 0.030
#const ENEMY_FILL_PERCENT = 0.15
# Maximum number of chests in a level
const MAX_CHESTS = 3
# Minimum number of chests in a level
......@@ -411,7 +412,10 @@ func spawn_holes():
randomize()
room = rooms[randi() % rooms.size()]
if room.count_elligible_hole > 0 && !room.spawn_room:
if rooms.size() > 1:
if room.count_elligible_hole > 0 && !room.spawn_room:
room_found = true
else:
room_found = true
room.spawn_hole(room.get_random_hole_spawn(), null)
......@@ -452,7 +456,8 @@ func spawn_enemies():
var spawn = elligible_spawns[i]
elligible_spawns.remove(i)
if coord_in_what_room(spawn).find_distance_individual(spawn, "PLAYER") < 4:
# Following logic removed as it too often causes the map generation to take incredible amounts of time to complete
if coord_in_what_room(spawn).is_distance_individual_greater_than(spawn, "PLAYER", 4):
enemy_spawns.append(spawn)
# Spawn chests
......
......@@ -90,6 +90,48 @@ func find_distance_individual(coord, value):
return distance_current
# Return the whether or not the given cell's distance from the nearest cell with
# the given content value is greater than the given max distance. If
# the value is "PLAYER", it will evaluate the distance from the player spawn
# cell.
func is_distance_individual_greater_than(coord, value, max_distance):
var distance_current = -1
var distance_found = false
var distance_greater_than = false
while !distance_found:
if str(value) != "PLAYER":
var surrounding_contents = []
distance_current += 1
for x_mod in range (-distance_current, distance_current + 1):
for y_mod in range (-distance_current, distance_current + 1):
if cells.keys().has(Vector2(coord.x + x_mod, coord.y + y_mod)):
surrounding_contents.append(cells[Vector2(coord.x + x_mod, coord.y + y_mod)].content)
elif value == CELL.WALL:
distance_found = true
if value in surrounding_contents:
distance_found = true
surrounding_contents = []
else:
if !spawn_room:
distance_found = true
distance_greater_than = true
else:
distance_current += 1
for x_mod in range (-distance_current, distance_current + 1):
for y_mod in range (-distance_current, distance_current + 1):
if cells.keys().has(Vector2(coord.x + x_mod, coord.y + y_mod)) && cells[Vector2(coord.x + x_mod, coord.y + y_mod)].player_spawn:
distance_found = true
if distance_current > max_distance:
distance_found = true
distance_greater_than = true
return distance_greater_than
# For each cell, find how far it is away from the nearest wall tile
func find_distances_wall():
for cell in cells:
......
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' lang='' xml:lang=''>
<head>
<meta charset='utf-8' />
<meta name='viewport' content='width=device-width, user-scalable=no' />
<link id='-gd-engine-icon' rel='icon' type='image/png' href='favicon.png' />
<title>Cs 4096 - 97 Top Down Game</title>
<style type='text/css'>
body {
touch-action: none;
margin: 0;
border: 0 none;
padding: 0;
text-align: center;
background-color: black;
}
#canvas {
display: block;
margin: 0;
color: white;
}
#canvas:focus {
outline: none;
}
.godot {
font-family: 'Noto Sans', 'Droid Sans', Arial, sans-serif;
color: #e0e0e0;
background-color: #3b3943;
background-image: linear-gradient(to bottom, #403e48, #35333c);
border: 1px solid #45434e;
box-shadow: 0 0 1px 1px #2f2d35;
}
/* Status display
* ============== */
#status {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
display: flex;
justify-content: center;
align-items: center;
/* don't consume click events - make children visible explicitly */
visibility: hidden;
}
#status-progress {
width: 366px;
height: 7px;
background-color: #38363A;
border: 1px solid #444246;
padding: 1px;
box-shadow: 0 0 2px 1px #1B1C22;
border-radius: 2px;
visibility: visible;
}
@media only screen and (orientation:portrait) {
#status-progress {
width: 61.8%;
}
}
#status-progress-inner {
height: 100%;
width: 0;
box-sizing: border-box;
transition: width 0.5s linear;
background-color: #202020;
border: 1px solid #222223;
box-shadow: 0 0 1px 1px #27282E;
border-radius: 3px;
}
#status-indeterminate {
visibility: visible;
position: relative;
}
#status-indeterminate > div {
width: 4.5px;
height: 0;
border-style: solid;
border-width: 9px 3px 0 3px;
border-color: #2b2b2b transparent transparent transparent;
transform-origin: center 21px;
position: absolute;
}
#status-indeterminate > div:nth-child(1) { transform: rotate( 22.5deg); }
#status-indeterminate > div:nth-child(2) { transform: rotate( 67.5deg); }
#status-indeterminate > div:nth-child(3) { transform: rotate(112.5deg); }
#status-indeterminate > div:nth-child(4) { transform: rotate(157.5deg); }
#status-indeterminate > div:nth-child(5) { transform: rotate(202.5deg); }
#status-indeterminate > div:nth-child(6) { transform: rotate(247.5deg); }
#status-indeterminate > div:nth-child(7) { transform: rotate(292.5deg); }
#status-indeterminate > div:nth-child(8) { transform: rotate(337.5deg); }
#status-notice {
margin: 0 100px;
line-height: 1.3;
visibility: visible;
padding: 4px 6px;
visibility: visible;
}
</style>
</head>
<body>
<canvas id='canvas'>
HTML5 canvas appears to be unsupported in the current browser.<br />
Please try updating or use a different browser.
</canvas>
<div id='status'>
<div id='status-progress' style='display: none;' oncontextmenu='event.preventDefault();'><div id ='status-progress-inner'></div></div>
<div id='status-indeterminate' style='display: none;' oncontextmenu='event.preventDefault();'>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div id='status-notice' class='godot' style='display: none;'></div>
</div>
<script type='text/javascript' src='tdg.js'></script>
<script type='text/javascript'>//<![CDATA[
var engine = new Engine;
var setStatusMode;
var setStatusNotice;
(function() {
const EXECUTABLE_NAME = 'tdg';
const MAIN_PACK = 'tdg.pck';
const INDETERMINATE_STATUS_STEP_MS = 100;
var canvas = document.getElementById('canvas');
var statusProgress = document.getElementById('status-progress');
var statusProgressInner = document.getElementById('status-progress-inner');
var statusIndeterminate = document.getElementById('status-indeterminate');
var statusNotice = document.getElementById('status-notice');
var initializing = true;
var statusMode = 'hidden';
var animationCallbacks = [];
function animate(time) {
animationCallbacks.forEach(callback => callback(time));
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
function adjustCanvasDimensions() {
var scale = window.devicePixelRatio || 1;
var width = window.innerWidth;
var height = window.innerHeight;
canvas.width = width * scale;
canvas.height = height * scale;
canvas.style.width = width + "px";
canvas.style.height = height + "px";
}
animationCallbacks.push(adjustCanvasDimensions);
adjustCanvasDimensions();
setStatusMode = function setStatusMode(mode) {
if (statusMode === mode || !initializing)
return;
[statusProgress, statusIndeterminate, statusNotice].forEach(elem => {
elem.style.display = 'none';
});
animationCallbacks = animationCallbacks.filter(function(value) {
return (value != animateStatusIndeterminate);
});
switch (mode) {
case 'progress':
statusProgress.style.display = 'block';
break;
case 'indeterminate':
statusIndeterminate.style.display = 'block';
animationCallbacks.push(animateStatusIndeterminate);
break;
case 'notice':
statusNotice.style.display = 'block';
break;
case 'hidden':
break;
default:
throw new Error('Invalid status mode');
}
statusMode = mode;
}
function animateStatusIndeterminate(ms) {
var i = Math.floor(ms / INDETERMINATE_STATUS_STEP_MS % 8);
if (statusIndeterminate.children[i].style.borderTopColor == '') {
Array.prototype.slice.call(statusIndeterminate.children).forEach(child => {
child.style.borderTopColor = '';
});
statusIndeterminate.children[i].style.borderTopColor = '#dfdfdf';
}
}
setStatusNotice = function setStatusNotice(text) {
while (statusNotice.lastChild) {
statusNotice.removeChild(statusNotice.lastChild);
}
var lines = text.split('\n');
lines.forEach((line) => {
statusNotice.appendChild(document.createTextNode(line));
statusNotice.appendChild(document.createElement('br'));
});
};
engine.setProgressFunc((current, total) => {
if (total > 0) {
statusProgressInner.style.width = current/total * 100 + '%';
setStatusMode('progress');
if (current === total) {
// wait for progress bar animation
setTimeout(() => {
setStatusMode('indeterminate');
}, 500);
}
} else {
setStatusMode('indeterminate');
}
});
function displayFailureNotice(err) {
var msg = err.message || err;
console.error(msg);
setStatusNotice(msg);
setStatusMode('notice');
initializing = false;
};
if (!Engine.isWebGLAvailable()) {
displayFailureNotice('WebGL not available');
} else {
setStatusMode('indeterminate');
engine.setCanvas(canvas);
engine.startGame(EXECUTABLE_NAME, MAIN_PACK).then(() => {
setStatusMode('hidden');
initializing = false;
}, displayFailureNotice);
}
})();
//]]></script>
</body>
</html>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment