Quantcast
Channel: Active questions tagged game-maker - Stack Overflow
Viewing all articles
Browse latest Browse all 180

How can I generate maps using pieces in Gamemaker?

$
0
0

I am using Gamemaker Studio 2 to make a 2d platformer. I want the maps to be procedurally generated using pieces that are randomly shuffled and places in the room. So like lets say theres an array that sayspiece_1 = [0, 1, 1, 0, 0]

And the 1 is a wall, and 0 is air. I make a bunch of these arrays and then mix them up and generate the map.

A game that I want to mimic maps to look like is the game "hets". https://ditto.itch.io/hets

Here's my current code for the object oGenerate.The Create event,

randomize();wall_size = 32;part_size = 5;p1_1 = [1, 1, 1, 1, 1];p1_2 = [0, 0, 0, 1, 1];p1_3 = [1, 1, 1, 1, 1];p1_4 = [0, 0, 0, 0, 0];p1_5 = [0, 0, 0, 0, 0];p2_1 = [0, 1, 0, 1, 1];p2_2 = [0, 1, 0, 1, 1];p2_3 = [0, 1, 1, 1, 1];p2_4 = [0, 0, 0, 0, 0];p2_5 = [0, 1, 1, 0, 0];p3_1 = [0, 0, 0, 1, 1];p3_2 = [0, 1, 0, 1, 1];p3_3 = [0, 1, 1, 1, 1];p3_4 = [0, 0, 0, 0, 0];p3_5 = [1, 1, 0, 0, 0];p4_1 = [0, 1, 0, 1, 1];p4_2 = [0, 1, 0, 1, 1];p4_3 = [0, 1, 1, 1, 1];p4_4 = [1, 0, 0, 0, 0];p4_5 = [0, 1, 1, 0, 0];p5_1 = [0, 1, 0, 1, 1];p5_2 = [0, 1, 0, 1, 1];p5_3 = [0, 1, 1, 1, 1];p5_4 = [1, 1, 0, 0, 0];p5_5 = [0, 1, 1, 0, 0];p6_1 = [0, 1, 0, 1, 1];p6_2 = [0, 1, 0, 1, 1];p6_3 = [0, 1, 1, 1, 1];p6_4 = [1, 1, 0, 0, 0];p6_5 = [0, 1, 1, 0, 0];p7_1 = [0, 1, 0, 1, 1];p7_2 = [0, 1, 0, 1, 1];p7_3 = [0, 1, 1, 1, 1];p7_4 = [1, 1, 0, 0, 0];p7_5 = [0, 1, 1, 0, 0];p1_total = [p1_1, p1_2, p1_3, p1_4, p1_5];p1 = array_shuffle(p1_total);p2_total = [p2_1, p2_2, p2_3, p2_4, p2_5];p2 = array_shuffle(p2_total);p3_total = [p3_1, p3_2, p3_3, p3_4, p3_5];p3 = array_shuffle(p3_total);p4_total = [p4_1, p4_2, p4_3, p4_4, p4_5];p4 = array_shuffle(p3_total);p5_total = [p5_1, p5_2, p5_3, p5_4, p5_5];p5 = array_shuffle(p5_total);p6_total = [p6_1, p6_2, p6_3, p6_4, p6_5];p6 = array_shuffle(p6_total);p7_total = [p7_1, p7_2, p7_3, p7_4, p7_5];p7 = array_shuffle(p7_total);part = [p1, p2, p3, p4, p5, p6, p7];var part_shuffled = array_shuffle(part);// generate mapvar block_y = 0;var block_x = 0;//generate mapfor (var p_id = 0; p_id <= (array_length(part_shuffled) - 1); p_id += 1) {    //show_debug_message(p_id);    for (var pp_id = 0; pp_id <= (array_length(part_shuffled[p_id]) - 1); pp_id += 1) {        //show_debug_message(part_shuffled[p_id][pp_id]);        if (part_shuffled[p_id][pp_id][pp_id] == 0) {            // its air, do nothing!            //show_debug_message("empty space");        }        if (part_shuffled[p_id][pp_id][pp_id] == 1) {            //show_debug_message("wall space");            with (instance_create_layer(block_x, block_y, 0, oWall)) {                // something here               }        }        // update x and y cords        if (pp_id < 4) {            block_x += wall_size;           } else if (pp_id == 4) {            block_y += wall_size;        }        if (p_id == 2) {            block_x = 0;            }        //show_debug_message(block_x);        //show_debug_message(block_y);    }}

Here's a GIF of me generating a few maps.https://i.imgur.com/7MmLXUo.gif

Can someone let me know what I can do to make the maps come out good?

It's working good, but the thing is, is the maps arent coming out looking like a real map.


Viewing all articles
Browse latest Browse all 180

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>