Skip to content

Commit

Permalink
更新:update water & wave logic
Browse files Browse the repository at this point in the history
  • Loading branch information
park671 committed Jun 10, 2023
1 parent 045fea3 commit 4e7c1b1
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 75 deletions.
6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions app/src/main/cpp/graphic/bitmap_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,22 @@ byte *renderBitmapColorOffset(byte *originData, int colorOffset,
}
}
return result;
}

byte *renderBitmapWithScroll(byte *originData,
int width, int height,
int x, int y,
byte *result) {
int offset = y * 256 + x;
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
if(originData[i * width + j] == TRANSPARENT) {
//skip trans color!
continue;
} else {
result[i * 256 + offset + j] = originData[j * width + i];
}
}
}
return result;
}
4 changes: 4 additions & 0 deletions app/src/main/cpp/graphic/bitmap_render.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ byte *renderBitmapColorOffset(byte *originData, int colorOffset,
int width, int height,
int x, int y,
byte *result);
byte *renderBitmapWithScroll(byte *originData,
int width, int height,
int x, int y,
byte *result);

#endif //METALMAX_BITMAP_RENDER_H
5 changes: 5 additions & 0 deletions app/src/main/cpp/logic/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
#include "render.h"
#include "render_splash.h"

const byte up = 0b0001;
const byte down = 0b0010;
const byte left = 0b0100;
const byte right = 0b1000;

byte tik_clk = 16;

BaseRender *renderStack[10];
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/cpp/logic/logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

#include "../global.h"

extern "C" const byte up;
extern "C" const byte down;
extern "C" const byte left;
extern "C" const byte right;

void initLogic();
void releaseLogicThread();
void updateDirectKey(byte key);
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/cpp/logic/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@

class BaseRender {
protected:
const byte up = 0b0001;
const byte down = 0b0010;
const byte left = 0b0100;
const byte right = 0b1000;

const byte a = 0b0001;
const byte b = 0b0010;
const byte ta = 0b0100;
Expand Down
79 changes: 68 additions & 11 deletions app/src/main/cpp/logic/render_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "../graphic/native_graphic.h"
#include "../monster/monster_data/monster_data.h"
#include "render_menu.h"
#include "../maps/active_tile_bmp.h"

#define ANIMATION_DURATION 20

Expand Down Expand Up @@ -68,6 +69,7 @@ byte *MapRender::render(byte *screenBuffer) {
posX = player->renderX - 127;
posY = player->renderY - 127;
screenBuffer = renderMap(posX, posY, screenBuffer);
// renderWater(screenBuffer);
renderDoor(screenBuffer);
renderSprite(screenBuffer);
renderPlayers(screenBuffer, player);
Expand All @@ -81,6 +83,54 @@ void MapRender::renderPlayers(byte *screenBuffer, Character *player) const {
127, 127, screenBuffer);
}

int water_status_map[4] = {1,2,3,2};

byte water_status = 0;
int water_status_clk = 0;

bool isTileWater(unsigned short tileId) {
for(int i = 0;i<WATER_BLOCK_COUNT;i++) {
if (tileId == water_block_id[i]) {
return true;
}
}
return false;
}

void MapRender::renderWater(byte *screenBuffer) const {
int map_width = map_size[mapId * 2 + 1];
int startX = posX / 16;
int startY = posY / 16;
for (int x = startX; x < startX + 16; x++) {
for (int y = startY; y < startY + 16; y++) {
if(isTileWater(short_map_data[mapId][y * map_width + x])) {
int renderY = y * 16 - posY;
int renderX = x * 16 - posX;
if (renderX > 0 && renderX < 240 && renderY > 0 && renderY < 224) {
renderBitmapColorOffset(water[water_status_map[water_status] - 1],0,
16, 16,
renderX, renderY,
screenBuffer);
}
byte direct = 0;
if (!isTileWater(short_map_data[mapId][(y - 1) * map_width + (x)])) {
direct |= up;
}
if (!isTileWater(short_map_data[mapId][(y + 1) * map_width + (x)])) {
direct |= down;
}
if (!isTileWater(short_map_data[mapId][(y) * map_width + (x - 1)])) {
direct |= left;
}
if (!isTileWater(short_map_data[mapId][(y) * map_width + (x + 1)])) {
direct |= right;
}
renderWave(direct, water_status_map[water_status] - 1, screenBuffer, renderX, renderY);
}
}
}
}

void MapRender::renderSprite(byte *screenBuffer) const {
int spriteCount = map_sprite_count[mapId];
for (int i = 0; i < spriteCount; i++) {
Expand All @@ -100,22 +150,22 @@ void MapRender::renderSprite(byte *screenBuffer) const {

void MapRender::renderDoor(byte *screenBuffer) const {
Character *player = getDefaultPlayer();
if(player->inDoor) {
if (player->inDoor) {
int map_width = map_size[mapId * 2 + 1];
int x = player->x;
int y = player->y;
unsigned short fillTileId = -1;
for(int i = y-2;i<=y+2;i++) {
for (int i = y - 2; i <= y + 2; i++) {
unsigned short tileId = short_map_data[mapId][i * map_width + x];
if(tileId == 37 || tileId == 128 || tileId == 162) {
fillTileId = short_map_data[mapId][(i-1) * map_width + x];
if (tileId == 37 || tileId == 128 || tileId == 162) {
fillTileId = short_map_data[mapId][(i - 1) * map_width + x];
}
}
for(int i = y-1;i<=y+1;i++) {
for (int i = y - 1; i <= y + 1; i++) {
unsigned short tileId = short_map_data[mapId][i * map_width + x];
if(tileId == 37 || tileId == 72
|| tileId == 128 || tileId == 137
|| tileId == 162 || tileId == 193) {
if (tileId == 37 || tileId == 72
|| tileId == 128 || tileId == 137
|| tileId == 162 || tileId == 193) {
int renderY = i * 16;
int renderX = x * 16;
fillOneTileInScreen(renderX - posX, renderY - posY, fillTileId, screenBuffer);
Expand Down Expand Up @@ -198,6 +248,12 @@ void MapRender::tikLogic() {
isOriginPalette = false;
entranceAnimation--;
}
water_status_clk++;
if(water_status_clk > 60) {
water_status_clk = 0;
water_status++;
water_status %= 4;
}
}

void MapRender::onUnFocus() {
Expand Down Expand Up @@ -231,7 +287,7 @@ void MapRender::processKeyClick(byte directKey, byte functionKey) {
if (functionKey & tb) {
changeAudio(getAudioIdx() + 1);
}
if(functionKey & keyX) {
if (functionKey & keyX) {
DebugRender *debugRender = new DebugRender;
push(debugRender);
}
Expand Down Expand Up @@ -298,15 +354,16 @@ bool MapRender::processKey(byte directKey, byte functionKey) {

void MapRender::triggerDoor(Character *player) const {
int map_width = map_size[mapId * 2 + 1];
unsigned short tileId = short_map_data[mapId][getDefaultPlayer()->y * map_width + getDefaultPlayer()->x];
unsigned short tileId = short_map_data[mapId][getDefaultPlayer()->y * map_width +
getDefaultPlayer()->x];
if ((tileId == 37 || tileId == 72
|| tileId == 128 || tileId == 137
|| tileId == 162 || tileId == 193
)
&& (!player->inDoor)) {
renderEffect(EFFECT_DOOR);
player->inDoor = true;
} else if(player->inDoor) {
} else if (player->inDoor) {
renderEffect(EFFECT_DOOR);
player->inDoor = false;
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/cpp/logic/render_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class MapRender : public BaseRender {
void triggerDoor(Character *player) const;
void renderDoor(byte *screenBuffer) const;
void renderSprite(byte *screenBuffer) const;
void renderWater(byte *screenBuffer) const;
void resetPalette() const;
void renderPlayers(byte *screenBuffer, Character *player) const;
public:
Expand Down
Loading

0 comments on commit 4e7c1b1

Please sign in to comment.