Some more progress
This commit is contained in:
93
main.c
93
main.c
@@ -160,9 +160,6 @@ int processEvent(SDL_Event e) {
|
||||
int keyMod = e.key.keysym.mod;
|
||||
cursor = true;
|
||||
switch (keySym) {
|
||||
case SDLK_q:
|
||||
laneTarget = laneTarget == 1 ? 0 : 1;
|
||||
break;
|
||||
case SDLK_p:
|
||||
speed = speed == 0 ? 0.004f : 0;
|
||||
break;
|
||||
@@ -187,17 +184,18 @@ int processEvent(SDL_Event e) {
|
||||
}
|
||||
const Uint8 *keyboardState = SDL_GetKeyboardState(NULL);
|
||||
if (keyboardState[SDL_SCANCODE_LCTRL] || keyboardState[SDL_SCANCODE_RCTRL]) {
|
||||
currentScale += dAmount / 10.0f;
|
||||
if (currentScale > 4) {
|
||||
currentScale = 4;
|
||||
} else if (currentScale < 0.5f) {
|
||||
currentScale = 0.5f;
|
||||
}
|
||||
// currentScale += dAmount / 10.0f;
|
||||
// if (currentScale > 4) {
|
||||
// currentScale = 4;
|
||||
// } else if (currentScale < 0.5f) {
|
||||
// currentScale = 0.5f;
|
||||
// }
|
||||
//setZoom(currentScale);
|
||||
|
||||
|
||||
} else {
|
||||
setActivePlayerSlot(&player, player.inventory.activeSlotIndex + dAmount);
|
||||
moveActivePlayerSlot(&player, dAmount == -1,
|
||||
!(keyboardState[SDL_SCANCODE_LSHIFT] || keyboardState[SDL_SCANCODE_RSHIFT]));
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
@@ -209,41 +207,64 @@ void processMousePosition() {
|
||||
|
||||
uint32_t mouseButtons = SDL_GetMouseState(&player.cursor.windowX, &player.cursor.windowY);
|
||||
if (mouseButtons & SDL_BUTTON_LMASK) {
|
||||
if(player.cursor.targetTile->type == TYPE_AIR && player.inventory.activeSlotIndex < tileTypeIndex) {
|
||||
if (player.cursor.canReach && player.cursor.targetTile->type == TYPE_AIR &&
|
||||
player.inventory.activeSlotIndex < tileTypeIndex) {
|
||||
if (player.inventory.slotCounts[player.inventory.activeSlotIndex] > 0) {
|
||||
player.inventory.slotCounts[player.inventory.activeSlotIndex]--;
|
||||
player.cursor.targetTile->type = player.inventory.activeSlotIndex + 1;
|
||||
player.cursor.targetTile->type = player.inventory.activeSlotIndex;
|
||||
player.cursor.targetTile->direction = player.cursor.direction;
|
||||
}
|
||||
} else if (player.cursor.targetTile->type == player.inventory.activeSlotIndex) {
|
||||
player.cursor.targetTile->direction = player.cursor.direction;
|
||||
}
|
||||
} else if (mouseButtons & SDL_BUTTON_RMASK) {
|
||||
if (player.cursor.targetTile != player.cursor.prevTargetTile) {
|
||||
player.cursor.breakingProgress = 0;
|
||||
}
|
||||
int tileIndex = player.cursor.targetTile->type - 1;
|
||||
}
|
||||
if (player.cursor.canReach && mouseButtons & SDL_BUTTON_RMASK) {
|
||||
int tileIndex = player.cursor.targetTile->type;
|
||||
uint16_t targetBreakTime = TileRegistry[tileIndex].breakTime;
|
||||
if (targetBreakTime) {
|
||||
if (player.cursor.breakingProgress >= targetBreakTime) {
|
||||
if (player.cursor.targetTile->type - 1 < tileTypeIndex) {
|
||||
player.inventory.slotCounts[player.cursor.targetTile->type - 1]++;
|
||||
if (player.cursor.targetTile->type < tileTypeIndex) {
|
||||
player.inventory.slotCounts[player.cursor.targetTile->type]++;
|
||||
}
|
||||
if (player.cursor.targetTile->type == TYPE_BELT) {
|
||||
for (int lane = 0; lane < 2; lane++) {
|
||||
for (int slot = 0; slot < 2; slot++) {
|
||||
if (player.cursor.targetTile->items[lane][slot].active) {
|
||||
int itemType = player.cursor.targetTile->items[lane][slot].type;
|
||||
if (itemType < itemRegistryIndex) {
|
||||
player.inventory.slotCounts[itemType]++;
|
||||
}
|
||||
player.cursor.targetTile->items[lane][slot].active = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
player.cursor.targetTile->type = TYPE_AIR;
|
||||
player.cursor.breakingProgress = 0;
|
||||
} else {
|
||||
player.cursor.breakingProgress++;
|
||||
}
|
||||
printf("Player breaking %d\n", player.cursor.breakingProgress);
|
||||
//printf("Player breaking %d\n", player.cursor.breakingProgress);
|
||||
}
|
||||
|
||||
} else if (mouseButtons & SDL_BUTTON_MMASK) {
|
||||
} else {
|
||||
player.cursor.breakingProgress = 0;
|
||||
}
|
||||
if (player.cursor.targetTile != player.cursor.prevTargetTile) {
|
||||
player.cursor.breakingProgress = 0;
|
||||
}
|
||||
if (mouseButtons & SDL_BUTTON_MMASK) {
|
||||
if (player.cursor.targetTile->type > 0) {
|
||||
setActivePlayerSlot(&player, player.cursor.targetTile->type);
|
||||
}
|
||||
|
||||
}
|
||||
// Translate mouseRect coordinates to viewport space
|
||||
|
||||
player.cursor.windowX = ((player.cursor.windowX - viewport.x) * SCREEN_WIDTH) / viewport.w;
|
||||
player.cursor.windowY = (player.cursor.windowY - viewport.y) * SCREEN_HEIGHT / viewport.h;
|
||||
player.cursor.tileX = player.cursor.windowX / TILE_SIZE + (playerX / TILE_SIZE) - (SCREEN_WIDTH / TILE_SIZE / 2);
|
||||
player.cursor.tileY = player.cursor.windowY / TILE_SIZE + (playerY / TILE_SIZE) - (SCREEN_HEIGHT / TILE_SIZE / 2);
|
||||
player.cursor.tileX = (player.cursor.windowX + playerX) / TILE_SIZE - (SCREEN_WIDTH / TILE_SIZE / 2);
|
||||
player.cursor.tileY = (player.cursor.windowY + playerY) / TILE_SIZE - (SCREEN_HEIGHT / TILE_SIZE / 2);
|
||||
player.cursor.prevTargetTile = player.cursor.targetTile;
|
||||
player.cursor.targetTile = &tileMap[player.cursor.tileY][player.cursor.tileX];
|
||||
}
|
||||
@@ -285,6 +306,31 @@ void processKeyboardHeld() {
|
||||
playerX = (MAP_WIDTH * TILE_SIZE) - (SCREEN_WIDTH / 2);
|
||||
}
|
||||
}
|
||||
|
||||
if (keyboardState[SDL_SCANCODE_Q]) {
|
||||
if (player.cursor.targetTile->type > 0) {
|
||||
setActivePlayerSlot(&player, player.cursor.targetTile->type);
|
||||
}
|
||||
}
|
||||
if (keyboardState[SDL_SCANCODE_Y]) {
|
||||
if (player.cursor.canReach && player.cursor.targetTile->type == TYPE_BELT &&
|
||||
player.inventory.slotCounts[player.inventory.activeSlotIndex] > 0) {
|
||||
bool done = false;
|
||||
for (uint8_t lane = 0; lane < 2; lane++) {
|
||||
for (uint8_t slot = 0; slot < 2; slot++) {
|
||||
if (!player.cursor.targetTile->items[lane][slot].active) {
|
||||
putItem(player.cursor.tileX, player.cursor.tileY, player.inventory.activeSlotIndex, lane, slot);
|
||||
player.inventory.slotCounts[player.inventory.activeSlotIndex]--;
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (done) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(__attribute__((unused)) int argc, __attribute__((unused)) char *args[]) {
|
||||
@@ -316,6 +362,7 @@ int main(__attribute__((unused)) int argc, __attribute__((unused)) char *args[])
|
||||
}
|
||||
|
||||
updateItems();
|
||||
updatePlayer(&player);
|
||||
status = render();
|
||||
if (status) {
|
||||
return status;
|
||||
|
Reference in New Issue
Block a user