look_dir -= ( window_mouse_get_x() - WINDOW_WIDTH / 2 ) / CAMERA_SENSITIVITY; look_pitch -= ( window_mouse_get_y() - WINDOW_HEIGHT / 2 ) / CAMERA_SENSITIVITY; look_pitch = clamp( look_pitch, -CAMERA_PITCH_MAX, CAMERA_PITCH_MAX ); placetarget = [-1,-1,-1]; deletetarget = [-1,-1,-1]; var deleteobj = noone; var i = 0; do { var xtest = x + ((i + 32) * dcos( look_dir )); var ytest = y + ((i + 32) * dsin( look_dir )); var ztest = z + ((i + 32) * dsin( look_pitch )); var xto = x + i * dcos( look_dir ); var yto = y + i * dsin( look_dir ); var zto = z + i * dsin( look_pitch ); var blockstack = ds_list_create(); var blockbuild = ds_list_create(); var blocknum = instance_position_list(xtest, ytest, obj_block, blockstack, false); var buildnum = instance_position_list(xto, yto, obj_block, blockbuild, false); if ( blocknum > 0 ) { for (var j = 0; j < blocknum; j++) { if ( ztest > blockstack[|j].z && ztest < blockstack[|j].z + 64 && point_distance_3d(x, y, z, xtest, ytest, ztest) < 256 ) { deletetarget[0] = blockstack[|j].x div 64; deletetarget[1] = blockstack[|j].y div 64; deletetarget[2] = blockstack[|j].z div 64; deleteobj = blockstack[|j]; if (buildnum == 0) { placetarget[0] = xto div 64; placetarget[1] = yto div 64; placetarget[2] = zto div 64; } else { for (var k = 0; k < buildnum; k++) { if (!(zto > blockbuild[|k].z && zto < blockbuild[|k].z + 64)) { placetarget[0] = xto div 64; placetarget[1] = yto div 64; placetarget[2] = zto div 64; } } } } } } if ((placetarget[0] < 0 || placetarget[1] < 0 || placetarget[2] < 0) || (placetarget[0] >= CHUNK_SIZE || placetarget[1] >= CHUNK_SIZE || placetarget[2] >= CHUNK_SIZE)) { placetarget = [-1,-1,-1]; } i += 32; } until ( deletetarget != [-1,-1,-1] || i >= 256 ); window_mouse_set( WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2 ); var move_speed = 5; var dir_mod = 0; var up = 0; var down = 0; var left = 0; var right = 0; var ascend = 0; var descend = 0; var place = 0; var del = 0; if ( keyboard_check( ord("W") ) ) { up = 1; } if ( keyboard_check( ord("S") ) ) { down = 1; } if ( keyboard_check( ord("A") ) ) { left = 1; } if ( keyboard_check( ord("D") ) ) { right = 1; } if ( keyboard_check( vk_space ) ) { ascend = 1; } if ( keyboard_check( vk_control ) ) { descend = 1; } if ( keyboard_check( vk_escape ) ) { game_end(); } if ( mouse_check_button_pressed( mb_left ) ) { place = 1; } if ( mouse_check_button_pressed( mb_right ) ) { del = 1; } dir_mod = point_direction( 0, 0, (up - down), (right - left) ); if ( up || down || left || right ) { direction = look_dir + dir_mod; x += dcos( direction ) * move_speed; y += dsin( direction ) * move_speed; } if ( ascend ^^ descend ) { z = z + 4 * (ascend - descend); } if ( place && placetarget != [-1,-1,-1] ) { with (deleteobj.chunk_id) { chunk[obj_player.placetarget[0]][obj_player.placetarget[1]][obj_player.placetarget[2]] = BLOCKS_TEST; var brick = instance_create_layer(x + BLOCK_SIZE * obj_player.placetarget[0], y + BLOCK_SIZE * obj_player.placetarget[1], "Terrain", obj_block); with ( brick ) { chunk_id = deleteobj.chunk_id; z = other.z + BLOCK_SIZE * obj_player.placetarget[2]; } } }