Commit b745e8d1 authored by Max Kobelt's avatar Max Kobelt
Browse files

Add alien textures

parent 1e43511e
......@@ -30,4 +30,5 @@ if (NOT raylib_FOUND) # If there's none, fetch and build raylib
endif()
add_subdirectory(src)
add_subdirectory(img)
#set(raylib_VERBOSE 1)
file(COPY . DESTINATION ${PROJECT_BINARY_DIR}/src/img)
\ No newline at end of file
......@@ -3,10 +3,13 @@
#include <stdlib.h>
#include <stdbool.h>
#define ALIEN_SIZE 8
#define ALIEN_OFFSET 2
#define ALIEN_SIZE 30
#define ALIEN_OFFSET 5
extern const int GAME_SCREEN_WIDTH, LASER_CANON_SPEED;
extern const int GAME_SCREEN_WIDTH, LASER_CANON_SPEED, FRAME_RATE;
extern Texture2D ALIEN_UP, ALIEN_DOWN, ALIEN_SHOOT;
size_t framesCount = 0;
Aliens *spawnAliens() {
Aliens *aliens = malloc(sizeof *aliens);
......@@ -31,7 +34,8 @@ void drawAliens(Aliens *aliens) {
for (int j = 0; j < ALIEN_COLS; ++j) {
for (int i = 0; i < ALIEN_ROWS; ++i) {
if (aliens->instances[j][i]) {
DrawRectangle(aliens->pos.x + j * (ALIEN_SIZE + ALIEN_OFFSET), aliens->pos.y + i * (ALIEN_SIZE + ALIEN_OFFSET), ALIEN_SIZE, ALIEN_SIZE, WHITE);
bool up = (i + j) % 2 == (framesCount++ / (FRAME_RATE * 7)) % 2;
DrawTexture(up ? ALIEN_UP : ALIEN_DOWN, aliens->pos.x + j * (ALIEN_SIZE + ALIEN_OFFSET), aliens->pos.y + i * (ALIEN_SIZE + ALIEN_OFFSET), WHITE);
}
}
}
......
......@@ -12,7 +12,10 @@ extern const int GAME_SCREEN_WIDTH, GAME_SCREEN_HEIGHT, FRAME_RATE;
const int LASER_CANON_SPEED = 2;
Projectile *playerProj;
Aliens* aliens;
Texture2D ALIEN_UP, ALIEN_DOWN, ALIEN_SHOOT;
Rectangle laserCanon;
Rectangle gameBorder;
Vector2 laserCanonPos;
......@@ -20,6 +23,10 @@ int laserCanonSize;
void initGame() {
aliens = spawnAliens();
ALIEN_UP = LoadTexture("img/alien_up.png");
ALIEN_DOWN = LoadTexture("img/alien_down.png");
ALIEN_SHOOT = LoadTexture("img/alien_shoot.png");
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};
......
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