Setup cammera2d and types
This commit is contained in:
parent
39abfaa978
commit
fdebdd3ca2
6 changed files with 201 additions and 63 deletions
86
alyson/src/alyson.c
Normal file
86
alyson/src/alyson.c
Normal file
|
@ -0,0 +1,86 @@
|
|||
#include <alyson.h>
|
||||
#include <raylib.h>
|
||||
#include <stdio.h>
|
||||
#include <rlyson.h>
|
||||
|
||||
#include "../../cmake-build-minsizerel/_deps/raylib-src/src/raymath.h"
|
||||
|
||||
#define WINDOW_TITLE "Alyson Engine"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
SetTargetFPS(60);
|
||||
|
||||
InitWindow(900, 500, WINDOW_TITLE " -- 900x500");
|
||||
|
||||
|
||||
Texture2D logo = LoadTexture(MANGLE_RES_PATH("Raylib_logo.png"));
|
||||
|
||||
|
||||
|
||||
Camera2D camera = { 0 };
|
||||
camera.target = (Vector2){
|
||||
(float)(GetScreenWidth()) / 2.f,
|
||||
(float)(GetScreenHeight()) / 2.f
|
||||
};
|
||||
camera.offset = (Vector2){ (float)(GetScreenWidth()) / 2.f,
|
||||
(float)(GetScreenHeight()) / 2.f };
|
||||
camera.rotation = 0.0f;
|
||||
camera.zoom = 1.0f;
|
||||
|
||||
init(0);
|
||||
|
||||
while (!WindowShouldClose()) {
|
||||
const float dt = GetFrameTime();
|
||||
|
||||
if (IsWindowResized()) {
|
||||
SetWindowTitle(TextFormat("%s -- %dx%d", WINDOW_TITLE, GetScreenWidth(), GetScreenHeight()));
|
||||
}
|
||||
|
||||
BeginDrawing();
|
||||
BeginMode2D(camera);
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
camera.rotation += dt * 10.f;
|
||||
if (camera.rotation > 360.f) {
|
||||
camera.rotation -= 360.f;
|
||||
}
|
||||
|
||||
DrawTexture(logo, GetScreenWidth() / 2 - logo.width / 2, GetScreenHeight() / 2 - logo.height / 2, WHITE);
|
||||
DrawTextFull(
|
||||
GetFontDefault(),
|
||||
WINDOW_TITLE,
|
||||
(Vector2) {
|
||||
(float)(GetScreenWidth()) / 2.f,
|
||||
(float)(GetScreenHeight()) - 60.f
|
||||
},
|
||||
TEXT_ORIENTATION_CENTER, 0.f,
|
||||
40.f, 5.f,
|
||||
0.f, BLACK
|
||||
);
|
||||
|
||||
update(dt);
|
||||
render(dt);
|
||||
|
||||
EndMode2D();
|
||||
|
||||
// log the delta time
|
||||
DrawTextFull(
|
||||
GetFontDefault(),
|
||||
TextFormat("%.3f", dt),
|
||||
(Vector2) {
|
||||
30.f,
|
||||
30.f
|
||||
},
|
||||
TEXT_ORIENTATION_RIGHT, 0.0f,
|
||||
20.f, 5.f,
|
||||
0.f, BLACK
|
||||
);
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
UnloadTexture(logo);
|
||||
CloseWindow();
|
||||
return 0;
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
#include <alyson.hpp>
|
||||
#include <raylib.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <rlyson.h>
|
||||
|
||||
#define WINDOW_TITLE "Alyson Engine"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
SetTargetFPS(60);
|
||||
|
||||
InitWindow(900, 500, WINDOW_TITLE " -- 900x500");
|
||||
|
||||
|
||||
Texture2D logo = LoadTexture(MANGLE_RES_PATH("Raylib_logo.png"));
|
||||
|
||||
|
||||
Camera2D camera = { 0 };
|
||||
camera.target = (Vector2){ 0, 0 };
|
||||
camera.offset = (Vector2){ 0, 0 };
|
||||
camera.rotation = 0.0f;
|
||||
camera.zoom = 1.0f;
|
||||
|
||||
init(0);
|
||||
|
||||
while (!WindowShouldClose()) {
|
||||
float dt = GetFrameTime();
|
||||
|
||||
if (IsWindowResized()) {
|
||||
SetWindowTitle((std::string(WINDOW_TITLE) + " -- " + std::to_string(GetScreenWidth()) + "x" + std::to_string(GetScreenHeight())).c_str());
|
||||
}
|
||||
|
||||
BeginDrawing();
|
||||
BeginMode2D(camera);
|
||||
ClearBackground(RAYWHITE);
|
||||
camera.rotation += dt;
|
||||
camera.rotation = (int)camera.rotation % 360;
|
||||
|
||||
DrawTexture(logo, GetScreenWidth() / 2 - logo.width / 2, GetScreenHeight() / 2 - logo.height / 2, WHITE);
|
||||
DrawTextFull(
|
||||
GetFontDefault(),
|
||||
WINDOW_TITLE,
|
||||
{ GetScreenWidth() / 2.f, GetScreenHeight() - 60.f },
|
||||
TEXT_ORIENTATION_CENTER, 0.f,
|
||||
40.f, 5.f,
|
||||
0.f, BLACK
|
||||
);
|
||||
|
||||
update(dt);
|
||||
render(dt);
|
||||
|
||||
EndMode2D();
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
UnloadTexture(logo);
|
||||
CloseWindow();
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue