java - How to assign a value to a reference? -
i'm trying create roguelike in java practice. code generate floor (right big room wall tiles on edge). i'm trying set tiles in tile array either wall tile or floor tile. although when leave settile method, revert value before entering method. i'm going insane. here's code:
public floor(int width, int height) { this.tiles = new tile[(width+1)*(height+1)]; this.width = width; this.height = height; generatetiles(); boolean test = false; } public tile gettile(int x, int y) { homecoming tiles[y * width + x]; } public void settile(int x, int y, tile tile) { tile tiletoset = gettile(x,y); tiletoset = tile; } private void generatetiles() { (int = 0; < tiles.length; i++) { tiles[i] = new tile(); } //make top wall (int = 0; i<width;i++) { settile(i,0,new walltile()); } } }
your settile
doesn't create sense. you're retrieving tile @ position, storing in local variable tiletoset
, overwriting value of variable.
what you're trying storing given tile in tiles
array. analogous how gettile
implemented, can with:
public void settile(int x, int y, tile tile) { tiles[y * width + x] = tile; }
note not equivalent (but seem think is) with:
public void settile(int x, int y, tile tile) { tile tiletoset = tiles[y * width + x]; tiletoset = tile; }
java processing
No comments:
Post a Comment