Permalink
Browse files

Improved the town shop menu, it now displays if you are buying or sel…

…ling items, the cost of the item, how much gold you have, and a description of the item. Finally it also supports scrolling for when there are more items then can be fit on the screen.
  • Loading branch information...
1 parent edc3513 commit ce5eac580a0fb7f99085431d1566c580342a268b @SergeDavid committed Mar 25, 2012
Showing with 69 additions and 34 deletions.
  1. +4 −5 DebugHandler.js
  2. +19 −8 Item.js
  3. +46 −21 TownEngine.js
View
@@ -2,19 +2,18 @@
*
* @arthor Serge-David */
-//@Deprecated TODO: Currently only using this for jumping straight into specific conditions during startup, remove when done.
-function DebugStartup() {
- /*
+function DebugStartup() {
+ /*
newGame();
map[loc.y][loc.x] = tile.Town;
openTown();
hero.gold = 1000; */
};
-function debugMsg(text) {
+function debugMessage(text) {
document.getElementById("debug").innerHTML = text;
}
-function debugCont(text) {
+function debugMessageAddon(text) {
document.getElementById("debug").innerHTML += "\n" +text;
}
View
27 Item.js
@@ -15,7 +15,7 @@ var itemInfo = {
var items = {//TODO: Work on this so that I can handle many items such as drain life, potion, magic spells, equipment, and quest items.
0 : {
name : "Potion",//keep
- desc : "An item that heals the user for 50 health.",//keep
+ desc : "Restores 50 health to the user.",//keep
target : itemInfo.Caster,//keep
type : itemInfo.Item,//Is it a helm, armor, weapon, useable item, magic spell, quest item (key).
cost : 10,//How much gold it takes to buy
@@ -25,7 +25,7 @@ var items = {//TODO: Work on this so that I can handle many items such as drain
},
1 : {
name : "H-Potion",
- desc : "",
+ desc : "Restores 100 health to the user.",
target : itemInfo.Caster,
type : itemInfo.Item,
cost : 40,
@@ -35,7 +35,7 @@ var items = {//TODO: Work on this so that I can handle many items such as drain
},
2 : {
name : "M-Potion",
- desc : "",
+ desc : "Restores Cake to the user.",
target : itemInfo.Caster,
type : itemInfo.Item,
cost : 80,
@@ -45,7 +45,7 @@ var items = {//TODO: Work on this so that I can handle many items such as drain
},
3 : {
name : "Elixar",
- desc : "An item that restores 25 mana to the user.",
+ desc : "Replenishes 25 mana when used.",
target : itemInfo.Caster,
type : itemInfo.Item,
cost : 25,
@@ -55,7 +55,7 @@ var items = {//TODO: Work on this so that I can handle many items such as drain
},
4 : {
name : "H-Elixar",
- desc : "An item that restores 25 mana to the user.",
+ desc : "Replenishes 26 mana when used.",
target : itemInfo.Caster,
type : itemInfo.Item,
cost : 25,
@@ -65,7 +65,7 @@ var items = {//TODO: Work on this so that I can handle many items such as drain
},
5 : {
name : "M-Elixar",
- desc : "An item that restores 25 mana to the user.",
+ desc : "Replenishes 28 mana when used.",
target : itemInfo.Caster,
type : itemInfo.Item,
cost : 25,
@@ -75,20 +75,31 @@ var items = {//TODO: Work on this so that I can handle many items such as drain
},
6 : {
name : "Dagger",
- desc : "An item that restores 25 mana to the user.",
+ desc : "Side Effects: Pointy end may cause external bleeding.",
target : itemInfo.Enemy,//Not needed for
type : itemInfo.Weapon,
cost : 25,
sell : 15,
total : 0,
effect : {damage : 5}
},
+ 7 : {
+ name : "Sword",
+ desc : "Side Effects: Pointy end may cause external bleeding.",
+ target : itemInfo.Enemy,//Not needed for
+ type : itemInfo.Weapon,
+ cost : 25,
+ sell : 15,
+ total : 0,
+ effect : {damage : 5}
+ }
}
+//TODO: See about using these arrays instead of populating an array every time I need to use one.
var shopItem;//Potions, elixars, antidotes, etc.
var shopWeapon;//Daggers, Swords, Bullwhips, etc.
var shopArmor;//Helmets, Shields, etc. (2 slots, head armor and body armor)
-function itemPopulate(type) {//TODO: All of this crap isn't working ARRRGH!!!!
+function itemPopulate(type) {
var array = new Array();
var a = 0;
for (var i in items) {
View
@@ -11,6 +11,8 @@
var selling = false;//A flag to flip selling and buying
var itemList;//A compiled list of every item with the type the particular shop is selling.
var itemLength;//How many items are in the itemList, used to make rendering it a tiny bit faster.
+var itemListTop = 0;//This is the id of the top most item on the list.
+var itemListTotal = 7;//How many items are shown at once max.
function handleTown() {
if (menuState > 0) {
@@ -47,14 +49,25 @@ function handleStore() {
selling = !selling;
break;
case input.Up:
- if (menuPointer > 0) {menuPointer--;}
+ if (menuPointer > 0) {
+ menuPointer--;
+ if (itemListTop > 0 && itemListTop >= menuPointer) {
+ itemListTop--;
+ }
+ }
break;
case input.Down:
- if (menuPointer < itemLength - 1) {menuPointer++;}
+ if (menuPointer < itemLength - 1) {
+ menuPointer++;
+ if (itemListTop + itemListTotal < itemList.length && itemListTop < menuPointer - 5) {
+ itemListTop++;
+ }
+ }
break;
case input.Cancel:
- menuPointer = 0;//TODO: Base it on which menu is up currently displayed.
+ //menuPointer = menuState-1;
menuState = 0;
+ itemListTop = 0;
break;
case input.Enter:
if (!selling) {itemBuy(itemList[menuPointer]);}
@@ -66,7 +79,6 @@ function handleStore() {
function openTown() {
if (map[loc.y][loc.x] == tile.Town) {
gameState = state.Town;
- //itemList = new Array(items.Potion, items[1], items[2], items[3]);
}
};
@@ -79,7 +91,7 @@ function renderTown() {
ctx.fillStyle = color.Text;
ctx.font = font.Large;
if (menuState > 0) {
- renderStore(0);
+ renderStore(menuState);
}
else {
var names = new Array("Items","Weapons","Armors","Helmets");
@@ -97,29 +109,42 @@ function renderTown() {
function renderStore(type) {
var name;
switch (type) {
- case 0:
+ case 2: name = "Smithery"; break;
+ case 3: name = "Armor Guild"; break;
+ case 4: name = "Mad Hatter"; break;
default: name = "Apothecary"; break;
}
ctx.fillStyle = color.MenuBorder;
- ctx.fillRect(20, 50, 360, 6);
+ ctx.fillRect(20, 48, 360, 3);
+ ctx.fillRect(20, 72, 360, 4);
+ ctx.fillRect(224, 72, 4, 210);
+ ctx.fillRect(328, 72, 4, 210);
+ //TODO: Add seperators for the different parts Name, Cost, Total
+
ctx.fillStyle = color.Text;
ctx.font = font.Large;
- ctx.fillText(name,40,24);
- ctx.fillText("gold " + hero.gold, 200, 24);
+ ctx.fillText(name,30,22);
+
ctx.font = font.Small;
+ ctx.fillText("Gold " + hero.gold, 270, 30);
+ if (selling) {ctx.fillText("Selling", 200, 30);}
+ else {ctx.fillText("Buying", 200, 30);}
+ ctx.fillText(itemList[menuPointer].desc, 24, 55);
+
+ ctx.fillText("Name", 30, 84);
+ ctx.fillText("Cost", 236, 84);
+ ctx.fillText("Total", 346, 84);
+
//TODO: Setup for allowing scrolling based on the menuPointer location in the length variable.
- for (var i = 0; i < itemLength; i++) {
- if (i == menuPointer) {
- ctx.fillStyle = color.MenuSelect;
- ctx.fillRect(28, 68+(20*i), 60, 20);
- }
- else {
- ctx.fillStyle = color.MenuOption;
- ctx.fillRect(28, 68+(20*i), 60, 20);
- }
+ //7 items total, it scrolls when you reach the 2nd from the top or bottom
+ for (var i = 0; i < itemLength && i < itemListTotal; i++) {
+ if (i+itemListTop == menuPointer) {ctx.fillStyle = color.MenuSelect;}
+ else {ctx.fillStyle = color.MenuOption;}
+ ctx.fillRect(26, 104+(24*i), 192, 22);
+
ctx.fillStyle = color.Text;
- ctx.fillText(itemList[i].name, 30, 70+(20*i));
- ctx.fillText("Total : " + itemList[i].total, 200, 70+(20*i));
+ ctx.fillText(itemList[i+itemListTop].name, 30, 108+(24*i));
+ ctx.fillText("$ " + itemList[i+itemListTop].cost, 236, 108+(24*i));
+ ctx.fillText("x " + itemList[i+itemListTop].total, 346, 108+(24*i));
}
-
}

0 comments on commit ce5eac5

Please sign in to comment.