First commit.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
// 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") give_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, posX, posY
|
||||
this.type="character"
|
||||
this.dirs=new Array(8)
|
||||
this.posX=0
|
||||
this.posY=0
|
||||
}
|
||||
|
||||
character.prototype.dir=function(dir,row,stand,walk,run) {
|
||||
this.dirs[dir]=new Array()
|
||||
this.dirs[dir][0]=row
|
||||
this.dirs[dir][1]=stand
|
||||
this.dirs[dir][2]=walk
|
||||
this.dirs[dir][3]=run
|
||||
}
|
||||
|
||||
character.prototype.create=function() {
|
||||
this.elem=document.createElement("div")
|
||||
this.elem=document.createElement("div")
|
||||
this.elem.style.background="url("+this.src+")"
|
||||
this.elem.style.width=(this.width)+"px"
|
||||
this.elem.style.height=(this.height)+"px"
|
||||
}
|
||||
|
||||
character.prototype.remove=function() {
|
||||
characters_container.removeChild(this.elem)
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
function style_bg_img(background) {
|
||||
var cssurl
|
||||
if (background.indexOf(".")!=-1) cssurl=["url(",")"]
|
||||
else cssurl=["",""]
|
||||
return cssurl[0]+background+cssurl[1]
|
||||
}
|
||||
|
||||
function create(scr) {
|
||||
scr.create()
|
||||
link(scr)
|
||||
}
|
||||
|
||||
function remove(obj) {
|
||||
if (obj.type="character") take_life(obj)
|
||||
obj.remove()
|
||||
delete obj
|
||||
}
|
||||
|
||||
function getkeycode(e) {
|
||||
var keycode
|
||||
if (window.event) keycode=window.event.keyCode
|
||||
else if (e) keycode=e.which
|
||||
else keycode=0
|
||||
return keycode
|
||||
}
|
||||
|
||||
function START_systems() {
|
||||
key_up=false
|
||||
key_right=false
|
||||
key_down=false
|
||||
key_left=false
|
||||
key_shift=false
|
||||
key_control=false
|
||||
|
||||
key_order=new Array()
|
||||
for (var i=0;i<4;i++) {
|
||||
key_order[i]=0
|
||||
}
|
||||
|
||||
direction=7
|
||||
character_state=1
|
||||
|
||||
document.onkeydown=keydown
|
||||
document.onkeyup=keyup
|
||||
|
||||
characters=new Array()
|
||||
row_num=new Array()
|
||||
col_num=new Array()
|
||||
col_length=new Array()
|
||||
|
||||
define_pixel_movement(3,5)
|
||||
|
||||
frame_showing_speed=150
|
||||
character_movement_speed=50
|
||||
frame_showing()
|
||||
character_movement()
|
||||
|
||||
//setInterval(debugging,100)
|
||||
}
|
||||
|
||||
function debugging() {
|
||||
document.title=direction+" | "+col_length[0]+" | "+col_num[0]+" | "+character_state
|
||||
}
|
||||
|
||||
function define_pixel_movement(walk,run) {
|
||||
pixel_movement=[0,walk,run]
|
||||
diagonal_pixel_movement=[0,Math.sqrt(walk*walk/2),Math.sqrt(run*run/2)]
|
||||
}
|
||||
|
||||
function show_frame(cha_num,row,col) {
|
||||
characters[cha_num].elem.style.backgroundPosition="-"+(col*(cha.width+1)+1)+"px -"+(cha.dirs[row][0]*(cha.height+1)+1)+"px"
|
||||
}
|
||||
|
||||
function frame_showing() {
|
||||
for (var i=0;i<characters.length;i++) {
|
||||
if (col_num[i]<col_length[i]) col_num[i]++
|
||||
else col_num[i]=0
|
||||
show_frame(i,row_num[0],characters[i].dirs[row_num[i]][character_state][col_num[i]])
|
||||
}
|
||||
setTimeout(frame_showing,frame_showing_speed)
|
||||
}
|
||||
|
||||
function character_movement() {
|
||||
var pixmove=pixel_movement[character_state-1]
|
||||
var dia_pixmove=diagonal_pixel_movement[character_state-1]
|
||||
var x,y
|
||||
for (var i=0;i<characters.length;i++) {
|
||||
switch(direction) {
|
||||
case 1:
|
||||
y=characters[i].posY-pixmove
|
||||
if (y>-1) characters[i].posY=y
|
||||
break;
|
||||
case 2:
|
||||
y=characters[i].posY-dia_pixmove
|
||||
x=characters[i].posX+dia_pixmove
|
||||
if (y>-1) characters[i].posY=y
|
||||
if (x<current_screen.width-characters[i].width+1) characters[i].posX=x
|
||||
break;
|
||||
case 3:
|
||||
x=characters[i].posX+pixmove
|
||||
if (x<current_screen.width-characters[i].width+1) characters[i].posX=x
|
||||
break;
|
||||
case 4:
|
||||
x=characters[i].posX+dia_pixmove
|
||||
y=characters[i].posY+dia_pixmove
|
||||
if (x<current_screen.width-characters[i].width+1) characters[i].posX=x
|
||||
if (y<current_screen.height-characters[i].height+1) characters[i].posY=y
|
||||
break;
|
||||
case 5:
|
||||
y=characters[i].posY+pixmove
|
||||
if (y<current_screen.height-characters[i].height+1) characters[i].posY=y
|
||||
break;
|
||||
case 6:
|
||||
y=characters[i].posY+dia_pixmove
|
||||
x=characters[i].posX-dia_pixmove
|
||||
if (y<current_screen.height-characters[i].height+1) characters[i].posY=y
|
||||
if (x>-1) characters[i].posX=x
|
||||
break;
|
||||
case 7:
|
||||
x=characters[i].posX-pixmove
|
||||
if (x>-1) characters[i].posX=x
|
||||
break;
|
||||
case 8:
|
||||
x=characters[i].posX-dia_pixmove
|
||||
y=characters[i].posY-dia_pixmove
|
||||
if (x>-1) characters[i].posX=x
|
||||
if (y>-1) characters[i].posY=y
|
||||
break;
|
||||
}
|
||||
characters[i].elem.style.left=characters[i].posX+"px"
|
||||
characters[i].elem.style.top=characters[i].posY+"px"
|
||||
}
|
||||
setTimeout(character_movement,character_movement_speed)
|
||||
}
|
||||
|
||||
function get_character_state() {
|
||||
if (key_order[0]==0) character_state=1
|
||||
else if (!key_shift && key_order[0]>0) character_state=2
|
||||
else if (key_shift && key_order[0]>0) character_state=3
|
||||
}
|
||||
|
||||
function get_row_num() {
|
||||
for (var i=0;i<characters.length;i++) {
|
||||
if (!characters[i].dirs[direction-1]) {
|
||||
if (direction==2 && key_order[1]==1) row_num[i]=0
|
||||
else if (direction==2 && key_order[1]==2) row_num[i]=2
|
||||
else if (direction==4 && key_order[1]==2) row_num[i]=2
|
||||
else if (direction==4 && key_order[1]==3) row_num[i]=4
|
||||
else if (direction==6 && key_order[1]==3) row_num[i]=4
|
||||
else if (direction==6 && key_order[1]==4) row_num[i]=6
|
||||
else if (direction==8 && key_order[1]==4) row_num[i]=6
|
||||
else if (direction==8 && key_order[1]==1) row_num[i]=0
|
||||
}
|
||||
else row_num[i]=direction-1
|
||||
}
|
||||
}
|
||||
|
||||
function get_col_length() {
|
||||
get_character_state()
|
||||
get_row_num()
|
||||
for (var i=0;i<characters.length;i++) {
|
||||
col_length[i]=characters[i].dirs[row_num[i]][character_state].length-1
|
||||
}
|
||||
}
|
||||
|
||||
function find_direction() {
|
||||
if (key_order[0]==1 && key_order[1]!=2 && key_order[1]!=4) direction=1
|
||||
else if ((key_order[0]==1 && key_order[1]==2) || (key_order[0]==2 && key_order[1]==1)) direction=2
|
||||
else if (key_order[0]==2 && key_order[1]!=1 && key_order[1]!=3) direction=3
|
||||
else if ((key_order[0]==2 && key_order[1]==3) || (key_order[0]==3 && key_order[1]==2)) direction=4
|
||||
else if (key_order[0]==3 && key_order[1]!=2 && key_order[1]!=4) direction=5
|
||||
else if ((key_order[0]==3 && key_order[1]==4) || (key_order[0]==4 && key_order[1]==3)) direction=6
|
||||
else if (key_order[0]==4 && key_order[1]!=3 && key_order[1]!=1) direction=7
|
||||
else if ((key_order[0]==4 && key_order[1]==1) || (key_order[0]==1 && key_order[1]==4)) direction=8
|
||||
else direction=0
|
||||
}
|
||||
|
||||
function keydown(e) {
|
||||
var keycode=getkeycode(e)
|
||||
|
||||
if (keycode==38 && !key_up) {
|
||||
key_up=true
|
||||
key_order.splice(0,0,1)
|
||||
key_order.splice(3,1)
|
||||
}
|
||||
else if (keycode==39 && !key_right) {
|
||||
key_right=true
|
||||
key_order.splice(0,0,2)
|
||||
key_order.splice(3,1)
|
||||
}
|
||||
else if (keycode==40 && !key_down) {
|
||||
key_down=true
|
||||
key_order.splice(0,0,3)
|
||||
key_order.splice(3,1)
|
||||
}
|
||||
else if (keycode==37 && !key_left) {
|
||||
key_left=true
|
||||
key_order.splice(0,0,4)
|
||||
key_order.splice(3,1)
|
||||
}
|
||||
else if (keycode==16) key_shift=true
|
||||
else if (keycode==17) key_control=true
|
||||
|
||||
if (keycode==38 || keycode==39 || keycode==40 || keycode==37) find_direction()
|
||||
if (keycode==38 || keycode==39 || keycode==40 || keycode==37 || keycode==16) get_col_length()
|
||||
}
|
||||
|
||||
function keyup(e) {
|
||||
var keycode=getkeycode(e)
|
||||
|
||||
if (keycode==38 && key_up) {
|
||||
key_up=false
|
||||
for (var i=0;i<4;i++) {
|
||||
if (key_order[i]==1) key_order.splice(i,1)
|
||||
}
|
||||
key_order.splice(3,0,0)
|
||||
}
|
||||
else if (keycode==39 && key_right) {
|
||||
key_right=false
|
||||
for (var i=0;i<4;i++) {
|
||||
if (key_order[i]==2) key_order.splice(i,1)
|
||||
}
|
||||
key_order.splice(3,0,0)
|
||||
}
|
||||
else if (keycode==40 && key_down) {
|
||||
key_down=false
|
||||
for (var i=0;i<4;i++) {
|
||||
if (key_order[i]==3) key_order.splice(i,1)
|
||||
}
|
||||
key_order.splice(3,0,0)
|
||||
}
|
||||
else if (keycode==37 && key_left) {
|
||||
key_left=false
|
||||
for (var i=0;i<4;i++) {
|
||||
if (key_order[i]==4) key_order.splice(i,1)
|
||||
}
|
||||
key_order.splice(3,0,0)
|
||||
}
|
||||
else if (keycode==16) key_shift=false
|
||||
else if (keycode==17) key_control=false
|
||||
|
||||
if (key_order[0]>0 && (keycode==38 || keycode==39 || keycode==40 || keycode==37)) find_direction()
|
||||
if (keycode==38 || keycode==39 || keycode==40 || keycode==37 || keycode==16) get_col_length()
|
||||
}
|
||||
|
||||
function link(scr) {
|
||||
current_screen=scr
|
||||
}
|
||||
|
||||
function give_life(cha) {
|
||||
col_num[characters.length]=0
|
||||
characters[characters.length]=cha
|
||||
get_col_length()
|
||||
}
|
||||
|
||||
function take_life(cha) {
|
||||
for (var i=0;i<characters.length;i++) {
|
||||
if (characters[i]==cha) characters.splice(i,1)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
* {
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
|
||||
body {
|
||||
font:normal 11px arial;
|
||||
}
|
||||
|
||||
#gamebox {
|
||||
position:absolute;
|
||||
top:50%;
|
||||
left:50%;
|
||||
}
|
||||
|
||||
#characters {
|
||||
position:absolute;
|
||||
top:0;
|
||||
left:0;
|
||||
}
|
||||
|
||||
#characters div {
|
||||
position:absolute;
|
||||
top:0;
|
||||
left:0;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3c.org/1999/xhtml">
|
||||
<head>
|
||||
<title>Eon Aton</title>
|
||||
<link href='general.css' type='text/css' rel='stylesheet' />
|
||||
<script type='text/javascript' src='functions.js'></script>
|
||||
<script type='text/javascript' src='classes.js'></script>
|
||||
<script type='text/javascript' src='load.js'></script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,175 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<information>
|
||||
<defaults>
|
||||
|
||||
<actions>
|
||||
<action id="showdescription">
|
||||
document.title+="..."
|
||||
</action>
|
||||
</actions>
|
||||
|
||||
<objects>
|
||||
<object id="box1">
|
||||
<name>A box</name>
|
||||
<description>It is nothing but a.. box.</description>
|
||||
<image>
|
||||
<dimensions>
|
||||
<width>60</width>
|
||||
<height>50</height>
|
||||
</dimensions>
|
||||
<address>objs/box1.png</address>
|
||||
</image>
|
||||
<position>
|
||||
<x>100</x>
|
||||
<y>70</y>
|
||||
</position>
|
||||
<actions>
|
||||
<action rel="showdescription"></action>
|
||||
</actions>
|
||||
</object>
|
||||
</objects>
|
||||
|
||||
<characters>
|
||||
<character>
|
||||
<name>Simple arrows</name>
|
||||
<description>Simple arrows explaining how character movement works.</description>
|
||||
<image>
|
||||
<dimensions>
|
||||
<width>64</width>
|
||||
<height>48</height>
|
||||
</dimensions>
|
||||
<address>char/simplearrows.png</address>
|
||||
</image>
|
||||
<movement>
|
||||
<speed>10</speed>
|
||||
<directions>
|
||||
<topcenter>
|
||||
<row>1</row>
|
||||
<stand>1-2</stand>
|
||||
<walk>3-6</walk>
|
||||
<run>7-10</run>
|
||||
</topcenter>
|
||||
<topright>
|
||||
<row>2</row>
|
||||
<stand>1-2</stand>
|
||||
<walk>3-6</walk>
|
||||
<run>7-10</run>
|
||||
</topright>
|
||||
<middleright>
|
||||
<row>3</row>
|
||||
<stand>1-2</stand>
|
||||
<walk>3-6</walk>
|
||||
<run>7-10</run>
|
||||
</middleright>
|
||||
<bottomright>
|
||||
<row>4</row>
|
||||
<stand>1-2</stand>
|
||||
<walk>3-6</walk>
|
||||
<run>7-10</run>
|
||||
</bottomright>
|
||||
<bottomcenter>
|
||||
<row>5</row>
|
||||
<stand>1-2</stand>
|
||||
<walk>3-6</walk>
|
||||
<run>7-10</run>
|
||||
</bottomcenter>
|
||||
<bottomleft>
|
||||
<row>6</row>
|
||||
<stand>1-2</stand>
|
||||
<walk>3-6</walk>
|
||||
<run>7-10</run>
|
||||
</bottomleft>
|
||||
<middleleft>
|
||||
<row>7</row>
|
||||
<stand>1-2</stand>
|
||||
<walk>3-6</walk>
|
||||
<run>7-10</run>
|
||||
</middleleft>
|
||||
<topleft>
|
||||
<row>8</row>
|
||||
<stand>1-2</stand>
|
||||
<walk>3-6</walk>
|
||||
<run>7-10</run>
|
||||
</topleft>
|
||||
</directions>
|
||||
</movement>
|
||||
</character>
|
||||
</characters>
|
||||
|
||||
<maps>
|
||||
<map>
|
||||
<name>The Sun</name>
|
||||
<description>The great star</description>
|
||||
<image>
|
||||
<dimensions>
|
||||
<width>640</width>
|
||||
<height>400</height>
|
||||
<viswidth>640</viswidth>
|
||||
<visheight>400</visheight>
|
||||
</dimensions>
|
||||
<address>maps/sun.png</address>
|
||||
</image>
|
||||
<objects>
|
||||
<object rel="box1"></object>
|
||||
</objects>
|
||||
</map>
|
||||
</maps>
|
||||
|
||||
</defaults>
|
||||
|
||||
<actions>
|
||||
<action state="default"></action>
|
||||
|
||||
<action id="msg2">
|
||||
alert("Hmm...")
|
||||
</action>
|
||||
</actions>
|
||||
|
||||
<objects>
|
||||
<object state="default"></object>
|
||||
|
||||
<object id="box2">
|
||||
<name>A small box</name>
|
||||
<description>Aha! A small box!</description>
|
||||
<image>
|
||||
<dimensions>
|
||||
<width>30</width>
|
||||
<height>25</height>
|
||||
</dimensions>
|
||||
<address>objs/box2.png</address>
|
||||
</image>
|
||||
<position>
|
||||
<x>200</x>
|
||||
<y>100</y>
|
||||
</position>
|
||||
<actions>
|
||||
<action rel="msg2"></action>
|
||||
</actions>
|
||||
</object>
|
||||
</objects>
|
||||
|
||||
<characters>
|
||||
<character state="default"></character>
|
||||
|
||||
<character>
|
||||
<name>Wiz the Wizard</name>
|
||||
<description>A poorly drawn wizard, fighting against all evil.</description>
|
||||
<image>
|
||||
<address>char/wizard.png</address>
|
||||
</image>
|
||||
</character>
|
||||
</characters>
|
||||
|
||||
<maps>
|
||||
<map state="default"></map>
|
||||
|
||||
<map>
|
||||
<name>The valley of Sunshine</name>
|
||||
<description>Beams of light break through the sky.</description>
|
||||
<image>
|
||||
<address>maps/sunshine.png</address>
|
||||
</image>
|
||||
</map>
|
||||
</maps>
|
||||
|
||||
</information>
|
||||
@@ -0,0 +1,56 @@
|
||||
window.onload=function(){
|
||||
START_systems()
|
||||
|
||||
scr=new screen()
|
||||
scr.name="The Sun"
|
||||
scr.description="The great star"
|
||||
scr.background="maps/sun.png"
|
||||
scr.bbackground="#000"
|
||||
scr.width=640
|
||||
scr.height=400
|
||||
scr.viswidth=scr.width
|
||||
scr.visheight=scr.height
|
||||
create(scr)
|
||||
|
||||
cha=new character()
|
||||
cha.name="Wiz the Wizard"
|
||||
cha.description="A poorly drawn wizard, fighting against all evil."
|
||||
cha.src="char/wizard.png"
|
||||
cha.width=48
|
||||
cha.height=64
|
||||
cha.posX=285
|
||||
cha.posY=140
|
||||
|
||||
cha.dir(0,0,[0,1],[2,3,4,5],[6,7,8,9])
|
||||
cha.dir(1,1,[0,1],[2,3,4,5],[6,7,8,9])
|
||||
cha.dir(2,2,[0,1],[2,3,4,5],[6,7,8,9])
|
||||
cha.dir(3,3,[0,1],[2,3,4,5],[6,7,8,9])
|
||||
cha.dir(4,4,[0,1],[2,3,4,5],[6,7,8,9])
|
||||
cha.dir(5,5,[0,1],[2,3,4,5],[6,7,8,9])
|
||||
cha.dir(6,6,[0,1],[2,3,4,5],[6,7,8,9])
|
||||
cha.dir(7,7,[0,1],[2,3,4,5],[6,7,8,9])
|
||||
|
||||
cha.create()
|
||||
scr.add(cha)
|
||||
|
||||
chab=new character()
|
||||
chab.name="test"
|
||||
chab.description="test"
|
||||
chab.src="char/simplearrows.png"
|
||||
chab.width=48
|
||||
chab.height=64
|
||||
chab.posX=50
|
||||
chab.posY=160
|
||||
|
||||
chab.dir(0,0,[0,1],[2,3,4,5],[6,7,8,9])
|
||||
chab.dir(1,1,[0,1],[2,3,4,5],[6,7,8,9])
|
||||
chab.dir(2,2,[0,1],[2,3,4,5],[6,7,8,9])
|
||||
chab.dir(3,3,[0,1],[2,3,4,5],[6,7,8,9])
|
||||
chab.dir(4,4,[0,1],[2,3,4,5],[6,7,8,9])
|
||||
chab.dir(5,5,[0,1],[2,3,4,5],[6,7,8,9])
|
||||
chab.dir(6,6,[0,1],[2,3,4,5],[6,7,8,9])
|
||||
chab.dir(7,7,[0,1],[2,3,4,5],[6,7,8,9])
|
||||
|
||||
chab.create()
|
||||
scr.add(chab)
|
||||
}
|
||||
Reference in New Issue
Block a user