upd
This commit is contained in:
35
items/item.c
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;
|
||||
|
||||
|
Reference in New Issue
Block a user