function AjaxRequest(Url, Feedback, Arg) { Url = 'core/ajax/request/'+Url; if(window.XMLHttpRequest) Request = new XMLHttpRequest(); else if(window.ActiveXObject) Request = new ActiveXObject("Microsoft.XMLHTTP"); Request.onreadystatechange = function () { if(Request.readyState==4){ if(Request.status==200) { eval(Feedback); } else if(Request.status==404) { alert('Page introuvable'); } else { alert('Erreur inconnue.'); } } } Request.open("GET", Url, true); Request.send(null); }function XML2JS(xmlDoc) { var containerTag = 'page'; var Data = new Array(); var rawData = xmlDoc.getElementsByTagName(containerTag)[0]; for (i = 0; i < rawData.childNodes.length; i++) { if (rawData.childNodes[i].nodeType == 1) { Data[rawData.childNodes[i].tagName] = rawData.childNodes[i].firstChild.nodeValue; } } return Data; }function CreateGamespace() { SizeX = document.body.clientWidth; SizeY = document.body.clientHeight; document.getElementById('Gamespace').style.position = 'absolute'; document.getElementById('Gamespace').style.top = '0px'; document.getElementById('Gamespace').style.left = '0px'; document.getElementById('Gamespace').style.width = SizeX; document.getElementById('Gamespace').style.height = SizeY; document.getElementById('Gamespace').style.overflow = 'hidden'; document.body.style.background= GamespaceBg; }function ResizeGamespace(Repeat) { if(Repeat!=1) { setTimeout("ResizeGamespace(1);",50); } SizeX = document.body.clientWidth; SizeY = document.body.clientHeight; document.getElementById('Gamespace').style.width = SizeX; document.getElementById('Gamespace').style.height = SizeY; }function StartGamespace() { LockAction = 0; window.onresize = ResizeGamespace; document.onmousemove = MouseMove; document.onclick = MouseClick; document.onmouseup = Drop; setInterval("ScrollMap(ScrollY,ScrollX);",DefInterval); if(Locator==1) {CreateLocator();} }function CreateMap(SizeX, SizeY) { Map = '
'; Map += '
'; Map += '
'; Map += '
'; Map += '
'; Map += ''; Map += ''; //Map += '
'; Map += '
'; Map += '
'; Map += '
'; Map += '
'; document.getElementById('Gamespace').innerHTML = Map; document.getElementById('Map').style.top = '0px'; document.getElementById('Map').style.left = '0px'; MapStr = ''; MapPartNbX = SizeX/MapPartSizeX; MapPartNbY = SizeY/MapPartSizeY; MapPartNb = MapPartNbX*MapPartNbY; MapStr += ''; for(i=1;i<=MapPartNbY;i++) { MapStr += ''; for(j=1;j<=MapPartNbX;j++) { MapStr += ''; } MapStr += ''; } MapStr += '
 
'; document.getElementById('MapBack').innerHTML = MapStr; MapSizeX = SizeX; MapSizeY = SizeY; MapX = 0; MapY = 0; } function ChangeMapBg(NewMapBg) { document.getElementById('MapBack').innerHTML = ''; MapBg = NewMapBg; } LockScroll = 0; Top=0; Bottom=0; Left=0; Right=0; function ScrollMap(MoveX, MoveY) { if(WinOpen == 0) { Top = document.getElementById('Map').style.top; Top = Top.replace('px',''); Top = Top.replace('pt',''); Bottom = Top*1 + MapSizeY*1 - SizeY*1; Left = document.getElementById('Map').style.left; Left = Left.replace('px',''); Left = Left.replace('pt',''); Right = Left*1 + MapSizeX*1 - SizeX*1; CurMove=''; if(MoveX>0 && TopBorderLim) {MapX=BorderLim; CurMove+='';} if(MoveX<0 && Bottom>-BorderLim) {MapX += MoveX; CurMove+='s';} if(Bottom<-BorderLim) {MapX = -MapSizeY*1 + SizeY*1 - BorderLim; CurMove+='';} if(MoveY>0 && LeftBorderLim) {MapY=BorderLim; CurMove+='';} if(MoveY<0 && Right>-BorderLim) {MapY += MoveY; CurMove+='e';} if(Right<-BorderLim) {MapY = -MapSizeX*1 + SizeX*1 - BorderLim; CurMove+='';} if(MapSizeYStaticZone || RapX<-StaticZone) {ScrollX = VirtScrollX;} else {ScrollX = 0;} if(RapY>StaticZone || RapY<-StaticZone) {ScrollY = VirtScrollY;} else {ScrollY = 0;} } function MouseXCoord() { CoordX = CurrentX - Left; return CoordX; } function MouseYCoord() { CoordY = CurrentY - Top; return CoordY; }OldLoc = 0; function CreateLocator() { if(Locator == 1) { MaxLocSize = 250; if(MapSizeX >= MapSizeY) { Rapport = MaxLocSize/MapSizeX; } else { Rapport = MaxLocSize/MapSizeY; } LocSizeX = MapSizeX*Rapport; LocSizeY = MapSizeY*Rapport; Loc = '
'; Loc += ''; Loc += '
'; Loc += '
'; if (OldLoc != Loc) { if(OldLoc==0) { document.getElementById('Locator').innerHTML = Loc; OldLoc = Loc; } else { document.getElementById('MapPos').style.left = Math.round(Left*Rapport*(-1)); document.getElementById('MapPos').style.top = Math.round(Top*Rapport*(-1)); document.getElementById('MapPos').style.width = SizeX*Rapport; document.getElementById('MapPos').style.height = SizeY*Rapport; OldLoc = Loc; } } } } function HideLocator() { document.getElementById('Locator').innerHTML = ''; Locator = 0; }function CenterView(ptX,ptY) { MapX = (-ptX)+SizeY/2; MapY = (-ptY)+SizeX/2; }MapPartLoaded = new Array; function LoadMap(MapY,MapX) { //position actuelle MapPartX = Math.round(-MapX/MapPartSizeX)+1; MapPartY = Math.round(-MapY/MapPartSizeY)+1; //nombre de parties au total NbPartTotalX = (MapSizeX/MapPartSizeX); NbPartTotalY = (MapSizeY/MapPartSizeY); //nombre de parties affichées NbPartX = Math.round(SizeX/MapPartSizeX)-1; NbPartY = Math.round(SizeY/MapPartSizeY)-1; //surface à afficher MinX = MapPartX - MapPreload; MaxX = MapPartX + NbPartX + MapPreload; MinY = MapPartY - MapPreload; MaxY = MapPartY + NbPartY + MapPreload; //sort de la map ? if(MinX < 1) {MinX = 1;} if(MinY < 1) {MinY = 1;} if(MaxX > NbPartTotalX) {MaxX = NbPartTotalX;} if(MaxY > NbPartTotalY) {MaxY = NbPartTotalY;} //info debug //ShowMapLoading(MinX+'->'+MaxX+'
'+MinY+'->'+MaxY,1); //affiche la surface for(X=MinX;X<=MaxX;X++) { for(Y=MinY;Y<=MaxY;Y++) { LoadMapPict(X,Y); } } } function LoadMapPict(MapPartX,MapPartY) { PartNum = ((MapPartX)+(MapPartY-1)*16); if(MapPartLoaded[PartNum]!=1) { document.getElementById('map'+PartNum).style.background = "url("+MapBg+PartNum+".jpg)"; MapPartLoaded[PartNum]=1; } } function ShowMapLoading(Text,Init) { document.getElementById('debug').innerHTML = Text; }Elmt = new Array(); DirectElmt = new Array(); function CreateChar(posX,posY,Obj,ObjId,TranspChar) { if(TranspChar != undefined) {Transp = ' -Moz-opacity: '+TranspChar+'; filter: alpha(opacity: '+TranspChar*100+')';} else {Transp = '';} ObjImg = ''; ObjDiv = '
'+ObjImg+'
'; if(document.getElementById(ObjId) == null) { document.getElementById('Elmt').innerHTML += ObjDiv; document.getElementById(ObjId).style.position = 'absolute'; Elmt[ObjId]=Obj; Moving[ObjId] = 0; } if(DirectElmt[ObjId]!=Obj && document.getElementById(ObjId).style.top!=0) {document.getElementById(ObjId).innerHTML = ObjImg;} DirectElmt[ObjId]=Obj; if(posX<0) {posX = 0;} if(posY<0) {posY = 0;} if(posX+50>MapSizeX) {posX = MapSizeX-50;} if(posY+50>MapSizeY) {posY = MapSizeY-50;} document.getElementById(ObjId).style.left = posX; document.getElementById(ObjId).style.top = posY; //window.status = ObjId; //window.status = posX+'/'+posY; }Moving = new Array(); Move = new Array(); Loop = new Array(); Direct = ''; function MoveChar(CharID,TargX,TargY,Speed) { CharX = document.getElementById(CharID).style.left; CharX = CharX.replace('px',''); CharX = CharX.replace('pt',''); CharY = document.getElementById(CharID).style.top; CharY = CharY.replace('px',''); CharY = CharY.replace('pt',''); DistX = TargX - CharX; DistY = TargY - CharY; OldDirect = Direct; Direct = ''; if(DistY < (-100)) {Direct += 'n';} else if (DistY > 150) {Direct += 's';} if(DistX < (-100)) {Direct += 'o';} else if (DistX > 150) {Direct += 'e';} if(Direct == '') {Direct = OldDirect;} DistTotale = Math.sqrt(DistX*DistX+DistY*DistY); DeltaX = DistX/DistTotale; DeltaY = DistY/DistTotale; Loop[CharID] = 0; Mvt = Moving[CharID]; if(Mvt != 0) {StopMove(CharID);} ToEval = "CreateChar("+CharX+"+"+DeltaX+"*Loop["+CharID+"],"+CharY+"+"+DeltaY+"*Loop["+CharID+"],'"+Elmt[CharID]+"/"+Direct+"',"+CharID+");Loop["+CharID+"]+="+Speed+";if(Loop["+CharID+"]>="+DistTotale+") {EndMove("+CharID+");clearInterval(Move["+CharID+"]);}"; Move[CharID] = setInterval(ToEval,DefInterval); Moving[CharID] = 1; } function StopMove(CharID) { clearInterval(Move[CharID]); Moving[CharID] = 0; } function EndMove(CharID) { Moving[CharID] = 0; }function CreateObj(Map,posX,posY,Obj,ObjId) { Obj = '
'; if(document.getElementById(ObjId) == null) { document.getElementById(Map).innerHTML += Obj; } if(posX<0) {posX = 0;} if(posY<0) {posY = 0;} if(posX+50>MapSizeX) {posX = MapSizeX-50;} if(posY+50>MapSizeY) {posY = MapSizeY-50;} document.getElementById(ObjId).style.position = 'absolute'; document.getElementById(ObjId).style.left = posX; document.getElementById(ObjId).style.top = posY; }WinOpen = 0; function CreateWin(WinSizeX,WinSizeY,Text,WinId,Centered,Overflow) { if(Overflow == 1) { Overflow = ' overflow: auto;'; } if(document.getElementById(WinId)==null) { SizeBox = WinSizeY-50; Win = '
'; Win += '
'+WinId+'
'; Win += '
'; Win += Text; Win += '
'; Win += 'Close'; Win += '
'; Win += '
'; document.getElementById('Window').innerHTML += Win; WinOpen++; } else { if(document.getElementById(WinId).style.visibility == 'hidden') { document.getElementById(WinId).style.visibility = 'visible'; WinOpen++; } } } function CloseWindow(WinId) { document.getElementById(WinId).style.visibility = 'hidden'; WinOpen--; } WinFix = new Array(); WinDrag = ''; function Drag(WinId,Init) { if(Init == 1) { WinPosX = document.getElementById(WinId).style.left; WinPosX = WinPosX.replace('px',''); WinPosX = WinPosX.replace('pt',''); WinPosY = document.getElementById(WinId).style.top; WinPosY = WinPosY.replace('px',''); WinPosY = WinPosY.replace('pt',''); WinDecalX = MouseXCoord() - WinPosX; WinDecalY = MouseYCoord() - WinPosY; WinDrag = WinId; } if(WinDrag != '') { WinFix[WinId] = setTimeout("Drag('"+WinId+"');",DefInterval); document.getElementById(WinId).style.left = MouseXCoord()-WinDecalX*1; document.getElementById(WinId).style.top = MouseYCoord()-WinDecalY*1; } if(WinLightDrag == 1) { document.getElementById(WinId).style.MozOpacity = 1; document.getElementById(WinId).filters.alpha.opacity = 100; } } function Drop() { if(WinDrag != '') { if(WinLightDrag == 1) { setTimeout("document.getElementById('"+WinDrag+"').style.MozOpacity = WinOpacity;",DefInterval); setTimeout("document.getElementById('"+WinDrag+"').filters.alpha.opacity = WinOpacity*100;",DefInterval); } WinDrag = ''; } }function CreateDialog(BoxX,BoxY,Text,BoxId) { if(document.getElementById(BoxId)==null) { TextBox = '
'; TextBox += Text; TextBox += ''; TextBox += ''; TextBox += '
'; document.getElementById('Box').innerHTML += TextBox; } else { document.getElementById(BoxId).style.visibility = 'visible'; document.getElementById(BoxId).style.left = BoxX; document.getElementById(BoxId).style.top = BoxY; document.getElementById(BoxId).innerHTML = Text; } } function CloseDialog(BoxId) { document.getElementById(BoxId).style.visibility = 'hidden'; StickDialog(BoxId); } StickBox = new Array(); function StickDialog(BoxId,ElmtId) { if(ElmtId != undefined) { PosX = document.getElementById(ElmtId).style.left; PosY = document.getElementById(ElmtId).style.top; PosX = PosX.replace('px',''); PosX = PosX.replace('pt',''); PosY = PosY.replace('px',''); PosY = PosY.replace('pt',''); PosX -= 140; document.getElementById(BoxId).style.visibility = 'visible'; document.getElementById(BoxId).style.left = PosX; document.getElementById(BoxId).style.top = PosY; StickBox[BoxId] = setTimeout("StickDialog('"+BoxId+"','"+ElmtId+"');",DefInterval); } else { clearTimeout(StickBox[BoxId]); } }//////////////// //FICHIER GAME// //////////////// //à terme vous devriez pouvoir adapter le moteur à vos besoin en utilisant ce seul fichier //pour l'instant ça me semble délicat, cependant vous pouvez déjà voir ici un exemple d'utilisation basique du moteur //PARAMETRES //Le "Volumetric Lights" est une sorte de blur, c'était au début un bug et j'ai trouvé que ça rendait pas mal sur les toits/arbres //ça rame pas mal par contre OverMask = 0; //"Volumetric Lights" activé OverMaskOpacity = 0.2; //intensité (immonde lorsque > 0.4) ScrollSpeed = 50; //vitesse de défilement de la map StaticZone = 0.4; //sensibilité pour le scroll, 0 < StaticZone < 0.5 BorderLim = 0; //affiche une bordure autour de la map, plutôt laid en fait DynCursor = 1; //change l'apparence du curseur pendant le scroll DefInterval = 5; //temps par défaut pour les setTimeout WinOpacity = 0.9; //opacité des fenêtres WinLightDrag = 1; //annule l'opacité des fenêtres pendant les dragndrop Locator = 0; //affiche map GamespaceBg = 'url(img/map/bg/fog.gif)'; //map de fond MapBg = 'img/map/bg/AR3300/'; //dossier de la map MapPartSizeX = 320; //taille x de chaque morceau de la map MapPartSizeY = 240; //taille y MapPreload = 1; //chargement de la map en dehors de la zone visible function StartGame() { CreateGamespace(); //crée un div prenant tout l'écran où sera crée la map CreateMap(5120,3840); //crée la map de tailler 5120*3840 (attention pour l'instant l'image MapBg sera ETIREE si elle est trop petite) StartGamespace(); //démarre le tout //CreateChar(400,900,'Elemental, Water',17,0.65); CenterView(2060,2260); //cadre la vue sur ces coordonnées (assez peu précis en fait) //CreateChar est aussi utilisé pour crée des objets tels que la fumée ou de l'eau... //C'est assez illogique la fonction changera bientôt de nom CreateChar(2510,3035,'FOUNTN',2,0.7); //créer l'objet FOUNTN aux coord 2510,3035 avec l'id 2 et une opacité de 0.7 //veiller à ne pas créer 2 objets avec le même id CreateChar(1940,355,'CHIMSMK',3,0.4); CreateChar(2585,1125,'CHIMSMK',4,0.4); CreateChar(1325,1045,'CHIMSMK',5,0.4); CreateChar(4752,2425,'CHIMSMK',6,0.4); CreateChar(930,2560,'CHIMSMK',7,0.4); CreateChar(795,2710,'CHIMSMK',8,0.4); CreateChar(4476,2553,'CHIMSMK',9,0.4); CreateChar(4738,2571,'CHIMSMK',10,0.4); CreateChar(4490,2419,'CHIMSMK',11,0.4); CreateChar(3005,1713,'BUTRFLY',12); CreateChar(3657,993,'BUTRFLY',13); CreateChar(3275,995,'BUTRFLY',14); CreateChar(4492,1084,'BUTRFLY',15); CreateChar(1539,970,'BUTRFLY',16); CreateChar(1500,1500,'wyvern',1); MoveChar(1,2350,2300,5); //bouge l'objet d'id 1 (la wyvern) vers le point 2350,2300 à la vitesse 5. } //les fonctions "Action" sont appelés lorsque certains évenèment ont lieu function ActionClick() { MoveChar(1,MouseXCoord(),MouseYCoord(),5); //MouseXCoord()/MouseYCoord() retourne les coordonnées du curseur, tenant compte de la position de la map sur l'écran } function ActionMove() { window.status = Math.round(MouseXCoord())+'/'+Math.round(MouseYCoord()); //affiche en status les coordonnées de la souris, pratique pour placer de nouveau objet } function ActionOver(Id) { //ci-dessous, un petit essaie d'intégrer Ajax au moteur... très basique. //pour essayer décommenter aussi l'elemental d'eau /*if(Id == 17) { CreateDialog(100,100,'',18); //crée un div de dialogue au point 100,100, d'id 18, contenant l'image spinner.gif StickDialog(18,17); //"colle" ce div à l'élémental AjaxRequest('test.php','CreateDialog(100,100,Request.responseText,18);'); //appelle en arrière plan la page test.php, quand le résultalt arrive place dans le div de dialogue le contenu du fichier }*/ } function ActionOut(Id) { } //pour modifier le menu regarder dans le fichier index //CreateWin(350,350,WinAbout(),'About'); //crée une fenêtre déplaçable d'id 'About' au point 350,350 //de contenu WinAbout(), fonction définie dans le fichier game/win/options.win.js //si quelqu'un a une idée pour un menu plus ergonomique je suis preneur ! function WinOptions() { Options = ''; if(ScrollSpeed < 0) {ScrollSpeed=0;} Options += '

Scroll speed
'; Options += 'down '; Options += ScrollSpeed; Options += ' up'; Options += '

'; Options += '

Mouse sensitivity
'; if (StaticZone == 0) { Options += 'Scroll less'; } else { Options += 'Scroll more'; } Options += '

'; Options += '

Cursor
'; if (DynCursor == 0) { Options += 'Change cursor shape while scrolling'; } else { Options += 'Do not change cursor shape while scrolling'; } Options += '

'; Options += '

Map borders
'; if (BorderLim == 0) { Options += 'Show map borders'; } else { Options += 'Keep focus on the map'; } Options += '

'; Options += '

Volumetric Lights
'; if (OverMask == 0) { Options += 'On'; } else { Options += 'Off'; } Options += '

'; return(Options); } function RefreshOptions() { document.getElementById('OptionsBox').innerHTML=WinOptions(); }function WinAbout() { About = '
'; About += '

ForgotEngine
αlpha

build 0700

'; About += ''; About += '
'; return(About ); }