C
Carcophan
Guest
Hello everyone!
Not sure I am wording this properly, so I am sorry in advance for any confusion.
I am looking to delete a single 'background tile' from a room, through mouse click.
I can already successfully delete that part of the instance layer, when clicking the mouse, but it does not delete the portion of the background layer UNDER the instance layer too. Meaning - I can delete a 'wall' from the game but not the background image/tile that is auto-tiled under the 'wall' image/sprite/tile. (Hence my problem with naming and wording causing confusion - not sure the finite wording of this).
There is a Tile Layer (called "WallTiles") which is populated with a tileset (called "ts_Walls"). There is also a background layer ("Background"), which is auto-tiled horizontally and vertically throughout the room from a "spr_floor_tile".
I am able to use "tilemap_set(map_id, 0, mx, my);" to delete the ts_Walls from the game room, but I cannot seem to 'move' the character through that new emptied space after I delete it.
I want to be able to make a new 'path' by deleting walls. Note that none of walls the are actually 'wall objects'. The only objects I have in the game are a 'level' object and a 'player' object (where the click/delete action originates), so no collisions are done with walls.
*UPDATED CODE BELOW TO BE MORE INCLUSIVE*
The end goal here would be to see the 'other' background image, under the primary background. So deleting the primary background would allow us to see through the layer to the pink sub-background image in place.
Not sure I am wording this properly, so I am sorry in advance for any confusion.
I am looking to delete a single 'background tile' from a room, through mouse click.
I can already successfully delete that part of the instance layer, when clicking the mouse, but it does not delete the portion of the background layer UNDER the instance layer too. Meaning - I can delete a 'wall' from the game but not the background image/tile that is auto-tiled under the 'wall' image/sprite/tile. (Hence my problem with naming and wording causing confusion - not sure the finite wording of this).
There is a Tile Layer (called "WallTiles") which is populated with a tileset (called "ts_Walls"). There is also a background layer ("Background"), which is auto-tiled horizontally and vertically throughout the room from a "spr_floor_tile".
I am able to use "tilemap_set(map_id, 0, mx, my);" to delete the ts_Walls from the game room, but I cannot seem to 'move' the character through that new emptied space after I delete it.
I want to be able to make a new 'path' by deleting walls. Note that none of walls the are actually 'wall objects'. The only objects I have in the game are a 'level' object and a 'player' object (where the click/delete action originates), so no collisions are done with walls.
Code:
A few of the examples that I have tried:
//ds_grid_set(grid_, mx, my, -1);
//layer_background_index(back_id, 0);
//grid_[# mx, my] = FLOOR;
//ds_grid_set(grid_, mx, my, VOID);
//ds_grid_set(grid_, mx, my, FLOOR);
//ds_grid_set(grid_, mx, my, 0);
//tilemap_set_at_pixel(map_id, tileIndexOfMouse, mx, my);
//tilemap_set_at_pixel(grid_, tileIndexOfMouse, mx, my);
//tile_set_index(map_id, 0)
//tile_set_index(grid_, 0)
//tile_set_empty(tileIndexOfMouse);
//tilemap_set(map_id, VOID, mx, my);
//draw_sprite_ext(spr_floor_tile, 0, mx, my, CELL_WIDTH, CELL_HEIGHT, 0, c_white, 0);
//sprite_collision_mask(0, false, 2, 0, 0, 0, 0, 0, 255);
Code:
The portion of the code that makes the tiles themselves in the room:
//This is the object_Level create event
randomize();
shadow_surface_ = noone;
////get the tile layer maps id
var _wall_map_id = layer_tilemap_get_id("WallTiles");
width_ = room_width div CELL_WIDTH;
height_ = room_height div CELL_HEIGHT;
grid_ = ds_grid_create(width_, height_);
ds_grid_set_region(grid_, 0, 0, width_, height_, VOID);
//create the controller - will set floor tiles as it goes
var _controller_x = width_ div 2
var _controller_y = height_ div 2
var _controller_direction = irandom(3);
var _steps = 400; //smaller this number the smaller the level (less floor tiles drawn)
var _player_start_x = _controller_x * CELL_WIDTH + CELL_WIDTH / 2;
var _player_start_y = _controller_y * CELL_HEIGHT + CELL_HEIGHT / 2;
instance_create_layer(_player_start_x, _player_start_y, "Instances", obj_Player01);
var _direction_change_odds = 1;
repeat(_steps){ //do 400 times/tiles
grid_[# _controller_x, _controller_y] = FLOOR;
//random the direction
if(irandom(_direction_change_odds) == _direction_change_odds){
_controller_direction = irandom(3);
}
//move controller around the 'map' to draw auto tiles
var _x_direction = lengthdir_x(1, _controller_direction * 90);
var _y_direction = lengthdir_y(1, _controller_direction * 90);
_controller_x += _x_direction;
_controller_y += _y_direction;
//ensure the controller didnt go outside the bounds/grid of the room
if(_controller_x < 2 || _controller_x >= width_ - 2) {
_controller_x += _x_direction * 2;
}
if(_controller_y < 2 || _controller_y >= height_ - 2) {
_controller_y += _y_direction * 2;
}
}
//for loop to loop through the grid
for (var _y = 1; _y < height_ - 1; _y++) {
//no more tiles in this direction, so stop drawing floor tile/grid
for (var _x = 1; _x < width_ - 1; _x++){
if(grid_[# _x, _y] != FLOOR){
var _north_tile = grid_[# _x, _y-1] == VOID;
var _west_tile = grid_[# _x-1, _y] == VOID;
var _east_tile = grid_[# _x+1, _y] == VOID;
var _south_tile = grid_[# _x, _y+1] == VOID;
//var _tile_index = NORTH * _north_tile + WEST * _west_tile + EAST * _east_tile + SOUTH * _south_tile + 1;
_tile_index = NORTH * _north_tile + WEST * _west_tile + EAST * _east_tile + SOUTH * _south_tile + 1;
//removes 'single tile holes' from the random room generation code
if(_tile_index == 1) {
grid_[# _x, _y] = FLOOR;
}
}
}
}
for (var _y = 1; _y < height_ - 1; _y++) {
for (var _x = 1; _x < width_ - 1; _x++){
if(grid_[# _x, _y] != FLOOR){
var _north_tile = grid_[# _x, _y-1] == VOID;
var _west_tile = grid_[# _x-1, _y] == VOID;
var _east_tile = grid_[# _x+1, _y] == VOID;
var _south_tile = grid_[# _x, _y+1] == VOID;
//var _tile_index = NORTH * _north_tile + WEST * _west_tile + EAST * _east_tile + SOUTH * _south_tile + 1;
_tile_index = NORTH * _north_tile + WEST * _west_tile + EAST * _east_tile + SOUTH * _south_tile + 1;
tilemap_set(_wall_map_id, _tile_index, _x, _y);
}
}
}
//from the object_Level draw event:
if not surface_exists(shadow_surface_){
shadow_surface_ = surface_create(room_width, room_height);
surface_set_target(shadow_surface_);
draw_clear_alpha(c_black, 0);
for (var _y = 0; _y < height_ -1; _y++){
for(var _x = 0; _x < width_ -1; _x++){
if grid_[# _x, _y] == FLOOR && grid_[# _x, _y - 1] == VOID {
draw_sprite_ext(spr_Player01_shadow, 0, _x * CELL_WIDTH, _y * CELL_HEIGHT, 1, 1, 0, c_white, 0.5);
}
}
}
surface_reset_target();
}
draw_surface(shadow_surface_, 0, 0);
Last edited by a moderator: