From d0a28aa8113810b0291618520ef88b53832baaa0 Mon Sep 17 00:00:00 2001 From: SilicaAndPina Date: Fri, 24 Jul 2020 15:08:32 +1200 Subject: [PATCH] CommitLog | --- objects/obj_chunk.object.gmx | 128 +++++++++++++++++++- objects/obj_controller_world_gen.object.gmx | 19 ++- sprites/images/spr_chunk_0.png | Bin 3788 -> 76 bytes sprites/spr_chunk.sprite.gmx | 10 +- 4 files changed, 148 insertions(+), 9 deletions(-) diff --git a/objects/obj_chunk.object.gmx b/objects/obj_chunk.object.gmx index 9d7ca99..e67fd99 100644 --- a/objects/obj_chunk.object.gmx +++ b/objects/obj_chunk.object.gmx @@ -7,7 +7,133 @@ 0 <undefined> <undefined> - + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + /// GENERATE CHUNK +var total_size = CHUNK_SIZE*TILE_SIZE; + +instance_list = array_create(total_size); +cur_inst = 0; +loaded = true; + +// GENERATION +for(var xx = 0; xx < CHUNK_SIZE*TILE_SIZE; xx+= TILE_SIZE) +{ + for(var yy = 0; yy < CHUNK_SIZE*TILE_SIZE; yy+= TILE_SIZE) + { + if(random_range(0,100) > 50) + { + instance_list[cur_inst] = instance_create(x+xx,y+yy, obj_asteriod); + cur_inst ++; + } + } +} + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + var chunk_total_size = CHUNK_SIZE * TILE_SIZE + + +if(distance_to_object(obj_player) > chunk_total_size+(TILE_SIZE*5)) +{ + event_user(0); +} + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + for(var i = 0; i < cur_inst; i++) +{ + instance_activate_object(instance_list[i]); +} +loaded = true; + + + + + + + + 1 + 603 + 7 + 0 + 0 + -1 + 2 + + + self + 0 + 0 + + + 1 + for(var i = 0; i < cur_inst; i++) +{ + instance_deactivate_object(instance_list[i]); +} +loaded = false; +instance_deactivate_object(id); + + + + + + 0 0 0 diff --git a/objects/obj_controller_world_gen.object.gmx b/objects/obj_controller_world_gen.object.gmx index 91219d4..b77bcf1 100644 --- a/objects/obj_controller_world_gen.object.gmx +++ b/objects/obj_controller_world_gen.object.gmx @@ -50,7 +50,9 @@ 1 - var playX = obj_player.x; + /// Load / Unload Chunks + +var playX = obj_player.x; var playY = obj_player.y; var chunk_total_size = (CHUNK_SIZE*TILE_SIZE); @@ -58,7 +60,6 @@ var chunk_total_size = (CHUNK_SIZE*TILE_SIZE); var chunkRelX = playX % chunk_total_size; var chunkRelY = playY % chunk_total_size; - var chunkX = (obj_player.x - chunkRelX); var chunkY = (obj_player.y - chunkRelY); @@ -83,10 +84,22 @@ if(chunkX == 0 && (playX < 0 && playX >= chunk_total_size/ } -if(!place_meeting(chunkX, chunkY,obj_chunk)) +instance_activate_region(chunkX,chunkY,12,12,true); +var chunkat = instance_position(chunkX, chunkY,obj_chunk); + +if(chunkat == noone) // create { + show_debug_message("Generating chunk: "+string(chunkX)+","+string(chunkY)); instance_create(chunkX,chunkY,obj_chunk); } +else // load +{ + if(chunkat.loaded = false) + { + show_debug_message("Loading chunk: "+string(chunkX)+","+string(chunkY)); + event_perform_object(chunkat,ev_user1,0); + } +} diff --git a/sprites/images/spr_chunk_0.png b/sprites/images/spr_chunk_0.png index 82f0e794f9a9e960a69fc5c6be26a4172ebcdfc3..a5bbd77fd79eb10941cbc6a35090b0f599a9d77e 100644 GIT binary patch literal 76 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2V8<6ZZI=>f4346LYhE&W+P6+t@f4+vzstNnJ Z7`IKiCRnDb9S)Rc@O1TaS?83{1ORr46XyT` literal 3788 zcmeAS@N?(olHy`uVBq!ia0y~yU;;9k7&zE~)R&4YzZe+!CVRR#hE&XXd(F^~)q%(P zVEupZ!;Cq*ICRS9nfPi=|5@WXY02|nf4(w!PWtk@l0n6@%7DK?#gqRT;{=tL2kWXB z>=+L07rgrTKmfx7zmR@rXT}EWKwCZ@R)%*jUo8wo7VHuscjz!v2}TW73y|`!DZl WaYovmn*{8oGI+ZBxvX0 0 1 - 0 + 255 0 1 0 - 511 + 9 0 - 511 + 9 0 0 0 0 - 512 - 512 + 10 + 10 images\spr_chunk_0.png