metanohi-misc-subsites/old-projects/eonaton/game/stuff/backup.20-12-08-17.54/classes.js

73 lines
2.3 KiB
JavaScript

// Screen
function screen() {
var type, name, description, background, bbackground, width, height, viswidth, visheight, elem
this.type="screen"
}
screen.prototype.create=function() {
document.body.style.background=style_bg_img(this.bbackground)
this.elem=document.createElement("div")
this.elem.style.background=style_bg_img(this.background)
this.elem.id="gamebox"
this.elem.style.width=(this.viswidth)+"px"
this.elem.style.height=(this.visheight)+"px"
this.elem.style.marginLeft=(-this.viswidth/2)+"px"
this.elem.style.marginTop=(-this.visheight/2)+"px"
document.body.appendChild(this.elem)
characters_container=document.createElement("div")
characters_container.id="characters"
this.elem.appendChild(characters_container)
}
screen.prototype.add=function(obj) {
eval(obj.type+"s_container").appendChild(obj.elem)
if (obj.type=="character") bring_to_life(obj)
}
screen.prototype.remove=function() {
document.body.style.background=""
document.body.removeChild(this.elem)
}
// Character
function character() {
var type, name, description, src, width, height, dirs, elem, elems
this.type="character"
this.dirs=new Array(8)
}
character.prototype.dir=function(dir) {
this.dirs[dir[0]]=new Array()
this.dirs[dir[0]][0]=dir[1]
for (var i=1;i<4;i++) {
this.dirs[dir[0]][i]=new Array()
}
for (i=2;i<dir.length;i++) {
if (dir[i]==1) this.dirs[dir[0]][1].push(i-2)
else if (dir[i]==2) this.dirs[dir[0]][2].push(i-2)
else if (dir[i]==3) this.dirs[dir[0]][3].push(i-2)
}
this.dirs[dir[0]][4]=dir.length-2
}
character.prototype.create=function() {
this.elems=new Array(8)
this.elem=document.createElement("div")
for (var i=0;i<8;i++) {
if (this.dirs[i]) {
this.elems[i]=new Array()
for (var ii=0;ii<this.dirs[i][4];ii++) {
this.elems[i][ii]=document.createElement("div")
this.elems[i][ii].style.background="url("+this.src+")"
this.elems[i][ii].style.backgroundPosition="-"+(ii*(this.width+1)+1)+"px -"+(this.dirs[i][0]*(this.height+1)+1)+"px"
this.elems[i][ii].style.width=(this.width)+"px"
this.elems[i][ii].style.height=(this.height)+"px"
this.elem.appendChild(this.elems[i][ii])
}
}
}
}
character.prototype.remove=function() {
characters_container.removeChild(this.elem)
}