Hopefully last commit
This commit is contained in:
184
tiles/tile.c
184
tiles/tile.c
@@ -10,6 +10,68 @@
|
||||
#include "../util/font.h"
|
||||
#include "miner.h"
|
||||
#include "turret.h"
|
||||
#include "../util/perlin.h"
|
||||
#include "../util/button.h"
|
||||
#include "../util/audio.h"
|
||||
#include "ammoCrafter.h"
|
||||
#include "wiredrawer.h"
|
||||
#include "core.h"
|
||||
|
||||
MiniRect enemySpawn;
|
||||
MiniRect playerCore;
|
||||
SDL_Rect viewport;
|
||||
|
||||
uint16_t DISPLAY_MAP_WIDTH = 30;
|
||||
uint16_t DISPLAY_MAP_HEIGHT = 16;
|
||||
|
||||
uint16_t DISPLAY_WIDTH = 30 * TILE_SIZE;
|
||||
uint16_t DISPLAY_HEIGHT = 16 * TILE_SIZE;
|
||||
|
||||
void setTileView(uint16_t w, uint16_t h) {
|
||||
DISPLAY_MAP_WIDTH = w;
|
||||
DISPLAY_MAP_HEIGHT = h;
|
||||
DISPLAY_WIDTH = DISPLAY_MAP_WIDTH * TILE_SIZE;
|
||||
DISPLAY_HEIGHT = DISPLAY_MAP_HEIGHT * TILE_SIZE;
|
||||
screenRect.x = 0;
|
||||
screenRect.y = 0;
|
||||
screenRect.w = DISPLAY_WIDTH;
|
||||
screenRect.h = DISPLAY_HEIGHT;
|
||||
SDL_RenderSetLogicalSize(mainRenderer, DISPLAY_WIDTH, DISPLAY_HEIGHT);
|
||||
SDL_SetWindowSize(window, DISPLAY_WIDTH, DISPLAY_HEIGHT);
|
||||
viewport = screenRect;
|
||||
SDL_RenderSetViewport(mainRenderer, &viewport);
|
||||
SDL_SetWindowPosition(window, 0, 0);
|
||||
audioData.maxPanDistance = DISPLAY_WIDTH / 2;
|
||||
|
||||
SDL_DestroyTexture(hudTexture);
|
||||
SDL_DestroyTexture(entityTexture);
|
||||
SDL_DestroyTexture(itemsTexture);
|
||||
SDL_DestroyTexture(tilesTexture);
|
||||
SDL_DestroyTexture(backgroundTexture);
|
||||
|
||||
|
||||
hudTexture = SDL_CreateTexture(mainRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, screenRect.w,
|
||||
screenRect.h);
|
||||
entityTexture = SDL_CreateTexture(mainRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, screenRect.w,
|
||||
screenRect.h);
|
||||
|
||||
SDL_SetTextureBlendMode(entityTexture, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetTextureBlendMode(hudTexture, SDL_BLENDMODE_BLEND);
|
||||
|
||||
|
||||
itemsTexture = SDL_CreateTexture(mainRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, screenRect.w,
|
||||
screenRect.h);
|
||||
tilesTexture = SDL_CreateTexture(mainRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, screenRect.w,
|
||||
screenRect.h);
|
||||
SDL_SetTextureBlendMode(tilesTexture, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetTextureBlendMode(itemsTexture, SDL_BLENDMODE_BLEND);
|
||||
backgroundTexture = SDL_CreateTexture(mainRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET,
|
||||
screenRect.w,
|
||||
screenRect.h);
|
||||
PlayerRect.x = (DISPLAY_WIDTH / 2) - (PlayerRect.w / 2);
|
||||
PlayerRect.y = (DISPLAY_HEIGHT / 2) - (PlayerRect.h / 2);
|
||||
initButtons();
|
||||
}
|
||||
|
||||
int scrollFrame = 0;
|
||||
unsigned long beltFrames = 0;
|
||||
@@ -117,7 +179,7 @@ void registerTile(char fname[20], SDL_Renderer *renderer) {
|
||||
TileRegistry[indexTile].animation.atlasRects[o][frame] = allocate_32x32(textures[o], renderer);
|
||||
}
|
||||
|
||||
printf("Bound %s to %d\n", fname, indexTile);
|
||||
//printf("Bound %s to %d\n", fname, indexTile);
|
||||
TileRegistry[indexTile].type = indexTile;
|
||||
TileRegistry[indexTile].maxHealth = 200;
|
||||
TileRegistry[indexTile].animation.frameCount = frame + 1;
|
||||
@@ -262,8 +324,14 @@ void loadBackgroundTiles(SDL_Renderer *renderer) {
|
||||
void preSetupTiles() {
|
||||
TileRegistry[TYPE_MINER].animation.startFrame = 1;
|
||||
TileRegistry[TYPE_FURNACE].animation.divisor = 8;
|
||||
|
||||
TileRegistry[TYPE_WIRECRAFTER].animation.divisor = 8;
|
||||
TileRegistry[TYPE_SPLITTER].animation.divisor = 8;
|
||||
TileRegistry[TYPE_AMMOCRAFTER].animation.divisor = 8;
|
||||
|
||||
TileRegistry[TYPE_CORE].animation.divisor = 8;
|
||||
BackgroundTileRegistry[BGType_WATER_DEEP].animation.divisor = 16;
|
||||
BackgroundTileRegistry[BGType_ENEMY_FLOOR].animation.divisor = 16;
|
||||
BackgroundTileRegistry[BGType_WATER_SHALLOW].animation.divisor = 12;
|
||||
BackgroundTileRegistry[BGType_GRASS_FLOWER0].animation.divisor = 16;
|
||||
BackgroundTileRegistry[BGType_GRASS_FLOWER1].animation.divisor = 16;
|
||||
@@ -309,6 +377,9 @@ void setupTiles() {
|
||||
BackgroundTileRegistry[BGType_WATER_DEEP].walkable = false;
|
||||
|
||||
initFurnaceTile();
|
||||
initWireDrawerTile();
|
||||
initAmmoCrafterTile();
|
||||
initCoreTile();
|
||||
}
|
||||
|
||||
uint16_t getBreakTime(int type) {
|
||||
@@ -481,4 +552,113 @@ bool isWalkable(MiniRect tileCoords) {
|
||||
|
||||
void updateTiles() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Main generator:
|
||||
void genInitMap() {
|
||||
const double terrainScale = 2;
|
||||
const double humidityScale = 1;
|
||||
const double oreScale = 2;
|
||||
const int terrainOct = 4;
|
||||
const int humidityOct = 4;
|
||||
const int oreOct = 4;
|
||||
|
||||
int seedX = rand();
|
||||
int seedY = rand();
|
||||
int seedN = rand();
|
||||
|
||||
// Min/max trackers
|
||||
double terrainMin = 1e9, terrainMax = -1e9;
|
||||
double humidityMin = 1e9, humidityMax = -1e9;
|
||||
double oreNrmMin = 1e9, oreNrmMax = -1e9;
|
||||
for (uint16_t y = 0; y < MAP_HEIGHT; y++) {
|
||||
for (uint16_t x = 0; x < MAP_WIDTH; x++) {
|
||||
double terrain = pnoise2d(x + 1000 + seedX,
|
||||
y + 1000 + seedY,
|
||||
terrainScale, terrainOct, seedN);
|
||||
double humidity = pnoise2d(x + seedX,
|
||||
y + seedY,
|
||||
humidityScale, humidityOct, seedN);
|
||||
double oreNrm = pnoise2d(x + 9999 + seedX,
|
||||
y + 1111 + seedY,
|
||||
oreScale, oreOct, seedN);
|
||||
|
||||
// Track min/max
|
||||
if (terrain < terrainMin) terrainMin = terrain;
|
||||
if (terrain > terrainMax) terrainMax = terrain;
|
||||
|
||||
if (humidity < humidityMin) humidityMin = humidity;
|
||||
if (humidity > humidityMax) humidityMax = humidity;
|
||||
|
||||
if (oreNrm < oreNrmMin) oreNrmMin = oreNrm;
|
||||
if (oreNrm > oreNrmMax) oreNrmMax = oreNrm;
|
||||
|
||||
// [Same as your original terrain generation logic...]
|
||||
BackgroundType baseType = BGType_COBBLE0;
|
||||
if (terrain < 0.30) {
|
||||
baseType = (humidity < 0.5) ? BGType_WATER_SHALLOW : BGType_WATER_DEEP;
|
||||
} else if (terrain < 0.35) {
|
||||
if (humidity < 0.3) baseType = BGType_SAND4;
|
||||
else if (humidity < 0.6) baseType = BGType_SAND2;
|
||||
else baseType = BGType_SAND7;
|
||||
} else if (terrain < 0.7) {
|
||||
double grassVal = (terrain - 0.35) / (0.70 - 0.35);
|
||||
int idx = (int) (grassVal * 3.0);
|
||||
if (idx >= 4) idx = 3;
|
||||
if (humidity > 0.6 && ((rand() & 0xFF) < 10)) {
|
||||
int flowerIdx = rand() % 4;
|
||||
baseType = (BackgroundType) (BGType_GRASS_FLOWER0 + flowerIdx);
|
||||
} else {
|
||||
baseType = (BackgroundType) (BGType_GRASS0 + idx);
|
||||
}
|
||||
} else if (terrain < 0.85) {
|
||||
int idx = rand() % 4;
|
||||
baseType = (BackgroundType) (BGType_COBBLE0 + idx);
|
||||
} else {
|
||||
int idx = rand() % 4;
|
||||
baseType = (BackgroundType) (BGType_TILES0 + idx);
|
||||
}
|
||||
|
||||
BackgroundType finalType = baseType;
|
||||
if (baseType != BGType_WATER_SHALLOW && baseType != BGType_WATER_DEEP) {
|
||||
if (oreNrm > 0.86) {
|
||||
double sub = (oreNrm - 0.86) / (1.0 - 0.86);
|
||||
if (sub < 0.25) finalType = BGType_IRON_ORE;
|
||||
else if (sub < 0.50) finalType = BGType_SILVER_ORE;
|
||||
else if (sub < 0.80) finalType = BGType_GOLD_ORE;
|
||||
else finalType = BGType_PLATINUM_ORE;
|
||||
}
|
||||
}
|
||||
|
||||
if (finalType > BGType_END) {
|
||||
finalType = BGType_COBBLE0;
|
||||
}
|
||||
backgroundMap[y][x].type = finalType;
|
||||
}
|
||||
enemySpawn.x = MAP_WIDTH - 10;
|
||||
enemySpawn.y = 10;
|
||||
for (int enX = enemySpawn.x - 5; enX < enemySpawn.x + 6; enX++) {
|
||||
for (int enY = enemySpawn.y - 5; enY < enemySpawn.y + 6; enY++) {
|
||||
backgroundMap[enY][enX].type = BGType_ENEMY_FLOOR;
|
||||
}
|
||||
}
|
||||
playerCore.x = 8;
|
||||
playerCore.y = MAP_HEIGHT - 10;
|
||||
for (int plX = playerCore.x - 5; plX < playerCore.x + 6; plX++) {
|
||||
for (int plY = playerCore.y - 5; plY < playerCore.y + 6; plY++) {
|
||||
backgroundMap[plY][plX].type = BGType_TILES0;
|
||||
}
|
||||
}
|
||||
tileMap[playerCore.y][playerCore.x].type = TYPE_CORE;
|
||||
tileMap[playerCore.y][playerCore.x].direction = ORIENT_LEFT;
|
||||
tileMap[playerCore.y][playerCore.x].health = TileRegistry[TYPE_CORE].maxHealth;
|
||||
tileMap[playerCore.y][playerCore.x].fixedFrame = 0;
|
||||
tileMap[playerCore.y][playerCore.x].rect = playerCore;
|
||||
|
||||
}
|
||||
|
||||
// Debug printout
|
||||
printf("Terrain Noise: min = %f, max = %f\n", terrainMin, terrainMax);
|
||||
printf("Humidity Noise: min = %f, max = %f\n", humidityMin, humidityMax);
|
||||
printf("Ore Normalized: min = %f, max = %f\n", oreNrmMin, oreNrmMax);
|
||||
}
|
||||
|
Reference in New Issue
Block a user