7
0
mirror of https://gitlab.com/raylibtemplates/rt.git synced 2026-06-10 10:45:12 -04:00

5 Commits

Author SHA1 Message Date
maple
439ba4478d Split Drawing into separate file 2025-12-21 12:24:27 -06:00
maple
a21cc3c1f4 Remove unneccessary import 2025-12-21 12:04:20 -06:00
maple
2e78dbd9df Update Raylib Version 2025-12-20 23:19:17 -06:00
maple
8600517c12 Seperate update into new file 2025-12-20 22:50:45 -06:00
Maple Redleaf
4d94c9b4b7 Separate constants into new file 2025-12-19 12:22:18 -06:00
9 changed files with 60 additions and 23 deletions

View File

@@ -5,15 +5,15 @@ project(game C CXX)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Dependencies # Dependencies
set(RAYLIB_VERSION 5.5) find_package(raylib QUIET) # QUIET or REQUIRED
find_package(raylib ${RAYLIB_VERSION} QUIET) # QUIET or REQUIRED
if(NOT raylib_FOUND) # If there's none, fetch and build raylib if(NOT raylib_FOUND) # If there's none, fetch and build raylib
include(FetchContent) include(FetchContent)
FetchContent_Declare( FetchContent_Declare(
raylib raylib
DOWNLOAD_EXTRACT_TIMESTAMP OFF DOWNLOAD_EXTRACT_TIMESTAMP OFF
URL https://github.com/raysan5/raylib/archive/refs/tags/${RAYLIB_VERSION}.tar.gz GIT_REPOSITORY https://github.com/raysan5/raylib.git
) GIT_TAG master
)
FetchContent_GetProperties(raylib) FetchContent_GetProperties(raylib)
if(NOT raylib_POPULATED) # Have we downloaded raylib yet? if(NOT raylib_POPULATED) # Have we downloaded raylib yet?
set(FETCHCONTENT_QUIET NO) set(FETCHCONTENT_QUIET NO)

7
src/consts.c Normal file
View File

@@ -0,0 +1,7 @@
#include "consts.h"
const int SCREEN_WIDTH = 320;
const int SCREEN_HEIGHT = 240;
const int WIN_WIDTH = 1280;
const int WIN_HEIGHT = 720;

5
src/consts.h Normal file
View File

@@ -0,0 +1,5 @@
extern const int SCREEN_WIDTH;
extern const int SCREEN_HEIGHT;
extern const int WIN_WIDTH;
extern const int WIN_HEIGHT;

14
src/draw.c Normal file
View File

@@ -0,0 +1,14 @@
#include "draw.h"
#include "main.h"
#include "raylib.h"
#include "raymath.h"
void Draw() {
ClearBackground(BLACK);
DrawCircleV((Vector2){160.0f, 120.0f}, 120.0f, WHITE);
BeginMode3D(cam);
{
DrawModel(cube, Vector3Zero(), 1.0f, WHITE);
}
EndMode3D();
}

1
src/draw.h Normal file
View File

@@ -0,0 +1 @@
extern void Draw();

View File

@@ -1,7 +1,10 @@
#include "main.h"
#include "consts.h"
#include "draw.h"
#include "raylib.h" #include "raylib.h"
#include "raymath.h" #include "raymath.h"
#include "update.h"
#include <math.h> #include <math.h>
#include <stdio.h>
#include "../data/cube.png.h" #include "../data/cube.png.h"
@@ -9,15 +12,10 @@
#include <emscripten/emscripten.h> #include <emscripten/emscripten.h>
#endif #endif
#define SCREEN_WIDTH (320)
#define SCREEN_HEIGHT (240)
#define WIN_WIDTH (1280)
#define WIN_HEIGHT (720)
#define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b))
void MainLoop(); static void MainLoop();
RenderTexture2D target; RenderTexture2D target;
@@ -60,25 +58,16 @@ int main(void) {
return 0; return 0;
} }
void MainLoop() { static void MainLoop() {
int winWidth = GetScreenWidth(), winHeight = GetScreenHeight(); int winWidth = GetScreenWidth(), winHeight = GetScreenHeight();
float scale = float scale =
MIN((float)winWidth / SCREEN_WIDTH, (float)winHeight / SCREEN_HEIGHT); MIN((float)winWidth / SCREEN_WIDTH, (float)winHeight / SCREEN_HEIGHT);
cube.transform = Update();
MatrixMultiply(MatrixRotateXYZ(Vector3Scale((Vector3){1.0f, 1.5f, 2.5f},
GetFrameTime())),
cube.transform);
BeginTextureMode(target); BeginTextureMode(target);
{ {
ClearBackground(BLACK); Draw();
DrawCircleV((Vector2){160.0f, 120.0f}, 120.0f, WHITE);
BeginMode3D(cam);
{
DrawModel(cube, Vector3Zero(), 1.0f, WHITE);
}
EndMode3D();
} }
EndTextureMode(); EndTextureMode();

9
src/main.h Normal file
View File

@@ -0,0 +1,9 @@
#include "raylib.h"
extern RenderTexture2D target;
extern Image texImg;
extern Texture2D texture;
extern Camera3D cam;
extern Model cube;

11
src/update.c Normal file
View File

@@ -0,0 +1,11 @@
#include "update.h"
#include "main.h"
#include "raylib.h"
#include "raymath.h"
void Update() {
cube.transform =
MatrixMultiply(MatrixRotateXYZ(Vector3Scale((Vector3){1.0f, 1.5f, 2.5f},
GetFrameTime())),
cube.transform);
}

1
src/update.h Normal file
View File

@@ -0,0 +1 @@
extern void Update();