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

New scoreboard, updated weapons, player can now choose and name their ship via...

New scoreboard, updated weapons, player can now choose and name their ship via a flashy rotating sprite ship chooser thingy dealio type thing and stuff.
parent a92b63a5
No related branches found
No related tags found
No related merge requests found
Showing
with 301 additions and 112 deletions
...@@ -4,11 +4,11 @@ bearings = n,ne,e,se,s,sw,w,nw ...@@ -4,11 +4,11 @@ bearings = n,ne,e,se,s,sw,w,nw
positions = normal,destroyed positions = normal,destroyed
movement = rotating movement = rotating
constantmotion = 1 constantmotion = 1
speed = .75 speed = .7
speedstep = .1 speedstep = .1
minimumspeed = .75 minimumspeed = .7
maximumspeed = .05 maximumspeed = .05
weapon = photonTorpedo weapon = photonTorpedo2
attackspeed = .5 attackspeed = .5
name = The Borg name = The Borg
type = ship type = ship
......
...@@ -4,11 +4,11 @@ bearings = n,ne,e,se,s,sw,w,nw ...@@ -4,11 +4,11 @@ bearings = n,ne,e,se,s,sw,w,nw
positions = normal,destroyed positions = normal,destroyed
movement = rotating movement = rotating
constantmotion = 1 constantmotion = 1
speed = .25 speed = .3
speedstep = .1 speedstep = .1
minimumspeed = .5 minimumspeed = .5
maximumspeed = .05 maximumspeed = .05
weapon = photonTorpedo weapon = photonTorpedo3
attackspeed = .5 attackspeed = .5
name = Cardassians name = Cardassians
type = ship type = ship
......
File added
width = 8
height = 4
bearings = n,ne,e,se,s,sw,w,nw
positions = normal,destroyed
movement = rotating
constantmotion = 1
speed = .5
speedstep = .05
minimumspeed = .6
maximumspeed = .2
weapon = photonTorpedo3
attackspeed = .2
type = ship
health = 9
\ No newline at end of file
width = 8
height = 4
bearings = n,ne,e,se,s,sw,w,nw
positions = normal,destroyed
movement = rotating
constantmotion = 1
speed = .6
speedstep = .1
minimumspeed = .7
maximumspeed = .3
weapon = photonTorpedo2
attackspeed = .3
type = ship
health = 11
\ No newline at end of file
...@@ -4,11 +4,11 @@ bearings = n,ne,e,se,s,sw,w,nw ...@@ -4,11 +4,11 @@ bearings = n,ne,e,se,s,sw,w,nw
positions = normal,destroyed positions = normal,destroyed
movement = rotating movement = rotating
constantmotion = 1 constantmotion = 1
speed = .2 speed = .3
speedstep = .1 speedstep = .1
minimumspeed = .2 minimumspeed = .2
maximumspeed = .05 maximumspeed = .05
weapon = photonTorpedo weapon = photonTorpedo1
attackspeed = .5 attackspeed = .5
name = Gorn name = Gorn
type = ship type = ship
......
                    {{                         {                                  {                            {{                              {                                                                          {     
\ No newline at end of file
...@@ -5,10 +5,10 @@ positions = normal,destroyed ...@@ -5,10 +5,10 @@ positions = normal,destroyed
movement = rotating movement = rotating
constantmotion = 1 constantmotion = 1
speed = .5 speed = .5
speedstep = .1 speedstep = .05
minimumspeed = .5 minimumspeed = .5
maximumspeed = .1 maximumspeed = .1
weapon = photonTorpedo weapon = photonTorpedo1
attackspeed = .3 attackspeed = .4
type = ship type = ship
health = 11 health = 7
\ No newline at end of file \ No newline at end of file
...@@ -8,7 +8,7 @@ speed = .8 ...@@ -8,7 +8,7 @@ speed = .8
speedstep = .1 speedstep = .1
minimumspeed = .8 minimumspeed = .8
maximumspeed = .05 maximumspeed = .05
weapon = photonTorpedo weapon = photonTorpedo2
attackspeed = .5 attackspeed = .5
name = Klingons name = Klingons
type = ship type = ship
......
...@@ -8,7 +8,7 @@ speed = 1 ...@@ -8,7 +8,7 @@ speed = 1
speedstep = .1 speedstep = .1
minimumspeed = 1 minimumspeed = 1
maximumspeed = .05 maximumspeed = .05
weapon = photonTorpedo weapon = photonTorpedo1
attackspeed = .7 attackspeed = .7
name = Pakleds name = Pakleds
type = ship type = ship
......
width = 1
height = 1
bearings = n,ne,e,se,s,sw,w,nw
positions = normal
movement = rotating
constantmotion = 1
speed = .03
range = 16
type = weapon
damage = 1
\ No newline at end of file
...@@ -6,4 +6,5 @@ movement = rotating ...@@ -6,4 +6,5 @@ movement = rotating
constantmotion = 1 constantmotion = 1
speed = .03 speed = .03
range = 20 range = 20
type = weapon type = weapon
\ No newline at end of file damage = 2
\ No newline at end of file
\ No newline at end of file
width = 1
height = 1
bearings = n,ne,e,se,s,sw,w,nw
positions = normal
movement = rotating
constantmotion = 1
speed = .02
range = 24
type = weapon
damage = 3
\ No newline at end of file
...@@ -4,11 +4,11 @@ bearings = n,ne,e,se,s,sw,w,nw ...@@ -4,11 +4,11 @@ bearings = n,ne,e,se,s,sw,w,nw
positions = normal,destroyed positions = normal,destroyed
movement = rotating movement = rotating
constantmotion = 1 constantmotion = 1
speed = .5 speed = .3
speedstep = .1 speedstep = .1
minimumspeed = .5 minimumspeed = .5
maximumspeed = .05 maximumspeed = .05
weapon = photonTorpedo weapon = photonTorpedo3
attackspeed = .5 attackspeed = .5
name = Romulans name = Romulans
type = ship type = ship
......
...@@ -2,13 +2,18 @@ load("sbbsdefs.js"); ...@@ -2,13 +2,18 @@ load("sbbsdefs.js");
load("json-client.js"); load("json-client.js");
load("event-timer.js"); load("event-timer.js");
load("frame.js"); load("frame.js");
load("layout.js");
load("sprite.js"); load("sprite.js");
var maxEnemies = 5;
var sysStatus, userInput, player, timer, waveTimer, jsonClient, serverIni; var sysStatus, userInput, player, timer, waveTimer, jsonClient, serverIni;
var frame, splashFrame, fieldFrame, statusFrame, clockFrame, clockSubFrame, uhOhFrame, scoreFrame, helpFrame; var frame, fieldFrame, statusFrame, clockFrame, clockSubFrame, uhOhFrame;
var player = { var player = {
round : 0, round : 0,
score : 0, score : 0,
shipName : "",
sprite : {} sprite : {}
}; };
var enemySprites = []; var enemySprites = [];
...@@ -20,6 +25,158 @@ var enemies = [ ...@@ -20,6 +25,158 @@ var enemies = [
"gorn", "gorn",
"pakled" "pakled"
]; ];
var ships = [
"galaxy",
"intrepid",
"defiant"
];
var cycle = function() {
Sprite.cycle();
timer.cycle();
if(frame.cycle())
console.gotoxy(console.screen_columns, console.screen_rows);
}
var splash = function() {
var splashFrame = new Frame(1, 1, 80, 24, 0, frame);
splashFrame.load(js.exec_dir + "startrek.bin", 80, 24);
splashFrame.top();
splashFrame.open();
cycle();
console.getkey();
splashFrame.close();
splashFrame.delete();
}
var init = function() {
js.branch_limit = 0;
sysStatus = bbs.sys_status;
bbs.sys_status|=SS_MOFF;
KEY_WEAPON = " ";
frame = new Frame(1, 1, 80, 24, 0);
fieldFrame = new Frame(1, 1, 80, 24, 0, frame);
statusFrame = new Frame(1, 24, 66, 1, BG_BLUE|WHITE, frame);
clockFrame = new Frame(67, 24, 14, 1, BG_BLUE|WHITE, frame);
clockSubFrame = new Frame(78, 24, 2, 1, BG_BLUE|WHITE, clockFrame);
uhOhFrame = new Frame(1, 12, 80, 1, 0, frame);
uhOhFrame.transparent = true;
fieldFrame.load(js.exec_dir + "starfield.bin", 80, 24);
timer = new Timer();
var f = new File(js.exec_dir + "server.ini");
f.open("r");
serverIni = f.iniGetObject();
f.close();
frame.open();
statusFrame.top();
frame.draw();
}
var removeShip = function(s) {
Sprite.aerials[s].remove();
Sprite.aerials[s].frame.delete();
}
var rotateSprites = function(sprites) {
for(var s in sprites)
sprites[s].turn("cw");
}
var ucfl = function(str) {
str = str[0].toUpperCase() + str.substr(1);
return str;
}
var dots = function(d) {
var str = "";
for(var dd = 0; dd < d; dd++)
str += ascii(254);
return str;
}
var setup = function() {
var setupFrame = new Frame(1, 1, 80, 24, 0, frame);
setupFrame.load(js.exec_dir + "starfield.bin", 80, 24);
var layout = new Layout(setupFrame);
var shipSprites = [];
var viewWidth = 13;
var x = Math.floor((80 - (ships.length * viewWidth)) / 2);
for(var s = 0; s < ships.length; s++) {
var view = layout.addView(ucfl(ships[s]), x, 4, viewWidth - 1, 16);
view.show_tabs = false;
var tab = view.addTab("frame", "frame");
var sprite = new Sprite.Aerial(ships[s], tab.frame, tab.frame.x, tab.frame.y, 'n');
var weapon = new Sprite.Aerial(sprite.ini.weapon, tab.frame, tab.frame.x, tab.frame.y, 'n');
sprite.ini.constantmotion = 0;
shipSprites.push(sprite);
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
);
x = x + viewWidth;
}
timer.addEvent(1000, true, rotateSprites, [shipSprites]);
layout.open();
setupFrame.open();
setupFrame.gotoxy(1, 2);
setupFrame.center("What class of ship do you want to command, Captain " + ucfl(user.alias) + "?", WHITE);
setupFrame.draw();
var userInput = "";
setupFrame.top();
while(ascii(userInput) != 13) {
userInput = console.inkey(K_NONE, 5);
if(userInput == KEY_LEFT || userInput == KEY_RIGHT)
userInput = "\x09";
layout.getcmd(userInput);
layout.cycle();
cycle();
}
setupFrame.gotoxy(1, 21);
setupFrame.center("What is the name of your " + layout.current.title + "-class starship?", WHITE);
cycle();
while(player.shipName == "") {
console.gotoxy(25, 23);
player.shipName = console.getstr("USS ", 30, K_LINE|K_EDIT);
}
for(var s in Sprite.aerials)
removeShip(s);
player.sprite = new Sprite.Aerial(layout.current.title.toLowerCase(), fieldFrame, 40, 10, 'n', 'normal');
layout.close();
setupFrame.close();
setupFrame.delete();
frame.invalidate();
timer.events = [];
}
var showHelp = function() {
var helpFrame = new Frame(8, 4, 64, 16, 0, frame);
helpFrame.load(js.exec_dir + "help.bin", 64, 16);
helpFrame.top();
helpFrame.open();
cycle();
console.getkey();
helpFrame.close();
helpFrame.delete();
}
var checkScreenEdge = function(sprite) { var checkScreenEdge = function(sprite) {
if(sprite.x < -3) if(sprite.x < -3)
...@@ -46,7 +203,8 @@ var putEnemy = function(re) { ...@@ -46,7 +203,8 @@ var putEnemy = function(re) {
var spawnEnemies = function() { var spawnEnemies = function() {
var re = Math.floor(Math.random() * enemies.length); var re = Math.floor(Math.random() * enemies.length);
for(var x = 0; x < player.round; x++) { var roundMax = Math.floor((player.round + 1) / 2);
for(var x = 0; x < ((roundMax > maxEnemies) ? maxEnemies : roundMax); x++) {
while(!putEnemy(re)) { while(!putEnemy(re)) {
} }
} }
...@@ -61,18 +219,21 @@ var spawnEnemies = function() { ...@@ -61,18 +219,21 @@ var spawnEnemies = function() {
putStats(); putStats();
uhOhFrame.top(); uhOhFrame.top();
statusFrame.top(); statusFrame.top();
timer.addEvent(250, 12, cycleWarning, [Sprite.aerials[Sprite.aerials.length - 1].ini.name]); timer.addEvent(250, 12, cycleWarning, ["Oh no! " + Sprite.aerials[Sprite.aerials.length - 1].ini.name + "!"]);
timer.addEvent(3000, false, removeWarning); timer.addEvent(3000, false, removeWarning);
if(player.round % 5 == 0)
waveTimer.interval = waveTimer.interval - 5000;
} }
var removeShip = function(s) { var countdown = function() {
Sprite.aerials[s].remove(); clockSubFrame.clear();
clockSubFrame.putmsg(parseInt(waveTimer.nextrun * .001));
} }
var cycleWarning = function(enemy) { var cycleWarning = function(warning) {
var c = Math.floor(Math.random() * 15) + 1; var c = Math.floor(Math.random() * 15) + 1;
uhOhFrame.clear(); uhOhFrame.clear();
uhOhFrame.center("Oh no! " + enemy + "!", c); uhOhFrame.center(warning, c);
} }
var removeWarning = function() { var removeWarning = function() {
...@@ -90,66 +251,28 @@ var putStats = function() { ...@@ -90,66 +251,28 @@ var putStats = function() {
); );
} }
var countdown = function() { var deathKnell = function() {
clockSubFrame.clear(); uhOhFrame.top();
clockSubFrame.putmsg(parseInt(waveTimer.nextrun * .001)); for(var n = 0; n < 20; n++) {
} cycleWarning("You done goofed!");
cycle();
var init = function() { mswait(200);
js.branch_limit = 0; }
sysStatus = bbs.sys_status; while(console.input_buffer_level > 0) {
bbs.sys_status|=SS_MOFF; console.inkey();
KEY_WEAPON = " "; }
frame = new Frame(1, 1, 80, 24, 0);
splashFrame = new Frame(1, 1, 80, 24, 0, frame);
fieldFrame = new Frame(1, 1, 80, 24, 0, frame);
statusFrame = new Frame(1, 24, 66, 1, BG_BLUE|WHITE, frame);
clockFrame = new Frame(67, 24, 14, 1, BG_BLUE|WHITE, frame);
clockSubFrame = new Frame(78, 24, 2, 1, BG_BLUE|WHITE, clockFrame);
uhOhFrame = new Frame(1, 12, 80, 1, 0, frame);
scoreFrame = new Frame(1, 1, 80, 24, BG_BLACK|WHITE, frame);
helpFrame = new Frame(8, 4, 64, 16, 0, frame);
uhOhFrame.transparent = true;
splashFrame.load(js.exec_dir + "startrek.bin", 80, 24);
fieldFrame.load(js.exec_dir + "starfield.bin", 80, 24);
helpFrame.load(js.exec_dir + "help.bin", 64, 16);
player.sprite = new Sprite.Aerial("enterprise", fieldFrame, 40, 10, 'n', 'normal');
timer = new Timer();
var f = new File(js.exec_dir + "server.ini");
f.open("r");
serverIni = f.iniGetObject();
f.close();
frame.open();
scoreFrame.bottom();
helpFrame.bottom();
statusFrame.top();
splashFrame.top();
frame.draw();
}
var showHelp = function() {
helpFrame.top();
frame.cycle();
console.getkey();
helpFrame.bottom();
} }
var gamePlay = function() { var gamePlay = function() {
player.round = 1; player.round = 1;
timer.addEvent(5000, 1, spawnEnemies); player.sprite.frame.draw();
timer.addEvent(2000, 1, spawnEnemies);
waveTimer = timer.addEvent(30000, true, spawnEnemies); waveTimer = timer.addEvent(30000, true, spawnEnemies);
putStats(); putStats();
statusFrame.top();
while(!js.terminated) { while(!js.terminated) {
if(player.sprite.ini.health < 1) { if(player.sprite.ini.health < 1)
deathKnell();
break; break;
}
userInput = console.inkey(K_NONE, 5); userInput = console.inkey(K_NONE, 5);
if(ascii(userInput) == 27) if(ascii(userInput) == 27)
break; break;
...@@ -185,7 +308,7 @@ var gamePlay = function() { ...@@ -185,7 +308,7 @@ var gamePlay = function() {
&& &&
(o[oo].owner != Sprite.aerials[s]) (o[oo].owner != Sprite.aerials[s])
) { ) {
Sprite.aerials[s].ini.health = Sprite.aerials[s].ini.health - 1; Sprite.aerials[s].ini.health = Sprite.aerials[s].ini.health - parseInt(o[oo].ini.damage);
o[oo].remove(); o[oo].remove();
} else if( } else if(
o[oo].ini.type == "ship" && Sprite.aerials[s].ini.type == "ship" o[oo].ini.type == "ship" && Sprite.aerials[s].ini.type == "ship"
...@@ -206,80 +329,87 @@ var gamePlay = function() { ...@@ -206,80 +329,87 @@ var gamePlay = function() {
putStats(); putStats();
} }
} }
timer.cycle(); cycle();
Sprite.cycle();
if(frame.cycle())
console.gotoxy(80, 24);
}
waveTimer.abort = true;
}
var deathKnell = function() {
uhOhFrame.top();
for(var n = 0; n < 20; n++) {
cycleWarning("You done goofed");
frame.cycle();
mswait(200);
} }
if(player.sprite.ini.health < 1)
deathKnell();
timer.events = [];
} }
var scoreBoard = function() { var scoreBoard = function() {
var scoreObj = { var scoreObj = {
'alias' : user.alias, 'alias' : user.alias,
'system' : system.name, 'system' : system.name,
'shipName' : player.shipName,
'round' : player.round - 1, 'round' : player.round - 1,
'score' : player.score, 'score' : player.score,
'when' : time() 'when' : time()
}; };
try { try {
jsonClient = new JSONClient(serverIni.host, serverIni.port); jsonClient = new JSONClient(serverIni.host, serverIni.port);
var scores = jsonClient.read("STARTREK", "STARTREK.SCORES", 1); var scores = jsonClient.read("STARTREK", "STARTREK.HIGHSCORES", 1);
if(scores === undefined) { if(scores === undefined) {
scores = []; scores = [scoreObj];
jsonClient.write("STARTREK", "STARTREK.SCORES", scores, 2); jsonClient.write("STARTREK", "STARTREK.HIGHSCORES", scores, 2);
} }
jsonClient.push("STARTREK", "STARTREK.SCORES", scoreObj, 2);
jsonClient.disconnect();
} catch(err) { } catch(err) {
log(LOG_ERR, "JSON client error: " + err); log(LOG_ERR, "JSON client error: " + err);
return false; return false;
} }
scoreFrame.center("Recent scores"); var scoreFrame = new Frame(1, 1, 80, 24, BG_BLACK|WHITE, frame);
scoreFrame.open();
scoreFrame.center("High scores");
scoreFrame.putmsg("\r\n\r\n"); scoreFrame.putmsg("\r\n\r\n");
scoreFrame.putmsg( scoreFrame.putmsg(
format( format(
"%-30s%-30s%-10s%s\r\n\r\n", "%-30s%-30s%-10s%s\r\n\r\n",
"Player", "System", "Round", "Score" "Player", "Ship", "Round", "Score"
), ),
LIGHTCYAN LIGHTCYAN
); );
scores.push(scoreObj); var writeBack = false;
shownUsers = []; for(var s = 0; s < scores.length; s++) {
for(var s = scores.length - 1; s > (scores.length >= 19) ? scores.length - 20 : 0; s = s - 1) { if(player.score > scores[s].score && !writeBack) {
if(shownUsers.indexOf(scores[s].alias) >= 0) writeBack = true;
continue; scores.splice(s, 0, scoreObj);
shownUsers.push(scores[s].alias); }
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) {
writeBack = true;
scores.push(scoreObj);
scoreFrame.putmsg( scoreFrame.putmsg(
format( format(
"%-30s%-30s%-10s%s\r\n", "%-30s%-30s%-10s%s\r\n",
scores[s].alias, scores[s].system, scores[s].round, scores[s].score scores[s].alias, scores[s].shipName, scores[s].round, scores[s].score
) ),
WHITE
); );
} }
if(writeBack) {
while(scores.length > 18) {
scores.pop();
}
jsonClient.write("STARTREK", "STARTREK.HIGHSCORES", scores, 2);
}
jsonClient.disconnect();
scoreFrame.crlf(); scoreFrame.crlf();
scoreFrame.center("<Press any key>", LIGHTRED); scoreFrame.center("<Press any key>", LIGHTRED);
scoreFrame.top(); scoreFrame.top();
frame.cycle(); cycle();
mswait(1000);
while(console.input_buffer_level > 0) {
console.inkey();
}
console.getkey(); console.getkey();
} }
var main = function() { var main = function() {
console.getkey(); splash();
splashFrame.close(); setup();
gamePlay(); gamePlay();
scoreBoard(); scoreBoard();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment