upd
Before Width: | Height: | Size: 763 B After Width: | Height: | Size: 763 B |
Before Width: | Height: | Size: 777 B After Width: | Height: | Size: 777 B |
Before Width: | Height: | Size: 785 B After Width: | Height: | Size: 785 B |
Before Width: | Height: | Size: 780 B After Width: | Height: | Size: 780 B |
Before Width: | Height: | Size: 780 B After Width: | Height: | Size: 780 B |
Before Width: | Height: | Size: 839 B After Width: | Height: | Size: 839 B |
Before Width: | Height: | Size: 846 B After Width: | Height: | Size: 846 B |
Before Width: | Height: | Size: 853 B After Width: | Height: | Size: 853 B |
Before Width: | Height: | Size: 841 B After Width: | Height: | Size: 841 B |
Before Width: | Height: | Size: 799 B After Width: | Height: | Size: 799 B |
Before Width: | Height: | Size: 801 B After Width: | Height: | Size: 801 B |
Before Width: | Height: | Size: 772 B After Width: | Height: | Size: 772 B |
Before Width: | Height: | Size: 777 B After Width: | Height: | Size: 777 B |
Before Width: | Height: | Size: 785 B After Width: | Height: | Size: 785 B |
Before Width: | Height: | Size: 780 B After Width: | Height: | Size: 780 B |
Before Width: | Height: | Size: 839 B After Width: | Height: | Size: 839 B |
Before Width: | Height: | Size: 846 B After Width: | Height: | Size: 846 B |
Before Width: | Height: | Size: 853 B After Width: | Height: | Size: 853 B |
Before Width: | Height: | Size: 799 B After Width: | Height: | Size: 799 B |
Before Width: | Height: | Size: 801 B After Width: | Height: | Size: 801 B |
Before Width: | Height: | Size: 772 B After Width: | Height: | Size: 772 B |
35
items/item.c
@@ -25,8 +25,9 @@ bool putOntoNext(ItemOnBelt *itm, int nx, int ny, Tile *next, TileTypeReg *ntt,
|
||||
if (next->items[newLane].type == 0 && (*ntt).allowedInItems[newLane][itm->type]) {
|
||||
// MOVE it
|
||||
ItemOnBelt moved = *itm;
|
||||
moved.tileX = nx;
|
||||
moved.tileY = ny;
|
||||
moved.prevTile = moved.tile;
|
||||
moved.tile.x = nx;
|
||||
moved.tile.y = ny;
|
||||
if (!(*ntt).itemMoves) {
|
||||
moved.offset = 0.5f;
|
||||
}
|
||||
@@ -47,6 +48,12 @@ OrientDirection rotateMainDirection(OrientDirection dir, int steps) {
|
||||
|
||||
// The main directions indices array
|
||||
int mainDirs[] = {1, 3, 5, 7};
|
||||
if (steps == -1) {
|
||||
mainDirs[1] = 7;
|
||||
mainDirs[3] = 3;
|
||||
mainDirs[0] = 5;
|
||||
mainDirs[2] = 1;
|
||||
}
|
||||
int count = 4;
|
||||
|
||||
// Find index of dir in mainDirs
|
||||
@@ -153,6 +160,10 @@ void updateItems() {
|
||||
if (nx < 0 || nx >= MAP_WIDTH || ny < 0 || ny >= MAP_HEIGHT)
|
||||
continue;
|
||||
|
||||
if (nx == itm->prevTile.x && ny == itm->prevTile.y) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Tile *next = &tileMap[ny][nx];
|
||||
TileTypeReg ntt = TileRegistry[next->type];
|
||||
|
||||
@@ -181,6 +192,9 @@ void updateItems() {
|
||||
continue;
|
||||
}
|
||||
Tile *next = &tileMap[ny][nx];
|
||||
if (nx == itm->prevTile.x && ny == itm->prevTile.y) {
|
||||
continue;
|
||||
}
|
||||
TileTypeReg ntt = TileRegistry[next->type];
|
||||
int newLane = lane;
|
||||
switch (next->type) {
|
||||
@@ -252,11 +266,11 @@ uint8_t laneTarget = 0;
|
||||
|
||||
void renderItem(ItemOnBelt item, SDL_Renderer *renderer, int lane, SDL_Rect playerRect) {
|
||||
SDL_Rect rect = {0};
|
||||
rect.x = item.tileX * TILE_SIZE;
|
||||
rect.y = item.tileY * TILE_SIZE;
|
||||
rect.x = item.tile.x * TILE_SIZE;
|
||||
rect.y = item.tile.y * TILE_SIZE;
|
||||
|
||||
// get raw direction code
|
||||
int dir = tileMap[item.tileY][item.tileX].direction;
|
||||
int dir = tileMap[item.tile.y][item.tile.x].direction;
|
||||
|
||||
//--- 1) build a unit vector (dxf, dyf) for this orientation
|
||||
float dxf = 0.0f, dyf = 0.0f;
|
||||
@@ -370,13 +384,13 @@ void renderItem(ItemOnBelt item, SDL_Renderer *renderer, int lane, SDL_Rect play
|
||||
char tempStr[50];
|
||||
SDL_Rect rectA = {0};
|
||||
if (debugMode) {
|
||||
SDL_Rect tileArea = {item.tileX * TILE_SIZE, item.tileY * TILE_SIZE,
|
||||
SDL_Rect tileArea = {item.tile.x * TILE_SIZE, item.tile.y * TILE_SIZE,
|
||||
TILE_SIZE, TILE_SIZE};
|
||||
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 32);
|
||||
adjustRect(&tileArea, playerRect);
|
||||
SDL_RenderFillRect(renderer, &tileArea);
|
||||
rectA.x = item.tileX * TILE_SIZE;
|
||||
rectA.y = item.tileY * TILE_SIZE;
|
||||
rectA.x = item.tile.x * TILE_SIZE;
|
||||
rectA.y = item.tile.y * TILE_SIZE;
|
||||
rectA.w = TILE_SIZE;
|
||||
rectA.h = TILE_SIZE;
|
||||
sprintf(tempStr, "L%d\n%f\n%f\n%f", lane, item.offset, xOffset, yOffset);
|
||||
@@ -404,8 +418,9 @@ void renderItem(ItemOnBelt item, SDL_Renderer *renderer, int lane, SDL_Rect play
|
||||
void putItem(int x, int y, ItemType itemType, uint8_t lane) {
|
||||
tileMap[y][x].items[lane].type = itemType;
|
||||
tileMap[y][x].items[lane].offset = 0;
|
||||
tileMap[y][x].items[lane].tileX = x;
|
||||
tileMap[y][x].items[lane].tileY = y;
|
||||
tileMap[y][x].items[lane].tile.x = x;
|
||||
tileMap[y][x].items[lane].tile.y = y;
|
||||
tileMap[y][x].items[lane].prevTile = tileMap[y][x].items[lane].tile;
|
||||
}
|
||||
|
||||
void loadItems(SDL_Renderer *renderer) {
|
||||
|
@@ -40,7 +40,8 @@ typedef enum ItemType {
|
||||
|
||||
typedef struct ItemOnBelt {
|
||||
float offset;
|
||||
int tileX, tileY;
|
||||
MiniRect tile;
|
||||
MiniRect prevTile;
|
||||
ItemType type;
|
||||
} ItemOnBelt;
|
||||
|
||||
|
2
main.c
@@ -244,7 +244,7 @@ int render() {
|
||||
renderPlayer(&player);
|
||||
|
||||
|
||||
if (!renderAtlas) {
|
||||
if (renderAtlas == 0) {
|
||||
SDL_RenderCopy(mainRenderer, backgroundTexture, &screenRect, &screenRect);
|
||||
SDL_RenderCopy(mainRenderer, tilesTexture, &screenRect, &screenRect);
|
||||
SDL_RenderCopy(mainRenderer, itemsTexture, &screenRect, &screenRect);
|
||||
|
@@ -7,6 +7,7 @@
|
||||
#include "../tiles/tile.h"
|
||||
#include "../util/font.h"
|
||||
#include "../util/atlas.h"
|
||||
#include "../entity/entity.h"
|
||||
|
||||
#define HEALTH_MARGIN 4
|
||||
|
||||
@@ -22,6 +23,7 @@ SDL_Rect PlayerRect;
|
||||
SDL_Rect playerTextureRect;
|
||||
|
||||
SDL_Rect targetItemBGRect;
|
||||
SDL_Rect waveInfoBGRect;
|
||||
|
||||
SDL_Rect targetItemRect;
|
||||
|
||||
@@ -142,6 +144,11 @@ void initPlayer(Player *plr) {
|
||||
targetItemBGRect.x = 0;
|
||||
targetItemBGRect.y = DISPLAY_HEIGHT - TILE_SIZE - fonts[2].size * 2;
|
||||
|
||||
waveInfoBGRect.y = 0;
|
||||
waveInfoBGRect.x = 0;
|
||||
waveInfoBGRect.w = 380;
|
||||
waveInfoBGRect.h = 80;
|
||||
|
||||
targetItemRect.w = TILE_SIZE;
|
||||
targetItemRect.h = TILE_SIZE;
|
||||
|
||||
@@ -249,6 +256,18 @@ void renderPlayer(Player *plr) {
|
||||
|
||||
SDL_SetRenderDrawColor(mainRenderer, 0, 0, 0, 255);
|
||||
SDL_RenderFillRect(mainRenderer, &targetItemBGRect);
|
||||
SDL_RenderFillRect(mainRenderer, &waveInfoBGRect);
|
||||
|
||||
|
||||
char hudStr[50];
|
||||
char waveStr[30];
|
||||
if (entities.activeCount > 0) {
|
||||
snprintf(waveStr, 30, "Remaining enemies: %d", entities.activeCount);
|
||||
} else {
|
||||
snprintf(waveStr, 30, "Next wave in: %dm %ds", waveInfo.waveTimer / 60, waveInfo.waveTimer % 60);
|
||||
}
|
||||
snprintf(hudStr, 30, "Wave: %d\n%s\n", waveInfo.waveCounter, waveStr);
|
||||
renderText(mainRenderer, fonts[1], hudStr, 0,0);
|
||||
|
||||
targetItemRect.y = DISPLAY_HEIGHT - TILE_SIZE;
|
||||
targetItemRect.x = TILE_SIZE / 4;
|
||||
|
@@ -20,11 +20,6 @@
|
||||
#define DISPLAY_WIDTH DISPLAY_MAP_WIDTH * TILE_SIZE
|
||||
#define DISPLAY_HEIGHT DISPLAY_MAP_HEIGHT * TILE_SIZE
|
||||
|
||||
typedef struct MiniRect {
|
||||
int x;
|
||||
int y;
|
||||
} MiniRect;
|
||||
|
||||
#define MAX_TILES MAP_WIDTH * MAP_HEIGHT
|
||||
|
||||
|
||||
|
@@ -5,8 +5,8 @@
|
||||
#ifndef FACTORYGAME_ATLAS_H
|
||||
#define FACTORYGAME_ATLAS_H
|
||||
|
||||
#define ATLAS_SIZE 1024
|
||||
#define MAX_RECTS 2048
|
||||
#define ATLAS_SIZE 2048
|
||||
#define MAX_RECTS 4096
|
||||
#define TILE_SIZE 32
|
||||
#define QUADRANT_SIZE 16
|
||||
#define ATLAS_TILES_PER_ROW (ATLAS_SIZE / TILE_SIZE)
|
||||
|
@@ -90,8 +90,9 @@ void updateMachine(Tile *tile,
|
||||
in1->type = TYPE_AIR;
|
||||
if (in2->type != TYPE_AIR) in2->type = TYPE_AIR;
|
||||
out->type = result;
|
||||
out->tileX = tile->rect.x;
|
||||
out->tileY = tile->rect.y;
|
||||
out->prevTile = out->tile;
|
||||
out->tile.x = tile->rect.x;
|
||||
out->tile.y = tile->rect.y;
|
||||
out->offset = -0.5f;
|
||||
}
|
||||
}
|
||||
|
@@ -13,6 +13,8 @@
|
||||
SDL_Window *window = NULL;
|
||||
volatile bool running = true;
|
||||
|
||||
WaveInfo waveInfo;
|
||||
|
||||
const char OrientStrings[ORIENT_DIRECTION_COUNT][10] = {
|
||||
"LEFT_DOWN",
|
||||
"LEFT",
|
||||
|
13
util/util.h
@@ -44,6 +44,19 @@ typedef struct Animation {
|
||||
} Animation;
|
||||
|
||||
|
||||
typedef struct MiniRect {
|
||||
int x;
|
||||
int y;
|
||||
} MiniRect;
|
||||
|
||||
typedef struct WaveInfo {
|
||||
int waveCounter;
|
||||
int waveTimer;
|
||||
} WaveInfo;
|
||||
|
||||
extern WaveInfo waveInfo;
|
||||
|
||||
|
||||
typedef struct OrientedAnimation {
|
||||
SDL_Rect atlasRects[ORIENT_DIRECTION_COUNT][TILE_SIZE * 2];
|
||||
unsigned char frameCount;
|
||||
|