a simple game practicum with raylib
這是一個簡單的使用raylib的遊戲,主要是用來練習raylib的基本功能。
因為是練習用,所脙會非常隨性,你可能會發現程式風格極為混亂!是的,我喜歡混亂,那代表著無限的可能性。
當然也會有無限的錯誤,請多多包涵。
為什麼用C語言來練習呢?C代表著最大程度的自由,你可以用任何你喜歡的方式來寫程式。
What you think. what you write code. NO LIMIT. NO strange RULES.
主框架:
#include "commdef.h"
#include "game.h"
#include "raylib.h"
#include "slime.h"
#include "timer.h"
#include <stdio.h>
Game game = { 0 };
int main()
{
SetTraceLogLevel(LOG_ERROR);
InitWindow(SCR_WIDTH, SCR_HEIGHT, "Slime War");
SetTargetFPS(FPS);
GameInit(&game);
while (!WindowShouldClose()) {
GameUpdate(&game);
BeginDrawing();
ClearBackground((Color) { 0x18, 0x18, 0x18, 0xFF });
GameDraw(&game);
EndDrawing();
}
GameDestroy(&game);
CloseWindow();
return 0;
}
Game 模組:
#include "game.h"
#include "enemy.h"
#include "player.h"
#include "raylib.h"
#include "sprite.h"
#include "spritepool.h"
#include "timer.h"
#include "weapon.h"
#include <stdlib.h>
#include <string.h>
void GameInit(Game* game)
{
PlayerInit((Vec2) { 0, 0 }, 6, 100);
EnemyInit();
WeaponInit((Vec2) { 0, 0 });
gTimer.Init();
SpritePoolInit();
TryAddEnemy(ENEMY_SLIME);
TryAddEnemy(ENEMY_SLIME);
TryAddEnemy(ENEMY_SLIME);
TryAddEnemy(ENEMY_SLIME);
}
void GameDestroy(Game* game)
{
SpritePoolDestroy();
}
void GameUpdate(Game* game)
{
gTimer.Update();
EnemySpawn();
PlayerUpdate();
EnemyUpdate();
SpritePoolUpdate();
WeasponUpdate(PlayerPosition());
}
void GameDraw(Game* game)
{
PlayerDraw();
EnemyDraw();
WeaponDraw();
}