Advertisement
Guest User

Shitty Voxel Engine

a guest
Oct 15th, 2016
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define main
  2. // Chunks
  3. chunk_map = ds_map_create();
  4.  
  5. chunk_models = 0;
  6. chunk_index = 0;
  7.  
  8. // No arguments... Compromises!
  9. chunk_create_x = 0;
  10. chunk_create_y = 0;
  11.  
  12. // Textures
  13. block_tex = background_add("http://i189.photobucket.com/albums/z5/Prince_Deity/DiamondBlock57.png", false, false);
  14. texture_set_interpolation(false);
  15.  
  16. draw_wait = 120; // Wait for the texture to download. May have to adjust based on internet speed...
  17.  
  18. // Camera
  19. x = -20;
  20. y = -20;
  21. z = 0;
  22. zspeed = 0;
  23.  
  24. cam_x = 0;
  25. cam_y = 0;
  26. cam_z = 0;
  27.  
  28. yaw = 0; yaw_to = yaw;
  29. pitch = 0; pitch_to = pitch;
  30.  
  31. mouse_lock();
  32.  
  33. // D3D
  34. d3d_start();
  35.  
  36. d3d_set_lighting(true);
  37. d3d_light_define_ambient(c_dkgray);
  38.  
  39. d3d_light_define_direction(0, 0.3, 0.5, -1.0, c_white);
  40. d3d_light_enable(0, true);
  41.  
  42. room_speed = 60;
  43.  
  44.  
  45.  
  46. #define step
  47. mouse_look();
  48. camera_movement();
  49.  
  50. // Chunk Generation
  51. var cx, cy;
  52. cx = x & -16;
  53. cy = y & -16;
  54.  
  55. var find = ds_map_find_value(chunk_map, string(cx) + "_" + string(cy));
  56. if (is_undefined(find)) {
  57.     chunk_create_x = cx;
  58.     chunk_create_y = cy;
  59.    
  60.     create_chunk();
  61. }
  62.  
  63.  
  64.  
  65. #define draw
  66. draw_wait--;
  67.  
  68. if (draw_wait < 0) {
  69.     d3d_set_projection_ext(
  70.         x, y, z,
  71.         x + cam_x, y + cam_y, z + cam_z,
  72.        
  73.         0, 0, 1, 70, view_wview / view_hview, 0.1, 1000
  74.     );
  75.    
  76.     // Draw Chunks
  77.     d3d_set_lighting(true);
  78.     draw_set_color(c_white);
  79.    
  80.     for (var i = 0; i < chunk_index; i++) {
  81.         d3d_model_draw(chunk_models[i], 0, 0, 0, background_get_texture(block_tex));
  82.     }
  83.    
  84.     d3d_set_lighting(false);
  85. }
  86.  
  87.  
  88.  
  89. #define draw_gui
  90. draw_set_color(c_black);
  91.  
  92. if (draw_wait < 0) {
  93.     draw_text(2, 2, "FPS: " + string(fps));
  94.     draw_text(2, 20, "Ha, wow!");
  95. } else {
  96.     draw_text(2, 2, "Loading...");
  97. }
  98.  
  99.  
  100.  
  101. #define game_end
  102. ds_map_destroy(chunk_map);
  103.  
  104.  
  105.  
  106.  
  107.  
  108. #define mouse_look
  109. yaw_to -= mouse_delta_x * 0.3;
  110. pitch_to -= mouse_delta_y * 0.3;
  111. pitch_to = clamp(pitch_to, -89, 89);
  112.  
  113. // Smooth Look
  114. yaw = lerp(yaw, yaw_to, 0.6);
  115. pitch = lerp(pitch, pitch_to, 0.6);
  116.  
  117. // Update Look Vector
  118. cam_x = dcos(yaw);
  119. cam_y = -dsin(yaw);
  120. cam_z = dtan(pitch);
  121.  
  122.  
  123.  
  124.  
  125.  
  126. #define camera_movement
  127. var spd = 0.2;
  128. if (keyboard_check(ord('W'))) motion_add(yaw, spd);
  129. if (keyboard_check(ord('A'))) motion_add(yaw + 90, spd);
  130. if (keyboard_check(ord('S'))) motion_add(yaw + 180, spd);
  131. if (keyboard_check(ord('D'))) motion_add(yaw + 270, spd);
  132.  
  133. if (keyboard_check(vk_space)) zspeed += spd;
  134. if (keyboard_check(vk_shift)) zspeed -= spd;
  135.  
  136. speed *= 0.8;
  137. zspeed *= 0.8;
  138.  
  139. // Apply Movement
  140. z += zspeed;
  141.  
  142.  
  143.  
  144.  
  145.  
  146. #define create_chunk
  147. ds_map_add(chunk_map, string(chunk_create_x) + "_" + string(chunk_create_y), chunk_index);
  148.  
  149. chunk_models[chunk_index] = d3d_model_create();
  150.  
  151. for (var xx = chunk_create_x; xx < chunk_create_x + 16; xx++) {
  152.     for (var yy = chunk_create_y; yy < chunk_create_y + 16; yy++) {
  153.         var noise = choose(2, 2, 3);
  154.        
  155.         for (var zz = 0; zz < noise; zz++) {
  156.             d3d_model_block(chunk_models[chunk_index], xx, yy, zz, xx + 1, yy + 1, zz + 1, 1, 1);
  157.         }
  158.     }
  159. }
  160.  
  161. chunk_index++;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement