Skip to content

Commit

Permalink
made 1 time cutscene work (kind of)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chasmiccoder committed Feb 9, 2022
1 parent bb98c90 commit 29f7c2c
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 88 deletions.
Binary file added images/dhriti.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions images/problem.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
The problem is that when a cutscene is being played,
the game objects pause their behaviour.
But when the cutscene ends, the person's behaviour is starting
from the first item in the behaviour loop.

We need to be able to pick off from where we left
232 changes: 149 additions & 83 deletions js/OverworldMap.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
let hemanthPath = [
{who: "hemanth", type: "walk", direction: "right"},
{who: "hemanth", type: "walk", direction: "right"},
{who: "hemanth", type: "walk", direction: "right"},
{who: "hemanth", type: "walk", direction: "right"},
{who: "hemanth", type: "walk", direction: "right"},
{who: "hemanth", type: "walk", direction: "right"},
{who: "hemanth", type: "walk", direction: "right"},
{who: "hemanth", type: "walk", direction: "right"},

{who: "hemanth", type: "stand", direction: "right", time:500},
{type: "textMessage", text: "Are you up for applying to the technical department?"},
{type: "textMessage", text: "If so, enter the portal and hit 'Enter'!"},

{who: "hemanth", type: "walk", direction: "left"},
{who: "hemanth", type: "walk", direction: "left"},
{who: "hemanth", type: "walk", direction: "left"},
{who: "hemanth", type: "walk", direction: "left"},
{who: "hemanth", type: "walk", direction: "left"},
{who: "hemanth", type: "walk", direction: "left"},
{who: "hemanth", type: "walk", direction: "left"},
{who: "hemanth", type: "walk", direction: "left"},
]

// hemanth's cutscene's set of coordinates
let hemanth_cutscene_set_of_coords = [`${10*32},${9*32}`,`${11*32},${10*9}`,`${12*32},${9*32}`,`${13*32},${9*32}`,`${14*32},${9*32}`,`${15*32},${9*32}`,`${16*32},${9*32}`,`${17*32},${9*32}`,`${18*32},${9*32}`,`${19*32},${9*32}`,];

class OverworldMap {
constructor(config) {
// adding a back-reference to the overworld
Expand Down Expand Up @@ -59,7 +86,7 @@ class OverworldMap {
this.isCutscenePlaying = false;

// reset npc's to do their normal behaviour
Object.values(this.gameObjects).forEach(object => object.doBehaviorEvent(this))
Object.values(this.gameObjects).forEach(object => object.doBehaviorEvent(this));
}

checkForActionCutscene() {
Expand All @@ -83,13 +110,28 @@ class OverworldMap {
checkForFootstepCutscene() {
const hero = this.gameObjects['hero'];
const match = this.cutsceneSpaces[`${hero.x},${hero.y}`];

// is undefined for normal tiles, but displays the object if you step on a tile that triggers a cutscene
// console.log(match);

if(!this.isCutscenePlaying && match) {
this.startCutscene(match[0].events); // right now it's pulling the behavior at the 0th index. Can be changed depending on the current story
}


// if hero steps on a 'set' of tiles that triggers 'one' cutscene
// then remove that 'set' of tiles for that corresponding cutscene from cutsceneSpaces
// optimize later, dividing by 32 for now, but use proper utils function later
const hero_tile = `${hero.x},${hero.y}`;
if (hemanth_cutscene_set_of_coords.includes(hero_tile)) {
console.log("before:", this.cutsceneSpaces);
// let tmp = {...this.cutsceneSpa
for(let i = 0; i < hemanth_cutscene_set_of_coords.length; i++) {
delete this.cutsceneSpaces[hemanth_cutscene_set_of_coords[i]];
}
// this.cutsceneSpaces = [...tmp];
console.log("after:", this.cutsceneSpaces);
}
}

addWall(x,y) {
Expand Down Expand Up @@ -117,8 +159,8 @@ window.OverworldMaps = {
hero: new Person({
isPlayerControlled: true,
src: "./images/brownGuy1.png",
x: utils.withGrid(18),
y: utils.withGrid(25)
x: utils.withGrid(9),
y: utils.withGrid(10)
}),

// myDrone: new Person({
Expand All @@ -132,9 +174,9 @@ window.OverworldMaps = {
// }),

npcA: new Person({
x: utils.withGrid(7),
x: utils.withGrid(19),
y: utils.withGrid(9),
src: "./images/npc1.png",
src: "./images/brownGuy1.png",
behaviorLoop: [
{type: "stand", direction: "left", time: 800},
{type: "stand", direction: "up", time: 800},
Expand All @@ -147,111 +189,135 @@ window.OverworldMaps = {
events: [
{type: "textMessage", text: "I'm busy...", faceHero: "npcA"},
{type: "textMessage", text: "Go away!"},
{who: "hero", type: "walk", direction: "left"}
// {who: "hero", type: "walk", direction: "left"}
]
},

// saying a different thing later
// {
// events: [
// {type: "textMessage", text: "Congrats on beating that boss!"}
// ]
// }
]
],
}),
// // saying a different thing later
// // {
// // events: [
// // {type: "textMessage", text: "Congrats on beating that boss!"}
// // ]
// // }
// ]
// }),

npcB: new Person({
x: utils.withGrid(8),
y: utils.withGrid(5),
src: "./images/npc2.png",
// behaviorLoop: [
// {type: "walk", direction: "left"},
// {type: "stand", direction: "left", time: 800},
// {type: "walk", direction: "up"},
// {type: "walk", direction: "right"},
// {type: "walk", direction: "down"}
// ]
}),
// npcB: new Person({
// x: utils.withGrid(8),
// y: utils.withGrid(5),
// src: "./images/brownGuy1.png",
// behaviorLoop: [
// {type: "walk", direction: "left"},
// // {type: "stand", direction: "left", time: 800},
// {type: "walk", direction: "up"},
// {type: "walk", direction: "right"},
// {type: "walk", direction: "down"},
// ],
// talking: [
// {
// // defined this way so that people can say different things, at different points in time
// events: [
// {type: "textMessage", text: "It's about drive, it's about power", faceHero: "hemanth"},
// {type: "textMessage", text: "We stay hungry, we devour!"},
// // {who: "hero", type: "walk", direction: "left"}
// ]
// },
// ]
// }),


hemanth: new Person({
x: utils.withGrid(2),
y: utils.withGrid(10),
src: "./images/brownGuy1.png",
behaviorLoop: [
{type:"walk",direction:"right"},
{type:"walk",direction:"up"},
{type:"walk",direction:"right"},
{type:"walk",direction:"right"},
{type:"walk",direction:"down"},
{type:"walk",direction:"right"},
{type:"walk",direction:"right"},
{type:"walk",direction:"right"},
{type:"walk",direction:"right"},
{type:"walk",direction:"right"},
// {type:"stand",direction:"r",time:500},
{type:"walk",direction:"down"},
{type:"walk",direction:"left"},
{type:"walk",direction:"left"},
{type:"walk",direction:"left"},
{type:"walk",direction:"left"},
{type:"walk",direction:"left"},
{type:"walk",direction:"down"},
{type:"walk",direction:"left"},
{type:"walk",direction:"left"},
// {type:"stand",direction:"u",time:500},
{type:"walk",direction:"up"},
{type:"walk",direction:"left"},
{type:"walk",direction:"up"},
{type: "stand", direction: "left", time: 800},
{type: "stand", direction: "up", time: 800},
{type: "stand", direction: "right", time: 1200},
{type: "stand", direction: "up", time: 300}
],
talking: [
{
// defined this way so that people can say different things, at different points in time
events: [
{type: "textMessage", text: "It's about drive, it's about power", faceHero: "hemanth"},
{type: "textMessage", text: "We stay hungry, we devour!"},
// {who: "hero", type: "walk", direction: "left"}
]
},
]
}),

// saying a different thing later
// {
// events: [
// {type: "textMessage", text: "Congrats on beating that boss!"}
// ]
// }
dhriti: new Person({
x: utils.withGrid(2),
y: utils.withGrid(31),
src: "./images/dhriti.png",
behaviorLoop: [
{type: "stand", direction: "left", time: 800},
{type: "stand", direction: "up", time: 800},
{type: "stand", direction: "right", time: 1200},
{type: "stand", direction: "up", time: 300}
],
talking: [
{
// defined this way so that people can say different things, at different points in time
events: [
{type: "textMessage", text: "It's about drive, it's about power", faceHero: "dhriti"},
{type: "textMessage", text: "We stay hungry, we devour!"},
]
},
]
}),

},
walls: {
[utils.asGridCoord(7,6)]: true,
[utils.asGridCoord(8,6)]: true,
[utils.asGridCoord(7,7)]: true,
[utils.asGridCoord(8,7)]: true,
// [utils.asGridCoord(7,6)]: true,
// [utils.asGridCoord(8,6)]: true,
// [utils.asGridCoord(7,7)]: true,
// [utils.asGridCoord(8,7)]: true,
},
cutsceneSpaces: {
[utils.asGridCoord(7,4)]: [
// doing it this way so that for example if you step on a cutscene space
// and if the cutscene gets over, then the same cutscene should not play when you step on the same tile again
{
events: [
{who: "npcB", type: "walk", direction: "left"},
{who: "npcB", type: "stand", direction: "up", time:500},
{type: "textMessage", text: "You can't be in there!"},
{who: "npcB", type: "walk", direction: "right"},
{who: "hero", type: "walk", direction: "down"},
{who: "hero", type: "walk", direction: "left"},
]
}
],
[utils.asGridCoord(5,10)]: [
{
events: [
{type: "changeMap", map: "Kitchen"} // gets referenced in OverworldEvent
]
}
]
[utils.asGridCoord(10,9)]: [{events: hemanthPath}],
[utils.asGridCoord(11,9)]: [{events: hemanthPath}],
[utils.asGridCoord(12,9)]: [{events: hemanthPath}],
[utils.asGridCoord(13,9)]: [{events: hemanthPath}],
[utils.asGridCoord(14,9)]: [{events: hemanthPath}],
[utils.asGridCoord(15,9)]: [{events: hemanthPath}],
[utils.asGridCoord(16,9)]: [{events: hemanthPath}],
[utils.asGridCoord(17,9)]: [{events: hemanthPath}],
[utils.asGridCoord(18,9)]: [{events: hemanthPath}],
[utils.asGridCoord(19,9)]: [{events: hemanthPath}],



// [utils.asGridCoord(5,10)]: [
// {
// events: [
// {type: "changeMap", map: "Kitchen"} // gets referenced in OverworldEvent
// ]
// }
// ]
// [utils.asGridCoord(7,4)]: [
// // doing it this way so that for example if you step on a cutscene space
// // and if the cutscene gets over, then the same cutscene should not play when you step on the same tile again
// {
// events: [
// {who: "npcB", type: "walk", direction: "left"},
// {who: "npcB", type: "stand", direction: "up", time:500},
// {type: "textMessage", text: "You can't be in there!"},
// {who: "npcB", type: "walk", direction: "right"},
// {who: "hero", type: "walk", direction: "down"},
// {who: "hero", type: "walk", direction: "left"},
// ]
// }
// ],
// [utils.asGridCoord(5,10)]: [
// {
// events: [
// {type: "changeMap", map: "Kitchen"} // gets referenced in OverworldEvent
// ]
// }
// ]

}
},
Expand Down
8 changes: 3 additions & 5 deletions js/Person.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Person extends GameObject {
"left": ["x", -2],
"right": ["x", 2]
}

}

update(state) {
Expand All @@ -30,25 +31,24 @@ class Person extends GameObject {
direction: state.arrow
})
}

this.updateSprite(state);
}
}

startBehavior(state, behavior) {

// set character direction to whatever behavior has
this.direction = behavior.direction;
if(behavior.type === "walk") {

// stop if space is not free (wall collision)
if(state.map.isSpaceTaken(this.x, this.y, this.direction)) {

// if the player bumps into an npc, then once the npc can move, he should start moving
behavior.retry && setTimeout(() => {
// this.retrying = true;
this.startBehavior(state, behavior);
}, 10);


return; // stop the function
}

Expand All @@ -60,7 +60,6 @@ class Person extends GameObject {

if(behavior.type === "stand") {
this.isStanding = true;

setTimeout(() => {
utils.emitEvent("PersonStandComplete", {
whoId: this.id
Expand All @@ -77,7 +76,6 @@ class Person extends GameObject {

if(this.movingProgressRemaining === 0) {
// walking is finished

utils.emitEvent("PersonWalkingComplete", {
whoId: this.id
});
Expand Down

0 comments on commit 29f7c2c

Please sign in to comment.