Skip to content
Snippets Groups Projects
Commit a1022b06 authored by echicken's avatar echicken
Browse files

DigitalMan's up at 3 AM reporting bugs in bad old games.

Possibly fix dupe dummy score on first run. Didn't test lol.

Added 'N' for immediate next wave.
ESC to quit still works, but now Q does too.

Tidied up a bit, but wow ... this is pretty bad. You'd think
I wrote most of it over the course of a drunken evening seven
years ago or something.
parent 090b81ed
No related branches found
No related tags found
No related merge requests found
......@@ -31,14 +31,13 @@ var ships = [
"defiant"
];
var cycle = function() {
function cycle() {
Sprite.cycle();
timer.cycle();
if(frame.cycle())
console.gotoxy(console.screen_columns, console.screen_rows);
if (frame.cycle()) console.gotoxy(console.screen_columns, console.screen_rows);
}
var splash = function() {
function splash() {
var splashFrame = new Frame(1, 1, 80, 24, 0, frame);
splashFrame.load(js.exec_dir + "startrek.bin", 80, 24);
splashFrame.top();
......@@ -49,7 +48,7 @@ var splash = function() {
splashFrame.delete();
}
var init = function() {
function init() {
js.branch_limit = 0;
sysStatus = bbs.sys_status;
bbs.sys_status|=SS_MOFF;
......@@ -66,15 +65,15 @@ var init = function() {
timer = new Timer();
if(file_exists(js.exec_dir + "server.ini")) {
if (file_exists(js.exec_dir + "server.ini")) {
var f = new File(js.exec_dir + "server.ini");
f.open("r");
serverIni = f.iniGetObject();
f.close();
} else {
serverIni = {
'host' : 'localhost',
'port' : 10088
host: 'localhost',
port: 10088
};
}
......@@ -83,29 +82,31 @@ var init = function() {
frame.draw();
}
var removeShip = function(s) {
function removeShip(s) {
Sprite.aerials[s].remove();
Sprite.aerials[s].frame.delete();
}
var rotateSprites = function(sprites) {
for(var s in sprites)
function rotateSprites(sprites) {
for (var s in sprites) {
sprites[s].turn("cw");
}
}
var ucfl = function(str) {
function ucfl(str) {
str = str[0].toUpperCase() + str.substr(1);
return str;
}
var dots = function(d) {
function dots(d) {
var str = "";
for(var dd = 0; dd < d; dd++)
for (var dd = 0; dd < d; dd++) {
str += ascii(254);
}
return str;
}
var setup = function() {
function setup() {
var setupFrame = new Frame(1, 1, 80, 24, 0, frame);
setupFrame.load(js.exec_dir + "starfield.bin", 80, 24);
......@@ -114,7 +115,7 @@ var setup = function() {
var shipSprites = [];
var viewWidth = 13;
var x = Math.floor((80 - (ships.length * viewWidth)) / 2);
for(var s = 0; s < ships.length; s++) {
for (var s = 0; s < ships.length; s++) {
var view = layout.addView(ucfl(ships[s]), x, 5, viewWidth - 1, 16);
view.show_tabs = false;
var tab = view.addTab("frame", "frame");
......@@ -125,15 +126,12 @@ var setup = function() {
weapon.remove();
weapon.frame.delete();
tab.frame.gotoxy(1, 7);
tab.frame.putmsg(
format(
"Speed\r\n\1h\1g%s\r\n\r\n\1h\1wShields\r\n\1h\1c%s\r\n\r\n\1h\1wWeapons\r\n\1h\1r%s",
dots(Math.floor((1 - sprite.ini.maximumspeed) * 10)),
dots(sprite.ini.health - 1),
dots(weapon.ini.damage * 3)
),
WHITE
);
tab.frame.putmsg(format(
"Speed\r\n\1h\1g%s\r\n\r\n\1h\1wShields\r\n\1h\1c%s\r\n\r\n\1h\1wWeapons\r\n\1h\1r%s",
dots(Math.floor((1 - sprite.ini.maximumspeed) * 10)),
dots(sprite.ini.health - 1),
dots(weapon.ini.damage * 3)
), WHITE);
x = x + viewWidth;
}
timer.addEvent(1000, true, rotateSprites, [shipSprites]);
......@@ -151,7 +149,7 @@ var setup = function() {
var userInput = "";
setupFrame.top();
while(ascii(userInput) != 13) {
while (ascii(userInput) != 13) {
userInput = console.inkey(K_NONE, 5);
layout.getcmd(userInput);
layout.cycle();
......@@ -161,13 +159,14 @@ var setup = function() {
setupFrame.gotoxy(1, 21);
setupFrame.center("What is the name of your " + layout.current.title + "-class starship?", WHITE);
cycle();
while(player.shipName == "") {
while (player.shipName == "") {
console.gotoxy(25, 23);
player.shipName = console.getstr("USS ", 30, K_LINE|K_EDIT);
}
for(var s in Sprite.aerials)
for (var s in Sprite.aerials) {
removeShip(s);
}
player.sprite = new Sprite.Aerial(layout.current.title.toLowerCase(), fieldFrame, 40, 10, 'n', 'normal');
layout.close();
......@@ -177,7 +176,7 @@ var setup = function() {
timer.events = [];
}
var showHelp = function() {
function showHelp() {
var helpFrame = new Frame(8, 4, 64, 16, 0, frame);
helpFrame.load(js.exec_dir + "help.bin", 64, 16);
helpFrame.top();
......@@ -188,22 +187,24 @@ var showHelp = function() {
helpFrame.delete();
}
var checkScreenEdge = function(sprite) {
if(sprite.x < -3)
function checkScreenEdge(sprite) {
if (sprite.x < -3) {
sprite.moveTo(77, sprite.y);
if(sprite.y < -2)
sprite.moveTo(sprite.x, 23);
if(sprite.x > 77)
} else if (sprite.x > 77) {
sprite.moveTo(-3, sprite.y);
if(sprite.y > 23)
}
if (sprite.y < -2) {
sprite.moveTo(sprite.x, 23);
} else if (sprite.y > 23) {
sprite.moveTo(sprite.x, -2);
}
}
var putEnemy = function(re) {
function putEnemy(re) {
var rx = Math.floor(Math.random() * 73) + 1;
var ry = Math.floor(Math.random() * 20) + 1;
var s = new Sprite.Aerial(enemies[re], fieldFrame, rx, ry, 'n', 'normal');
if(Sprite.checkOverlap(s).length > 0) {
if (Sprite.checkOverlap(s).length > 0) {
s.remove();
return false;
}
......@@ -211,14 +212,16 @@ var putEnemy = function(re) {
return true;
}
var spawnEnemies = function() {
function spawnEnemies() {
var re = Math.floor(Math.random() * enemies.length);
var roundMax = Math.floor((player.round + 1) / 2);
for(var x = 0; x < ((roundMax > maxEnemies) ? maxEnemies : roundMax); x++) {
var _enemies = Math.min(roundMax, maxEnemies);
for (var x = 0; x < _enemies; x++) {
while(!putEnemy(re)) {
mswait(1);
}
}
if(player.round == 1) {
if (player.round == 1) {
timer.addEvent(1000, true, countdown);
clockFrame.putmsg("Next wave: ");
countdown();
......@@ -231,107 +234,96 @@ var spawnEnemies = function() {
statusFrame.top();
timer.addEvent(250, 12, cycleWarning, ["Oh no! " + Sprite.aerials[Sprite.aerials.length - 1].ini.name + "!"]);
timer.addEvent(3000, false, removeWarning);
if(player.round % 5 == 0)
waveTimer.interval = waveTimer.interval - 5000;
if (player.round % 5 == 0) waveTimer.interval = waveTimer.interval - 5000;
}
var countdown = function() {
function countdown() {
clockSubFrame.clear();
clockSubFrame.putmsg(parseInt(waveTimer.nextrun * .001));
}
var cycleWarning = function(warning) {
function cycleWarning(warning) {
var c = Math.floor(Math.random() * 15) + 1;
uhOhFrame.clear();
uhOhFrame.center(warning, c);
}
var removeWarning = function() {
function removeWarning() {
uhOhFrame.clear();
uhOhFrame.bottom();
}
var putStats = function() {
function putStats() {
statusFrame.clear();
statusFrame.putmsg(
format(
"[ESC] quit [H]elp | Round: %s Shields: %s Score: %s",
player.round - 1, player.sprite.ini.health - 1, player.score
)
);
statusFrame.putmsg(format(
"[Q]uit [H]elp [N]ext | Round: %s Shields: %s Score: %s",
player.round - 1, player.sprite.ini.health - 1, player.score
));
}
var deathKnell = function() {
function deathKnell() {
uhOhFrame.top();
for(var n = 0; n < 20; n++) {
for (var n = 0; n < 20; n++) {
cycleWarning("You done goofed!");
cycle();
mswait(200);
}
while(console.input_buffer_level > 0) {
while (console.input_buffer_level > 0) {
console.inkey();
}
}
var gamePlay = function() {
function gamePlay() {
player.round = 1;
player.sprite.frame.draw();
timer.addEvent(2000, 1, spawnEnemies);
waveTimer = timer.addEvent(30000, true, spawnEnemies);
putStats();
statusFrame.top();
while(!js.terminated) {
if(player.sprite.ini.health < 1)
break;
userInput = console.inkey(K_NONE, 5);
if(ascii(userInput) == 27)
break;
else if(userInput.toUpperCase() == "H")
while (!js.terminated) {
if (player.sprite.ini.health < 1) break;
userInput = console.inkey(K_NONE, 5).toUpperCase();
if (userInput == '\x1B' || userInput == 'Q') break;
if (userInput == "H") {
showHelp();
player.sprite.getcmd(userInput);
for(var s = 0; s < Sprite.aerials.length; s++) {
if(!Sprite.aerials[s].open)
continue;
} else if (userInput == 'N') {
waveTimer.run();
} else {
player.sprite.getcmd(userInput);
}
for (var s = 0; s < Sprite.aerials.length; s++) {
if (!Sprite.aerials[s].open) continue;
checkScreenEdge(Sprite.aerials[s]);
if(
Sprite.aerials[s].ini.type == "ship"
&&
Sprite.aerials[s] != player.sprite
&&
system.timer - Sprite.aerials[s].lastMove > Sprite.aerials[s].ini.speed
&&
if (Sprite.aerials[s].ini.type == "ship" &&
Sprite.aerials[s] != player.sprite &&
system.timer - Sprite.aerials[s].lastMove > Sprite.aerials[s].ini.speed &&
Sprite.aerials[s].pursue(player.sprite)
) {
Sprite.aerials[s].getcmd(KEY_WEAPON);
}
var o = Sprite.checkOverlap(Sprite.aerials[s]);
if(!o)
continue;
for(var oo in o) {
if(!o[oo].open)
continue;
if(o[oo].ini.type == "weapon" && Sprite.aerials[s].ini.type == "weapon") {
if (!o) continue;
for (var oo in o) {
if (!o[oo].open) continue;
if (o[oo].ini.type == "weapon" && Sprite.aerials[s].ini.type == "weapon") {
Sprite.aerials[s].remove();
o[oo].remove();
} else if(
(o[oo].ini.type == "weapon" && Sprite.aerials[s].ini.type == "ship")
&&
} else if (
(o[oo].ini.type == "weapon" && Sprite.aerials[s].ini.type == "ship") &&
(o[oo].owner != Sprite.aerials[s])
) {
Sprite.aerials[s].ini.health = Sprite.aerials[s].ini.health - parseInt(o[oo].ini.damage);
o[oo].remove();
} else if(
o[oo].ini.type == "ship" && Sprite.aerials[s].ini.type == "ship"
&&
} else if (
o[oo].ini.type == "ship" && Sprite.aerials[s].ini.type == "ship" &&
o[oo].position != "destroyed" && Sprite.aerials[s].position != "destroyed"
) {
Sprite.aerials[s].ini.health = 0;
o[oo].ini.health = 0;
}
if(Sprite.aerials[s] == player.sprite || o[oo] == player.sprite)
putStats();
if (Sprite.aerials[s] == player.sprite || o[oo] == player.sprite) putStats();
}
if(Sprite.aerials[s].ini.hasOwnProperty("health") && Sprite.aerials[s].ini.health < 1) {
if (Sprite.aerials[s].ini.hasOwnProperty("health") && Sprite.aerials[s].ini.health < 1) {
Sprite.aerials[s].position = "destroyed";
Sprite.aerials[s].open = false;
player.score = player.score + ((Sprite.aerials[s].ini.hasOwnProperty("points")) ? parseInt(Sprite.aerials[s].ini.points) * player.round : 0);
......@@ -341,24 +333,25 @@ var gamePlay = function() {
}
cycle();
}
if(player.sprite.ini.health < 1)
deathKnell();
if (player.sprite.ini.health < 1) deathKnell();
timer.events = [];
}
var scoreBoard = function() {
function scoreBoard() {
var firstRun = false;
var scoreObj = {
'alias' : user.alias,
'system' : system.name,
'shipName' : player.shipName,
'round' : player.round - 1,
'score' : player.score,
'when' : time()
alias: user.alias,
system: system.name,
shipName: player.shipName,
round: player.round - 1,
score: player.score,
when: time()
};
try {
jsonClient = new JSONClient(serverIni.host, serverIni.port);
var scores = jsonClient.read("STARTREK", "STARTREK.HIGHSCORES", 1);
if(scores === undefined) {
if (scores === undefined) {
firstRun = true;
scores = [scoreObj];
jsonClient.write("STARTREK", "STARTREK.HIGHSCORES", scores, 2);
}
......@@ -370,40 +363,28 @@ var scoreBoard = function() {
scoreFrame.open();
scoreFrame.center("High scores");
scoreFrame.putmsg("\r\n\r\n");
scoreFrame.putmsg(
format(
"%-30s%-30s%-10s%s\r\n\r\n",
"Player", "Ship", "Round", "Score"
),
LIGHTCYAN
);
scoreFrame.putmsg(format("%-30s%-30s%-10s%s\r\n\r\n", "Player", "Ship", "Round", "Score"), LIGHTCYAN);
var writeBack = false;
for(var s = 0; s < scores.length; s++) {
if(player.score > scores[s].score && !writeBack) {
for (var s = 0; s < scores.length; s++) {
if (player.score > scores[s].score && !writeBack) {
writeBack = true;
scores.splice(s, 0, scoreObj);
}
scoreFrame.putmsg(
format(
"%-30s%-30s%-10s%s\r\n",
scores[s].alias, scores[s].shipName, scores[s].round, scores[s].score
),
WHITE
);
scoreFrame.putmsg(format(
"%-30s%-30s%-10s%s\r\n",
scores[s].alias, scores[s].shipName, scores[s].round, scores[s].score
), WHITE);
}
if(!writeBack && scores.length < 18) {
if (!writeBack && scores.length < 18) {
writeBack = true;
scores.push(scoreObj);
scoreFrame.putmsg(
format(
"%-30s%-30s%-10s%s\r\n",
scores[s].alias, scores[s].shipName, scores[s].round, scores[s].score
),
WHITE
);
if (!firstRun) scores.push(scoreObj);
scoreFrame.putmsg(format(
"%-30s%-30s%-10s%s\r\n",
scores[s].alias, scores[s].shipName, scores[s].round, scores[s].score
), WHITE);
}
if(writeBack) {
while(scores.length > 18) {
if (writeBack) {
while (scores.length > 18) {
scores.pop();
}
jsonClient.write("STARTREK", "STARTREK.HIGHSCORES", scores, 2);
......@@ -417,14 +398,14 @@ var scoreBoard = function() {
console.getkey();
}
var main = function() {
function main() {
splash();
setup();
gamePlay();
scoreBoard();
}
var cleanUp = function() {
function cleanUp() {
frame.close();
console.clear();
bbs.sys_status = sysStatus;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment