Skip to content

Commit

Permalink
Merge pull request #3 from math-pixel/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
math-pixel authored Jan 29, 2023
2 parents 8cafe89 + 099c503 commit 031daaf
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 41 deletions.
8 changes: 4 additions & 4 deletions JSON/allMaps.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"sizeCarrousel":50,
"xStart":0,
"yStart":0,
"nbRow":11,
"nbColumn":11,
"tour":{
"name": "tour",
"xStart":0,
"yStart":0,
"nbRow":11,
"nbColumn":11,
"layers":[
[
[0,0,0,0,0,0,0,0,0,0,0],
Expand Down
91 changes: 71 additions & 20 deletions src/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,34 @@ function drawingGrid(x,y,w,h,array){

function moveMap() {

if (keyIsDown(LEFT_ARROW)) {
//*boncing world
worldBoncing = getWorldBoncingArray();
let TOP = isCamNotBoncingBorderWorld(rectCam, 'TOP', worldBoncing);
let RIGHT = isCamNotBoncingBorderWorld(rectCam, 'RIGHT', worldBoncing);
let LEFT = isCamNotBoncingBorderWorld(rectCam, 'LEFT', worldBoncing);
let BOTTOM = isCamNotBoncingBorderWorld(rectCam, 'BOTTOM', worldBoncing);


console.log("top", TOP,"right",RIGHT,"left",LEFT,"bottom",BOTTOM)

if (keyIsDown(LEFT_ARROW) && LEFT) {
xStartWorld1 += 5;
}

if (keyIsDown(RIGHT_ARROW)) {
if (keyIsDown(RIGHT_ARROW) && RIGHT) {
xStartWorld1 -= 5;
}

if (keyIsDown(UP_ARROW)) {
if (keyIsDown(UP_ARROW) && TOP) {
yStartWorld1 += 5;
}

if (keyIsDown(DOWN_ARROW)) {
if (keyIsDown(DOWN_ARROW) && BOTTOM) {
yStartWorld1 -= 5;
}

}

function BoncingMapCamera(currentWorldArray){

}

// si out of array
// camera stop avant de voir la sortie du tableau
function mustAddMapAtWorlds(){
Expand All @@ -77,65 +83,110 @@ function mustAddMapAtWorlds(){

// Haut Gauche
if (currentX -1 >= 0 && currentY-1 >= 0 ) {
ArrayWorldDisplay.push(worlds1[world1.World[currentY-1][currentX-1]]);
ArrayWorldDisplay.push(Maps[world1.World[currentY-1][currentX-1]]);
}

// Haut Milieu
if (currentY-1 >= 0 ) {
ArrayWorldDisplay.push(worlds1[world1.World[currentY -1][currentX]]);
ArrayWorldDisplay.push(Maps[world1.World[currentY -1][currentX]]);
}

// Haut Droite
if (currentX + 1 < world1.World[0].length && currentY-1 >= 0 ) {
ArrayWorldDisplay.push(worlds1[world1.World[currentY -1][currentX +1]]);
ArrayWorldDisplay.push(Maps[world1.World[currentY -1][currentX +1]]);
}

// Milieu Gauche
if ( currentX -1 >= 0) {
ArrayWorldDisplay.push(worlds1[world1.World[currentY][currentX -1]]);
ArrayWorldDisplay.push(Maps[world1.World[currentY][currentX -1]]);
}

// Milieu Milieu => current Pos
if ( world1.World[currentY][currentX] != undefined) {
ArrayWorldDisplay.push(worlds1[world1.World[currentY][currentX]]);
ArrayWorldDisplay.push(Maps[world1.World[currentY][currentX]]);
}

// Milieu Droite
if ( currentX + 1 < world1.World[0].length) {
ArrayWorldDisplay.push(worlds1[world1.World[currentY][currentX + 1]]);
ArrayWorldDisplay.push(Maps[world1.World[currentY][currentX + 1]]);
}

// Bas Gauche
if ( currentX - 1 >= 0 && currentY + 1 < world1.World.length) {
ArrayWorldDisplay.push(worlds1[world1.World[currentY + 1][currentX -1]]);
ArrayWorldDisplay.push(Maps[world1.World[currentY + 1][currentX -1]]);
}

// Bas Milieu
if ( currentY + 1 < world1.World.length) {
ArrayWorldDisplay.push(worlds1[world1.World[currentY +1][currentX]]);
ArrayWorldDisplay.push(Maps[world1.World[currentY +1][currentX]]);
}

// Bas Droite
if (currentX + 1 < world1.World[0].length && currentY + 1 < world1.World.length) {
ArrayWorldDisplay.push(worlds1[world1.World[currentY +1][currentX +1]]);
ArrayWorldDisplay.push(Maps[world1.World[currentY +1][currentX +1]]);
}
}

function getWorldBoncingArray(){

let xMin = xStartWorld1 + sideCarrousel;
let yMin = yStartWorld1 + sideCarrousel;
let xMax = ( xStartWorld1 + sideCarrousel * nbRow * world1.World[0].length) - sideCarrousel ;
let yMax = ( yStartWorld1 + sideCarrousel * nbColumn * world1.World.length) - sideCarrousel ;

return [xMin,yMin,xMax,yMax]
}


function isCamNotBoncingBorderWorld(rectCam /*[x,y,x2,y2]*/, sideDirection, arrayWorld /*[x,y,x2,y2]*/){
switch(sideDirection){
case 'TOP':
if (rectCam[1] > arrayWorld[1]) {
return true
}else{
return false
}
case 'RIGHT':
if (rectCam[2] < arrayWorld[2]) {
return true
}else{
return false
}
case 'BOTTOM':
if (rectCam[3] < arrayWorld[3]) {
return true
}else{
return false
}
case 'LEFT':
if (rectCam[0] > arrayWorld[0]) {
return true
}else{
return false
}
default:
return false
}
}

function drawMap(){


moveMap();

mustAddMapAtWorlds()
mustAddMapAtWorlds();

ArrayWorldDisplay.forEach((elm, index)=>{

// console.log(elm);
let indexElm = findIndexValueIn2dArray(world1.World,elm.name)
let indexElm = findIndexValueIn2dArray(world1.World,elm.name);
//x,y,w,h,array
drawingGrid(xStartWorld1 + sideCarrousel * elm.nbRow * indexElm[1] ,yStartWorld1 + sideCarrousel * elm.nbColumn * indexElm[0] ,sideCarrousel,sideCarrousel,elm.layers[0]);
drawingGrid(xStartWorld1 + sideCarrousel * nbRow * indexElm[1] ,yStartWorld1 + sideCarrousel * nbColumn * indexElm[0] ,sideCarrousel,sideCarrousel,elm.layers[0]);
})

fill(255,255,20,80)
rect(Xcam,Ycam,Wcam,Hcam)

// fill(0,255,255,80)
// rect(Xcam, Ycam,sideCarrousel*8,sideCarrousel*4)

Expand Down
48 changes: 31 additions & 17 deletions src/configuration.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,57 @@
var world1
let worlds1 =[]
let world1
let Maps =[]

function loadAsset(){
// load all JSON FILE
world1 = loadJSON("../JSON/world.json", (e)=>{

});
worlds1 = loadJSON("../JSON/allMaps.json", (e)=> {
initVariableWorld();
Maps = loadJSON("../JSON/allMaps.json", (e)=> {
initVariableWorld(e);
});
}


//moteur de jeu
var engine = "engine1";
let engine = "engine1";

// map
var ArrayWorldDisplay = [];
let ArrayWorldDisplay = [];

var xStartWorld1 = 250;
var yStartWorld1 = 250;
let sideCarrousel;

let currentWorld = "tour";
let xStartWorld1 = 250;
let yStartWorld1 = 250;

let worldBoncing = []; //[x,y,w,h]

// cam
const Xcam = xStartWorld1 + 75;
const Ycam = yStartWorld1 + 150;
let nbRow;
let nbColumn;

let currentWorld = "tour"; // pour set le world a cette map la

//perso
var xPlayer = 500;
var yPlayer = 500;
let xPlayer = 500;
let yPlayer = 500;

// cam
const Hcam = 300;
const Wcam = Hcam * (16/9);
const Xcam = ( xPlayer + 20 / 2) - Wcam/2;
const Ycam = (yPlayer + 20 / 2) - Hcam/2;

const rectCam = [Xcam,Ycam,Xcam + Wcam, Ycam +Hcam]



function initVariableWorld(e){
sideCarrousel = e.sizeCarrousel;

function initVariableWorld(){
sideCarrousel = worlds1.sizeCarrousel;
nbRow = e.nbRow;
nbColumn = e.nbColumn;

for (let index = 0; index < 1; index++) {
ArrayWorldDisplay.push(worlds1[Object.keys(worlds1)[index]])
ArrayWorldDisplay.push(Maps[Object.keys(Maps)[index]])
}

console.log(ArrayWorldDisplay)
Expand Down

0 comments on commit 031daaf

Please sign in to comment.