Browse Source

updateRoom just takes the state, which has a location. Working on game logic

tags/v0.1.0
Fen Dweller 6 years ago
parent
commit
f886af0873
No known key found for this signature in database GPG Key ID: E80B35A6F11C3656
6 changed files with 54 additions and 7 deletions
  1. +0
    -0
      entity.js
  2. +26
    -0
      game.js
  3. +6
    -0
      satiate.css
  4. +6
    -0
      satiate.html
  5. +6
    -0
      satiate.js
  6. +10
    -7
      world.js

+ 0
- 0
entity.js View File


+ 26
- 0
game.js View File

@@ -0,0 +1,26 @@
function initGame(game, state) {
state.info = {};
state.info.time = 60 * 60 * 9;
}

// TODO: format string this lol
function renderTime(time) {
let hours = Math.floor(time / 3600) % 12;
const ampm = Math.floor(time / 3600) % 24 < 12 ? "AM" : "PM";
let minutes = Math.floor(time / 60) % 60;
let seconds = time % 60;

if (minutes <= 9)
minutes = "0" + minutes;

if (seconds <= 9)
seconds = "0" + seconds;

return hours + ":" + minutes + ":" + seconds + " " + ampm;
}

function updateWorldInfo(state) {
const timeInfo = document.querySelector("#world-info-time");

timeInfo.textContent = "Time: " + renderTime(state.info.time);
}

+ 6
- 0
satiate.css View File

@@ -36,6 +36,12 @@ html, body {
flex: 2; flex: 2;
} }


#world-info {
margin: 10px;
background: #222;
flex: 5;
}

#self-info { #self-info {
margin: 10px; margin: 10px;
background: #222; background: #222;


+ 6
- 0
satiate.html View File

@@ -6,6 +6,8 @@
<title>Satiate</title> <title>Satiate</title>
<link rel="stylesheet" href="satiate.css"> <link rel="stylesheet" href="satiate.css">
<script src="audio.js"></script> <script src="audio.js"></script>
<script src="entity.js"></script>
<script src="game.js"></script>
<script src="world.js"></script> <script src="world.js"></script>
<script src="satiate.js"></script> <script src="satiate.js"></script>
<meta name="theme-color" content="#000000" /> <meta name="theme-color" content="#000000" />
@@ -22,6 +24,10 @@
<div id="menu"> <div id="menu">
this is the menu, eventually this is the menu, eventually
</div> </div>
<div id="world-info">
this is world info
<div id="world-info-time">Time to get a watch!</div>
</div>
<div id="self-info"> <div id="self-info">
this is your own info this is your own info
</div> </div>


+ 6
- 0
satiate.js View File

@@ -28,11 +28,17 @@ function print(lines) {
log.scrollTop = log.scrollHeight; log.scrollTop = log.scrollHeight;
} }


function refresh() {
updateRoom(state);
updateWorldInfo(state);
}

// setup the game // setup the game


function init() { function init() {
initWorld("demo", state); initWorld("demo", state);
initAudio("demo", state); initAudio("demo", state);
initGame("demo", state);


goToRoom("Home", state); goToRoom("Home", state);
} }


+ 10
- 7
world.js View File

@@ -55,8 +55,9 @@ function moveToRoom(src, exit, dest, state) {
} }


state.world[dest].move(state.world[dest], state); state.world[dest].move(state.world[dest], state);
state.player.location = dest;


updateRoom(dest, state);
updateRoom(state);
} }


function goToRoom(dest, state) { function goToRoom(dest, state) {
@@ -70,14 +71,16 @@ function goToRoom(dest, state) {
} }
} }


updateRoom(dest, state);
state.player.location = dest;
updateRoom(state);
} }


function updateRoom(dest, state) {
const room = state.world[dest];
function updateRoom(state) {
const name = state.player.location
const room = state.world[name];


if (!state.player.rooms[dest.id]) {
state.player.rooms[dest.id] = {};
if (!state.player.rooms[name.id]) {
state.player.rooms[name.id] = {};
} }


const areaName = document.querySelector("#area-name"); const areaName = document.querySelector("#area-name");
@@ -160,7 +163,7 @@ function updateRoom(dest, state) {


button.addEventListener("click", () => { button.addEventListener("click", () => {
action.execute(room, state); action.execute(room, state);
updateRoom(room.id, state);
refresh();
}); });


button.addEventListener("mouseenter", () => { button.addEventListener("mouseenter", () => {


Loading…
Cancel
Save