Basic input & rendering working
This commit is contained in:
+36
-2
@@ -63,6 +63,28 @@ unsigned char* makeCodeFromSource(const char* source) {
|
|||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//sprites seen on the screen
|
||||||
|
typedef struct Entity {
|
||||||
|
Texture2D texture;
|
||||||
|
Rectangle rect;
|
||||||
|
Vector2 position;
|
||||||
|
} Entity;
|
||||||
|
|
||||||
|
Entity loadEntity(const char* fileName, Rectangle rect) {
|
||||||
|
Entity entity = {0};
|
||||||
|
entity.texture = LoadTexture(fileName);
|
||||||
|
entity.rect = rect;
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
void unloadEntity(Entity entity) {
|
||||||
|
UnloadTexture(entity.texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawEntity(Entity entity) {
|
||||||
|
DrawTextureRec(entity.texture, entity.rect, entity.position, WHITE);
|
||||||
|
}
|
||||||
|
|
||||||
//main file
|
//main file
|
||||||
int main() {
|
int main() {
|
||||||
//example Toy controlling the window stuff
|
//example Toy controlling the window stuff
|
||||||
@@ -96,17 +118,29 @@ int main() {
|
|||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
//load a sprite
|
//load a sprite
|
||||||
Image sprite = LoadImage("assets/pacman.png");
|
Entity entity = loadEntity("assets/pacman.png", (Rectangle){0,0,16,16});
|
||||||
|
|
||||||
while (!WindowShouldClose()) {
|
while (!WindowShouldClose()) {
|
||||||
|
//input
|
||||||
|
if (IsKeyDown(KEY_UP)) entity.position.y -= 10.0f;
|
||||||
|
if (IsKeyDown(KEY_DOWN)) entity.position.y += 10.0f;
|
||||||
|
if (IsKeyDown(KEY_LEFT)) entity.position.x -= 10.0f;
|
||||||
|
if (IsKeyDown(KEY_RIGHT)) entity.position.x += 10.0f;
|
||||||
|
|
||||||
//drawing
|
//drawing
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
DrawText("Do you have games on your phone?", 100, 100, 20, LIGHTGRAY);
|
|
||||||
|
drawEntity(entity);
|
||||||
|
|
||||||
|
DrawFPS(0,0);
|
||||||
|
// DrawText("Do you have games on your phone?", 100, 100, 20, LIGHTGRAY);
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unloadEntity(entity);
|
||||||
|
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
|
|
||||||
Toy_freeVM(&vm);
|
Toy_freeVM(&vm);
|
||||||
|
|||||||
Reference in New Issue
Block a user