Browse Source

WIP Map creation & decoration;

poc/map
Nero Ignis 4 years ago
parent
commit
d28594f5c3
  1. 27
      css/app.css
  2. BIN
      img/tiles/clear_hexagon.png
  3. 0
      img/tiles/environment/birch_1.png
  4. 0
      img/tiles/environment/birch_2.png
  5. 0
      img/tiles/environment/birch_3.png
  6. 0
      img/tiles/environment/birch_4.png
  7. 0
      img/tiles/structure/lumberjack.png
  8. 123
      index.html
  9. 252
      js/app.js

27
css/app.css

@ -39,20 +39,33 @@ @@ -39,20 +39,33 @@
#mapwrapper {
text-align: center;
overflow: auto;
height: 70vh;
height: 60vh;
overflow-scrolling: auto;
}
#mapwrapper::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
border-radius: 10px;
background-color: #F5F5F5;
}
.tile {
background-image: url('../img/tiles/grass.png');
}
.tile:hover {
opacity: 70%;
}
.tilebutton {
height: 40px;
width: 35px;
margin: 0.5em;
}
.deco-button {
background-image: url('../img/tiles/clear_hexagon.png');
background-size: 100% 100%;
}
.deco-button {
padding: 3px;
}
#mapwrapper.card-body {
padding: 0;
}

BIN
img/tiles/clear_hexagon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

0
img/tiles/environment/birch_1.png

0
img/tiles/environment/birch_2.png

0
img/tiles/environment/birch_3.png

0
img/tiles/environment/birch_4.png

0
img/tiles/structure/house_with_stall.png → img/tiles/structure/lumberjack.png

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

123
index.html

@ -12,24 +12,129 @@ @@ -12,24 +12,129 @@
</head>
<body>
<div id="root" class="container-fluid mt-2">
<div class="modal fade" id="buildingModal" tabindex="-1" aria-labelledby="buildingModalLabel" aria-hidden="true" v-if="modalBuilding">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="buildingModalLabel">{{ modalBuilding.name }}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="float-right" v-if="modalBuilding.isUpgradeable">
<a href="javascript:" @click="buyUpgrade(modalBuilding)"><i
class="fas fa-arrow-up text-success"></i> {{ modalBuilding.price }} <img
class="resource-icon" src="img/gold.png"> </a>
</div>
<div class="float-left icon-level-container">
<img class="building-icon" :src="'img/' + modalBuilding.icon + '.png'"
:alt="modalBuilding.name + '_icon'">
<div class="level-marker">{{ modalBuilding.level === 10 ? 'X' : modalBuilding.level }}</div>
</div>
{{ modalBuilding.amount }} <img class="resource-icon"
:src="'img/' + modalBuilding.resource + '.png'"
:alt="modalBuilding.resource + '_icon'"> every
{{ modalBuilding.intervalInSeconds }}s<br/>
<span v-if="modalBuilding.hasRequirements" v-html="getRequirementsText(modalBuilding)"></span>
<div class="progress">
<div class="progress-bar progress-bar-success text-light" role="progressbar"
:style="'width: ' + modalBuilding.loader + '%;'" aria-valuenow="10"
aria-valuemin="0"
aria-valuemax="100">
<span v-if="!modalBuilding.hasMissingResources">
{{ modalBuilding.loader }} %
</span>
<span class="text-danger" v-else>
Missing resources!
</span>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="row">
<!-- <div class="col-md-12">-->
<!-- <div class="alert alert-warning alert-dis">-->
<!-- This game is in an early state of development, resources could be resetted everytime and bugs may appear. Also not every building is balanced yet.-->
<!-- </div>-->
<!-- </div>-->
<div class="col-xl-8">
<div class="card">
<div class="card-header">Map</div>
<div class="card-body" id="mapwrapper">
<div id="">
<div class="mapRow" v-for="row in map">
<div class="mapRow" v-for="(row, rowNumber) in map">
<nobr>
<a v-for="tile in row">
<img :src="tile.asset" alt="" class="tile" style="display: inline-block;" @click="interactWithTile(tile)"/>
<a v-for="(tile, colNumber) in row">
<img :src="tile.asset" alt="" class="tile" style="display: inline-block;" @click="interactWithTile(tile, rowNumber, colNumber)"/>
</a>
</nobr>
</div>
<div class="" style="position: relative; bottom: 43em; width: 5em;">
<div class="card-body">
<div class="nav-item">
<a href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Building
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<button v-for="building in buildings" @click="initiateBuilding(building)" class="tilebutton">
<img :src="'img/' + building.icon + '.png'"
data-toggle="tooltip"
data-placement="left"
:title="building.name + ' (' + getResourcesNeededToBuildText(building) + ')'"/>
</button>
</div>
</div>
<div class="nav-item">
<a href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Deco
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<button class="tilebutton deco-button"
v-for="item in mapDecorations"
@click="selectDecoration(item)"
data-toggle="tooltip"
data-placement="left"
:title="item.name + ' (' + item.price + ' Gold)'">
<img :src="item.path" class="deco-button-image"/>
</button>
</div>
</div>
<div class="nav-item">
<a href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Roads
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<button class="tilebutton deco-button"
v-for="item in roads"
@click="selectDecoration(item)"
data-toggle="tooltip"
data-placement="left"
:title="item.name + ' (' + item.price + ' Gold)'">
<img :src="item.path" class="deco-button-image"/>
</button>
</div>
</div>
<button class="tilebutton deco-button"
@click="selection = {bulldozer: true}"
data-toggle="tooltip"
data-placement="left"
title="Bulldozer">
<img src="img/tiles/environment/fire.png"/>
</button>
<button class="tilebutton deco-button cancel"
v-if="selection"
@click="selection = null"
data-toggle="tooltip"
data-placement="left"
title="Cancel">
<i class="fas fa-ban" style="color: darkred"></i>
</button>
</div>
</div>
</div>
</div>

252
js/app.js

@ -206,43 +206,209 @@ let game = new Vue({ @@ -206,43 +206,209 @@ let game = new Vue({
},
currentQuest: null,
questSkipCounter: 0,
loadedIntervals: []
loadedIntervals: [],
selectedBuilding: null,
selectedDecoration: null,
selection: null,
modalBuilding: null,
mapDecorations: [
{
path: 'img/tiles/environment/birch_small.png',
name: 'dummy',
price: 50
},
{
path: 'img/tiles/environment/birch_large.png',
name: 'dummy',
price: 50
},
{
path: 'img/tiles/environment/spruce_small.png',
name: 'dummy',
price: 50
},
{
path: 'img/tiles/environment/spruce_large.png',
name: 'dummy',
price: 50
},
{
path: 'img/tiles/environment/bush.png',
name: 'dummy',
price: 50
},
{
path: 'img/tiles/environment/bush_berries.png',
name: 'dummy',
price: 50
},
{
path: 'img/tiles/environment/stone.png',
name: 'dummy',
price: 50
},
{
path: 'img/tiles/environment/stone_0.png',
name: 'Stone 1',
price: 50
},
{
path: 'img/tiles/environment/stone_1.png',
name: 'Stone 2',
price: 50
},
{
path: 'img/tiles/environment/stone_3.png',
name: 'Stone 3',
price: 50
},
{
path: 'img/tiles/dummy/dummy',
name: 'dummy',
price: 50
},
{
path: 'img/tiles/environment/wood_log.png',
name: 'Log',
price: 50
},
],
roads: [
{
path: 'img/tiles/roads/corner_n_o.png',
name: 'Log',
price: 50
},
{
path: 'img/tiles/roads/corner_n_w.png',
name: 'Log',
price: 50
},
{
path: 'img/tiles/roads/corner_o_s.png',
name: 'Log',
price: 50
},
{
path: 'img/tiles/roads/corner_s_w.png',
name: 'Log',
price: 50
},
{
path: 'img/tiles/roads/cross.png',
name: 'Log',
price: 50
},
{
path: 'img/tiles/roads/end_n.png',
name: 'Log',
price: 50
},
{
path: 'img/tiles/roads/end_o.png',
name: 'Log',
price: 50
},
{
path: 'img/tiles/roads/end_s.png',
name: 'Log',
price: 50
},
{
path: 'img/tiles/roads/end_w.png',
name: 'Log',
price: 50
},
{
path: 'img/tiles/roads/straight_n_s.png',
name: 'Log',
price: 50
},
{
path: 'img/tiles/roads/straight_o_w.png',
name: 'Log',
price: 50
},
{
path: 'img/tiles/roads/t_n_o_s.png',
name: 'Log',
price: 50
},
{
path: 'img/tiles/roads/t_n_o_w.png',
name: 'Log',
price: 50
},
{
path: 'img/tiles/roads/t_n_s_w.png',
name: 'Log',
price: 50
},
{
path: 'img/tiles/roads/t_o_s_w.png',
name: 'Log',
price: 50
},
]
},
created() {
this.generateMap(100, 50);
this.setTile(1, 1, {
asset: 'img/tiles/environment/birch_large.png'
});
this.setTile(1, 2, {
asset: 'img/tiles/environment/birch_large.png'
});
this.setTile(2, 1, {
asset: 'img/tiles/environment/birch_large.png'
});
this.setTile(2, 2, {
asset: 'img/tiles/structure/house.png',
building: 'lumberjack'
let game = this;
this.generateMap(10, 10);
$(function () {
$('[data-toggle="tooltip"]').tooltip()
});
this.setTile(5, 4, {
asset: 'img/tiles/structure/blacksmith.png',
building: 'blacksmith'
$('#buildingModal').on('close.bs.modal', function (event) {
game.modalBuilding = null;
});
// this.storageNames = {
// lastVersion: 'lastVersion',
// resources: 'resources' + this.version,
// buildings: 'buildings' + this.version,
// }
//
// this.checkVersion();
//
// this.checkBuildings();
// this.loadResourcesFromStorage();
// this.loadBuildingsFromStorage();
// this.reloadBuildings();
this.storageNames = {
lastVersion: 'lastVersion',
resources: 'resources' + this.version,
buildings: 'buildings' + this.version,
}
this.checkVersion();
this.checkBuildings();
this.loadResourcesFromStorage();
this.loadBuildingsFromStorage();
this.reloadBuildings();
},
methods: {
// Map generation
// Map system
getResourcesNeededToBuildText(building) {
let game = this;
let message = '';
if (building.resourcesToBuild) {
Object.keys(building.resourcesToBuild).forEach((resourceName, resourceAmount) => {
if (message.length > 0) {
message += ', '
}
message += building.resourcesToBuild[resourceName] + ' ' + game.resources[resourceName].name;
});
} else {
message += building.price + '<img class="resource-icon" src="img/gold.png"/>';
}
return message;
},
initiateBuilding(building) {
this.selection = {
building: building
};
},
selectDecoration(item) {
this.selection = {
decoration: item
};
},
generateMap(rows, cols) {
let map = [];
@ -266,9 +432,31 @@ let game = new Vue({ @@ -266,9 +432,31 @@ let game = new Vue({
this.map[x-1][y-1] = tile;
},
interactWithTile(tile) {
interactWithTile(tile, x, y) {
if (game.selection) {
if (game.selection.building) {
tile.asset = 'img/tiles/structure/' + game.selection.building.name.toLowerCase() + '.png';
tile.building = game.selection.building.name.toLowerCase();
this.selection = null;
}
if (game.selection.decoration) {
tile.asset = game.selection.decoration.path;
tile.building = null;
// decorations can only be cancelled by cancel button
}
if (game.selection.bulldozer) {
tile.asset = 'img/tiles/trans.png';
tile.building = null;
// bulldozer can only be cancelled by cancel button
}
}
if (tile.building) {
this.sendNotification(tile.building);
this.modalBuilding = this.buildings[tile.building];
$('#buildingModal').modal('show');
this.$forceUpdate();
}
},

Loading…
Cancel
Save