Draw the level
This commit is contained in:
parent
daf7317c08
commit
3d23849838
4
game.c
4
game.c
@ -33,6 +33,9 @@ void initialize_game(Game *g) {
|
|||||||
g->bullets->entities = malloc(10 * sizeof(Entity*));
|
g->bullets->entities = malloc(10 * sizeof(Entity*));
|
||||||
g->bullets->count = 0;
|
g->bullets->count = 0;
|
||||||
g->bullets->capacity = 10;
|
g->bullets->capacity = 10;
|
||||||
|
|
||||||
|
g->level = malloc(sizeof(Level));
|
||||||
|
init_level(g, g->level);
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_entity(Entities *entities, Entity *e) {
|
void add_entity(Entities *entities, Entity *e) {
|
||||||
@ -113,6 +116,7 @@ void run_frame(Game *g) {
|
|||||||
void draw_frame(Game *g) {
|
void draw_frame(Game *g) {
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
draw_level(g->level);
|
||||||
draw_player(g->player);
|
draw_player(g->player);
|
||||||
FOREACH_ENEMY {
|
FOREACH_ENEMY {
|
||||||
INIT_ENEMY;
|
INIT_ENEMY;
|
||||||
|
2
game.h
2
game.h
@ -16,11 +16,13 @@ typedef struct Game Game;
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "entity.h"
|
#include "entity.h"
|
||||||
|
#include "level.h"
|
||||||
|
|
||||||
struct Game {
|
struct Game {
|
||||||
Player *player;
|
Player *player;
|
||||||
Entities *enemies;
|
Entities *enemies;
|
||||||
Entities *bullets;
|
Entities *bullets;
|
||||||
|
Level *level;
|
||||||
/*
|
/*
|
||||||
Levels levels;
|
Levels levels;
|
||||||
*/
|
*/
|
||||||
|
28
level.c
Normal file
28
level.c
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include "level.h"
|
||||||
|
|
||||||
|
void init_level(Game *g, Level *l) {
|
||||||
|
l->width = 50;
|
||||||
|
l->length = 30;
|
||||||
|
l->data_size = l->width * l->length;
|
||||||
|
l->data = malloc(l->data_size * sizeof(char));
|
||||||
|
for (int i = 0; i < l->data_size; i++) {
|
||||||
|
l->data[i] = 3;
|
||||||
|
}
|
||||||
|
l->game = g;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color COLORS[4] = {BLACK, DARKGRAY, GRAY, LIGHTGRAY};
|
||||||
|
void draw_tile(Level *l, int x, int y) {
|
||||||
|
size_t index = x + (y * l->width);
|
||||||
|
size_t data = l->data[index] & 3;
|
||||||
|
Color c = COLORS[data];
|
||||||
|
DrawRectangle(x * 32, y * 32, 32, 32, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_level(Level *l) {
|
||||||
|
for (int i = 0; i < l->width; i++) {
|
||||||
|
for (int j = 0; j < l->length; j++) {
|
||||||
|
draw_tile(l, i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user