-
-
Save wbbradley/da0e7413c58dc77e46ee2ecacbb1fe6f to your computer and use it in GitHub Desktop.
Raylib 32x32 competition template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************************************************************************** | |
* | |
* raylib 32x32 game/demo competition | |
* | |
* Competition consist in developing a videogame in a 32x32 pixels screen size. | |
* | |
* RULES: | |
* | |
* 1) Use only raylib (and included libraries), no external libraries allowed | |
* 2) The submission should consist of just one source file | |
* 3) Render your game/demo to a 32x32 pixels render texture, | |
* show what you could do with a 32x32 RGB LED matrix! | |
* 4) No external resources, you CAN only create them programmatically, | |
* 5) Game/demo can be 2D or 3D, choose wisely | |
* 5) Shaders (if used) should be included in the source as string (char *) | |
* and loaded with LoadShaderCode() | |
* 6) Code must compile and execute in PLATFORM_DESKTOP (Windows, Linux, macOS) | |
* | |
* | |
* LICENSE: zlib/libpng | |
* | |
* Copyright (c) 2020 <TODO: participant_name> (<TODO: participant_github_name>) | |
* | |
* This software is provided "as-is", without any express or implied warranty. In no event | |
* will the authors be held liable for any damages arising from the use of this software. | |
* | |
* Permission is granted to anyone to use this software for any purpose, including commercial | |
* applications, and to alter it and redistribute it freely, subject to the following restrictions: | |
* | |
* 1. The origin of this software must not be misrepresented; you must not claim that you | |
* wrote the original software. If you use this software in a product, an acknowledgment | |
* in the product documentation would be appreciated but is not required. | |
* | |
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented | |
* as being the original software. | |
* | |
* 3. This notice may not be removed or altered from any source distribution. | |
* | |
**********************************************************************************************/ | |
#include "raylib.h" | |
#include "raymath.h" | |
#define max(a, b) ((a)>(b)? (a) : (b)) | |
#define min(a, b) ((a)<(b)? (a) : (b)) | |
const int windowWidth = 512; // NOTE: Game will be scaled x16 | |
const int windowHeight = 512; | |
const int gameScreenWidth = 32; | |
const int gameScreenHeight = 32; | |
int main(void) | |
{ | |
SetTraceLogLevel(LOG_WARNING); | |
SetConfigFlags(FLAG_VSYNC_HINT); | |
InitWindow(windowWidth, windowHeight, "my 32x32 game/demo"); | |
// Render texture initialization, used to hold the rendering | |
RenderTexture2D target = LoadRenderTexture(gameScreenWidth, gameScreenHeight); | |
SetTextureFilter(target.texture, FILTER_POINT); // Texture scale filter to use! | |
// ------------ YOUR CODE here ------------- | |
// NOTE: You don't need to use 3D! (no extra points!) | |
Camera camera = { 0 }; | |
camera.position = (Vector3){ 0.0f, 1.0f, 2.0f }; | |
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; | |
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; | |
camera.fovy = 45.0f; | |
camera.type = CAMERA_PERSPECTIVE; | |
// Generate torus mesh | |
Mesh mesh = GenMeshTorus(0.5f, 1.0f, 16, 32); | |
Model model = LoadModelFromMesh(mesh); | |
// Checked texture for the torus | |
Image imChecked = GenImageChecked(16, 16, 4, 4, RED, WHITE); | |
Texture texChecked = LoadTextureFromImage(imChecked); | |
UnloadImage(imChecked); | |
// Assign generated checked texture to model texture | |
model.materials[0].maps[MAP_DIFFUSE].texture = texChecked; | |
Vector3 angle = { 0 }; | |
int frameCount = 0; | |
// ------------ end of YOUR CODE ------------------ | |
SetTargetFPS(60); // Set our game to run at 60 frames-per-second | |
//-------------------------------------------------------------------------------------- | |
// Main game loop | |
while (!WindowShouldClose()) // Detect window close button or ESC key | |
{ | |
// Update | |
//---------------------------------------------------------------------------------- | |
frameCount++; | |
angle.x += 0.02; angle.y +=0.01; angle.z -= 0.002; | |
model.transform = MatrixRotateXYZ(angle); | |
// Compute required framebuffer scaling | |
float scale = min((float)GetScreenWidth()/gameScreenWidth, (float)GetScreenHeight()/gameScreenHeight); | |
//---------------------------------------------------------------------------------- | |
// Draw | |
//---------------------------------------------------------------------------------- | |
BeginDrawing(); | |
ClearBackground(BLACK); | |
// Draw everything in the render texture, note this will not be rendered on screen, yet | |
BeginTextureMode(target); | |
ClearBackground(BLACK); // Clear render texture background color | |
// ------------ YOUR CODE here ------------- | |
DrawTextEx(GetFontDefault(), "World", (Vector2){ 2, 23 }, GetFontDefault().baseSize, 1, (Color){ 0, 255, 255, 255 }); | |
BeginMode3D(camera); | |
DrawModel(model, (Vector3){ 0, 0, 0 }, 1, WHITE); | |
EndMode3D(); | |
DrawTextEx(GetFontDefault(), "Hello", (Vector2){ 4, 0 }, GetFontDefault().baseSize, 1, (Color){ 0, 255, 255, 255 }); | |
// ------------ end of YOUR CODE ------------------ | |
EndTextureMode(); | |
// Draw render texture to window, properly scaled | |
DrawTexturePro(target.texture, (Rectangle){ 0.0f, 0.0f, (float)target.texture.width, (float)-target.texture.height }, | |
(Rectangle){ (GetScreenWidth() - ((float)gameScreenWidth*scale))*0.5, (GetScreenHeight() - ((float)gameScreenHeight*scale))*0.5, | |
(float)gameScreenWidth*scale, (float)gameScreenHeight*scale }, (Vector2){ 0, 0 }, 0.0f, WHITE); | |
// Draw the grid like "stencil" is drawn over the squares to make them look not at all like LEDs! | |
for (int x = 0; x < GetScreenWidth(); x += 16) DrawRectangle(x, 0, 4, GetScreenHeight(), BLACK); | |
for (int y = 0; y < GetScreenHeight(); y += 16) DrawRectangle(0, y, GetScreenWidth(), 4, BLACK); | |
EndDrawing(); | |
//-------------------------------------------------------------------------------------- | |
} | |
// De-Initialization | |
//-------------------------------------------------------------------------------------- | |
UnloadRenderTexture(target); // Unload render texture | |
UnloadTexture(texChecked); | |
UnloadModel(model); | |
CloseWindow(); // Close window and OpenGL context | |
//-------------------------------------------------------------------------------------- | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment