Skip to content

Commit

Permalink
Merge pull request #2 from jgss-gabriel-sousa/0.18
Browse files Browse the repository at this point in the history
0.18
  • Loading branch information
jgss-gabriel-sousa authored Apr 11, 2024
2 parents b2c7454 + 8e22cca commit 5a34b5e
Show file tree
Hide file tree
Showing 21 changed files with 272 additions and 69 deletions.
26 changes: 24 additions & 2 deletions data/buildingsData.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ export const buildingsData = {
spritePlace: "city",
description: "",
jobs: {
worker: 3,
artificer: 2,
patrician: 1,
},
build: {
wood: 20,
Expand All @@ -161,7 +163,7 @@ export const buildingsData = {
jobs: {
worker: 2,
artificer: 2,
patrician: 1,
noble: 1,
},
build: {
wood: 20,
Expand Down Expand Up @@ -203,6 +205,7 @@ export const buildingsData = {
jobs: {
worker: 4,
artificer: 2,
patrician: 1,
},
build: {
wood: 20,
Expand Down Expand Up @@ -264,7 +267,8 @@ export const buildingsData = {
spritePlace: "city",
description: "",
jobs: {
worker: 2,
worker: 4,
noble: 1,
},
build: {
wood: 12,
Expand Down Expand Up @@ -389,4 +393,22 @@ export const buildingsData = {
leather: 0.75
}
},
barracks: {
name: "Quartel",
spriteSize: "lg",
spritePlace: "city",
description: "",
jobs: {
soldier: 50,
},
build: {
wood: 100,
stone: 30,
},
maintenance: {
gold: 5,
},
production: {
}
},
}
3 changes: 2 additions & 1 deletion data/gameData.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const game = {
modifiers:{},
activeEvents:{},

popDeaths:{},

impacts: {
popGrowth: 1,
popDeath: 1,
Expand All @@ -33,7 +35,6 @@ export const game = {
food_consumption: 0,
knowledge: 0,
popLimit: 0,
lifeQuality: 0,

productivity: 0,
happiness: 0.5,
Expand Down
10 changes: 10 additions & 0 deletions data/popsData.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ export const popsData = {
tools: 0.02,
},
},
soldier:{
name: "Soldado",
food_consumption: 0.1,
consumption: {
clothes: 0.01,
weapon: 0.01,
},
},
artificer:{
name: "Artífice",
food_consumption: 0.05,
Expand All @@ -49,6 +57,7 @@ export const popsData = {
consumption: {
ale: 0.05,
clothes: 0.03,
wine: 0.05,
},
},
noble:{
Expand All @@ -57,6 +66,7 @@ export const popsData = {
consumption: {
ale: 0.1,
clothes: 0.05,
wine: 0.1,
},
},
}
Binary file added img/background.webp
Binary file not shown.
Binary file removed img/grass.webp
Binary file not shown.
Binary file added img/icons/pop-deaths/cold.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/icons/pop-deaths/homeless.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/icons/pop-deaths/hungry.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/icons/pop-deaths/natural.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/icons/soldier.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 13 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@
<title>TownRise</title>
</head>
<body>
<div id="console">
<input type="text" name="" id="">
<button class="btn">OK</button>
<p></p>
</div>
<div id="main-interface">
<div id="start-game" class="container menu">
<h1>TownRise</h1>
<img src="./img/icon.png">
<input type="button" class="btn btn-active" value="Nova Vila" id="start">
<input type="button" class="btn btn-active" value="Carregar Vila" id="load">
<input type="button" class="btn btn-active" value="Opções" id="options">
<p>v<span id="game-version">0.17</span>.2 &copy; JGSS</p>
<p>v<span id="game-version">0.18</span> &copy; JGSS</p>
</div>
<div id="load-game" class="container menu hidden">
<h1>Carregar Vila</h1>
Expand All @@ -49,10 +54,10 @@ <h1>Carregar Vila</h1>
<div class="container" id="time">
<div id="game-time">
<input type="button" class="btn btn-active hidden" value="Voltar para o Menu" id="restart">
<input type="button" class="time-btn hidden" value="=" id="pause">
<input type="button" class="time-btn hidden" value=">" id="1x">
<input type="button" class="time-btn hidden" value=">>" id="5x">
<input type="button" class="time-btn hidden" value=">>>" id="10x">
<input type="button" class="btn time-btn hidden" value="=" id="pause">
<input type="button" class="btn time-btn hidden" value=">" id="1x">
<input type="button" class="btn time-btn hidden" value=">>" id="5x">
<input type="button" class="btn time-btn hidden" value=">>>" id="10x">
</div>
<p><span>Dia </span><span id="totalDays-stat">1</span><span> - Ano </span><span id="year-stat">0</span></p>
<p><span id="day-weather"><i class="fa-solid fa-sun"></i></span> <span id="day-stat">1</span> - <span id="season">Primavera</span></p>
Expand All @@ -75,6 +80,7 @@ <h1>Carregar Vila</h1>
</div>
<div id="map-section">
<div id="active-modifiers"></div>
<div id="pop-deaths"></div>
<div class="hidden container grass-spring" id="map">
<div class="map-div" id="map-city"></div>
<div class="map-div" id="map-farms"></div>
Expand Down Expand Up @@ -143,6 +149,7 @@ <h1>Carregar Vila</h1>
<div class="container" id="resources"></div>
</div>
</div>
<!--
<div id="pops"></div>
<div class="hidden" id="combat">
<div id="combat-container">
Expand Down Expand Up @@ -195,5 +202,6 @@ <h1>Inimigos</h1>
</div>
</div>
</div>
-->
</body>
</html>
11 changes: 9 additions & 2 deletions scripts/handleInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { setGameSpeed, pauseGame } from "./gameTime.js";
import { initPopulation } from "./ui/popUI.js";
import { updateDataInfo } from "./ui/ui.js";
import { selectGameDifficultyUI, gameOptionsUI } from "./ui/options.js";
import { initBuildings } from "./ui/buildingsUI.js";
import { buildingsBootstrap, updateMapItemsScale } from "./ui/buildingsUI.js";

import { jobs } from "./jobs.js";
import { buildBuilding, destroyBuilding } from "./buildings.js";
Expand All @@ -19,6 +19,10 @@ window.addEventListener("beforeunload", function (event) {
event.returnValue = "\o/";
});

window.onresize = e => {
document.querySelector("body").style.height = window.innerHeight-20+"px";
};

window.onclick = e => {
//Buildings
const b = e.target.id.replace(/^add-/, "");
Expand All @@ -27,7 +31,7 @@ window.onclick = e => {
}
if(game.destroyBuildingCheck){
if(e.target.parentNode.classList.contains("map-item")){
const building = e.target.parentNode.classList[3].substring(4)
const building = e.target.parentNode.classList[3].substring(4);
destroyBuilding(building, 1);
}
}
Expand Down Expand Up @@ -121,6 +125,9 @@ async function startSequence(type) {
initBuildings();
initPopulation();
updateDataInfo();
popBootstrap();
populationStart();
updateMapItemsScale();

game.isStarted = true;
game.isPaused = true;
Expand Down
31 changes: 27 additions & 4 deletions scripts/population.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { popsUpdate } from "./pops.js";
import { game } from "../data/gameData.js";
import { rand } from "./funcs.js";
import { logPush } from "./ui/log.js";
import { popDeathsUI } from "./ui/ui.js";

let difficulty;

Expand Down Expand Up @@ -44,13 +45,19 @@ export function popGrowth(){
logPush("1 cidadão morreu");
else
logPush((popDeath-popGrowth)+" cidadãos morreram");


if(game.popDeaths.hasOwnProperty("natural"))
game.popDeaths["natural"] += popDeath;
else
game.popDeaths["natural"] = popDeath;
}
}

function popDeaths(){
hungryDeaths();
homelessDeaths();
withoutClothesDeaths();
cold();
//randDeaths();

function hungryDeaths(){
Expand All @@ -65,6 +72,11 @@ function popDeaths(){

if(popDeath > 1) logPush(popDeath+" cidadãos morreram de fome");
if(popDeath == 1) logPush(popDeath+" cidadão morreu de fome");

if(game.popDeaths.hasOwnProperty("hungry"))
game.popDeaths["hungry"] += popDeath;
else
game.popDeaths["hungry"] = popDeath;

if(!game.population) game.population = 0;
}
Expand Down Expand Up @@ -106,19 +118,25 @@ function popDeaths(){

homelessDeathChance = Math.round(homelessDeathChance);

let popDeath = rand(0,100) < homelessDeathChance;
const popDeathChance = rand(0, 100) < homelessDeathChance;
let popDeath = 0;

if(popDeath){
if(popDeathChance){
popDeath = Math.ceil((rand(0,homelessDeathChance)/100)*homelessPops);
}

game.population -= popDeath;

if(popDeath > 1) logPush(popDeath+" cidadãos morreram sem abrigo");
if(popDeath == 1) logPush(popDeath+" cidadão morreu sem abrigo");

if(game.popDeaths.hasOwnProperty("homeless"))
game.popDeaths["homeless"] += popDeath;
else
game.popDeaths["homeless"] = popDeath;
}

function withoutClothesDeaths(){
function cold(){
if(rand(0,5) != 0) return;

let popWithoutClothes = game.population - Math.floor(game.clothes);
Expand All @@ -132,6 +150,11 @@ function popDeaths(){

if(popDeath < 0) popDeath = 0;

if(game.popDeaths.hasOwnProperty("cold"))
game.popDeaths["cold"] += popDeath;
else
game.popDeaths["cold"] = popDeath;

game.population -= popDeath;
}
}
21 changes: 10 additions & 11 deletions scripts/sound.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { rand } from "./funcs.js"

var audio = new Audio();
export let audio = new Audio();
const NUMBER_OF_SONGS = 7;

export function soundStart(){
Expand All @@ -12,20 +12,19 @@ export function soundtrack(){
if(audio.paused){
const newSongID = rand(0,NUMBER_OF_SONGS);
audio = new Audio("./songs/"+newSongID+".mp3");
audio.volume = Number(localStorage.getItem("mv-volume"))/4;

const tryToPlay = setInterval(() => {
audio.play()
.then(() => {
clearInterval(tryToPlay);
})
.catch(error => {
console.error(error);
});
.then(() => {
clearInterval(tryToPlay);
})
.catch(error => {
;
});

audio.addEventListener('ended', setTimeout(soundtrack, rand(500,4000)));
}, 1000);
}

audio.volume = Number(localStorage.getItem("mv-volume"))/4;

window.setTimeout(soundtrack, 500);
}

8 changes: 8 additions & 0 deletions scripts/time/month.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { eventsData } from "../../data/eventsData.js";
export function advanceMonth(){
shuffleArr(eventsData);

resetPopDeaths();

if(game.season == "spring"){
game.season = "summer";

Expand All @@ -29,4 +31,10 @@ export function advanceMonth(){
document.getElementById("map").classList.remove("map-winter");
advanceYear();
}
}

function resetPopDeaths(){
for(const m in game.popDeaths){
game.popDeaths[m] = 0;
}
}
14 changes: 7 additions & 7 deletions scripts/ui/buildingsUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function buildingHTML(id){

let buildingHTML = `
<div class="map-item map-item-${building.spriteSize} map-${building.spritePlace} map-${id}">
<img src="./img/buildings/${id}.png">
<img src="./img/buildings/${id}.png" draggable="false">
</div>`;

if(building.spritePlace == "city") city.innerHTML += buildingHTML;
Expand Down Expand Up @@ -139,12 +139,12 @@ export function updateMapItemsScale(){
let mWidth = -Math.round(mapItems * 0.1);
let mHeight = -Math.round(mapItems * 0.05);

if(mWidth < -10) mWidth = -10;
if(mHeight < -7) mHeight = -7;
if(mWidth < -15) mWidth = -15;
if(mHeight < -10) mHeight = -10;

//IMG Sizes
let modifier = Math.round(mapItems*0.1);
if(modifier > 32) modifier = 32;
let modifier = Math.round(mapItems*0.15);
if(modifier > 48) modifier = 48;

let smSize = 48 - modifier;
let mdSize = 64 - modifier;
Expand All @@ -155,7 +155,7 @@ export function updateMapItemsScale(){
document.querySelector("#map").style.setProperty("--marginHeight", mHeight+"px");
document.querySelector("#map").style.setProperty("--sm_img_size", smSize+"px");
document.querySelector("#map").style.setProperty("--md_img_size", mdSize+"px");
document.querySelector("#map").style.setProperty("--lg_img_size", lgSize+"px");
document.querySelector("#map").style.setProperty("--lg_img_size", lgSize+"px");
}

const buildings = [
Expand All @@ -168,7 +168,7 @@ const buildings = [
["businesses",
["bakery","tavern"]],
["handicraft",
["tailorsmith","armory","blacksmith"]],
["tailorsmith","armory","blacksmith","barracks"]],
["resources",
["huntingCabin","foundry","lumbermill","mine","deepMine"]],
];
Expand Down
Loading

0 comments on commit 5a34b5e

Please sign in to comment.