From bd0ff931dcbe66f358bcce710cbe398d302cf426 Mon Sep 17 00:00:00 2001 From: magicalfeyfenny Date: Sat, 10 Jul 2021 20:21:52 -0400 Subject: [PATCH] jam entry, attempted to add things but couldnt figure it out --- minecraft-in-24h-jam.yyp | 2 +- objects/obj_block/Create_0.gml | 20 +++- objects/obj_player/Create_0.gml | 3 + objects/obj_player/Draw_0.gml | 0 objects/obj_player/Step_0.gml | 65 ++++++++++++- objects/obj_player/obj_player.yy | 1 + rooms/rm_main/rm_main.yy | 2 +- scripts/Script3/Script3.gml | 91 ------------------- scripts/scr_initialize/scr_initialize.gml | 9 +- .../scr_model_load_block.gml | 83 +++++++++++++++++ .../scr_model_load_block.yy} | 2 +- 11 files changed, 177 insertions(+), 101 deletions(-) create mode 100644 objects/obj_player/Draw_0.gml delete mode 100644 scripts/Script3/Script3.gml create mode 100644 scripts/scr_model_load_block/scr_model_load_block.gml rename scripts/{Script3/Script3.yy => scr_model_load_block/scr_model_load_block.yy} (82%) diff --git a/minecraft-in-24h-jam.yyp b/minecraft-in-24h-jam.yyp index 3faa2f5..e7a4cdf 100644 --- a/minecraft-in-24h-jam.yyp +++ b/minecraft-in-24h-jam.yyp @@ -3,7 +3,7 @@ {"id":{"name":"spr_testtex_bottom","path":"sprites/spr_testtex_bottom/spr_testtex_bottom.yy",},"order":9,}, {"id":{"name":"obj_player","path":"objects/obj_player/obj_player.yy",},"order":0,}, {"id":{"name":"scr_vertex_add_point","path":"scripts/scr_vertex_add_point/scr_vertex_add_point.yy",},"order":3,}, - {"id":{"name":"Script3","path":"scripts/Script3/Script3.yy",},"order":7,}, + {"id":{"name":"scr_model_load_block","path":"scripts/scr_model_load_block/scr_model_load_block.yy",},"order":7,}, {"id":{"name":"spr_testtex_top","path":"sprites/spr_testtex_top/spr_testtex_top.yy",},"order":8,}, {"id":{"name":"scr_initialize","path":"scripts/scr_initialize/scr_initialize.yy",},"order":4,}, {"id":{"name":"obj_block","path":"objects/obj_block/obj_block.yy",},"order":0,}, diff --git a/objects/obj_block/Create_0.gml b/objects/obj_block/Create_0.gml index 0c921fd..fc6cee6 100644 --- a/objects/obj_block/Create_0.gml +++ b/objects/obj_block/Create_0.gml @@ -1,12 +1,21 @@ z = 0; -var s = 64; -var color = c_white; +//var s = 64; +//var color = c_white; b_tex = spr_testtex_bottom; -b_face = global.model_cube[BOTTOM_FACE]; - - +t_tex = spr_testtex_top; +n_tex = spr_testtex_side; +s_tex = spr_testtex_side; +w_tex = spr_testtex_side; +e_tex = spr_testtex_side; +b_face = global.model_cube[| BOTTOM_FACE]; +t_face = global.model_cube[| TOP_FACE]; +n_face = global.model_cube[| NORTH_FACE]; +s_face = global.model_cube[| SOUTH_FACE]; +w_face = global.model_cube[| WEST_FACE]; +e_face = global.model_cube[| EAST_FACE]; +/* #region bottom face b_tex = spr_testtex_bottom; b_face = vertex_create_buffer(); @@ -91,3 +100,4 @@ vertex_add_point( e_face, s, 0, 0, 1, 0, 0, 1, 1, color, 1); vertex_end( e_face ); #endregion +*/ \ No newline at end of file diff --git a/objects/obj_player/Create_0.gml b/objects/obj_player/Create_0.gml index 2668480..2914fb7 100644 --- a/objects/obj_player/Create_0.gml +++ b/objects/obj_player/Create_0.gml @@ -1,4 +1,7 @@ look_dir = 0; look_pitch = 0; +placetarget = [-1,-1,-1]; +deletetarget = [-1,-1,-1]; + z = 70; \ No newline at end of file diff --git a/objects/obj_player/Draw_0.gml b/objects/obj_player/Draw_0.gml new file mode 100644 index 0000000..e69de29 diff --git a/objects/obj_player/Step_0.gml b/objects/obj_player/Step_0.gml index 45270c1..c0ddc3c 100644 --- a/objects/obj_player/Step_0.gml +++ b/objects/obj_player/Step_0.gml @@ -2,6 +2,50 @@ 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; @@ -12,6 +56,8 @@ 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; @@ -34,6 +80,12 @@ if ( keyboard_check( vk_control ) ) { 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) ); @@ -44,5 +96,16 @@ if ( up || down || left || right ) { } if ( ascend ^^ descend ) { - z = z + 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]; + } + } } \ No newline at end of file diff --git a/objects/obj_player/obj_player.yy b/objects/obj_player/obj_player.yy index 4e81282..60d9a84 100644 --- a/objects/obj_player/obj_player.yy +++ b/objects/obj_player/obj_player.yy @@ -20,6 +20,7 @@ "eventList": [ {"isDnD":false,"eventNum":0,"eventType":0,"collisionObjectId":null,"resourceVersion":"1.0","name":"","tags":[],"resourceType":"GMEvent",}, {"isDnD":false,"eventNum":0,"eventType":3,"collisionObjectId":null,"resourceVersion":"1.0","name":"","tags":[],"resourceType":"GMEvent",}, + {"isDnD":false,"eventNum":0,"eventType":8,"collisionObjectId":null,"resourceVersion":"1.0","name":"","tags":[],"resourceType":"GMEvent",}, ], "properties": [], "overriddenProperties": [], diff --git a/rooms/rm_main/rm_main.yy b/rooms/rm_main/rm_main.yy index 4e7cd04..06d8250 100644 --- a/rooms/rm_main/rm_main.yy +++ b/rooms/rm_main/rm_main.yy @@ -14,7 +14,7 @@ ], "layers": [ {"instances":[ - {"properties":[],"isDnd":false,"objectId":{"name":"obj_world","path":"objects/obj_world/obj_world.yy",},"inheritCode":false,"hasCreationCode":false,"colour":4294967295,"rotation":0.0,"scaleX":1.0,"scaleY":1.0,"imageIndex":0,"imageSpeed":1.0,"inheritedItemId":null,"frozen":false,"ignore":false,"inheritItemSettings":false,"x":0.0,"y":0.0,"resourceVersion":"1.0","name":"inst_5DBB2C44","tags":[],"resourceType":"GMRInstance",}, + {"properties":[],"isDnd":false,"objectId":{"name":"obj_chunk","path":"objects/obj_chunk/obj_chunk.yy",},"inheritCode":false,"hasCreationCode":false,"colour":4294967295,"rotation":0.0,"scaleX":1.0,"scaleY":1.0,"imageIndex":0,"imageSpeed":1.0,"inheritedItemId":null,"frozen":false,"ignore":false,"inheritItemSettings":false,"x":0.0,"y":0.0,"resourceVersion":"1.0","name":"inst_5DBB2C44","tags":[],"resourceType":"GMRInstance",}, ],"visible":true,"depth":0,"userdefinedDepth":false,"inheritLayerDepth":false,"inheritLayerSettings":false,"gridX":32,"gridY":32,"layers":[],"hierarchyFrozen":false,"resourceVersion":"1.0","name":"Terrain","tags":[],"resourceType":"GMRInstanceLayer",}, {"instances":[ {"properties":[],"isDnd":false,"objectId":{"name":"obj_camera","path":"objects/obj_camera/obj_camera.yy",},"inheritCode":false,"hasCreationCode":false,"colour":4294967295,"rotation":0.0,"scaleX":1.0,"scaleY":1.0,"imageIndex":0,"imageSpeed":1.0,"inheritedItemId":null,"frozen":false,"ignore":false,"inheritItemSettings":false,"x":0.0,"y":0.0,"resourceVersion":"1.0","name":"inst_78CCA660","tags":[],"resourceType":"GMRInstance",}, diff --git a/scripts/Script3/Script3.gml b/scripts/Script3/Script3.gml deleted file mode 100644 index 0df65ea..0000000 --- a/scripts/Script3/Script3.gml +++ /dev/null @@ -1,91 +0,0 @@ -/// @function -/// @param -function Script3(){ - -//TODO: Create a DS list for the model and return it - - #region bottom face - b_face = vertex_create_buffer(); - vertex_begin( b_face, global.vertex_format ); - - vertex_add_point( b_face, 0, 0, 0, 0, 0, -1, 0, 0, color, 1); - vertex_add_point( b_face, s, 0, 0, 0, 0, -1, 1, 0, color, 1); - vertex_add_point( b_face, s, s, 0, 0, 0, -1, 1, 1, color, 1); - vertex_add_point( b_face, s, s, 0, 0, 0, -1, 1, 1, color, 1); - vertex_add_point( b_face, 0, s, 0, 0, 0, -1, 0, 1, color, 1); - vertex_add_point( b_face, 0, 0, 0, 0, 0, -1, 0, 0, color, 1); - - vertex_end( b_face ); - #endregion -#region top face -t_tex = spr_testtex_top; -t_face = vertex_create_buffer(); -vertex_begin( t_face, global.vertex_format ); - -vertex_add_point( t_face, 0, 0, s, 0, 0, 1, 0, 0, color, 1); -vertex_add_point( t_face, s, 0, s, 0, 0, 1, 1, 0, color, 1); -vertex_add_point( t_face, s, s, s, 0, 0, 1, 1, 1, color, 1); -vertex_add_point( t_face, s, s, s, 0, 0, 1, 1, 1, color, 1); -vertex_add_point( t_face, 0, s, s, 0, 0, 1, 0, 1, color, 1); -vertex_add_point( t_face, 0, 0, s, 0, 0, 1, 0, 0, color, 1); - -vertex_end( t_face ); -#endregion -#region north face -n_tex = spr_testtex_side; -n_face = vertex_create_buffer(); -vertex_begin( n_face, global.vertex_format ); - -vertex_add_point( n_face, 0, 0, 0, 0, -1, 0, 1, 1, color, 1); -vertex_add_point( n_face, s, 0, 0, 0, -1, 0, 0, 1, color, 1); -vertex_add_point( n_face, s, 0, s, 0, -1, 0, 0, 0, color, 1); -vertex_add_point( n_face, s, 0, s, 0, -1, 0, 0, 0, color, 1); -vertex_add_point( n_face, 0, 0, s, 0, -1, 0, 1, 0, color, 1); -vertex_add_point( n_face, 0, 0, 0, 0, -1, 0, 1, 1, color, 1); - -vertex_end( n_face ); -#endregion -#region south face -s_tex = spr_testtex_side; -s_face = vertex_create_buffer(); -vertex_begin( s_face, global.vertex_format ); - -vertex_add_point( s_face, 0, s, 0, 0, 1, 0, 1, 1, color, 1); -vertex_add_point( s_face, s, s, 0, 0, 1, 0, 0, 1, color, 1); -vertex_add_point( s_face, s, s, s, 0, 1, 0, 0, 0, color, 1); -vertex_add_point( s_face, s, s, s, 0, 1, 0, 0, 0, color, 1); -vertex_add_point( s_face, 0, s, s, 0, 1, 0, 1, 0, color, 1); -vertex_add_point( s_face, 0, s, 0, 0, 1, 0, 1, 1, color, 1); - -vertex_end( s_face ); -#endregion -#region west face -w_tex = spr_testtex_side; -w_face = vertex_create_buffer(); -vertex_begin( w_face, global.vertex_format ); - -vertex_add_point( w_face, 0, 0, 0, -1, 0, 0, 1, 1, color, 1); -vertex_add_point( w_face, 0, s, 0, -1, 0, 0, 0, 1, color, 1); -vertex_add_point( w_face, 0, s, s, -1, 0, 0, 0, 0, color, 1); -vertex_add_point( w_face, 0, s, s, -1, 0, 0, 0, 0, color, 1); -vertex_add_point( w_face, 0, 0, s, -1, 0, 0, 1, 0, color, 1); -vertex_add_point( w_face, 0, 0, 0, -1, 0, 0, 1, 1, color, 1); - -vertex_end( w_face ); -#endregion -#region east face -e_tex = spr_testtex_side; -e_face = vertex_create_buffer(); -vertex_begin( e_face, global.vertex_format ); - -vertex_add_point( e_face, s, 0, 0, 1, 0, 0, 1, 1, color, 1); -vertex_add_point( e_face, s, s, 0, 1, 0, 0, 0, 1, color, 1); -vertex_add_point( e_face, s, s, s, 1, 0, 0, 0, 0, color, 1); -vertex_add_point( e_face, s, s, s, 1, 0, 0, 0, 0, color, 1); -vertex_add_point( e_face, s, 0, s, 1, 0, 0, 1, 0, color, 1); -vertex_add_point( e_face, s, 0, 0, 1, 0, 0, 1, 1, color, 1); - -vertex_end( e_face ); -#endregion - -} \ No newline at end of file diff --git a/scripts/scr_initialize/scr_initialize.gml b/scripts/scr_initialize/scr_initialize.gml index 5ab2dcb..168461e 100644 --- a/scripts/scr_initialize/scr_initialize.gml +++ b/scripts/scr_initialize/scr_initialize.gml @@ -22,6 +22,13 @@ #macro BLOCKS_TEST 1 #macro CHUNKS_TEST 1 +#macro BOTTOM_FACE 0 +#macro TOP_FACE 1 +#macro NORTH_FACE 2 +#macro SOUTH_FACE 3 +#macro WEST_FACE 4 +#macro EAST_FACE 5 + #endregion gml_pragma( "global", "scr_initialize()" ); @@ -39,7 +46,7 @@ function scr_initialize() { gpu_set_zwriteenable( true ); global.fog = gpu_get_fog(); - + global.model_cube = scr_model_load_block( BLOCK_SIZE, c_white ); return 0; } \ No newline at end of file diff --git a/scripts/scr_model_load_block/scr_model_load_block.gml b/scripts/scr_model_load_block/scr_model_load_block.gml new file mode 100644 index 0000000..94144f5 --- /dev/null +++ b/scripts/scr_model_load_block/scr_model_load_block.gml @@ -0,0 +1,83 @@ +/// @function scr_model_load_block(); +/// @param {real} _size +/// @param {color} _col + +function scr_model_load_block( _size, _col ){ + + #region bottom face + var b_face = vertex_create_buffer(); + vertex_begin( b_face, global.vertex_format ); + vertex_add_point( b_face, 0, 0, 0, 0, 0, -1, 0, 0, _col, 1); + vertex_add_point( b_face, _size, 0, 0, 0, 0, -1, 1, 0, _col, 1); + vertex_add_point( b_face, _size, _size, 0, 0, 0, -1, 1, 1, _col, 1); + vertex_add_point( b_face, _size, _size, 0, 0, 0, -1, 1, 1, _col, 1); + vertex_add_point( b_face, 0, _size, 0, 0, 0, -1, 0, 1, _col, 1); + vertex_add_point( b_face, 0, 0, 0, 0, 0, -1, 0, 0, _col, 1); + vertex_end( b_face ); + #endregion + + #region top face + var t_face = vertex_create_buffer(); + vertex_begin( t_face, global.vertex_format ); + vertex_add_point( t_face, 0, 0, _size, 0, 0, 1, 0, 0, _col, 1); + vertex_add_point( t_face, _size, 0, _size, 0, 0, 1, 1, 0, _col, 1); + vertex_add_point( t_face, _size, _size, _size,0, 0, 1, 1, 1, _col, 1); + vertex_add_point( t_face, _size, _size, _size,0, 0, 1, 1, 1, _col, 1); + vertex_add_point( t_face, 0, _size, _size, 0, 0, 1, 0, 1, _col, 1); + vertex_add_point( t_face, 0, 0, _size, 0, 0, 1, 0, 0, _col, 1); + vertex_end( t_face ); + #endregion + + #region north face + var n_face = vertex_create_buffer(); + vertex_begin( n_face, global.vertex_format ); + vertex_add_point( n_face, 0, 0, 0, 0, -1, 0, 1, 1, _col, 1); + vertex_add_point( n_face, _size, 0, 0, 0, -1, 0, 0, 1, _col, 1); + vertex_add_point( n_face, _size, 0, _size, 0, -1, 0, 0, 0, _col, 1); + vertex_add_point( n_face, _size, 0, _size, 0, -1, 0, 0, 0, _col, 1); + vertex_add_point( n_face, 0, 0, _size, 0, -1, 0, 1, 0, _col, 1); + vertex_add_point( n_face, 0, 0, 0, 0, -1, 0, 1, 1, _col, 1); + vertex_end( n_face ); + #endregion + + #region south face + var s_face = vertex_create_buffer(); + vertex_begin( s_face, global.vertex_format ); + vertex_add_point( s_face, 0, _size, 0, 0, 1, 0, 1, 1, _col, 1); + vertex_add_point( s_face, _size, _size, 0, 0, 1, 0, 0, 1, _col, 1); + vertex_add_point( s_face, _size, _size, _size,0, 1, 0, 0, 0, _col, 1); + vertex_add_point( s_face, _size, _size, _size,0, 1, 0, 0, 0, _col, 1); + vertex_add_point( s_face, 0, _size, _size, 0, 1, 0, 1, 0, _col, 1); + vertex_add_point( s_face, 0, _size, 0, 0, 1, 0, 1, 1, _col, 1); + vertex_end( s_face ); + #endregion + + #region west face + var w_face = vertex_create_buffer(); + vertex_begin( w_face, global.vertex_format ); + vertex_add_point( w_face, 0, 0, 0, -1, 0, 0, 1, 1, _col, 1); + vertex_add_point( w_face, 0, _size, 0, -1, 0, 0, 0, 1, _col, 1); + vertex_add_point( w_face, 0, _size, _size, -1, 0, 0, 0, 0, _col, 1); + vertex_add_point( w_face, 0, _size, _size, -1, 0, 0, 0, 0, _col, 1); + vertex_add_point( w_face, 0, 0, _size, -1, 0, 0, 1, 0, _col, 1); + vertex_add_point( w_face, 0, 0, 0, -1, 0, 0, 1, 1, _col, 1); + vertex_end( w_face ); + #endregion + + #region east face + var e_face = vertex_create_buffer(); + vertex_begin( e_face, global.vertex_format ); + vertex_add_point( e_face, _size, 0, 0, 1, 0, 0, 1, 1, _col, 1); + vertex_add_point( e_face, _size, _size, 0, 1, 0, 0, 0, 1, _col, 1); + vertex_add_point( e_face, _size, _size, _size, 1, 0, 0, 0, 0, _col, 1); + vertex_add_point( e_face, _size, _size, _size, 1, 0, 0, 0, 0, _col, 1); + vertex_add_point( e_face, _size, 0, _size, 1, 0, 0, 1, 0, _col, 1); + vertex_add_point( e_face, _size, 0, 0, 1, 0, 0, 1, 1, _col, 1); + vertex_end( e_face ); + #endregion + + var model = ds_list_create(); + ds_list_add( model, b_face, t_face, n_face, s_face, w_face, e_face ); + + return model; +} \ No newline at end of file diff --git a/scripts/Script3/Script3.yy b/scripts/scr_model_load_block/scr_model_load_block.yy similarity index 82% rename from scripts/Script3/Script3.yy rename to scripts/scr_model_load_block/scr_model_load_block.yy index e7570b9..df0b072 100644 --- a/scripts/Script3/Script3.yy +++ b/scripts/scr_model_load_block/scr_model_load_block.yy @@ -6,7 +6,7 @@ "path": "minecraft-in-24h-jam.yyp", }, "resourceVersion": "1.0", - "name": "Script3", + "name": "scr_model_load_block", "tags": [], "resourceType": "GMScript", } \ No newline at end of file