Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// addToAlpha(obj, alpha)
- // add a new object to the alpha array
- array_push(alpha, obj);
- //call and creation
- // create an array of objects
- var alpha = [obj_player, obj_enemy1, obj_enemy2];
- // update positions of objects in the alpha array by adding 10 to x and 5 to y
- changePositions(alpha, 10, 5);
- //Run
- /// changePositions(alpha, deltaX, deltaY)
- for (var i = 0; i < array_length_1d(alpha); i++) {
- var obj = alpha[i];
- obj.x += deltaX; // add deltaX to x position
- obj.y += deltaY; // add deltaY to y position
- }
Advertisement
Comments
-
- /// Map Array Storage where Map is your 2d Array
- // define the size of each tile
- var tile_size = 32;
- // define the number of rows and columns in the map
- var num_rows = array_height_2d(map);
- var num_cols = array_length_2d(map, 0);
- // define the offset of the currently visible row
- var row_offset = 0;
- // define the number of visible rows
- var num_visible_rows = room_height div tile_size;
- // draw the visible portion of the map
- for (var row = row_offset; row < row_offset + num_visible_rows; row++) {
- for (var col = 0; col < num_cols; col++) {
- var tile = map[row, col];
- draw_sprite(tile_sprite, tile, col*tile_size, (row-row_offset)*tile_size);
- }
- }
- // increment the row offset when scrolling down
- if (keyboard_check_pressed(vk_down)) {
- row_offset += 1;
- }
- // decrement the row offset when scrolling up
- if (keyboard_check_pressed(vk_up)) {
- row_offset -= 1;
- }
-
- // Saw this in a forum might work for your map
- var tile_size = 32; // size of each tile in pixels
- var start_row = floor(scroll_y / tile_size); // first visible row
- var end_row = min(start_row + ceil(view_hview[0] / tile_size), array_height_2d(map) - 1); // last visible row
- for (var y = start_row; y <= end_row; y++) {
- for (var x = 0; x < array_length_2d(map, 1); x++) {
- // draw the tile at (x, y) in the array
- var tile = map[x, y mod array_height_2d(map)];
- draw_sprite(tile_sprite, tile, x * tile_size, (y - start_row) * tile_size - (scroll_y mod tile_size));
- }
- }
Add Comment
Please, Sign In to add comment
Advertisement