actualiser js
This commit is contained in:
parent
44e5c98da7
commit
1ece079030
1 changed files with 329 additions and 156 deletions
345
js/script.js
345
js/script.js
|
@ -13,42 +13,57 @@ const Biome = {
|
||||||
SWAMP: { acceptStructure:false, movements:['fly'],affinities:[('water',0.6),('earth',0.2),('dark',0.2)],name: 'Marais', winterColor: '#0b2e10ff', fallColor: '#0b2e10ff', summerColor: '#0b2e10ff', autumnColor: '#0b2e10ff',maxElevation:1,minElevation:-1 }
|
SWAMP: { acceptStructure:false, movements:['fly'],affinities:[('water',0.6),('earth',0.2),('dark',0.2)],name: 'Marais', winterColor: '#0b2e10ff', fallColor: '#0b2e10ff', summerColor: '#0b2e10ff', autumnColor: '#0b2e10ff',maxElevation:1,minElevation:-1 }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
const NAME_PREFIXES = ["Chêne", "Sombre", "Pierre", "Haut", "Val", "Mur", "Guet", "Clair"];
|
||||||
|
const NAME_SUFFIXES = ["bourg", "fort", "ville", "mont", "port", "bois", "rivage", "gard"];
|
||||||
|
|
||||||
|
const Affinities = ['water','fire','sand','rock','dark','life','ice','wood','wind','metal','time','space','lava','light','spirit'];
|
||||||
|
|
||||||
|
const RACE = {
|
||||||
|
HUMAN: {strength:1,vitality:1,dexterity:1,intelligence:1,wisdom:1,luck:1}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const Affinities = ['water','fire','sand','rock','dark','life','ice','wood','wind','metal','time','space','lava','light','spirit']
|
|
||||||
|
|
||||||
const Slot = ['head','body','leg','foot','right-hand','left-hand','two-hands','finger1','finger2','neck','purse','backpack','belt1','belt2']
|
const Slot = ['head','body','leg','foot','right-hand','left-hand','two-hands','finger1','finger2','neck','purse','backpack','belt1','belt2'];
|
||||||
|
|
||||||
const ItemType = {lightWeapon:{slot:('right-hand','left-hand','backpack'),soul:true,enchant:true},
|
const ItemType = {lightWeapon:{slot:('right-hand','left-hand','backpack'),soul:true,enchant:true},
|
||||||
heavyWeapon:{slot:('two-hands','backpack'),soul:true,enchant:true},
|
heavyWeapon:{slot:('two-hands','backpack'),soul:true,enchant:true},
|
||||||
heavyArmor:{slot:('body','backpack'),soul:true,enchant:true},
|
heavyArmor:{slot:('body','backpack'),soul:true,enchant:true},
|
||||||
lightArmor:{slot:('body','backpack'),soul:true,enchant:true},
|
lightArmor:{slot:('body','backpack'),soul:true,enchant:true},
|
||||||
shield:{slot:('right-hand','left-hand','backpack'),soul:true,enchant:true},
|
shield:{slot:('right-hand','left-hand','backpack'),soul:true,enchant:true},
|
||||||
shoes:{slot:('foot','backpack'),soul:true,enchant:true},
|
shoes:{slot:('foot','backpack'),soul:true,enchant:true},
|
||||||
pant:{slot:('leg','backpack'),soul:true,enchant:true},
|
pant:{slot:('leg','backpack'),soul:true,enchant:true},
|
||||||
helmet:{slot:('leg','backpack'),soul:true,enchant:true},
|
helmet:{slot:('leg','backpack'),soul:true,enchant:true},
|
||||||
potion:{slot:('heal','backpack'),soul:false,enchant:false},
|
potion:{slot:('heal','backpack'),soul:false,enchant:false},
|
||||||
throwable:{slot:('belt','backpack'),soul:true,enchant:true},
|
throwable:{slot:('belt','backpack'),soul:true,enchant:true},
|
||||||
craftMaterial:{slot:('right-hand','left-hand','backpack'),soul:false,enchant:false},
|
craftMaterial:{slot:('backpack'),soul:false,enchant:false},
|
||||||
ring:{slot:('finger1','finger2','backpack'),soul:true,enchant:true},
|
ring:{slot:('finger1','finger2','backpack'),soul:true,enchant:true},
|
||||||
amulet:{slot:('neck','backpack'),soul:true,enchant:true},
|
amulet:{slot:('neck','backpack'),soul:true,enchant:true},
|
||||||
currency:{slot:('purse'),soul:true,enchant:true},
|
currency:{slot:('purse'),soul:true,enchant:true},
|
||||||
enchantMaterial:{slot:('backpack'),soul:false,enchant:false},
|
enchantMaterial:{slot:('backpack'),soul:false,enchant:false},
|
||||||
mercantMaterial:{slot:('backpack'),soul:false,enchant:false}
|
mercantMaterial:{slot:('backpack'),soul:false,enchant:false}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Items = {
|
const Items = {
|
||||||
'Épée en Bois': { name: 'Épée en Bois', itemType: 'lightWeapon', stats: { strength: 2 }, icon: '🗡️' ,enchantments:[] },
|
'Épée en Bois': { name: 'Épée en Bois', itemType: 'lightWeapon', stats: { strength: 2 }, icon: '🗡️' ,enchantments:[] },
|
||||||
'Armure de Cuir': { name: 'Armure de Cuir', itemType: 'lightArmor', stats: { vitality: 2 }, icon: '🧥',enchantments:[] },
|
'Armure de Cuir': { name: 'Armure de Cuir', itemType: 'lightArmor', stats: { vitality: 2 }, icon: '🧥',enchantments:[] },
|
||||||
'Claymore': { name: 'Claymore', itemType: 'lightArmor', stats: { vitality: 2 }, icon: '🧥',enchantments:['primal'] ,soul:new soul('cleaver','test')}
|
'Claymore': { name: 'Claymore', itemType: 'lightArmor', stats: { vitality: 2 }, icon: '🧥',enchantments:['primal'] ,soul:new soul('cleaver','test')},
|
||||||
};
|
'Bois': { name: 'Bois', itemType: 'craftMaterial', icon: '🌲',biome:['FOREST'],occurence:0.9},
|
||||||
|
'stone': { name: 'Pierre', itemType: 'craftMaterial', icon: '🗿',biome:['MOUNTAIN'],occurence:0.4},
|
||||||
|
'Herbes': { name: 'Herbes', itemType: 'craftMaterial', icon: '🌿',biome:['GRASSLAND'],occurence:0.4},
|
||||||
|
'Cristaux Magiques': { name: ' enchantMaterial',icon: '💎',biome:['MOUNTAIN','ENCHANTED_FOREST'],occurence:0.005},
|
||||||
|
'Fer': { name: 'Fer', itemType: 'craftMaterial', icon: '🔩',biome:['MOUNTAIN'],occurence:0.001},
|
||||||
|
'Mushroom': { name: 'Champignons', itemType: 'craftMaterial', icon: '🍄',biome:['FOREST'],occurence:0.01},
|
||||||
|
'gold': { name: 'Champignons', itemType: 'mercantMaterial', icon: '💰',biome:['MOUNTAIN','RIVER'],occurence:0.001}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const StructureType = {
|
const StructureType = {
|
||||||
'Épée en Bois': { name: 'Épée en Bois', itemType: 'lightWeapon', stats: { strength: 2 }, icon: '🗡️' ,enchantments:[] },
|
TOWN: { name: 'Ville', population:15, icon: '🗡️', occurence:0.001,design: `<svg width="0" height="0" style="position:absolute; display: none;"> <defs> <g id="city-svg" viewBox="0 0 100 100"> <defs> <linearGradient id="stoneGradient" x1="0%" y1="0%" x2="0%" y2="100%"> <stop offset="0%" style="stop-color:#A9A9A9;" /> <stop offset="100%" style="stop-color:#696969;" /> </linearGradient> <linearGradient id="stoneShadowGradient" x1="0%" y1="0%" x2="0%" y2="100%"> <stop offset="0%" style="stop-color:#808080;" /> <stop offset="100%" style="stop-color:#4A5568;" /> </linearGradient> </defs> <!-- Muraille --> <path d="M 10 95 L 15 70 L 85 70 L 90 95 Z" fill="url(#stoneShadowGradient)" stroke="#1A202C" stroke-width="2" /> <!-- Crénaux muraille --> <path d="M 15 70 L 15 65 L 25 65 L 25 70 L 35 70 L 35 65 L 45 65 L 45 70 L 55 70 L 55 65 L 65 65 L 65 70 L 75 70 L 75 65 L 85 65 L 85 70 Z" fill="url(#stoneShadowGradient)" stroke="#1A202C" stroke-width="1.5"/> <!-- Tour gauche --> <rect x="20" y="30" width="20" height="40" fill="url(#stoneGradient)" stroke="#1A202C" stroke-width="2"/> <rect x="18" y="25" width="24" height="5" fill="url(#stoneGradient)" stroke="#1A202C" stroke-width="2"/> <!-- Tour droite --> <rect x="60" y="30" width="20" height="40" fill="url(#stoneGradient)" stroke="#1A202C" stroke-width="2"/> <rect x="58" y="25" width="24" height="5" fill="url(#stoneGradient)" stroke="#1A202C" stroke-width="2"/> <!-- Donjon central --> <rect x="40" y="15" width="20" height="55" fill="url(#stoneGradient)" stroke="#1A202C" stroke-width="2"/> <path d="M 38 15 L 38 10 L 43 10 L 43 15 L 48 15 L 48 10 L 53 10 L 53 15 L 58 15 L 58 10 L 63 10 L 63 15 Z" fill="url(#stoneGradient)" stroke="#1A202C" stroke-width="1.5"/> </g> </defs> </svg>`},
|
||||||
'Armure de Cuir': { name: 'Armure de Cuir', itemType: 'lightArmor', stats: { vitality: 2 }, icon: '🧥',enchantments:[] },
|
VILLAGE: { name: 'Village', population:5, icon: '🗡️',occurence:0.005, design: `<svg width="0" height="0" style="position:absolute; display: none;"> <defs> <!-- Définition du Village --> <g id="village-svg" viewBox="0 0 100 100"> <defs> <linearGradient id="woodGradient" x1="0%" y1="0%" x2="0%" y2="100%"> <stop offset="0%" style="stop-color:#A0522D;" /> <stop offset="100%" style="stop-color:#8B4513;" /> </linearGradient> <linearGradient id="thatchGradient" x1="0%" y1="0%" x2="0%" y2="100%"> <stop offset="0%" style="stop-color:#D4A373;" /> <stop offset="100%" style="stop-color:#A0522D;" /> </linearGradient> </defs> <!-- Maison principale --> <rect x="20" y="50" width="60" height="45" fill="url(#woodGradient)" stroke="#1A202C" stroke-width="2"/> <polygon points="15,50 85,50 50,20" fill="url(#thatchGradient)" stroke="#1A202C" stroke-width="2"/> <!-- Petite maison derrière --> <rect x="65" y="60" width="25" height="35" fill="#8B4513" stroke="#1A202C" stroke-width="1.5"/> <polygon points="62,60 93,60 77.5,40" fill="#A0522D" stroke="#1A202C" stroke-width="1.5"/> <!-- Fenêtre --> <rect x="45" y="65" width="10" height="10" fill="#2D3748"/> </g> </defs> </svg>`},
|
||||||
'Claymore': { name: 'Claymore', itemType: 'lightArmor', stats: { vitality: 2 }, icon: '🧥',enchantments:['primal'] ,soul:new soul('cleaver','test')}
|
FARM: { name: 'Ferme', population:5, icon: '🗡️',occurence:0.010 },
|
||||||
};
|
CAMP:{ name: 'Campement', population:2, icon: '⛺',occurence:0.002 },
|
||||||
|
};
|
||||||
|
|
||||||
const MONSTER_TYPES = {
|
const MONSTER_TYPES = {
|
||||||
GOBLIN: { name: 'Gobelin', icon: '👺', hp: 30, strength: 3, xp: 25, loot: { 'Or': 5 } },
|
GOBLIN: { name: 'Gobelin', icon: '👺', hp: 30, strength: 3, xp: 25, loot: { 'Or': 5 } },
|
||||||
|
@ -56,29 +71,10 @@ const MONSTER_TYPES = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const ANIMAL_TYPES = {
|
const ANIMAL_TYPES = {
|
||||||
WOLF: { name: 'Loup', icon: '🐺', hp: 20, strength: 4, xp: 15, loot: { 'Cuir': 1, 'Os': 1 } },
|
WOLF: { name: 'Loup', icon: '🐺', hp: 20, strength: 4, xp: 15, loot: { 'Cuir': 1, 'Os': 1 }, design: `<svg width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"><defs><linearGradient id="wolfFurGradient" x1="0%" y1="0%" x2="0%" y2="100%"><stop offset="0%" style="stop-color:#4A5568;" /><stop offset="100%" style="stop-color:#2D3748;" /></linearGradient><linearGradient id="wolfShadowGradient" x1="0%" y1="0%" x2="0%" y2="100%"><stop offset="0%" style="stop-color:#2D3748;" /><stop offset="100%" style="stop-color:#1A202C;" /></linearGradient></defs><g><path d="M 50 10 L 90 40 L 80 95 L 20 95 L 10 40 Z" fill="url(#wolfFurGradient)" /><path d="M 50 10 L 70 45 L 50 55 L 30 45 Z" fill="url(#wolfShadowGradient)" /><path d="M 20 95 Q 40 70 50 75 Q 60 70 80 95 L 75 98 L 25 98 Z" fill="#2D3748" /><path d="M 25 42 L 10 20 L 35 30 Z" fill="#4A5568" stroke="#1A202C" stroke-width="1"/><path d="M 75 42 L 90 20 L 65 30 Z" fill="#4A5568" stroke="#1A202C" stroke-width="1"/><path d="M 28 38 L 18 25 L 35 32 Z" fill="#2D3748"/><path d="M 72 38 L 82 25 L 65 32 Z" fill="#2D3748"/><path d="M 50 50 L 65 80 L 50 90 L 35 80 Z" fill="#4A5568" /><path d="M 50 85 L 55 95 L 45 95 Z" fill="black" /><path d="M 35 45 Q 40 42 45 45 Q 40 48 35 45 Z" fill="#FBBF24" /><path d="M 65 45 Q 60 42 55 45 Q 60 48 65 45 Z" fill="#FBBF24" /><circle cx="39" cy="45" r="1" fill="black" /><circle cx="61" cy="45" r="1" fill="black" /><path d="M 18 50 L 10 40 L 25 55 Z" fill="#4A5568" /><path d="M 82 50 L 90 40 L 75 55 Z" fill="#4A5568" /><path d="M 20 65 L 5 55 L 22 70 Z" fill="#4A5568" /><path d="M 80 65 L 95 55 L 78 70 Z" fill="#4A5568" /></g></svg>`},
|
||||||
BOAR: { name: 'Sanglier', icon: '🐗', hp: 25, strength: 5, xp: 20, loot: { 'Cuir': 2 } },
|
BOAR: { name: 'Sanglier', icon: '🐗', hp: 25, strength: 5, xp: 20, loot: { 'Cuir': 2 } },
|
||||||
};
|
};
|
||||||
|
|
||||||
class world {
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.h = h;
|
|
||||||
}
|
|
||||||
setPosition(x,y,z) {
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.h = h;
|
|
||||||
}
|
|
||||||
|
|
||||||
getPosition() {
|
|
||||||
return { x: this.x, y: this.y, z: this.z };
|
|
||||||
}
|
|
||||||
// Méthode de l'objet
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class position {
|
class position {
|
||||||
|
|
||||||
|
@ -96,20 +92,25 @@ class position {
|
||||||
getPosition() {
|
getPosition() {
|
||||||
return { x: this.x, y: this.y, z: this.z };
|
return { x: this.x, y: this.y, z: this.z };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cartToIso() {
|
||||||
|
return {
|
||||||
|
x: (this.x - this.y) * 32,
|
||||||
|
y: (this.x + this.y) * 16
|
||||||
|
}
|
||||||
|
}
|
||||||
// Méthode de l'objet
|
// Méthode de l'objet
|
||||||
}
|
}
|
||||||
|
|
||||||
class tile {
|
class tile {
|
||||||
|
|
||||||
constructor(position,biome,elevation) {
|
constructor(position,elevation) {
|
||||||
this.position = position;
|
this.position = position;
|
||||||
if (!Object.values(Biome).includes(biome)) {
|
this.biome = this.setBiome();
|
||||||
throw new Error('Biome invalide !');
|
this.elevation = this.setElevation();
|
||||||
}
|
this.structure = this.setStructure();
|
||||||
this.biome = setBiome();
|
|
||||||
this.elevation = elevation;
|
|
||||||
this.structures = null;
|
|
||||||
this.explored = false;
|
this.explored = false;
|
||||||
|
this.design=null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Méthode de l'objet
|
// Méthode de l'objet
|
||||||
|
@ -125,17 +126,61 @@ class tile {
|
||||||
let tRaw = (simplex.noise2D(x * scale * 0.8, y * scale * 0.8) + 1) / 2;
|
let tRaw = (simplex.noise2D(x * scale * 0.8, y * scale * 0.8) + 1) / 2;
|
||||||
let mRaw = (simplex.noise2D(x * scale * 1.5, y * scale * 1.5) + 1) / 2;
|
let mRaw = (simplex.noise2D(x * scale * 1.5, y * scale * 1.5) + 1) / 2;
|
||||||
|
|
||||||
if (eRaw < 0.25) biome = BIOMES.WATER_DEEP;
|
if (eRaw < 0.25) this.biome = BIOMES.WATER_DEEP;
|
||||||
else if (eRaw < 0.3) biome = BIOMES.WATER_SHALLOW;
|
else if (eRaw < 0.3) this.biome = BIOMES.WATER_SHALLOW;
|
||||||
else if (eRaw < 0.35) biome = BIOMES.SAND;
|
else if (eRaw < 0.35) this.biome = BIOMES.SAND;
|
||||||
else if (eRaw > 0.85) biome = BIOMES.SNOW;
|
else if (eRaw > 0.85) this.biome = BIOMES.SNOW;
|
||||||
else if (eRaw > 0.75) biome = BIOMES.MOUNTAIN;
|
else if (eRaw > 0.75) this.biome = BIOMES.MOUNTAIN;
|
||||||
else {
|
else {
|
||||||
if (tRaw < 0.3) biome = BIOMES.DESERT;
|
if (tRaw < 0.3) this.biome = BIOMES.DESERT;
|
||||||
else if (tRaw > 0.6) biome = (mRaw > 0.7) ? BIOMES.ENCHANTED_FOREST : BIOMES.FOREST;
|
else if (tRaw > 0.6) this.biome = (mRaw > 0.7) ? BIOMES.ENCHANTED_FOREST : BIOMES.FOREST;
|
||||||
else biome = BIOMES.GRASSLAND;
|
else this.biome = BIOMES.GRASSLAND;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
setDesign(ctx){
|
||||||
|
if (!this.biome) return;
|
||||||
|
const screenPos = this.position.cartToIso();
|
||||||
|
const elevationHeight = this.position.h * 8;
|
||||||
|
|
||||||
|
ctx.save();
|
||||||
|
ctx.translate(screenPos.x, screenPos.y - elevationHeight);
|
||||||
|
const baseColor = this.biome.color;
|
||||||
|
const shadowColor = shadeColor(baseColor, -30);
|
||||||
|
ctx.fillStyle = shadowColor;
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(0, 32); ctx.lineTo(32, 16); ctx.lineTo(32, 16 + elevationHeight); ctx.lineTo(0, 32 + elevationHeight);
|
||||||
|
ctx.closePath();
|
||||||
|
ctx.fill();
|
||||||
|
ctx.fillStyle = shadeColor(shadowColor, -10);
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(0, 32); ctx.lineTo(-32, 16); ctx.lineTo(-32, 16 + elevationHeight); ctx.lineTo(0, 32 + elevationHeight);
|
||||||
|
ctx.closePath();
|
||||||
|
ctx.fill();
|
||||||
|
ctx.fillStyle = baseColor;
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(0, 0); ctx.lineTo(32, 16); ctx.lineTo(0, 32); ctx.lineTo(-32, 16);
|
||||||
|
ctx.closePath();
|
||||||
|
ctx.fill();
|
||||||
|
if (this.structure.type === 'village') {
|
||||||
|
ctx.fillStyle = '#D4A373';
|
||||||
|
ctx.fillRect(-8, -12, 16, 12);
|
||||||
|
ctx.fillStyle = '#8B4513';
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(0, -22); ctx.lineTo(-10, -12); ctx.lineTo(10, -12);
|
||||||
|
ctx.closePath();
|
||||||
|
ctx.fill();
|
||||||
|
} else if (this.structure.type === 'city') {
|
||||||
|
ctx.fillStyle = '#C0C0C0';
|
||||||
|
ctx.fillRect(-10, -20, 20, 20);
|
||||||
|
ctx.fillStyle = '#808080';
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(-10, -20); ctx.lineTo(-12, -22); ctx.lineTo(22, -22); ctx.lineTo(20, -20);
|
||||||
|
ctx.closePath();
|
||||||
|
ctx.fill();
|
||||||
|
}
|
||||||
|
ctx.restore();
|
||||||
|
}
|
||||||
|
|
||||||
setExplored(explored) {
|
setExplored(explored) {
|
||||||
this.explored=explored;
|
this.explored=explored;
|
||||||
}
|
}
|
||||||
|
@ -144,39 +189,30 @@ class tile {
|
||||||
}
|
}
|
||||||
setStructure(){
|
setStructure(){
|
||||||
var structureChance = rand();
|
var structureChance = rand();
|
||||||
if (structureChance < 0.005) {
|
if (structureChance < 0.005 && this.tile.biome.acceptStructure) {
|
||||||
structure = { type: 'city', name: NAME_PREFIXES[Math.floor(rand() * NAME_PREFIXES.length)] + NAME_SUFFIXES[Math.floor(rand() * NAME_SUFFIXES.length)], population: 100 + Math.floor(rand() * 150), buildings: ['Remparts', 'Place Forte (Château)', 'Grand Marché', 'Forge', 'Alchimiste', 'Enchanteur', 'Écurie', 'Ferme', 'Ferme', 'Ferme', 'Ferme', 'Ferme', 'Lieu de Culte', 'Nombreuses Maisons'] };
|
this.structure = { type: 'city', name: NAME_PREFIXES[Math.floor(rand() * NAME_PREFIXES.length)] + NAME_SUFFIXES[Math.floor(rand() * NAME_SUFFIXES.length)], population: TOWN.population + Math.floor(rand() * 150), buildings: ['Remparts', 'Place Forte (Château)', 'Grand Marché', 'Forge', 'Alchimiste', 'Enchanteur', 'Écurie', 'Ferme', 'Ferme', 'Ferme', 'Ferme', 'Ferme', 'Lieu de Culte', 'Nombreuses Maisons'] };
|
||||||
structureLocations.push({x, y, type: 'city'});
|
} else if (structureChance < 0.02 && this.tile.biome.acceptStructure) {
|
||||||
} else if (structureChance < 0.02) {
|
this.structure = { type: 'village', name: NAME_PREFIXES[Math.floor(rand() * NAME_PREFIXES.length)] + NAME_SUFFIXES[Math.floor(rand() * NAME_SUFFIXES.length)], population: VILLAGE.population + Math.floor(rand() * 20), buildings: ['Maison du Chef', 'Marchand', 'Lieu de Culte', 'Ferme', 'Ferme', 'Plusieurs Maisons'] };
|
||||||
structure = { type: 'village', name: NAME_PREFIXES[Math.floor(rand() * NAME_PREFIXES.length)] + NAME_SUFFIXES[Math.floor(rand() * NAME_SUFFIXES.length)], population: 20 + Math.floor(rand() * 20), buildings: ['Maison du Chef', 'Marchand', 'Lieu de Culte', 'Ferme', 'Ferme', 'Plusieurs Maisons'] };
|
|
||||||
structureLocations.push({x, y, type: 'village'});
|
|
||||||
}
|
}
|
||||||
if (!this.tile && this.tile.biome === BIOMES.GRASSLAND && Math.random() < 0.2) {
|
if (!this.tile && this.tile.biome === BIOMES.GRASSLAND && Math.random() < 0.2) {
|
||||||
tile.isFarm = true;
|
this.structure={type:'farm', name: 'farm', population: 2, buildings: []}
|
||||||
tile.farmCrop = null;
|
|
||||||
tile.farmHarvested = false;
|
|
||||||
// npcs.push({ x: nx, y: ny, homeX: loc.x, homeY: loc.y, workX: nx, workY: ny, type: 'farmer', icon: '🧑🌾' });
|
// npcs.push({ x: nx, y: ny, homeX: loc.x, homeY: loc.y, workX: nx, workY: ny, type: 'farmer', icon: '🧑🌾' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
class map {
|
class map {
|
||||||
constructor() {
|
constructor(size) {
|
||||||
this.tiles = null;
|
this.map_size = size;
|
||||||
this.map_size = 200;
|
this.tiles = initializeMap();
|
||||||
this.tile_width = 64;
|
|
||||||
this.tile_height = 32;
|
|
||||||
this.elevation = 8;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
initializeMap(){
|
initializeMap(){
|
||||||
console.time('Map Generation');
|
console.time('Map Generation');
|
||||||
const simplex = new SimplexNoise();
|
const simplex = new SimplexNoise();
|
||||||
mapData = Array(this.map_size).fill(null).map((_, y) => Array(this.map_size).fill(null).map((_, x) => {
|
this.tiles = Array(size).fill(null).map((_, y) => Array(size).fill(null).map((_, x) => new Tile(new Position(x, y))));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
class Time {
|
||||||
class time {
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.year = 812;
|
this.year = 812;
|
||||||
this.month = 1;
|
this.month = 1;
|
||||||
|
@ -220,7 +256,7 @@ class attributes {
|
||||||
}
|
}
|
||||||
|
|
||||||
class creature {
|
class creature {
|
||||||
constructor(name,attributes,level,affinities,name,alignments,position,species,race,hp,items) {
|
constructor(name,attributes,level,affinities,alignments,tile,species,race,hp,items) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.attributes = attributes;
|
this.attributes = attributes;
|
||||||
this.level = level;
|
this.level = level;
|
||||||
|
@ -229,6 +265,8 @@ class creature {
|
||||||
this.alignments = alignments;
|
this.alignments = alignments;
|
||||||
this.species = species;
|
this.species = species;
|
||||||
this.race = race;
|
this.race = race;
|
||||||
|
this.tile=tile;
|
||||||
|
this.items=items;
|
||||||
this.hp=hp;
|
this.hp=hp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,13 +299,44 @@ class npc {
|
||||||
}
|
}
|
||||||
|
|
||||||
class player {
|
class player {
|
||||||
constructor(name,creature,equipments) {
|
constructor(creature,equipments) {
|
||||||
this.creature=creature;
|
this.creature=creature;
|
||||||
this.equipments=equipments;
|
this.equipments=equipments;
|
||||||
|
this.color = '#E53E3E';
|
||||||
|
}
|
||||||
|
draw(ctx) {
|
||||||
|
const tile = this.creature.tile
|
||||||
|
if(!tile) return;
|
||||||
|
|
||||||
|
const screenPos = tile.cartToIso();
|
||||||
|
const elevationHeight = tile.position.h * 8;
|
||||||
|
|
||||||
|
ctx.save();
|
||||||
|
ctx.translate(screenPos.x, screenPos.y - elevationHeight);
|
||||||
|
ctx.fillStyle = 'rgba(0, 0, 0, 0.4)';
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.ellipse(0, 16 + 2, 6, 3, 0, 0, Math.PI * 2);
|
||||||
|
ctx.fill();
|
||||||
|
ctx.fillStyle = this.color;
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(0, 16 - 6, 8, 0, Math.PI * 2);
|
||||||
|
ctx.fill();
|
||||||
|
ctx.strokeStyle = shadeColor(this.color, -30);
|
||||||
|
ctx.lineWidth = 2;
|
||||||
|
ctx.stroke();
|
||||||
|
ctx.restore();
|
||||||
|
}
|
||||||
|
move(dx, dy) {
|
||||||
|
const newX = this.position.x + dx;
|
||||||
|
const newY = this.position.y + dy;
|
||||||
|
if (newX >= 0 && newX < gameMap.size && newY >= 0 && newY < gameMap.size) {
|
||||||
|
const targetTile = gameMap.tiles[newY][newX];
|
||||||
|
if (targetTile.biome && targetTile.biome.movements.includes('walk')) {
|
||||||
|
this.position.x = newX;
|
||||||
|
this.position.y = newY;
|
||||||
|
centerCameraOnPlayer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
move(position) {
|
|
||||||
this.position=position
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rename(name) {
|
rename(name) {
|
||||||
|
@ -278,7 +347,7 @@ class player {
|
||||||
equipment.equip(item,slot);
|
equipment.equip(item,slot);
|
||||||
updateAttribute();
|
updateAttribute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class settlement {
|
class settlement {
|
||||||
constructor(level,affinities,name,alignments,position,structures) {
|
constructor(level,affinities,name,alignments,position,structures) {
|
||||||
|
@ -297,7 +366,9 @@ class resource {
|
||||||
this.resourceType = resourceType;
|
this.resourceType = resourceType;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
}
|
}
|
||||||
|
collect(tile){
|
||||||
|
|
||||||
|
}
|
||||||
collect(creature){
|
collect(creature){
|
||||||
// check if creature can collect
|
// check if creature can collect
|
||||||
// transfer resulting items creature.items[]=this.resourceType.item
|
// transfer resulting items creature.items[]=this.resourceType.item
|
||||||
|
@ -332,7 +403,7 @@ class soul {
|
||||||
}
|
}
|
||||||
// Méthode de l'objet
|
// Méthode de l'objet
|
||||||
invoke() {
|
invoke() {
|
||||||
//replace current equipment
|
//
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -367,3 +438,105 @@ class item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
class Camera {
|
||||||
|
|
||||||
|
constructor(x=0,y=0) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y
|
||||||
|
}
|
||||||
|
// Méthode de l'objet
|
||||||
|
setPosition(positon) {
|
||||||
|
if (!isGameReady) return;
|
||||||
|
const screenPos = positon.cartToIso();
|
||||||
|
const elevationHeight = position.h * 8;
|
||||||
|
this.x = canvas.width / 2 - screenPos.x;
|
||||||
|
this.y = canvas.height / 2 - (screenPos.y - elevationHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
class world {
|
||||||
|
|
||||||
|
constructor(name) {
|
||||||
|
this.name = name;
|
||||||
|
this.map = new map(1000)
|
||||||
|
let spawnX, spawnY;
|
||||||
|
do {
|
||||||
|
spawnX = Math.floor(Math.random() * this.map.size);
|
||||||
|
spawnY = Math.floor(Math.random() * this.map.size);
|
||||||
|
} while (!this.map.tiles[spawnY][spawnX].biome || !this.map.tiles[spawnY][spawnX].biome.movements.includes('walk') );
|
||||||
|
this.player = new player(new creature('player',new attributes(HUMAN),1,null,null,this.map.tiles[spawnY][spawnX],'human',HUMAN,10,null),null);
|
||||||
|
this.camera = new Camera();
|
||||||
|
this.camera.setPosition(player.position);
|
||||||
|
}
|
||||||
|
// Méthode de l'objet
|
||||||
|
save() {
|
||||||
|
// delete after x Tick
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const controls = { up: false, down: false, left: false, right: false };
|
||||||
|
let lastMoveTime = 0;
|
||||||
|
let isGameReady = false;
|
||||||
|
const canvas = document.getElementById('gameCanvas');
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
const loadingScreen = document.getElementById('loading');
|
||||||
|
|
||||||
|
function handleMovement(player,currentTime) {
|
||||||
|
if (currentTime - lastMoveTime < 150) return;
|
||||||
|
let moved = false;
|
||||||
|
if (controls.up) { player.move(0, -1); moved = true; }
|
||||||
|
if (controls.down) { player.move(0, 1); moved = true; }
|
||||||
|
if (controls.left) { player.move(-1, 0); moved = true; }
|
||||||
|
if (controls.right) { player.move(1, 0); moved = true; }
|
||||||
|
if(moved) lastMoveTime = currentTime;
|
||||||
|
}
|
||||||
|
function gameLoop(world,currentTime) {
|
||||||
|
handleMovement(world.player,currentTime);
|
||||||
|
draw(currentTime);
|
||||||
|
requestAnimationFrame(gameLoop);
|
||||||
|
}
|
||||||
|
function setupControls() {
|
||||||
|
document.addEventListener('keydown', e => {
|
||||||
|
const key = e.key.toLowerCase();
|
||||||
|
if (key.startsWith('arrow')) { controls[key.replace('arrow', '')] = true; }
|
||||||
|
else if (['w', 'z'].includes(key)) { controls.up = true; }
|
||||||
|
else if (['s'].includes(key)) { controls.down = true; }
|
||||||
|
else if (['a', 'q'].includes(key)) { controls.left = true; }
|
||||||
|
else if (['d'].includes(key)) { controls.right = true; }
|
||||||
|
});
|
||||||
|
document.addEventListener('keyup', e => {
|
||||||
|
const key = e.key.toLowerCase();
|
||||||
|
if (key.startsWith('arrow')) { controls[key.replace('arrow', '')] = false; }
|
||||||
|
else if (['w', 'z'].includes(key)) { controls.up = false; }
|
||||||
|
else if (['s'].includes(key)) { controls.down = false; }
|
||||||
|
else if (['a', 'q'].includes(key)) { controls.left = false; }
|
||||||
|
else if (['d'].includes(key)) { controls.right = false; }
|
||||||
|
});
|
||||||
|
const controlMap = { 'btn-up': 'up', 'btn-down': 'down', 'btn-left': 'left', 'btn-right': 'right' };
|
||||||
|
for (const [id, dir] of Object.entries(controlMap)) {
|
||||||
|
const btn = document.getElementById(id);
|
||||||
|
btn.addEventListener('touchstart', e => { e.preventDefault(); controls[dir] = true; }, { passive: false });
|
||||||
|
btn.addEventListener('touchend', e => { e.preventDefault(); controls[dir] = false; });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function shadeColor(c, p) {
|
||||||
|
let R=parseInt(c.substring(1,3),16),G=parseInt(c.substring(3,5),16),B=parseInt(c.substring(5,7),16);R=parseInt(R*(100+p)/100);G=parseInt(G*(100+p)/100);B=parseInt(B*(100+p)/100);R=(R<255)?R:255;G=(G<255)?G:255;B=(B<255)?B:255;
|
||||||
|
return "#"+("0"+R.toString(16)).slice(-2)+("0"+G.toString(16)).slice(-2)+("0"+B.toString(16)).slice(-2);
|
||||||
|
}
|
||||||
|
function resizeCanvas() {
|
||||||
|
canvas.width = canvas.parentElement.clientWidth;
|
||||||
|
canvas.height = canvas.parentElement.clientHeight;
|
||||||
|
if (isGameReady) centerCameraOnPlayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
function initializeGame() {
|
||||||
|
resizeCanvas();
|
||||||
|
setupControls();
|
||||||
|
let world=new world('1sttest');
|
||||||
|
isGameReady = true;
|
||||||
|
centerCameraOnPlayer(world.player);
|
||||||
|
loadingScreen.style.display = 'none';
|
||||||
|
gameLoop(world);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue