# kleines rpg



## Jaress (25. Jun 2004)

Hallo, ich habe mal angefangen ein kleines rollenspiel mit dhtml zu schreiben, nur passt mit den arrays etwas nicht.

Mein problem ist: die linke, obere figur soll sich mit den tasten [W] nach oben  nach unten [A] nach links [D] nach rechts bewegen.....
die untere soll sich aber nicht mitbewegen!? wiso sie das tut weis und verstehe ich einfach nicht

kann mir da jemand helfen, an was das liegen könnte?

hier die vorschau:
http://jaress.space4free.de/images/private/demo/demo.php


Hier der code:

```
<script type="text/javascript">
<!--
var rand = 20;
var ende = 520;
var key = 1;
var richtung = 0;


var c;
var target;
var altKey;
var ctrlKey;

var data = new Array();
var object = new Array();
var num = 0;
var type = 1;
var url = 2;
var b = 3;
var h = 4;
var lvl = 5;
var step = 6;
var display = 7;
var div = 8;
var movex = 9;
var movey = 10;
var x = 11;
var y = 12;


var player = num;
data[player] = new Array();
data[player][type] = "char";
data[player][name] = "player";
data[player][b] = 15;
data[player][h] = 18;
num++;



var skele1 = num;
data[skele1] = new Array();
data[skele1][type] = "char";
data[skele1][name] = "skele1"
data[skele1][display] = "Skelettierter";
data[skele1][b] = 15;
data[skele1][h] = 18;
data[skele1][lvl] = 1;
num++;




for(var f in data) {
	data[f][x] = -100;
	data[f][y] = -100;
	data[f][movex] = 0;
	data[f][movey] = 0;
	if(data[f][type] == "char") 
		data[f][step] = 0;
	document.write("<div id=\"" + data[f][name] + "\"><img src=\"" + data[f][name] + "/" + data[f][name] + ".gif \" border=\"0\"</div>")
}





//testmap
object[0] = player;
object[1] = skele1;

data[player][x] = rand + 50;
data[player][y] = rand + 70;

data[skele1][x] = ende - 30;
data[skele1][y] = ende - 50;




for(var f in data) {
	div = eval(document.getElementById(data[f][name]));
	div.style.position = "absolute";
	div.style.top = data[f][y];
	div.style.left = data[f][x];
}









function move() {

	for(var f in object) {
		if(data[f][movex] || data[f][movey]) {	
			data[f][x] += data[f][movex];
			data[f][y] += data[f][movey];	
			div = eval(document.getElementById(data[f][name]));
			div.style.left = data[f][x]; 
			div.style.top = data[f][y];
		}
	}

	window.setTimeout("move()",10);

}






function keypress(e) {
	if(key) {
		if (window.event != null) {
			c=String.fromCharCode(window.event.keyCode).toUpperCase(); 
			altKey=window.event.altKey;
			ctrlKey=window.event.ctrlKey;
		}else{
			c=String.fromCharCode(e.charCode).toUpperCase();
			altKey=e.altKey;
			ctrlKey=e.ctrlKey;
		}
		if (window.event != null)
			target=window.event.srcElement;
		else
			target=e.originalTarget;
		if (target.nodeName.toUpperCase()=='INPUT' || target.nodeName.toUpperCase()=='TEXTAREA' || altKey || ctrlKey){
		}else{
			
			if (c == '<') { alert("CONSOLE/Arrays/\n=============\n" + f); }
			if (c == 'A') { data[player][movex] = -1; }
			if (c == 'D') { data[player][movex] = 1; }
			if (c == 'W') { data[player][movey] = -1; }
			if (c == 'S') { data[player][movey] = 1; }
		}
	}
}

function keyup(e) {
	
	
	if (window.event != null) {
		c=String.fromCharCode(window.event.keyCode).toUpperCase(); 
		altKey=window.event.altKey;
		ctrlKey=window.event.ctrlKey;
	}else{
		c=String.fromCharCode(e.charCode).toUpperCase();
		altKey=e.altKey;
		ctrlKey=e.ctrlKey;
	}
	if (window.event != null)
		target=window.event.srcElement;
	else
		target=e.originalTarget;
	if (target.nodeName.toUpperCase()=='INPUT' || target.nodeName.toUpperCase()=='TEXTAREA' || altKey || ctrlKey){
	}else{
			
		if (c == 'A') { data[player][movex] = 0; }
		if (c == 'D') { data[player][movex] = 0; }
		if (c == 'W') { data[player][movey] = 0; }
		if (c == 'S') { data[player][movey] = 0; }
	}
}





document.onkeypress=keypress;
document.onkeyup=keyup;
move();
//-->
</script>
```


----------



## Grizzly (25. Jun 2004)

Mal davon abgesehen, dass dieser Thread herzlich wenig mit Java und noch weniger mit Java 3D zu tun hat:


```
function keypress(e) {
	if(key) {
		if (window.event != null) {
			c=String.fromCharCode(window.event.keyCode).toUpperCase(); 
			altKey=window.event.altKey;
			ctrlKey=window.event.ctrlKey;
		}else{
			c=String.fromCharCode(e.charCode).toUpperCase();
			altKey=e.altKey;
			ctrlKey=e.ctrlKey;
		}
		if (window.event != null)
			target=window.event.srcElement;
		else
			target=e.originalTarget;
		if (target.nodeName.toUpperCase()=='INPUT' || target.nodeName.toUpperCase()=='TEXTAREA' || altKey || ctrlKey){
		}else{
			
			if (c == '<') { alert("CONSOLE/Arrays/\n=============\n" + f); }
			if (c == 'A') { data[player][movex] = -1; }
			if (c == 'D') { data[player][movex] = 1; }
			if (c == 'W') { data[player][movey] = -1; }
			if (c == 'S') { data[player][movey] = 1; }
		}
	}
}
```

Wo kommt die Variable key her? ???:L Und überhaupt: Das ganze Programm sieht aus, als hättest Du Java und JavaScript gemischt. :wink:


----------



## Illuvatar (25. Jun 2004)

Javascript.

--> Verschoben.

(Hätt nicht gedacht, dass _ich_ mal ne Javascriptfrage verschieben muss :wink: )


----------



## Jaress (25. Jun 2004)

ups sorry

also die abrage (key) kommt da her:

```
var key = 1;
```
(zeile 4)

gibt es den für das stück code keine hoffnung?


----------

