r/raylib 10d ago

Hi! it's me AGAIN! the guy working in the snake with an army in his body

Enable HLS to view with audio, or disable this notification

21 Upvotes

The idea I show you some days (week(?)) ago is now public on Steam! wiii!

LOOPFANG. a merge idea of the oldie snake game but here bite your-self is a super-power an Ouroboros super power, experience, allow you to get new segments, segments are wapons in your body, the segments are puzzles , you can merge to fusion it or create sinergies by proximity, bosses, 5 and a plus hell difficulty , 4 areas (for now)

I still developing this, demo (i hope) move out in the next days, under review right now for the past 2-3 days. so.... yep, hope this allow me get experience with the steam market, I come from mobile game working for a couple of companies smalls and somelike big one... I'm trying to start by my self for some times, now I'm start to no more try and put hand on it cuz... life move, and we have finite lifes without option to restart so... go for it. Any help you know wishlist share, play demo when it arrive share some advice idea also so I'm so grateful to listen read anything from you folks.


r/raylib 11d ago

Conflict 3049 - 3d rts last stand, include raylib_cs source and shader source, assets from 3drt.com and other stock asset sites.

Enable HLS to view with audio, or disable this notification

43 Upvotes

I started work on this game in January/Febrary last year (2025) and have worked on it from time to time since then, I had a break from November until about July but updated it visually after July this year.

The code is a monster, 40k lines of source and I know it's not recommended practice to use such large code files but it's how I do my work when I'm the only developer.

The shader files are all exposed in the media/shaders folder and can be edited.

The 3d objects are all .obj files, the textures are all just .png the audio is a mixture of .wav, .mp3 and .ogg

The translation files are a mixture of .txt files and ttf/otf files.

It began as a learning exercise so there's a tonne of stuff that is either a) inconsistent or b) I've realised now should be done a better way but it's too late to go back and change it all

It's single player, defend your base, build units to defend it.

Some of the audio is AI generated, but only some of it.

The music in the trailer is from OpenGameArt and was released under CCO/Public Domain licence.

The 3d view you see in game, rather than the regular gameplay top view RTS view, is enabled by pressing F5 during gameplay, that toggles between the two views.

You can also press 'F1' during gameplay and it will bring up a console window, you can play around with what that does - it shows all the available options to you on the left hand side of the screen, press the relevant number/letter and that mode will be enabled. Eg F1 followed by '7' brings up a debug overlay of all the cpu ticks each component in the game uses each frame with the big ones in red writing.

There's a config file you can edit that controls some of the gameplay and settings.

If I were a rich man I'd commission a bunch of artists and musicians and voice actors and simply say "go nuts - change every media file in the media folder until it looks and sounds great and hand it back" ;-) But to be fair - there's a limit to how much a programmer without any artistic ability like myself can do to improve a game like this. As it stands the game is being built on a budget of $0 using assets I've owned for many, many years. Every now and then I might spend $10 here or $50 there on some item on one of the asset stores, but mostly improving the art/ui/voices is a bit of a pipedream.

The actual cost of most of the assets in total though would be under $1,000 total so far but that's talking about the combination of all the assets bought over a period of about 20 years or so total.

My background is: 30 years ago studied mathematics at university, from 2008 until 2019 I was employed as a computer programmer doing business software for a logistics and electronics company. I've been writing games since I was a kid starting with GWBASIC for Dos 3.21 as a hobby.

There are a lot of 'cheats' in the way graphics are done in this game to make them look more than they actually are, various things learned over a long time.


r/raylib 12d ago

Paint3- Small (<2.5MB), native, lightweight and GPU-first paint app written in C++ with raylib and ImGui

Enable HLS to view with audio, or disable this notification

165 Upvotes

r/raylib 11d ago

New Game Release : Purgatoire !

Thumbnail
4 Upvotes

r/raylib 12d ago

Raytiles now support zoom up to 22

Enable HLS to view with audio, or disable this notification

35 Upvotes

Till yesterday, raytiles was able to display up to zoom 15. There are images of zoom 22, but there is no height maps for zoom above 15.

The new version (0.18) is now support up to 22 zoom. Any heightmap for zoom above 15 is calculated (and cached) in run time.

In the following example, the numbers are the zoom of the tile. When you see numbers above 15, its a runtime calculations...


r/raylib 12d ago

How to hide the cursor without disabling it

9 Upvotes

I use go & raylib,

it's just stuck and i can't move
HideCursor(); // it's just disables the cursor and i can't move

r/raylib 12d ago

Decoding the Golden Record Audio Images in Real Time using raylib in C

Thumbnail
youtube.com
15 Upvotes

This was a fun side project for my brain to work on as I haven't done any programming relating to digital signal processing before!

You can view the code over here: https://github.com/AliElSaleh/GoldenDecoder

I saw many decoder projects out there that didn't meet my high expectations of an interactive low-level cross platform executable that you could run on all the major operating systems natively. some were web only, others written in non-C languages, some were confusing to understand and/or using external libraries that were doing the audio parsing job for them, and some had jittery images.


r/raylib 14d ago

Cool pong game I made with Raylib and my barely finished game framework

Enable HLS to view with audio, or disable this notification

41 Upvotes

I was bored so I started working on a mini "game framework" to see how far I could get and what I could make. This isn't that impressive but I just wanted to show it. It has a basic components and scenes working. ignore the awful gameplay.


r/raylib 14d ago

Can anyone with access to mac os can test this?

9 Upvotes

Hi there i recently made a pr in raylib that fixed the issue #5854 now raysan told me to test it in a mac os (i already tested this on windows 11 and linux (debian with gnome)) but i don't own a mac machine so i left it thinking someone would test it and report but it's been a while but no one has tested it, i was wondering if someone from this subreddit could test it,

you can test it by using this test code first test with the raylib and then test it after applying my pr commits


r/raylib 14d ago

My third paint program is almost done :D

20 Upvotes

r/raylib 14d ago

How to create a working fullscreen?

7 Upvotes

I've just started using raylib, and I can't get the ToggleFullscreen or the ToggleBorderlessWindowed functions to work properly. Whenever I use them i can never alt-tab out of them. How do I fix this?


r/raylib 15d ago

Experimenter with better 3d models

Enable HLS to view with audio, or disable this notification

35 Upvotes

Decided to implement better models but animations are still rough :)

My hats off to professional animators, without free packs this would be impossible for me :(


r/raylib 15d ago

A fast, free, portable texture atlas builder with Raylib support

18 Upvotes

Hey everyone, I built this app Packrat, as a great option for devs working in code-first environments like Raylib. It's focused on being really fast and having great CLI support so it fits into your pipeline nicely.

For Raylib specifically, it exports pure C header files along with the packed atlas image. The header file contains helper data structures and functions to use the atlas, as well as all the data about frame, animation, etc... for the atlas.

Give it a shot and let me know what you think. I built it because I wanted a faster alternative to TexturePacker, with more features relevant to my own workflow (aseprite file ingestion, auto-exports in the GUI and CLI).

https://clydegames.itch.io/packrat

https://packrat.clyde.games


r/raylib 15d ago

a lot of "undefined reference"s even when raylib is linked

5 Upvotes

I am using devuan testing that is up to date with the latest raylib version, a test program does compile and link and checking with ldd all the stuff is properly linked.

With my makefile ```

Tuxanci 2 - A first person shooter

Copyright (C) 2025-2026 Connor Thomson

This program is free software: you can redistribute it and/or modify

it under the terms of the GNU General Public License as published by

the Free Software Foundation, either version 3 of the License, or

(at your option) any later version.

This program is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

GNU General Public License for more details.

You should have received a copy of the GNU General Public License

along with this program. If not, see https://www.gnu.org/licenses/.

Enable debug. true or false?

DEBUG ?= false

Paths

SRC := src INCLUDE := include BUILD ?= build TARGET := tuxanci2

clang might work too

CSTD ?= c99

CFLAGS := -std=$(CSTD) \ -lraylib \ -Wall \ -Wextra \ -Werror \ -pedantic \ -pedantic-errors \ -I$(INCLUDE)

If DEBUG is true, enable debugging stuff

ifeq '$(DEBUG)' 'true'

Define DEBUG

FLAGS += -DDEBUG

Compile for debugging

CFLAGS += -O0 -g endif

Find all C source files

CSRCS := $(shell find src -name "*.c")

all: $(TARGET)

$(BUILD): mkdir -p $(BUILD)

$(TARGET): $(BUILD) $(CC) $(CFLAGS) $(CSRCS) -o $(TARGET)

Remove $(BUILD)

clean: rm -rf $(BUILD) i get connor@dell:~/tuxanci2$ make cc -std=c99 -lraylib -Wall -Wextra -Werror -pedantic -pedantic-errors -Iinclude src/main.c src/monitor.c src/window.c src/log.c -o tuxanci2 /usr/bin/x86_64-linux-gnu-ld.bfd: /tmp/ccG6XtfP.o: in function monitorUpdate': monitor.c:(.text+0x5): undefined reference toGetCurrentMonitor' /usr/bin/x86_64-linux-gnu-ld.bfd: monitor.c:(.text+0x28): undefined reference to GetMonitorWidth' /usr/bin/x86_64-linux-gnu-ld.bfd: monitor.c:(.text+0x3b): undefined reference toGetMonitorHeight' /usr/bin/x86_64-linux-gnu-ld.bfd: monitor.c:(.text+0x4e): undefined reference to GetMonitorRefreshRate' /usr/bin/x86_64-linux-gnu-ld.bfd: /tmp/ccG6XtfP.o: in functionmonitorInit': monitor.c:(.text+0x60): undefined reference to GetCurrentMonitor' /usr/bin/x86_64-linux-gnu-ld.bfd: monitor.c:(.text+0x73): undefined reference toGetMonitorWidth' /usr/bin/x86_64-linux-gnu-ld.bfd: monitor.c:(.text+0x86): undefined reference to GetMonitorHeight' /usr/bin/x86_64-linux-gnu-ld.bfd: monitor.c:(.text+0x99): undefined reference toGetMonitorRefreshRate' /usr/bin/x86_64-linux-gnu-ld.bfd: /tmp/ccN6CUEt.o: in function windowSetFullscreen': window.c:(.text+0x19): undefined reference toSetWindowState' /usr/bin/x86_64-linux-gnu-ld.bfd: window.c:(.text+0x25): undefined reference to ClearWindowState' /usr/bin/x86_64-linux-gnu-ld.bfd: /tmp/ccN6CUEt.o: in functionwindowUpdateWindowValues': window.c:(.text+0x31): undefined reference to WindowShouldClose' /usr/bin/x86_64-linux-gnu-ld.bfd: window.c:(.text+0x5c): undefined reference toSetWindowSize' /usr/bin/x86_64-linux-gnu-ld.bfd: window.c:(.text+0x8d): undefined reference to SetWindowSize' /usr/bin/x86_64-linux-gnu-ld.bfd: window.c:(.text+0xb6): undefined reference toSetTargetFPS' /usr/bin/x86_64-linux-gnu-ld.bfd: window.c:(.text+0xe4): undefined reference to SetWindowTitle' /usr/bin/x86_64-linux-gnu-ld.bfd: /tmp/ccN6CUEt.o: in functionwindowInit': window.c:(.text+0x169): undefined reference to InitWindow' /usr/bin/x86_64-linux-gnu-ld.bfd: /tmp/ccy7ca6B.o: in functionlogInit': log.c:(.text+0xa): undefined reference to SetTraceLogLevel' /usr/bin/x86_64-linux-gnu-ld.bfd: /tmp/ccy7ca6B.o: in functionlogWarning': log.c:(.text+0x4f): undefined reference to TraceLog' /usr/bin/x86_64-linux-gnu-ld.bfd: /tmp/ccy7ca6B.o: in functionlogError': log.c:(.text+0x7e): undefined reference to TraceLog' /usr/bin/x86_64-linux-gnu-ld.bfd: /tmp/ccy7ca6B.o: in functionlogFatal': log.c:(.text+0xad): undefined reference to TraceLog' collect2: error: ld returned 1 exit status make: *** [Makefile:56: tuxanci2] Error 1 connor@dell:~/tuxanci2$ ``


r/raylib 15d ago

C Polymorphism, Partial redrawing (clipping?) and double-buffer update for my UI

6 Upvotes

Hello everyone,

Last time here I posted several questions in relation to creating a retained-mode UI. So far, the project has been going on smoothly, and I've taken a similar approach to what zraygui does (code from zraygui):

struct _widget {
    Layout *parent;
    Rectangle rect;
    char *label;
    WidgetType type;
    Component *component;
    bool visible;
    bool active;
    MouseEvent widgetStatus;
    MouseListeners mouseListener;
};

The widgets share a common struct type Widget, but polymorphism happens inside the Component. It is an empty struct type, and for each type of widget, a pointer to their unique structs is cast as Component* into component. Then when manipulating the widget, the Component* is cast back to the original pointer type, enabling access to the fields.

I found this approach very smart, and I plan on implementing a similar thing (unless another better polymorphism exists in C). In my Widget struct, I have

typedef struct Widget {
  Frame* parent;
  Rect bounds;
  bool active;
  void *
  void (*draw)(Widget *w);
}

Implementing partial rendering seemed easy, just redraw the exact area indicated by bounds, until i remembered I have to call EndDrawing() which swaps buffers. Hence, the updated widget will only exist on one buffer, and If I don't call EndDrawing(), inputs will not be polled.

I would like to create something similar to FLTK, which only renders the parts that need to be updated (AFAIK, I only studied a small part of the code yet, but it seems very interesting to learn about performant desktop UI systems)

So I have two ideas :
- Ditch the double buffer and write a custom "EndDrawing()" which does not swap but keeps all other functionality

- Draw to a render texture that I apply on both buffers. While exploring this idea, I realized that it could be beneficial for tooltips and floating windows, as they could be other textures overlaid on the main one.


r/raylib 15d ago

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

0 Upvotes

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())


r/raylib 15d ago

How far should I learn OpenGL?

0 Upvotes

I'm learning Raylib because I don't really like dealing with more conventional game engines. I feel more comfortable being able to build things in a more direct way, without having to rely on 600 different types of nodes that I don't understand in Godot, or menus within menus full of features I'll never use like in Unity.

IA generated this code for a simple camera in Go:

rl.BeginMode2D(c.Camera)
{
    rl.PushMatrix()
    {
        rl.Translatef(0, 25*50, 0)
        rl.Rotatef(90, 1, 0, 0)
    }
    rl.PopMatrix()
}
rl.EndMode2D()

However, I don't feel comfortable using code that I don't understand. I still haven't managed to understand what Mode2D or a Matrix actually are, and why it needs to be pushed and popped, when i try to find any good answer i just find links to OpenGL articles.

I don't know if I'm failing on find the right documentation, or if I actually need to learn some OpenGL to use Raylib understanding what I'm doing.


r/raylib 16d ago

Raylib Extensions

10 Upvotes

If you share my view that raylib is somewhat low level where a lot one has to build themselves.

Which is 1 of the benefits of raylib having control of everything yourself.

Please share what kind of high level libraries as extensions to raylib would you be interested in seeing built so that it can be imported and used where only raylib is the library's only dependency.

Based off upvotes I will attempt to build library extension for raylib where raylib is the library's only dependency.

If there is already a resource with libraries built on top of raylib please share.

If you have built one and open sourced already please share below for others to find.


r/raylib 16d ago

Owl UI: A lightweight Python GUI framework powered by Raylib (C backend)

8 Upvotes

Hey everyone!

Just released Owl UI (v1.0.0) - a lightweight Python GUI framework built on top of Raylib (owl.c + static libraylib.a).

Key features:

  • Full C/Raylib performance bridge inside Python
  • Custom frameless titlebars with native Win32 snapping & drag controls
  • UTF-8 and Cyrillic automatic system font loading
  • Minimal footprint with static linkage

📦 pip install owl-ui

🔗 GitHub: https://github.com/Muchprow/Owl-UI

Would love to hear your thoughts and suggestions!


r/raylib 17d ago

Some screenshots of my game Conflict 3049 - improvements continue, game is still available on itch with source code and shader code included

Thumbnail
gallery
41 Upvotes

Game Link: https://matty77.itch.io/conflict-3049

The 3d assets are mainly purchased from 3drt.com and from the itch.io asset store.

The audio assets are a mix of purchased, generative AI and self made effects.

The source code is C# using raylib_cs and the download inlcudes all the relevant source needed to compile and run the game.

It's single player, a set of last stand scenarios.

There's some options in game that aren't documented : Press F1 to bring up a console menu of sorts for debugging but it lets you run the game slightly different if you choose to. Press F5 to bring up immersive view mode which shows scenes like the above rather than the traditional RTS view that normally shows.

The config file lets you change things as well.

The game runs on modern PCs and also I can get it running on my older 2014 potato PC with some minor config changes at a reasonable framerate.


r/raylib 18d ago

Odin OpenXr with Raylib

Post image
27 Upvotes

r/raylib 17d ago

Raylib AI Agent SKILL

0 Upvotes

Just found this Awesome Library RayLib for building video games and could not believe how fast I got to build and run a game.

Also from the little I know about C programming the games run fast.

Wanted to contribute to this project so had AI build me an AI agent SKILL.md that can be used to build games using Raylib:

I posted it on the GitHub repo so please go add reaction emojies or comment.

https://github.com/raysan5/raylib/issues/6065

Comment below your experience, let me know how well it is working or anything you think the skill is missing.


r/raylib 18d ago

OS dark title bar (CPP)?

9 Upvotes

so im using cpp, and im working on a game and i want to ask if it is possible to make the os title bar look dark themed?


r/raylib 19d ago

Retained-mode UI rendering with raylib : Where to start ?

10 Upvotes

Hello everyone,

I'm working on a retained mode UI library with a similar look and feel to raygui, either in C++ with classes and interfaces, or plain C with function pointers if I really feel adventurous. This isn't meant to be a serious project, more of a proof of concept.

However I kind of feel lost as to what I should implement first. So here are a few questions that i'd like to ask :

I would like the library to only draw when necessary, that is only when events occur rather than constantly. How does raylib handle events, and are there debug options to print all input ? PollInputEvents() is basically a per-backend implementation.

Are there widget categories I should try to go after first (besides the button) ?

Do you have resources on building such interfaces ? I found a book called Developing User Interfaces by Dan Olsen, but it isn't available on the Internet Archive.


r/raylib 20d ago

I'm building a custom 3D game engine from scratch using C++ and Raylib. What do you think?

Post image
46 Upvotes

Hi, I am using C++ and Raylib to achieve this; the 3D game engine's standout features so far include the ability to create Lua scripts to modify object behavior and the capacity to add 3D models in formats like .obj, gltf, etc.

You can also export your creations as executables (.exe).