Skip to content

Commit

Permalink
EPIC refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Chasmiccoder committed Feb 11, 2022
1 parent 6c7580e commit de3947a
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 87 deletions.
199 changes: 124 additions & 75 deletions js/OverworldMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,71 @@ const getTreasureBox = (x,y,box_id) => {
return box;
}

// Generate the cutscene spaces for one cutscene event
// for example, with one function call, we can get the cutscenes defined for all tiles for one cutscene trigger
const generateCutsceneSpaces = (person_cutscene_set_of_coords_raw, personPath) => {
let coords = person_cutscene_set_of_coords_raw;
let dict = {};
for(let i = 0; i < coords.length; i++) {
dict[[utils.asGridCoord(coords[i][0],coords[i][1])]] = [{events: personPath}];
}
return dict;
}


// contains the footstep triggered cutscenes for all events in the game
let allCutsceneSpaces = {

...generateCutsceneSpaces(hemanth_cutscene_set_of_coords_raw, hemanthPath),
...generateCutsceneSpaces(dhriti_cutscene_set_of_coords_raw, dhritiPath),
...generateCutsceneSpaces(diya_cutscene_set_of_coords_raw, diyaPath),
...generateCutsceneSpaces(rehber_cutscene_set_of_coords_raw, rehberPath),
...generateCutsceneSpaces(vinamra_cutscene_set_of_coords_raw, vinamraPath),

// TODO
// [utils.asGridCoord(10,17)]: [{events: shreyasPath}],
// [utils.asGridCoord(11,17)]: [{events: shreyasPath}],
};

// All redirects to other urls (also triggered by footsteps)
let allRedirects = {
[utils.asGridCoord(14,5)]: [
{
events: [
{type: "textMessage", text: "Redirecting to the Technical Form!"},
{type: "redirectPerson", link: "./technical"},
]
}
],

[utils.asGridCoord(27,68)]: [
{
events: [
{type: "textMessage", text: "Redirecting to the Competitive Coding Form!"},
{type: "redirectPerson", link: "./competitive"},
]
}
],

[utils.asGridCoord(-2,31)]: [
{
events: [
{type: "textMessage", text: "Redirecting to the Design Form!"},
{type: "redirectPerson", link: "./design"},
]
}
],

[utils.asGridCoord(6,44)]: [
{
events: [
{type: "textMessage", text: "Redirecting to the Management Form!"},
{type: "redirectPerson", link: "./management"},
]
}
],
}

class OverworldMap {
constructor(config) {
// adding a back-reference to the overworld
Expand Down Expand Up @@ -126,19 +191,17 @@ class OverworldMap {
this.startCutscene(match[0].events); // right now it's pulling the behavior at the 0th index. Can be changed depending on the current story
}

// REFACTOR

// 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);
}

else if(dhriti_cutscene_set_of_coords.includes(hero_tile)) {
Expand All @@ -159,6 +222,14 @@ class OverworldMap {
}
}

else if(vinamra_cutscene_set_of_coords.includes(hero_tile)) {
for(let i = 0; i < vinamra_cutscene_set_of_coords.length; i++) {
delete this.cutsceneSpaces[vinamra_cutscene_set_of_coords[i]];
}
}



}

addWall(x,y) {
Expand All @@ -185,8 +256,8 @@ window.OverworldMaps = {
isPlayerControlled: true,
src: "./images/Hero.png",
useShadow: true,
x: utils.withGrid(28), // Starting point: 28,32
y: utils.withGrid(32),
x: utils.withGrid(15), // Starting point: 28,32
y: utils.withGrid(24),
}),

npcA: new Person({
Expand Down Expand Up @@ -252,7 +323,7 @@ window.OverworldMaps = {
events: [
{type: "textMessage", text: "It's about drive, it's about power", faceHero: "dhriti"},
{type: "textMessage", text: "We stay hungry, we devour!"},
]
]
},
]
}),
Expand Down Expand Up @@ -369,6 +440,48 @@ window.OverworldMaps = {
]
}),

vinamra: new Person({
x: utils.withGrid(23),
y: utils.withGrid(20),
src: "./images/brownGuy1.png",
useShadow: true,
behaviorLoop: [
{type: "stand", direction: "left", time: 800},
{type: "stand", direction: "down", time: 800},
{type: "stand", direction: "right", time: 1200},
{type: "stand", direction: "down", time: 300}
],
talking: [
{
events: [
{type: "textMessage", text: "It's about drive, it's about power", faceHero: "vinamra"},
]
},
]
}),

shreyas: new Person({
x: utils.withGrid(9),
y: utils.withGrid(20),
src: "./images/brownGuy1.png",
useShadow: true,
behaviorLoop: [
{type: "stand", direction: "left", time: 800},
{type: "stand", direction: "down", time: 800},
{type: "stand", direction: "right", time: 1200},
{type: "stand", direction: "down", time: 300}
],
talking: [
{
events: [
{type: "textMessage", text: "Shh, I got social anxiety...", faceHero: "shreyas"},
{type: "textMessage", text: "P.S: Why don't you give the web domain a try though?", faceHero: "shreyas"},
]
},
]
}),


twitterPerson1: getRoute(31,40,"Twitter", "https://twitter.com/ACM_VIT"),
twitterPerson2: getRoute(32,40,"Twitter", "https://twitter.com/ACM_VIT"),
instagramPerson1: getRoute(33,41,"Instagram","https://www.instagram.com/acmvit/"),
Expand All @@ -395,73 +508,9 @@ window.OverworldMaps = {
},
walls: WALLS,
cutsceneSpaces: {
// scope for refactoring
[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(9,31)]: [{events: dhritiPath}],
[utils.asGridCoord(9,32)]: [{events: dhritiPath}],
[utils.asGridCoord(9,33)]: [{events: dhritiPath}],
[utils.asGridCoord(9,34)]: [{events: dhritiPath}],
[utils.asGridCoord(9,35)]: [{events: dhritiPath}],
[utils.asGridCoord(9,36)]: [{events: dhritiPath}],
[utils.asGridCoord(9,37)]: [{events: dhritiPath}],

[utils.asGridCoord(12,38)]: [{events: diyaPath}],
[utils.asGridCoord(13,38)]: [{events: diyaPath}],
[utils.asGridCoord(14,38)]: [{events: diyaPath}],
[utils.asGridCoord(15,38)]: [{events: diyaPath}],
[utils.asGridCoord(16,38)]: [{events: diyaPath}],
[utils.asGridCoord(17,38)]: [{events: diyaPath}],
[utils.asGridCoord(18,38)]: [{events: diyaPath}],

[utils.asGridCoord(33,63)]: [{events: rehberPath}],
[utils.asGridCoord(34,63)]: [{events: rehberPath}],
[utils.asGridCoord(35,38)]: [{events: rehberPath}],

[utils.asGridCoord(14,5)]: [
{
events: [
{type: "textMessage", text: "Redirecting to the Technical Form!"},
{type: "redirectPerson", link: "./technical"},
]
}
],

[utils.asGridCoord(27,68)]: [
{
events: [
{type: "textMessage", text: "Redirecting to the Competitive Coding Form!"},
{type: "redirectPerson", link: "./competitive"},
]
}
],

[utils.asGridCoord(-2,31)]: [
{
events: [
{type: "textMessage", text: "Redirecting to the Design Form!"},
{type: "redirectPerson", link: "./design"},
]
}
],

[utils.asGridCoord(6,44)]: [
{
events: [
{type: "textMessage", text: "Redirecting to the Management Form!"},
{type: "redirectPerson", link: "./management"},
]
}
],
}
...allCutsceneSpaces,
...allRedirects,
},

},
}
56 changes: 45 additions & 11 deletions js/npc_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ const standDown = (who, duration = 500) => {
return {who: who, type: "stand", direction: "down", time:duration};
}

/*
For cutscenes:
*/

const getCutsceneSetOfCoords = (coordinateList) => {
let arr = [];
for(let i = 0; i < coordinateList.length; i++) {
Expand All @@ -41,8 +45,6 @@ const getCutsceneSetOfCoords = (coordinateList) => {
return arr;
}



// current person
let X = "hemanth";
let hemanthPath = [
Expand All @@ -54,8 +56,8 @@ let hemanthPath = [
]

// hemanth's cutscene's set of coordinates
let hemanth_cutscene_set_of_coords = [[10,9],[11,9],[12,9],[13,9],[14,9],[15,9],[16,9],[17,9],[18,9],[19,9]]
hemanth_cutscene_set_of_coords = getCutsceneSetOfCoords(hemanth_cutscene_set_of_coords);
let hemanth_cutscene_set_of_coords_raw = [[10,9],[11,9],[12,9],[13,9],[14,9],[15,9],[16,9],[17,9],[18,9],[19,9]] // raw == tile format and not in pixel format
let hemanth_cutscene_set_of_coords = getCutsceneSetOfCoords(hemanth_cutscene_set_of_coords_raw); // pixel format

X = "dhriti";
let dhritiPath = [
Expand All @@ -69,20 +71,20 @@ let dhritiPath = [
walkLeft(X),walkUp(X),walkLeft(X),walkUp(X),
]

let dhriti_cutscene_set_of_coords = [[9,31],[9,32],[9,33],[9,34],[9,35],[9,36],[9,37]];
dhriti_cutscene_set_of_coords = getCutsceneSetOfCoords(dhriti_cutscene_set_of_coords);
let dhriti_cutscene_set_of_coords_raw = [[9,31],[9,32],[9,33],[9,34],[9,35],[9,36],[9,37]];
let dhriti_cutscene_set_of_coords = getCutsceneSetOfCoords(dhriti_cutscene_set_of_coords_raw);

X = "diya";
let diyaPath = [
walkUp(X),walkLeft(X),walkUp(X),walkUp(X),walkUp(X),
standUp(X,500),
{type: "textMessage", text:"Will you be able to manage management?"},
{type: "textMessage", text:"Will you be able to manage management, while having a great social life?"},
{type: "textMessage", text: "If so, enter the portal center to apply!"},
walkRight(X),walkDown(X),walkDown(X),walkDown(X),walkDown(X),
]

let diya_cutscene_set_of_coords = [[12,38],[13,38],[14,38],[15,38],[16,38],[17,38],[18,38]];
diya_cutscene_set_of_coords = getCutsceneSetOfCoords(diya_cutscene_set_of_coords);
let diya_cutscene_set_of_coords_raw = [[12,38],[13,38],[14,38],[15,38],[16,38],[17,38],[18,38]];
let diya_cutscene_set_of_coords = getCutsceneSetOfCoords(diya_cutscene_set_of_coords_raw);

X = "rehber";
let rehberPath = [
Expand All @@ -93,5 +95,37 @@ let rehberPath = [
walkLeft(X),walkDown(X),walkDown(X),walkLeft(X),walkLeft(X),walkLeft(X),
]

let rehber_cutscene_set_of_coords = [[33,63],[34,63],[35,63]];
rehber_cutscene_set_of_coords = getCutsceneSetOfCoords(rehber_cutscene_set_of_coords);
let rehber_cutscene_set_of_coords_raw = [[33,63],[34,63],[35,63]];
let rehber_cutscene_set_of_coords = getCutsceneSetOfCoords(rehber_cutscene_set_of_coords_raw);


// Research cutscene
X = "vinamra";
let vinamraPath = [
walkDown(X),walkLeft(X),walkLeft(X),walkLeft(X),standLeft(X,200),
{type: "textMessage", text:"In the Research domain we work on cool, nonstandard technologies..."},
{type: "textMessage", text:"If you have a curious mindset, fill the research form!"},
walkRight(X),walkRight(X),walkRight(X),walkUp(X),standDown(X,200),
]

// if you have a curious mindset, fill research form!
let vinamra_cutscene_set_of_coords_raw = [[18,20],[18,21],[18,22],[18,23]]
let vinamra_cutscene_set_of_coords = getCutsceneSetOfCoords(vinamra_cutscene_set_of_coords_raw);


X = "shreyas"
let shreyasPath = [
walkDown(X),standRight(X,200),
{type: "textMessage", text:"To join our awesome web domain, hop into this portal you see ahead!"},
walkUp(X),standRight(X,200),
]

let shreyas_cutscene_set_of_coords_raw = [[10,17],[11,17],[11,18],[11,19],[11,20],[11,21],[11,22],[11,23],[11,24],[10,24]]
let shreyas_cutscene_set_of_coords = getCutsceneSetOfCoords(shreyas_cutscene_set_of_coords_raw);







2 changes: 1 addition & 1 deletion js/walls.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,4 +554,4 @@ const WALLS = {
[utils.asGridCoord(24,72)]: true,
[utils.asGridCoord(25,72)]: true,
[utils.asGridCoord(26,72)]: true,
};
};

0 comments on commit de3947a

Please sign in to comment.