Minecraft clone. No cubes are drawn only models  and I added a render distance yet it still lags. Why?
▲ 1 r/raylib

Minecraft clone. No cubes are drawn only models and I added a render distance yet it still lags. Why?

MAIN python file

#Recreating Minecraft in Raylib part 2: Indev
#To Do:
#1D A chunk and block class - Easy although I fear it lags my game
#2D 2d stuff like hearts, inventory - Hearts cube was fine but
#3D Better placing and destroying physics - Used screen center rather than where the player mouse was
#4D Jumping/Gravity - Forgot to set gravity to the oppposite of its power. Kept setting it to 0 and the player would just slow down rather than fall
#5 Collison with blocks
#6D Make multiple chunks
#7D Improve preformance with meshes and instances (fking what?) - We added the set config flags line we guchi for bow
#8 Day night cycle - More annoying than I could ever imagine
#9D Leaves - Not too hard just annoying didnt make too many either.
# Link to making a 3d texture atlas good luck bro https://www.raylib.com/examples/shaders/loader.html?name=shaders_texture_tiling

import pyray as pr
import math
import random
import asyncio
import Block
import Chunk
#Mixer
import pygame as pg
pg.init()
pg.mixer.init()

async def main():
pr.set_config_flags(pr.FLAG_VSYNC_HINT)

pr.init_window(800, 600, "Minecraft 0.2")
pr.disable_cursor()
pr.init_audio_device()

#Camera
camera = pr.Camera3D((4, 3, 4), (1, 0.5, 1), (0, 1, 0), 100, pr.CAMERA_PERSPECTIVE)
cameraMode = pr.CAMERA_FIRST_PERSON
#DayNight cycle
day_night = "nan"
sky_cycle_add_inc = 200
sky_cycle_cc = 0
day_night_level = 0.0
#Player
player = pr.Vector3(camera.position.x, camera.position.y, camera.position.z)
# model
player_size = pr.Vector3(0.5, 3, 0.5)
player_mesh = pr.gen_mesh_cube(1.0, 4.0, 1.0)
player_model = pr.load_model_from_mesh(player_mesh)
player_model.materials[0].maps[pr.MATERIAL_MAP_DIFFUSE].color = pr.BLUE
# gravity
gravity = 0
grav_vel = 0.05
jumpH = 2
#UI
# Hearts
hearts = []
heart_x = 100
# make hearts
for i in range(10):
new_heart = pr.Rectangle(heart_x, pr.get_screen_height() - 140, 30, 30)
heart_x += 35
hearts.append(new_heart)
# Inventory
inventory = []
inventory_x = 100
for i in range(10):
new_i = pr.Rectangle(inventory_x, pr.get_screen_height() - 100, 60, 60)
inventory_x += 60
inventory.append(new_i)
#World
world_size = 3
# Chunks
chunks = []
chunk_x = 1
chunk_z = 1
chunk_size = 16
# Blocks
blocks = []
block_size = pr.Vector3(1, 1, 1)
# make chunks
for z in range(world_size):
for x in range(world_size):
new_chunk = Chunk.chunk(chunk_x, 1, chunk_z, chunk_size, blocks, block_size)
chunks.append(new_chunk)
chunk_x += chunk_size
chunk_x = 1
chunk_z += chunk_size

#Textures
# Atlas
#atlas_texture = pr.Texture2D(pr.load_texture("Assets/Images/textures/texture_atlas.png"))
# Grass texture
grass_mesh = pr.gen_mesh_cube(1, 1, 1)
grass_model = pr.load_model_from_mesh(grass_mesh)
grass_texture = pr.load_texture("Assets/Images/textures/grass_tex.jpeg")
grass_model.materials[0].maps[pr.MATERIAL_MAP_DIFFUSE].texture = grass_texture
# Stone texture
stone_mesh = pr.gen_mesh_cube(1, 1, 1)
stone_model = pr.load_model_from_mesh(stone_mesh)
stone_texture = pr.load_texture("Assets/Images/textures/stone_tex.png")
stone_model.materials[0].maps[pr.MATERIAL_MAP_DIFFUSE].texture = stone_texture
# Wood texture
wood_mesh = pr.gen_mesh_cube(1, 1, 1)
wood_model = pr.load_model_from_mesh(wood_mesh)
wood_texture = pr.load_texture("Assets/Images/textures/wood_tex.jpeg")
wood_model.materials[0].maps[pr.MATERIAL_MAP_DIFFUSE].texture = wood_texture
# Leaves texture
leaves_mesh = pr.gen_mesh_cube(1, 1, 1)
leaves_model = pr.load_model_from_mesh(leaves_mesh)
leaves_texture = pr.load_texture("Assets/Images/textures/leaves_tex.png")
leaves_model.materials[0].maps[pr.MATERIAL_MAP_DIFFUSE].texture = leaves_texture
# Planks texture
plank_mesh = pr.gen_mesh_cube(1, 1, 1)
plank_model = pr.load_model_from_mesh(plank_mesh)
plank_texture = pr.load_texture("Assets/Images/textures/plank_tex.png")
plank_model.materials[0].maps[pr.MATERIAL_MAP_DIFFUSE].texture = plank_texture
# Water texture
water_mesh = pr.gen_mesh_cube(1, 1, 1)
water_model = pr.load_model_from_mesh(water_mesh)
water_texture = pr.load_texture("Assets/Images/textures/water_tex.jpeg")
water_model.materials[0].maps[pr.MATERIAL_MAP_DIFFUSE].texture = water_texture
# Heart
"""heart_image = pr.Image(pr.load_image("Assets/Images/heart_tex.png"))
heart_texture = pr.Texture2D(pr.load_texture_from_image(heart_image))"""

while not pr.window_should_close():
pr.update_camera(camera, cameraMode)
#Interact with blocks
screenCenter = pr.Vector2(float(pr.get_screen_width()/2), float(pr.get_screen_height()/2))
ray = pr.get_screen_to_world_ray(screenCenter, camera)
for block in blocks:
# bounding box for collison
block_box = pr.BoundingBox(pr.Vector3(block.x - block_size.x/2, block.y - block_size.y/2, block.z - block_size.z/2),
pr.Vector3(block.x + block_size.x/2, block.y + block_size.y/2, block.z + block_size.z/2))
mouse_ray_collison = pr.get_ray_collision_box(ray, block_box)
#Interacting with block
# mouse looking at block
if (mouse_ray_collison.hit):
# delete block
if (pr.is_mouse_button_pressed(pr.MOUSE_BUTTON_LEFT)):
blocks.remove(block)
# new block
if (pr.is_mouse_button_pressed(pr.MOUSE_BUTTON_RIGHT)):
new_block = Block.block(block.x, block.y + 1, block.z, block_size, "plank")
blocks.append(new_block)

pr.begin_drawing()
pr.clear_background(pr.SKYBLUE)
#Draw
#3D stuff
pr.begin_mode_3d(camera)

#Player
# draw
player = pr.Vector3(camera.position.x, camera.position.y, camera.position.z)
# gravity
gravity += grav_vel
camera.position.y -= gravity
camera.target.y -= gravity
# reset position
if (pr.is_key_pressed(pr.KEY_R)):
camera.position = pr.Vector3( 4, 4, 4)
gravity = -grav_vel
#Blocks
for block in blocks:
# Player collison
if pr.check_collision_boxes(pr.BoundingBox(pr.Vector3(player.x - player_size.x/2, player.y - player_size.y/2, player.z - player_size.z),
pr.Vector3(player.x + player_size.x/2, player.y + player_size.y/2, player.z + player_size.z/2)),
pr.BoundingBox(pr.Vector3(block.x - block_size.x/2, block.y - block_size.y/2, block.z - block_size.z/2),
pr.Vector3(block.x + block_size.x/2, block.y + block_size.y/2, block.z + block_size.z/2))):
# execption
if (block.type != "water"):
gravity = -grav_vel
if (pr.is_key_pressed(pr.KEY_SPACE)):
gravity -= jumpH

#Draw chunks
for chunk in chunks:
chunk.draw(camera, grass_model, stone_model, wood_model, leaves_model, plank_model, water_model)

#Draw player
#pr.draw_cube(player, player_size.x, player_size.y, player_size.z, pr.BLUE)
pr.draw_model(player_model, pr.Vector3(camera.position.x, camera.position.y, camera.position.z) , 1, pr.WHITE)

pr.end_mode_3d()

#2D stuff
#Day night cycle
if (day_night == "day"):
sky_cycle_cc += 1
if (sky_cycle_cc >= sky_cycle_add_inc):
day_night_level += 0.1
sky_cycle_cc = 0
if (day_night_level == 0.5):
day_night == "night"
if (day_night == "night"):
sky_cycle_cc += 1
if (sky_cycle_cc >= sky_cycle_add_inc):
day_night_level -= 0.1
sky_cycle_cc = 0
if (day_night_level == 0.0):
day_night == "day"
pr.draw_rectangle(0, 0, pr.get_screen_width(), pr.get_render_height(), pr.fade(pr.BLACK, day_night_level))
#UI
# Crosshair
pr.draw_rectangle(int(pr.get_screen_width()/2), int(pr.get_screen_height()/2), 2, 10, pr.WHITE)
pr.draw_rectangle(int(pr.get_screen_width()/2) - 4, int(pr.get_screen_height()/2) + 4, 10, 2, pr.WHITE)
# Hearts
for ht in hearts:
pr.draw_rectangle(int(ht.x), int(ht.y), int(ht.width), int(ht.height), pr.RED)
#pr.draw_texture(heart_texture, int(ht.x), int(ht.y), pr.WHITE)
# Inventory
for iv in inventory:
pr.draw_rectangle_lines_ex(pr.Rectangle(int(iv.x), int(iv.y), int(iv.width), int(iv.height)), 8.0, pr.GRAY)

# Numbers
pr.draw_fps(10, 10)

pr.end_drawing()
await asyncio.sleep(0)

#Exit game
else:
pr.unload_model(grass_model)
pr.unload_model(stone_model)
pr.unload_model(wood_model)
pr.unload_model(leaves_model)
pr.unload_model(plank_model)
pr.unload_model(water_model)
#pr.unload_texture(heart_texture)
# Reset window if fullscreen
if (pr.is_window_fullscreen()):
pr.toggle_fullscreen() # Exit fullscreen
pr.set_window_size(1920, 1080); # Reset to desired default resolution

pr.close_window()

asyncio.run(main())#Recreating Minecraft in Raylib part 2: Indev
#To Do:
#1D A chunk and block class - Easy although I fear it lags my game
#2D 2d stuff like hearts, inventory - Hearts cube was fine but
#3D Better placing and destroying physics - Used screen center rather than where the player mouse was
#4D Jumping/Gravity - Forgot to set gravity to the oppposite of its power. Kept setting it to 0 and the player would just slow down rather than fall
#5 Collison with blocks
#6D Make multiple chunks
#7D Improve preformance with meshes and instances (fking what?) - We added the set config flags line we guchi for bow
#8 Day night cycle - More annoying than I could ever imagine
#9D Leaves - Not too hard just annoying didnt make too many either.
# Link to making a 3d texture atlas good luck bro https://www.raylib.com/examples/shaders/loader.html?name=shaders_texture_tiling

import pyray as pr
import math
import random
import asyncio
import Block
import Chunk
#Mixer
import pygame as pg
pg.init()
pg.mixer.init()

async def main():
pr.set_config_flags(pr.FLAG_VSYNC_HINT)

pr.init_window(800, 600, "Minecraft 0.2")
pr.disable_cursor()
pr.init_audio_device()

#Camera
camera = pr.Camera3D((4, 3, 4), (1, 0.5, 1), (0, 1, 0), 100, pr.CAMERA_PERSPECTIVE)
cameraMode = pr.CAMERA_FIRST_PERSON
#DayNight cycle
day_night = "nan"
sky_cycle_add_inc = 200
sky_cycle_cc = 0
day_night_level = 0.0
#Player
player = pr.Vector3(camera.position.x, camera.position.y, camera.position.z)
# model
player_size = pr.Vector3(0.5, 3, 0.5)
player_mesh = pr.gen_mesh_cube(1.0, 4.0, 1.0)
player_model = pr.load_model_from_mesh(player_mesh)
player_model.materials[0].maps[pr.MATERIAL_MAP_DIFFUSE].color = pr.BLUE
# gravity
gravity = 0
grav_vel = 0.05
jumpH = 2
#UI
# Hearts
hearts = []
heart_x = 100
# make hearts
for i in range(10):
new_heart = pr.Rectangle(heart_x, pr.get_screen_height() - 140, 30, 30)
heart_x += 35
hearts.append(new_heart)
# Inventory
inventory = []
inventory_x = 100
for i in range(10):
new_i = pr.Rectangle(inventory_x, pr.get_screen_height() - 100, 60, 60)
inventory_x += 60
inventory.append(new_i)
#World
world_size = 3
# Chunks
chunks = []
chunk_x = 1
chunk_z = 1
chunk_size = 16
# Blocks
blocks = []
block_size = pr.Vector3(1, 1, 1)
# make chunks
for z in range(world_size):
for x in range(world_size):
new_chunk = Chunk.chunk(chunk_x, 1, chunk_z, chunk_size, blocks, block_size)
chunks.append(new_chunk)
chunk_x += chunk_size
chunk_x = 1
chunk_z += chunk_size

#Textures
# Atlas
#atlas_texture = pr.Texture2D(pr.load_texture("Assets/Images/textures/texture_atlas.png"))
# Grass texture
grass_mesh = pr.gen_mesh_cube(1, 1, 1)
grass_model = pr.load_model_from_mesh(grass_mesh)
grass_texture = pr.load_texture("Assets/Images/textures/grass_tex.jpeg")
grass_model.materials[0].maps[pr.MATERIAL_MAP_DIFFUSE].texture = grass_texture
# Stone texture
stone_mesh = pr.gen_mesh_cube(1, 1, 1)
stone_model = pr.load_model_from_mesh(stone_mesh)
stone_texture = pr.load_texture("Assets/Images/textures/stone_tex.png")
stone_model.materials[0].maps[pr.MATERIAL_MAP_DIFFUSE].texture = stone_texture
# Wood texture
wood_mesh = pr.gen_mesh_cube(1, 1, 1)
wood_model = pr.load_model_from_mesh(wood_mesh)
wood_texture = pr.load_texture("Assets/Images/textures/wood_tex.jpeg")
wood_model.materials[0].maps[pr.MATERIAL_MAP_DIFFUSE].texture = wood_texture
# Leaves texture
leaves_mesh = pr.gen_mesh_cube(1, 1, 1)
leaves_model = pr.load_model_from_mesh(leaves_mesh)
leaves_texture = pr.load_texture("Assets/Images/textures/leaves_tex.png")
leaves_model.materials[0].maps[pr.MATERIAL_MAP_DIFFUSE].texture = leaves_texture
# Planks texture
plank_mesh = pr.gen_mesh_cube(1, 1, 1)
plank_model = pr.load_model_from_mesh(plank_mesh)
plank_texture = pr.load_texture("Assets/Images/textures/plank_tex.png")
plank_model.materials[0].maps[pr.MATERIAL_MAP_DIFFUSE].texture = plank_texture
# Water texture
water_mesh = pr.gen_mesh_cube(1, 1, 1)
water_model = pr.load_model_from_mesh(water_mesh)
water_texture = pr.load_texture("Assets/Images/textures/water_tex.jpeg")
water_model.materials[0].maps[pr.MATERIAL_MAP_DIFFUSE].texture = water_texture
# Heart
"""heart_image = pr.Image(pr.load_image("Assets/Images/heart_tex.png"))
heart_texture = pr.Texture2D(pr.load_texture_from_image(heart_image))"""

while not pr.window_should_close():
pr.update_camera(camera, cameraMode)
#Interact with blocks
screenCenter = pr.Vector2(float(pr.get_screen_width()/2), float(pr.get_screen_height()/2))
ray = pr.get_screen_to_world_ray(screenCenter, camera)
for block in blocks:
# bounding box for collison
block_box = pr.BoundingBox(pr.Vector3(block.x - block_size.x/2, block.y - block_size.y/2, block.z - block_size.z/2),
pr.Vector3(block.x + block_size.x/2, block.y + block_size.y/2, block.z + block_size.z/2))
mouse_ray_collison = pr.get_ray_collision_box(ray, block_box)
#Interacting with block
# mouse looking at block
if (mouse_ray_collison.hit):
# delete block
if (pr.is_mouse_button_pressed(pr.MOUSE_BUTTON_LEFT)):
blocks.remove(block)
# new block
if (pr.is_mouse_button_pressed(pr.MOUSE_BUTTON_RIGHT)):
new_block = Block.block(block.x, block.y + 1, block.z, block_size, "plank")
blocks.append(new_block)

pr.begin_drawing()
pr.clear_background(pr.SKYBLUE)
#Draw
#3D stuff
pr.begin_mode_3d(camera)

#Player
# draw
player = pr.Vector3(camera.position.x, camera.position.y, camera.position.z)
# gravity
gravity += grav_vel
camera.position.y -= gravity
camera.target.y -= gravity
# reset position
if (pr.is_key_pressed(pr.KEY_R)):
camera.position = pr.Vector3( 4, 4, 4)
gravity = -grav_vel
#Blocks
for block in blocks:
# Player collison
if pr.check_collision_boxes(pr.BoundingBox(pr.Vector3(player.x - player_size.x/2, player.y - player_size.y/2, player.z - player_size.z),
pr.Vector3(player.x + player_size.x/2, player.y + player_size.y/2, player.z + player_size.z/2)),
pr.BoundingBox(pr.Vector3(block.x - block_size.x/2, block.y - block_size.y/2, block.z - block_size.z/2),
pr.Vector3(block.x + block_size.x/2, block.y + block_size.y/2, block.z + block_size.z/2))):
# execption
if (block.type != "water"):
gravity = -grav_vel
if (pr.is_key_pressed(pr.KEY_SPACE)):
gravity -= jumpH

#Draw chunks
for chunk in chunks:
chunk.draw(camera, grass_model, stone_model, wood_model, leaves_model, plank_model, water_model)

#Draw player
#pr.draw_cube(player, player_size.x, player_size.y, player_size.z, pr.BLUE)
pr.draw_model(player_model, pr.Vector3(camera.position.x, camera.position.y, camera.position.z) , 1, pr.WHITE)

pr.end_mode_3d()

#2D stuff
#Day night cycle
if (day_night == "day"):
sky_cycle_cc += 1
if (sky_cycle_cc >= sky_cycle_add_inc):
day_night_level += 0.1
sky_cycle_cc = 0
if (day_night_level == 0.5):
day_night == "night"
if (day_night == "night"):
sky_cycle_cc += 1
if (sky_cycle_cc >= sky_cycle_add_inc):
day_night_level -= 0.1
sky_cycle_cc = 0
if (day_night_level == 0.0):
day_night == "day"
pr.draw_rectangle(0, 0, pr.get_screen_width(), pr.get_render_height(), pr.fade(pr.BLACK, day_night_level))
#UI
# Crosshair
pr.draw_rectangle(int(pr.get_screen_width()/2), int(pr.get_screen_height()/2), 2, 10, pr.WHITE)
pr.draw_rectangle(int(pr.get_screen_width()/2) - 4, int(pr.get_screen_height()/2) + 4, 10, 2, pr.WHITE)
# Hearts
for ht in hearts:
pr.draw_rectangle(int(ht.x), int(ht.y), int(ht.width), int(ht.height), pr.RED)
#pr.draw_texture(heart_texture, int(ht.x), int(ht.y), pr.WHITE)
# Inventory
for iv in inventory:
pr.draw_rectangle_lines_ex(pr.Rectangle(int(iv.x), int(iv.y), int(iv.width), int(iv.height)), 8.0, pr.GRAY)

# Numbers
pr.draw_fps(10, 10)

pr.end_drawing()
await asyncio.sleep(0)

#Exit game
else:
pr.unload_model(grass_model)
pr.unload_model(stone_model)
pr.unload_model(wood_model)
pr.unload_model(leaves_model)
pr.unload_model(plank_model)
pr.unload_model(water_model)
#pr.unload_texture(heart_texture)
# Reset window if fullscreen
if (pr.is_window_fullscreen()):
pr.toggle_fullscreen() # Exit fullscreen
pr.set_window_size(1920, 1080); # Reset to desired default resolution

pr.close_window()

asyncio.run(main())

u/False-Increase4614 — 4 days ago
▲ 1 r/FAFSA+1 crossposts

How is this SAP appeal? Anything to add or change?

Dear Office of Financial Aid

I hope this message finds you well. I am writing today to explain the situations I faced, how it impacted my academic performance, and how I plan on moving forward. Just as my spring semester was about to start, a letter was put on the door of my family's home.  The letter discussed how my family were owed around 25, 000 dollars in debt we had to move out. Not only were my family given the day before to pack but when most of my family failed to finish packing the landlord called multiple people to move our stuff out and throw it out on the lawn. After packing the rest of our stuff, we would spend the next 3 months and the duration of my spring semester in a hotel room with half my family and the other half in the other hotel room. As you can imagine going through the whole ordeal, no longer having my own room and privacy and half of the things I used to took quite a toll on my family's mental health. While I tried my best to continue with my studies the lack of motivation I got from how easily and abruptly my life could change like that due to the decisions of others. Thankfully now I have a home and my entire family is housed in an albeit smaller home. With this new found structure I have found it much easier to focus on any project I work on and have the ability to finish it. I also plan to get a tutor at the recommendation of my counselor. I hope that by reading this message you will understand why I am ashamed for my grades and also need to be able to utilize financial aid to finish my education and one day secure the livelihood for my family. 

From, (My name)

(Image of the eviction letter)

reddit.com
u/False-Increase4614 — 2 months ago
▲ 6 r/raylib

Why isn't my split screen working?

For context I am using scissor mode to achieve this. Also the only parts that are working are the HUD, darkness and rain appearing on the left side. What isn't working is that any time I use the mouse to move camera 1, the other camera follows it. I already tried the texture split screen and it didn't work.

Also I'm using python.

u/False-Increase4614 — 2 months ago
▲ 8 r/raylib+1 crossposts

HUNTED (working title) - Teaser Trailer

Might need to increase the volume to hear properly

A maze horror game, one person runs the other hunts. Play against friends local/online or against an AI. Thinking of 5 different maps and will need to figure out 3D modeling and music.

youtube.com
u/False-Increase4614 — 2 months ago
▲ 17 r/pygame

Created a fake OS game for mothers day. MotherOS

Using python and pygame I made a game that took place in an OS where the different apps commonly found on an operating system were actually games. I currently have two games down and I did finish before mothers day and even got to show it to my mom witch she was grateful for.

Trash:

The trash game sees the player trying to drop different levels of heavy objects into a increasingly moving trash can. Blue is medium weight, white is light and red is heavy.

Text:

The text game is pong except the ball randomly changes speed from slow to fast. This is meant to correlate to different text respond speeds. This is why the right pong is green.

I plan on changing the game to NotAnOS if I ever plan on actually uploading it somewhere.

u/False-Increase4614 — 3 months ago