Some progress

This commit is contained in:
2025-05-29 22:37:44 +02:00
parent f6e59e74c7
commit d01bdbe819
11 changed files with 331 additions and 65 deletions

View File

@@ -17,7 +17,7 @@ void renderBelt(int x, int y, int w, int h, OrientDirection dir, SDL_Renderer *r
int px = x * TILE_SIZE;
int py = y * TILE_SIZE;
uint16_t tileType = tileMap[y][x].type;
uint16_t tileType = tileMap[y][x].type - 1;
SDL_Rect src1, src2, dst1, dst2;
@@ -64,7 +64,7 @@ void renderBelt(int x, int y, int w, int h, OrientDirection dir, SDL_Renderer *r
void renderAllBelts(SDL_Renderer *renderer) {
int scrollSpeed = 0; // pixels per step
int scrollSpeed = 1; // pixels per step
int scrollDelay = 1; // frames between steps
if (beltFrames++ % scrollDelay == 0) {
@@ -72,19 +72,31 @@ void renderAllBelts(SDL_Renderer *renderer) {
}
int tileSize = TILE_SIZE;
for (int y = (playerY / TILE_SIZE) - (DISPLAY_MAP_HEIGHT / 2);
y < (playerY / TILE_SIZE) + (DISPLAY_MAP_HEIGHT / 2); y++) {
for (int x = (playerX / TILE_SIZE) - (DISPLAY_MAP_WIDTH / 2);
x < (playerX / TILE_SIZE) + (DISPLAY_MAP_WIDTH / 2); x++) {
for (int y = (playerY / TILE_SIZE) - (DISPLAY_MAP_HEIGHT / 2) - 1;
y < (playerY / TILE_SIZE) + (DISPLAY_MAP_HEIGHT / 2) + 1; y++) {
if (y < 0 || y >= MAP_HEIGHT) {
continue;
}
for (int x = (playerX / TILE_SIZE) - (DISPLAY_MAP_WIDTH / 2) - 1;
x < (playerX / TILE_SIZE) + (DISPLAY_MAP_WIDTH / 2) + 1; x++) {
if (x < 0 || x >= MAP_WIDTH) {
continue;
}
Tile t = tileMap[y][x];
if (t.type != TYPE_BELT) continue;
renderBelt(x, y, tileSize, tileSize, t.direction, renderer);
}
}
for (int y = (playerY / TILE_SIZE) - (DISPLAY_MAP_HEIGHT / 2);
y < (playerY / TILE_SIZE) + (DISPLAY_MAP_HEIGHT / 2); y++) {
for (int x = (playerX / TILE_SIZE) - (DISPLAY_MAP_WIDTH / 2);
x < (playerX / TILE_SIZE) + (DISPLAY_MAP_WIDTH / 2); x++) {
for (int y = (playerY / TILE_SIZE) - (DISPLAY_MAP_HEIGHT / 2) - 1;
y < (playerY / TILE_SIZE) + (DISPLAY_MAP_HEIGHT / 2) + 1; y++) {
if (y < 0 || y >= MAP_HEIGHT) {
continue;
}
for (int x = (playerX / TILE_SIZE) - (DISPLAY_MAP_WIDTH / 2) - 1;
x < (playerX / TILE_SIZE) + (DISPLAY_MAP_WIDTH / 2) + 1; x++) {
if (x < 0 || x >= MAP_WIDTH) {
continue;
}
Tile t = tileMap[y][x];
if (t.type != TYPE_BELT) continue;
for (uint8_t lane = 0; lane < 2; lane++) {

View File

@@ -23,10 +23,8 @@ void generateTestMap() {
}
}
for (int x = (playerX / TILE_SIZE) - (DISPLAY_MAP_WIDTH / 2);
x < (playerX / TILE_SIZE) + (DISPLAY_MAP_WIDTH / 2); x += 1) {
for (int y = (playerY / TILE_SIZE) - (DISPLAY_MAP_HEIGHT / 2);
y < (playerY / TILE_SIZE) + (DISPLAY_MAP_HEIGHT / 2); y += 1) {
for (int x = 0; x < MAP_WIDTH; x += 1) {
for (int y = 0; y < MAP_HEIGHT; y += 1) {
tileMap[y][x].type = TYPE_BELT;
tileMap[y][x].frameOffset = 0;
@@ -43,12 +41,13 @@ void registerTile(char name[20], SDL_Renderer *renderer) {
memcpy(TileRegistry[tileTypeIndex].name, name, dot - name);
char texturePath[80];
snprintf(texturePath, 80, "./assets/tiles/%s", name);
SDL_Texture * texture = IMG_LoadTexture(renderer, texturePath);
SDL_Texture *texture = IMG_LoadTexture(renderer, texturePath);
TileRegistry[tileTypeIndex].textures[ORIENT_LEFT] = texture;
TileRegistry[tileTypeIndex].textures[ORIENT_RIGHT] = createFlippedTexture(renderer, texture, SDL_FLIP_HORIZONTAL);
TileRegistry[tileTypeIndex].textures[ORIENT_UP] = createRotatedTexture(renderer, texture, 90);
TileRegistry[tileTypeIndex].textures[ORIENT_DOWN] = createRotatedTexture(renderer, texture, 270);
TileRegistry[tileTypeIndex].type = tileTypeIndex;
TileRegistry[tileTypeIndex].breakTime = 60;
tileTypeIndex++;
}

View File

@@ -24,13 +24,15 @@ typedef struct {
uint16_t type;
char name[20];
SDL_Texture *textures[ORIENT_DIRECTION_COUNT];
uint16_t breakTime;
} TileType;
#define TILEREGISTRY_SIZE 512
extern TileType TileRegistry[TILEREGISTRY_SIZE];
#define TYPE_BELT 0
#define TYPE_AIR 0
#define TYPE_BELT 1
typedef struct {
OrientDirection direction;
@@ -46,4 +48,6 @@ extern Tile tileMap[MAP_HEIGHT][MAP_WIDTH];
void generateTestMap();
void loadTiles(SDL_Renderer *renderer);
extern uint16_t tileTypeIndex;
#endif //FACTORYGAME_TILE_H