Commit 9966591d authored by Max Kobelt's avatar Max Kobelt
Browse files

Draw basic aliens

parent 09509a4d
......@@ -8,8 +8,8 @@ target_sources(${PROJECT_NAME}
menu.c
game.h
game.c
position.h
alien.h
alien.c
projectile.h
projectile.c
)
#include "alien.h"
#include <stdlib.h>
#define ALIEN_SIZE 8
#define ALIEN_OFFSET 2
extern const int GAME_SCREEN_WIDTH;
Aliens spawnAliens() {
Aliens aliens = malloc(sizeof *aliens * ALIEN_ROWS);
for (int i = 0; i < ALIEN_ROWS; ++i) {
aliens[i] = malloc(sizeof **aliens * ALIEN_COLS);
for (int j = 0; j < ALIEN_COLS; ++j) {
aliens[i][j] = malloc(sizeof ***aliens);
Alien *alien = aliens[i][j];
alien->x = j * (ALIEN_SIZE + ALIEN_OFFSET);
alien->y = i * (ALIEN_SIZE + ALIEN_OFFSET);
}
}
return aliens;
}
void drawAliens(Aliens aliens) {
for (int i = 0; i < ALIEN_ROWS; ++i) {
for (int j = 0; j < ALIEN_COLS; ++j) {
Alien *alien = aliens[i][j];
if (alien) {
DrawRectangle(alien->x, alien->y, ALIEN_SIZE, ALIEN_SIZE, WHITE);
}
}
}
}
#pragma once
#include "position.h"
#include "raylib.h"
typedef struct {
Position pos;
} Alien;
#define ALIEN_ROWS 3
#define ALIEN_COLS 5
typedef Alien** Aliens;
typedef Vector2 Alien;
typedef Alien*** Aliens;
Aliens spawnAliens();
void drawAliens();
#include "game.h"
#include "projectile.h"
#include "alien.h"
#include "raylib.h"
......@@ -12,13 +13,14 @@
extern const int GAME_SCREEN_WIDTH, GAME_SCREEN_HEIGHT, FRAME_RATE;
Projectile *playerProj;
Aliens aliens;
Rectangle laserCanon;
Rectangle gameBorder;
Vector2 laserCanonPos;
int laserCanonSize;
void initGame() {
aliens = spawnAliens();
laserCanonSize = GAME_SCREEN_WIDTH / 20;
laserCanonPos = (Vector2) {(float) GAME_SCREEN_WIDTH / 2, (float) GAME_SCREEN_HEIGHT - (laserCanonSize * 2)};
laserCanon = (Rectangle) {(float) laserCanonPos.x, (float) laserCanonPos.y, (float) laserCanonSize, (float) laserCanonSize};
......@@ -53,6 +55,7 @@ void drawGame() {
if (playerProj) {
DrawRectangleRec((Rectangle) { playerProj->pos.x, playerProj->pos.y, PROJECTILE_WIDTH, PROJECTILE_HEIGHT }, WHITE);
}
drawAliens(aliens);
}
void spawnPlayerProjectile() {
......
#pragma once
#include <stddef.h>
typedef struct {
size_t x, y;
} Position;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment