Added Cost
This commit is contained in:
parent
ae892621db
commit
729b5a3f81
21
css/main.css
21
css/main.css
|
|
@ -71,6 +71,27 @@ body {
|
||||||
border-color: gray;
|
border-color: gray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#money {
|
||||||
|
position: fixed;
|
||||||
|
font-family: 'Electrolize', sans-serif;
|
||||||
|
font-size: 22px;
|
||||||
|
width: 1200;
|
||||||
|
height: 42px;
|
||||||
|
line-height: 42px;
|
||||||
|
text-align: center;
|
||||||
|
background-image: url(../images/moneybg.png);
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
-webkit-touch-callout: none; /* iOS Safari */
|
||||||
|
-webkit-user-select: none; /* Safari */
|
||||||
|
-khtml-user-select: none; /* Konqueror HTML */
|
||||||
|
-moz-user-select: none; /* Firefox */
|
||||||
|
-ms-user-select: none; /* Internet Explorer/Edge */
|
||||||
|
user-select: none; /* Non-prefixed version, currently
|
||||||
|
supported by Chrome and Opera */
|
||||||
|
}
|
||||||
|
|
||||||
.buildtile {
|
.buildtile {
|
||||||
width: 48;
|
width: 48;
|
||||||
height: 48;
|
height: 48;
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 572 B |
Binary file not shown.
|
After Width: | Height: | Size: 439 B |
|
|
@ -32,9 +32,11 @@
|
||||||
</div>
|
</div>
|
||||||
<div id="tooltip">
|
<div id="tooltip">
|
||||||
<span>
|
<span>
|
||||||
Example
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
<span id="money">
|
||||||
|
??? Dollar
|
||||||
|
</span>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,32 @@ class Tile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pay() {
|
||||||
|
var items = 0
|
||||||
|
for (var i = 0; i < this.cost.length; i++) {
|
||||||
|
if (this.cost[i].id == 0) {
|
||||||
|
if (this.cost[i].count <= money) {
|
||||||
|
items++
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (inventory.countOf(this.cost[i].id) >= this.cost[i].count) {
|
||||||
|
items++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (items == this.cost.length) {
|
||||||
|
for (var i = 0; i < this.cost.length; i++) {
|
||||||
|
if (this.cost[i].id == 0) {
|
||||||
|
money -= this.cost[i].count
|
||||||
|
} else {
|
||||||
|
inventory.take(this.cost[i].id, this.cost[i].count, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
unloadImages() {
|
unloadImages() {
|
||||||
this.images = {
|
this.images = {
|
||||||
"0": [],
|
"0": [],
|
||||||
|
|
@ -99,6 +125,7 @@ class Inventory {
|
||||||
for (var j = 0; j < count; j++) {
|
for (var j = 0; j < count; j++) {
|
||||||
for (var i = 0; i < this.items.length; i++) {
|
for (var i = 0; i < this.items.length; i++) {
|
||||||
if (this.items[i].id == id) {
|
if (this.items[i].id == id) {
|
||||||
|
if (factory != null)
|
||||||
factory.deleteItem(this.items[i])
|
factory.deleteItem(this.items[i])
|
||||||
this.items.splice(i, 1)
|
this.items.splice(i, 1)
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
23
js/game.js
23
js/game.js
|
|
@ -1,5 +1,6 @@
|
||||||
var factorys = []
|
var factorys = []
|
||||||
var inventory = {}
|
var inventory = {}
|
||||||
|
var money = 100
|
||||||
|
|
||||||
var items = []
|
var items = []
|
||||||
|
|
||||||
|
|
@ -163,6 +164,7 @@ function render() {
|
||||||
} else {
|
} else {
|
||||||
drawInventory(inventory, lang["player"])
|
drawInventory(inventory, lang["player"])
|
||||||
}
|
}
|
||||||
|
$('#money').text(money + " " + lang.items[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
function getItemFormId(id) {
|
function getItemFormId(id) {
|
||||||
|
|
@ -259,11 +261,26 @@ function drawInfoBar() {
|
||||||
$('#infoDesc h1').text("")
|
$('#infoDesc h1').text("")
|
||||||
$('#infoDesc p').text("")
|
$('#infoDesc p').text("")
|
||||||
}
|
}
|
||||||
if(selectedTile.maxwork!=0){
|
if (selectedTile.maxwork != 0 && mode != "selectbuilding" && mode != "building") {
|
||||||
$('#infoDesc p').css("height", 154)
|
$('#infoDesc p').css("height", 154)
|
||||||
infoCtx.fillStyle = "green";
|
infoCtx.fillStyle = "green";
|
||||||
infoCtx.fillRect(0, 228, 432*(selectedTile.currentwork/selectedTile.maxwork), 12)
|
infoCtx.fillRect(0, 228, 432 * (selectedTile.currentwork / selectedTile.maxwork), 12)
|
||||||
}else{
|
} else {
|
||||||
$('#infoDesc p').css("height", 166)
|
$('#infoDesc p').css("height", 166)
|
||||||
}
|
}
|
||||||
|
if (mode == "selectbuilding" || mode == "building") {
|
||||||
|
if (selectedTile != 0) {
|
||||||
|
infoCtx.textAlign = "center"
|
||||||
|
infoCtx.font = "18px Electrolize"
|
||||||
|
infoCtx.fillStyle = "black";
|
||||||
|
infoCtx.fillText(lang.cost, 336, 66)
|
||||||
|
infoCtx.textAlign = "start"
|
||||||
|
for (var i = 0; i < selectedTile.cost.length; i++) {
|
||||||
|
if (selectedTile.cost[i].id == 0)
|
||||||
|
infoCtx.fillText(selectedTile.cost[i].count + " " + lang.items[selectedTile.cost[i].id], 246, 86 + 20 * i)
|
||||||
|
else
|
||||||
|
infoCtx.fillText(selectedTile.cost[i].count + "x " + lang.items[selectedTile.cost[i].id], 246, 86 + 20 * i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"items": [{
|
"items": [{
|
||||||
"id": 0,
|
"id": 0,
|
||||||
"name": "coal"
|
"name": "money"
|
||||||
},{
|
},{
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"name": "log"
|
"name": "log"
|
||||||
|
|
|
||||||
23
js/tiles.js
23
js/tiles.js
|
|
@ -7,6 +7,10 @@ class Conveyorbelt extends Tile {
|
||||||
super(x, y, factory)
|
super(x, y, factory)
|
||||||
this.name = "conveyorbelt"
|
this.name = "conveyorbelt"
|
||||||
this.hasNoInventory = true
|
this.hasNoInventory = true
|
||||||
|
this.cost = [{
|
||||||
|
"id": 0,
|
||||||
|
"count": 20
|
||||||
|
}]
|
||||||
this.texture = {
|
this.texture = {
|
||||||
"0": ["conveyorbelt00", "conveyorbelt01", "conveyorbelt02", "conveyorbelt03", "conveyorbelt04", "conveyorbelt05", "conveyorbelt06"],
|
"0": ["conveyorbelt00", "conveyorbelt01", "conveyorbelt02", "conveyorbelt03", "conveyorbelt04", "conveyorbelt05", "conveyorbelt06"],
|
||||||
"1": []
|
"1": []
|
||||||
|
|
@ -23,6 +27,10 @@ class Treefarm extends Tile {
|
||||||
this.currentwork = 0
|
this.currentwork = 0
|
||||||
this.name = "treefarm"
|
this.name = "treefarm"
|
||||||
this.hasNoInventory = true
|
this.hasNoInventory = true
|
||||||
|
this.cost = [{
|
||||||
|
"id": 0,
|
||||||
|
"count": 30
|
||||||
|
}]
|
||||||
this.texture = {
|
this.texture = {
|
||||||
"0": [],
|
"0": [],
|
||||||
"1": ["treefarm10", "treefarm10", "treefarm10", "treefarm11", "treefarm11", "treefarm11", "treefarm12", "treefarm12", "treefarm12", "treefarm13", "treefarm13", "treefarm13", "treefarm14", "treefarm14", "treefarm14", "treefarm15", "treefarm15", "treefarm15"]
|
"1": ["treefarm10", "treefarm10", "treefarm10", "treefarm11", "treefarm11", "treefarm11", "treefarm12", "treefarm12", "treefarm12", "treefarm13", "treefarm13", "treefarm13", "treefarm14", "treefarm14", "treefarm14", "treefarm15", "treefarm15", "treefarm15"]
|
||||||
|
|
@ -47,6 +55,15 @@ class Saw extends Tile {
|
||||||
this.maxwork = 96
|
this.maxwork = 96
|
||||||
this.currentwork = 0
|
this.currentwork = 0
|
||||||
this.name = "saw"
|
this.name = "saw"
|
||||||
|
this.cost = [{
|
||||||
|
"id": 0,
|
||||||
|
"count": 50
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"count": 50
|
||||||
|
}
|
||||||
|
]
|
||||||
this.texture = {
|
this.texture = {
|
||||||
"0": [],
|
"0": [],
|
||||||
"1": ["saw10", "saw10", "saw10", "saw10", "saw11", "saw11", "saw11", "saw11", "saw12", "saw12", "saw12", "saw12", "saw13", "saw13", "saw13", "saw13"]
|
"1": ["saw10", "saw10", "saw10", "saw10", "saw11", "saw11", "saw11", "saw11", "saw12", "saw12", "saw12", "saw12", "saw13", "saw13", "saw13", "saw13"]
|
||||||
|
|
@ -59,7 +76,7 @@ class Saw extends Tile {
|
||||||
var requieredCount = 5
|
var requieredCount = 5
|
||||||
if (this.input.countOf(1) >= requieredCount) {
|
if (this.input.countOf(1) >= requieredCount) {
|
||||||
if (this.currentwork == 96) {
|
if (this.currentwork == 96) {
|
||||||
this.input.take(1, requieredCount,this.factory)
|
this.input.take(1, requieredCount, this.factory)
|
||||||
var item = new Item(2, this.x * 48, this.y * 48)
|
var item = new Item(2, this.x * 48, this.y * 48)
|
||||||
this.factory.items.push(item)
|
this.factory.items.push(item)
|
||||||
item.setDFromDirection(this.direction)
|
item.setDFromDirection(this.direction)
|
||||||
|
|
@ -79,6 +96,10 @@ class Collector extends Tile {
|
||||||
super(x, y, factory)
|
super(x, y, factory)
|
||||||
this.name = "collector"
|
this.name = "collector"
|
||||||
this.hasNoInventory = true
|
this.hasNoInventory = true
|
||||||
|
this.cost = [{
|
||||||
|
"id": 0,
|
||||||
|
"count": 50
|
||||||
|
}]
|
||||||
this.texture = {
|
this.texture = {
|
||||||
"0": [],
|
"0": [],
|
||||||
"1": ["collector10"]
|
"1": ["collector10"]
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,8 @@ function style() {
|
||||||
$('#infoDesc').css('margin-left', infoMarginLeft + 5)
|
$('#infoDesc').css('margin-left', infoMarginLeft + 5)
|
||||||
$('#itemcount').css('margin-top', itemCountMarginTop)
|
$('#itemcount').css('margin-top', itemCountMarginTop)
|
||||||
$('#itemcount').css('margin-left', screenMarginLeft)
|
$('#itemcount').css('margin-left', screenMarginLeft)
|
||||||
|
$('#money').css('margin-top', itemCountMarginTop - 42)
|
||||||
|
$('#money').css('margin-left', screenMarginLeft + 3)
|
||||||
screenleftpos = screenMarginLeft
|
screenleftpos = screenMarginLeft
|
||||||
screentoppos = screenMarginTop
|
screentoppos = screenMarginTop
|
||||||
infoleftpos = infoMarginLeft
|
infoleftpos = infoMarginLeft
|
||||||
|
|
@ -128,6 +130,7 @@ function onDocumentMouseMove(event) {
|
||||||
}
|
}
|
||||||
if (mousedown && mode == "build") {
|
if (mousedown && mode == "build") {
|
||||||
if (factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] == 0) {
|
if (factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] == 0) {
|
||||||
|
if (new toBuild().pay())
|
||||||
factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] = new toBuild(cursorScreenX, cursorScreenY, factorys[currentFactory])
|
factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] = new toBuild(cursorScreenX, cursorScreenY, factorys[currentFactory])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -253,6 +256,7 @@ function buildEvents() {
|
||||||
}
|
}
|
||||||
if (mode == "build") {
|
if (mode == "build") {
|
||||||
if (factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] == 0) {
|
if (factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] == 0) {
|
||||||
|
if (new toBuild().pay())
|
||||||
factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] = new toBuild(cursorScreenX, cursorScreenY, factorys[currentFactory])
|
factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] = new toBuild(cursorScreenX, cursorScreenY, factorys[currentFactory])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,10 @@
|
||||||
"description": "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."
|
"description": "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"items": ["Coal", "Log", "Planks"],
|
"items": ["Dollars", "Log", "Planks"],
|
||||||
"more": "show more...",
|
"more": "show more...",
|
||||||
"inventory": "Inventory",
|
"inventory": "Inventory",
|
||||||
"player": "Player",
|
"player": "Player",
|
||||||
"infotooltips": ["Build", "Move", "Rotate", "Delete!", "", "Upgrade", "Information", "", "Go To Space!!"]
|
"infotooltips": ["Build", "Move", "Rotate", "Delete!", "Upgrade", "Information", "Go To Space!!", "", ""],
|
||||||
|
"cost": "Cost"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue