Mineroboter
New member
Ich habe in meinem kleinen Spiel welches ich dort programmieren will ein mehrdimensionales Array um Daten von Blöcke zu speichern.
Zuerst wird ein Raum erstellt und korrekt aufgerufen.
Dann definiere ich das mehrdimensionale Array und weise allen Elementen eine 0 zu:
Das Problem ist, dass wenn ich
eingebe, spuckt er mir folgendes aus: 1,1,1,1,1,1,1,1,1,1,1,1.....
Eigentlich sollte er z.B. das ausspucken: 0,0,0,0,1,0,1,1,0,0,0,1,0,0,0 oder 1,0,1,0,0,0,1,0,0,1,0,0,0
Was mache ich falsch
Die Images zeigt er korrekt an....
Hinweis: block_ctx ist ein Canvas-Objekt auf dem die Bilder gezeichnet werden...
Zuerst wird ein Raum erstellt und korrekt aufgerufen.
Dann definiere ich das mehrdimensionale Array und weise allen Elementen eine 0 zu:
Code:
this.blocka = new Array();
this.blocka[0] = new Array(0,0,0,0);
this.blocka[1] = new Array(0,0,0,0);
this.blocka[2] = new Array(0,0,0,0);
this.blocka[3] = new Array(0,0,0,0);
this.blocka[4] = new Array(0,0,0,0);
this.blocka[5] = new Array(0,0,0,0);
Code:
var iron_ore_random = 15;
this.random(iron_ore_random, 100, 100, iron_ore);
this.random(iron_ore_random, 100, 200, iron_ore);
this.random(iron_ore_random, 100, 300, iron_ore);
this.random(iron_ore_random, 100, 400, iron_ore);
this.random(iron_ore_random, 200, 100, iron_ore);
this.random(iron_ore_random, 200, 200, iron_ore);
this.random(iron_ore_random, 200, 300, iron_ore);
this.random(iron_ore_random, 200, 400, iron_ore);
//......
Code:
Room.prototype.random = function(randomx, bx, by, block)
{
var b = 0
if (block == iron_ore)
b = 1
var rdm = Math.round(Math.random() * 100)
brx = (bx / 100) -1;
bry = (by / 100) -1;
if (rdm <= randomx)
if (this.blocka[brx][bry]==0)
block_ctx.drawImage(block, bx, by);
this.blocka[brx][bry] = b;
}
Code:
alert(blocka);
Eigentlich sollte er z.B. das ausspucken: 0,0,0,0,1,0,1,1,0,0,0,1,0,0,0 oder 1,0,1,0,0,0,1,0,0,1,0,0,0
Was mache ich falsch
Die Images zeigt er korrekt an....
Hinweis: block_ctx ist ein Canvas-Objekt auf dem die Bilder gezeichnet werden...
Zuletzt bearbeitet: