<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="javascript.css" type="text/css">
<title>Image KeyMove</title>
<script>
document.onkeydown = KeyCode;
x=300;
y=200;
ary = new Array("anime_1.gif", "anime_2.gif", "anime2.gif");
num = 0;
function KeyCode()
{
if(document.all)
kcode = event.keyCode;
else if(document.getElementById)
kcode = (event.keyCode)? event.keyCode: event.charCode;
else if(document.layers)
kcode = event.which;
switch(kcode)
{
case 0x25:
if (x>1) x-= 2;
break;
case 0x26:
if (y>1) y-= 2;
break;
case 0x27:
x+= 2;
break;
case 0x28:
y+= 2;
break;
case 0x0d: //GIF Chenge
num= (num+1)%3;
document.Enemy.src= ary[num];
break;
}
}
function moveImage()
{
document.Enemy.style.left= x;
document.Enemy.style.top= y;
}
</script>
</head>
<body onLoad="setInterval('moveImage()',25)">
<h1>矢印キーで画像を移動</h1>
<img src="anime_1.gif" name="Enemy"
style="position:absolute;left:300px;top:200px;">
</body>
</html>
|
<body onLoad="setInterval('moveImage()',25)">
|
function moveImage()
{
document.Enemy.style.left= x;
document.Enemy.style.top= y;
}
|
<img src="anime_1.gif" name="Enemy" style="position:absolute;left:300px;top:200px;"> |
ary = new Array("anime_1.gif", "anime_2.gif", "anime2.gif");
num = 0;
|
function KeyCode()
{
if(document.all)
kcode = event.keyCode;
else if(document.getElementById)
kcode = (event.keyCode)? event.keyCode: event.charCode;
else if(document.layers)
kcode = event.which;
switch(kcode)
{
case 0x25:
if (x>1) x-= 2;
break;
case 0x26:
if (y>1) y-= 2;
break;
case 0x27:
x+= 2;
break;
case 0x28:
y+= 2;
break;
case 0x0d: //GIF Chenge
num= (num+1)%3;
document.Enemy.src= ary[num];
break;
}
}
|
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="javascript.css" type="text/css">
<title>Walk</title>
<script type="text/javascript">
<!--
document.onkeydown = KeyCode;
x=200; //X座標
y=100; //Y座標
dir=0; //進行方向
chg=0; //画像の切り替え
function KeyCode()
{
if(document.all)
kcode = event.keyCode;
else if(document.getElementById)
kcode = (event.keyCode)? event.keyCode: event.charCode;
else if(document.layers)
kcode = event.which;
switch(kcode)
{
case 0x25: //←
if (x>1) x-= 2;
dir= 6;
break;
case 0x26: //↑
if (y>1) y-= 2;
dir= 0;
break;
case 0x27: //→
x+= 2;
dir= 2;
break;
case 0x28: //↓
y+= 2;
dir= 4;
break;
}
}
function walk()
{
chg= (chg+1)%16;
var n= dir+Math.floor(chg/8);
document.char.src= images[n].src;
document.char.style.left= x;
document.char.style.top= y;
}
function preload()
{
imgnum = 8; //画像の枚数
images = new Array();
for(i=0; i<imgnum; i++)
{ images[i] = new Image();
images[i].src = "chr47_"+i+".gif";
}
setInterval('walk()',50);
}
// -->
</script>
</head>
<body onLoad="preload()">
<h1>矢印キーでキャクターが歩く</h1>
<img src="chr47_0.gif" name="char"
style="position:absolute;left:300px;top:200px;">
</body>
</html>
|
<body onLoad="preload()">
function preload()
{
imgnum = 8; //画像の枚数
images = new Array();
for(i=0; i<imgnum; i++)
{ images[i] = new Image();
images[i].src = "chr47_"+i+".gif";
}
setInterval('walk()',50);
}
|
x=200; //X座標
y=100; //Y座標
dir=0; //進行方向
chg=0; //画像の切り替え
function walk()
{
chg= (chg+1)%2;
var n= dir+chg;
document.char.src= images[n].src;
document.char.style.left= x;
document.char.style.top= y;
}
|
document.onkeydown = KeyCode;
function KeyCode()
{
・・・
}
|

| ファイル名 | 説明 |
|---|---|
| game_map1.html | BG MAP を描画するプログラム |
| gamemap.css | マップチップの分割情報が定義された CSS ファイル |
| gamemap.js | BG の並び情報が定義された JavaScript ファイル |
| maps.png | 背景画像を構成するマップチップ画像ファイル |
document.write('<div class="info">BG(Back Ground) Map<br></div>');
|
<html> <head> <meta http-equiv="Content-Script-Type" content="text/javascript" charset="utf-8"> <link rel="stylesheet" href="gamemap.css" type="text/css"> </head> <body> <script src="gamemap.js"></script> </body> </html> |

| ファイル名 | 説明 |
|---|---|
| game_map2.html | マップ上でキャラクターを動かすプログラム |
| gamemap.css | マップチップの分割情報が定義された CSS ファイル |
| gamemap.js | BG の並び情報が定義された JavaScript ファイル |
| maps.png | 背景画像を構成するマップチップ画像ファイル |
| anime1.gif | 矢印キーで操作するキャラクター画像 |
<body bgcolor="#f4f8ff" onLoad="setInterval('moveImage()',25)">
|
<img src="anime1.gif" name="Dog" style="position:absolute;left:300px;top:200px;"> |
document.onkeydown = KeyCode;
x= 300;
y= 200;
function KeyCode()
{
・・・
}
|

| ファイル名 | 説明 |
|---|---|
| bg_wall.html | マップ上でキャラクターを動かすプログラム |
| gamemap.css | マップチップの分割情報が定義された背景画像の CSS ファイル |
| gamemap.js | BG の並び情報が定義された背景画像の JavaScript ファイル |
| maps.png | 背景画像を構成するマップチップ画像ファイル |
| chr47_0.gif~chr47_7.gif | 矢印キーで操作するキャラクター画像ファイル |
<link rel="stylesheet" href="gamemap.css" type="text/css">
<script src="gamemap.js"></script>
|
case 0x27: //→
if (x<1000) x+= 2;
dir= 2;
break;
case 0x28: //↓
if (y<484) y+= 2;
dir= 4;
break;
|

var att = [ 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ] |
<link rel="stylesheet" href="gamemap.css" type="text/css"> <script src="att.js" type="text/javascript"></script> |
function KeyCode()
{ ・
・
・
xw = x;
yw = y;
switch(kcode)
{
case 0x25: //←
if (xw>1) xw-= 2;
dir= 6;
break;
・
・
・
}
if (get_att()==0)
{ x = xw;
y = yw;
}
}
|
function get_att()
{
ywk = Math.floor((yw+12)/16);
xwk = Math.floor((xw+12)/16);
ps = map[ywk*64+xwk];
return att[ps];
}
|
flg=0; //鍵のフラグ
function KeyCode()
{ ・
・
・
switch(get_att())
{
case 2:
if (flg==0)
{ window.alert("鍵を拾った!");
flg = 1;
}
break;
case 3:
if (flg==1)
{ window.alert("宝物を手に入れた!");
flg = 2;
}
break;
case 0:
x = xw;
y = yw;
break;
}
|
![]()