ref: 03e0034bca7c1c13391010af3b5dddb4644a9998
parent: 61c75c0ffba159c0b62da4d292be8eb7d7a1d575
parent: ecc9f758b68d9fc00b150dae0f04248590debe2e
author: Clownacy <Clownacy@users.noreply.github.com>
date: Sun Feb 10 10:02:45 EST 2019
Merge branch 'master' of https://github.com/cuckydev/Cave-Story-Engine-2
--- a/src/Back.cpp
+++ b/src/Back.cpp
@@ -52,6 +52,7 @@
void PutBack(int fx, int fy)
{
RECT rect = {0, 0, gBack.partsW, gBack.partsH};
+ RECT rcSkyFiller = {106, 0, 255, 88};
switch (gBack.type)
{
@@ -90,30 +91,33 @@
case 6:
case 7:
//Sky
+ static unsigned int fillNext;
+ fillNext = 0;
+ for (int y = 0; y < WINDOW_HEIGHT - 240 + 88; y += 88)
+ {
+ fillNext = ((fillNext) * 214013 + 2531011);
+ for (int x = -(fillNext % 149); x < WINDOW_WIDTH; x += 149)
+ {
+ PutBitmap4(&grcGame, x, y, &rcSkyFiller, SURFACE_ID_LEVEL_BACKGROUND);
+ }
+ }
+
rect.top = 0;
rect.bottom = 88;
rect.left = 0;
rect.right = 320;
- PutBitmap4(&grcGame, (WINDOW_WIDTH - 320) / 2, 0, &rect, SURFACE_ID_LEVEL_BACKGROUND);
-
- rect.left = 106;
- rect.right = 255;
- for (int i = 0; i < ((WINDOW_WIDTH + 329) / 320); i++)
- {
- PutBitmap4(&grcGame, (WINDOW_WIDTH - 320) / 2 - (149 * (i + 1)), 0, &rect, SURFACE_ID_LEVEL_BACKGROUND);
- PutBitmap4(&grcGame, (WINDOW_WIDTH - 320) / 2 + 320 + (149 * i), 0, &rect, SURFACE_ID_LEVEL_BACKGROUND);
- }
-
+ PutBitmap4(&grcGame, (WINDOW_WIDTH - 320) / 2, WINDOW_HEIGHT - 240, &rect, SURFACE_ID_LEVEL_BACKGROUND);
+
//Cloud layer 1
rect.top = 88;
rect.bottom = 123;
rect.left = gBack.fx / 2;
rect.right = 320;
- PutBitmap4(&grcGame, 0, 88, &rect, SURFACE_ID_LEVEL_BACKGROUND);
+ PutBitmap4(&grcGame, 0, 88 + (WINDOW_HEIGHT - 240), &rect, SURFACE_ID_LEVEL_BACKGROUND);
rect.left = 0;
for (int i = 0; i < ((WINDOW_WIDTH + 329) / 320) + 1; i++)
- PutBitmap4(&grcGame, (320 * (i + 1)) - gBack.fx / 2 % 320, 88, &rect, SURFACE_ID_LEVEL_BACKGROUND);
+ PutBitmap4(&grcGame, (320 * (i + 1)) - gBack.fx / 2 % 320, 88 + (WINDOW_HEIGHT - 240), &rect, SURFACE_ID_LEVEL_BACKGROUND);
//Cloud layer 2
rect.top = 123;
@@ -120,11 +124,11 @@
rect.bottom = 146;
rect.left = gBack.fx % 320;
rect.right = 320;
- PutBitmap4(&grcGame, 0, 123, &rect, SURFACE_ID_LEVEL_BACKGROUND);
+ PutBitmap4(&grcGame, 0, 123 + (WINDOW_HEIGHT - 240), &rect, SURFACE_ID_LEVEL_BACKGROUND);
rect.left = 0;
for (int i = 0; i < ((WINDOW_WIDTH + 329) / 320) + 1; i++)
- PutBitmap4(&grcGame, (320 * (i + 1)) - gBack.fx % 320, 123, &rect, SURFACE_ID_LEVEL_BACKGROUND);
+ PutBitmap4(&grcGame, (320 * (i + 1)) - gBack.fx % 320, 123 + (WINDOW_HEIGHT - 240), &rect, SURFACE_ID_LEVEL_BACKGROUND);
//Cloud layer 3
rect.top = 146;
@@ -131,11 +135,11 @@
rect.bottom = 176;
rect.left = 2 * gBack.fx % 320;
rect.right = 320;
- PutBitmap4(&grcGame, 0, 146, &rect, SURFACE_ID_LEVEL_BACKGROUND);
+ PutBitmap4(&grcGame, 0, 146 + (WINDOW_HEIGHT - 240), &rect, SURFACE_ID_LEVEL_BACKGROUND);
rect.left = 0;
for (int i = 0; i < ((WINDOW_WIDTH + 329) / 320) + 1; i++)
- PutBitmap4(&grcGame, (320 * (i + 1)) - 2 * gBack.fx % 320, 146, &rect, SURFACE_ID_LEVEL_BACKGROUND);
+ PutBitmap4(&grcGame, (320 * (i + 1)) - 2 * gBack.fx % 320, 146 + (WINDOW_HEIGHT - 240), &rect, SURFACE_ID_LEVEL_BACKGROUND);
//Cloud layer 4
rect.top = 176;
@@ -142,11 +146,11 @@
rect.bottom = 240;
rect.left = 4 * gBack.fx % 320;
rect.right = 320;
- PutBitmap4(&grcGame, 0, 176, &rect, SURFACE_ID_LEVEL_BACKGROUND);
+ PutBitmap4(&grcGame, 0, 176 + (WINDOW_HEIGHT - 240), &rect, SURFACE_ID_LEVEL_BACKGROUND);
rect.left = 0;
for (int i = 0; i < ((WINDOW_WIDTH + 329) / 320) + 1; i++)
- PutBitmap4(&grcGame, (320 * (i + 1)) - 4 * gBack.fx % 320, 176, &rect, SURFACE_ID_LEVEL_BACKGROUND);
+ PutBitmap4(&grcGame, (320 * (i + 1)) - 4 * gBack.fx % 320, 176 + (WINDOW_HEIGHT - 240), &rect, SURFACE_ID_LEVEL_BACKGROUND);
break;
default:
--- a/src/Draw.cpp
+++ b/src/Draw.cpp
@@ -66,6 +66,8 @@
static bool IsEnableBitmap(SDL_RWops *fp)
{
+ return true;
+ /*
char str[16];
const char *extra_text = "(C)Pixel";
@@ -75,6 +77,7 @@
fp->read(fp, str, 1, len);
fp->seek(fp, 0, RW_SEEK_SET);
return memcmp(str, extra_text, len) == 0;
+ */
}
void ReleaseSurface(int s)
--- a/src/Ending.cpp
+++ b/src/Ending.cpp
@@ -17,8 +17,6 @@
#include "Draw.h"
#include "TextScr.h"
-#define MAX_STRIP 0x10
-
CREDIT Credit;
STRIP Strip[MAX_STRIP];
ILLUSTRATION Illust;
@@ -100,6 +98,10 @@
{
switch (Illust.act_no)
{
+ case 0: //Off-screen to the left
+ Illust.x = -0x14000;
+ break;
+
case 1: //Move in from the left
Illust.x += 0x5000;
if (Illust.x > 0)
@@ -111,10 +113,6 @@
if (Illust.x < -0x14000)
Illust.x = -0x14000;
break;
-
- case 0: //Off-screen to the left
- Illust.x = -0x14000;
- break;
}
}
@@ -137,6 +135,7 @@
//Initialize and release credits
void InitCreditScript()
{
+ //Clear script state and casts
memset(&Credit, 0, sizeof(CREDIT));
memset(Strip, 0, sizeof(Strip));
}
@@ -145,6 +144,7 @@
{
if (Credit.pData)
{
+ //Free script data
free(Credit.pData);
Credit.pData = NULL;
}
@@ -179,7 +179,8 @@
return false;
//Read data
- fp->read(fp, Credit.pData, 1, Credit.size);
+ SDL_RWread(fp, Credit.pData, 1, Credit.size);
+ SDL_RWclose(fp);
EncryptionBinaryData2((uint8_t*)Credit.pData, Credit.size);
//Reset credits
@@ -203,7 +204,6 @@
//Clear casts
memset(Strip, 0, sizeof(Strip));
- SDL_RWclose(fp);
return true;
}
@@ -210,7 +210,10 @@
//Get number from text (4 digit)
int GetScriptNumber(const char *text)
{
- return 1000 * *text - 48000 + 100 * text[1] - 4800 + 10 * text[2] - 480 + text[3] - 48;
+ return 1000 * text[0] - 48000 +
+ 100 * text[1] - 4800 +
+ 10 * text[2] - 480 +
+ text[3] - 48;
}
//Parse credits
@@ -218,6 +221,7 @@
{
while (Credit.offset < Credit.size)
{
+ //Get character
uint8_t character = Credit.pData[Credit.offset];
int a, b, len;
@@ -352,6 +356,7 @@
{
if (Credit.offset < Credit.size)
{
+ //Update script, or if waiting, decrement the wait value
if (Credit.mode == 1)
{
ActionCredit_Read();
@@ -379,23 +384,24 @@
//Scene of the island falling
int Scene_DownIsland(int mode)
{
- RECT rc_sprite;
- RECT rc_ground;
- RECT rc_sky;
- RECT rc_frame;
+ //Setup background
+ RECT rc_frame = {(WINDOW_WIDTH - 160) / 2, (WINDOW_HEIGHT - 80) / 2, (WINDOW_WIDTH + 160) / 2, (WINDOW_HEIGHT + 80) / 2};
+ RECT rc_sky = {0, 0, 160, 80};
+ RECT rc_ground = {160, 48, 320, 80};
+
+ //Setup island
+ RECT rc_sprite = {160, 0, 200, 24};
+
ISLAND_SPRITE sprite;
-
- rc_frame = {(WINDOW_WIDTH - 160) / 2, (WINDOW_HEIGHT - 80) / 2, (WINDOW_WIDTH + 160) / 2, (WINDOW_HEIGHT + 80) / 2};
- rc_sky = {0, 0, 160, 80};
- rc_ground = {160, 48, 320, 80};
- rc_sprite = {160, 0, 200, 24};
sprite.x = 0x15000;
sprite.y = 0x8000;
for (int wait = 0; wait < 900; wait++)
{
+ //Get pressed keys
GetTrg();
+ //Escape menu
if (gKey & 0x8000)
{
int escRet = Call_Escape();
@@ -408,6 +414,7 @@
switch (mode)
{
case 0:
+ //Move down
sprite.y += 0x33;
break;
@@ -418,27 +425,31 @@
{
if (wait >= 600)
{
+ //End scene
if (wait == 750)
wait = 900;
}
else
{
+ //Move down slow
sprite.y += 0xC;
}
}
else
{
+ //Move down slower
sprite.y += 0x19;
}
}
else
{
+ //Move down at normal speed
sprite.y += 0x33;
}
break;
}
-
+ //Draw scene
CortBox(&grcFull, 0);
PutBitmap3(&rc_frame, 80 + (WINDOW_WIDTH - 320) / 2, 80 + (WINDOW_HEIGHT - 240) / 2, &rc_sky, 21);
PutBitmap3(&rc_frame, sprite.x / 0x200 - 20 + (WINDOW_WIDTH - 320) / 2, sprite.y / 512 - 12 + (WINDOW_HEIGHT - 240) / 2, &rc_sprite, 21);
@@ -445,6 +456,7 @@
PutBitmap3(&rc_frame, 80 + (WINDOW_WIDTH - 320) / 2, 128 + (WINDOW_HEIGHT - 240) / 2, &rc_ground, 21);
PutTimeCounter(16, 8);
+ //Draw window
PutFramePerSecound();
if (!Flip_SystemTask())
return 0;
--- a/src/Ending.h
+++ b/src/Ending.h
@@ -32,6 +32,8 @@
int y;
};
+#define MAX_STRIP (WINDOW_HEIGHT / 16) + 1
+
void ActionStripper();
void PutStripper();
void SetStripper(int x, int y, char *text, int cast);
--- a/src/Frame.cpp
+++ b/src/Frame.cpp
@@ -22,15 +22,12 @@
const int num_x = ((WINDOW_WIDTH + 0xF) >> 4) + 1;
const int num_y = ((WINDOW_HEIGHT + 0xF) >> 4) + 1;
- if (map_w >= num_x || g_GameFlags & 8)
+ if (map_w >= num_x)
{
if (gFrame.x <= -0x200)
gFrame.x = 0;
if (gFrame.x > ((((map_w - 1) << 4) - ((g_GameFlags & 8) ? 320 : WINDOW_WIDTH))) << 9)
gFrame.x = (((map_w - 1) << 4) - ((g_GameFlags & 8) ? 320 : WINDOW_WIDTH)) << 9;
-
- if (g_GameFlags & 8)
- gFrame.x -= ((WINDOW_WIDTH - 320) / 2) << 9;
}
else
{
@@ -37,15 +34,12 @@
gFrame.x = (((map_w - 1) << 4) - WINDOW_WIDTH) << 8;
}
- if (map_l >= num_y || g_GameFlags & 8)
+ if (map_l >= num_y)
{
if (gFrame.y <= -0x200)
gFrame.y = 0;
if (gFrame.y > ((((map_l - 1) << 4) - ((g_GameFlags & 8) ? 240 : WINDOW_HEIGHT))) << 9)
gFrame.y = (((map_l - 1) << 4) - ((g_GameFlags & 8) ? 240 : WINDOW_HEIGHT)) << 9;
-
- if (g_GameFlags & 8)
- gFrame.y += ((WINDOW_HEIGHT - 240) / 2) << 9;
}
else
{
--- a/src/Game.cpp
+++ b/src/Game.cpp
@@ -50,7 +50,7 @@
int Random(int min, int max)
{
- return min + rand() % (max - min + 1);
+ return min + rep_rand() % (max - min + 1);
}
void PutNumber4(int x, int y, int value, bool bZero)
--- a/src/GenericLoad.cpp
+++ b/src/GenericLoad.cpp
@@ -2,6 +2,7 @@
#include "Draw.h"
#include "Sound.h"
#include "PixTone.h"
+#include "Ending.h"
static const PIXTONEPARAMETER gPtpTable[139] =
{
@@ -195,7 +196,7 @@
MakeSurface_Generic(40, 240, 29); //Unknown?
MakeSurface_Generic(320, 240, SURFACE_ID_LEVEL_SPRITESET_1);
MakeSurface_Generic(320, 240, SURFACE_ID_LEVEL_SPRITESET_2);
- MakeSurface_Generic(WINDOW_WIDTH, 240, SURFACE_ID_CREDIT_CAST);
+ MakeSurface_Generic(WINDOW_WIDTH, 16 * MAX_STRIP, SURFACE_ID_CREDIT_CAST);
size_t pixtone_bytes = MakePixToneObject(&gPtpTable[0], 2, 32);
pixtone_bytes += MakePixToneObject(&gPtpTable[2], 2, 33);
--- a/src/Main.cpp
+++ b/src/Main.cpp
@@ -44,6 +44,21 @@
const char *lpWindowName = "Cave Story Engine 2 ~ Doukutsu Monogatari Enjin 2";
#endif
+//A replication of MSVC's rand algorithm
+static unsigned long int next = 1;
+
+int rep_rand()
+{
+ next = ((next) * 214013 + 2531011);
+ return ((next) >> 16) & 0x7FFF;
+}
+
+void rep_srand(unsigned int seed)
+{
+ next = seed;
+}
+
+//Framerate stuff
void PutFramePerSecound()
{
if (bFps)
--- a/src/ValueView.cpp
+++ b/src/ValueView.cpp
@@ -43,7 +43,7 @@
//Get if negative or not
bool minus;
- if ( value >= 0 )
+ if (value >= 0)
{
minus = false;
}
@@ -85,6 +85,28 @@
gVV[index].rect.right = 40;
gVV[index].rect.bottom = 8 * (index + 1);
+ RECT rect[20];
+ rect[0] = {0, 56, 8, 64};
+ rect[1] = {8, 56, 16, 64};
+ rect[2] = {16, 56, 24, 64};
+ rect[3] = {24, 56, 32, 64};
+ rect[4] = {32, 56, 40, 64};
+ rect[5] = {40, 56, 48, 64};
+ rect[6] = {48, 56, 56, 64};
+ rect[7] = {56, 56, 64, 64};
+ rect[8] = {64, 56, 72, 64};
+ rect[9] = {72, 56, 80, 64};
+ rect[10] = {0, 64, 8, 72};
+ rect[11] = {8, 64, 16, 72};
+ rect[12] = {16, 64, 24, 72};
+ rect[13] = {24, 64, 32, 72};
+ rect[14] = {32, 64, 40, 72};
+ rect[15] = {40, 64, 48, 72};
+ rect[16] = {48, 64, 56, 72};
+ rect[17] = {56, 64, 64, 72};
+ rect[18] = {64, 64, 72, 72};
+ rect[19] = {72, 64, 80, 72};
+
//Get digits
int dig[4];
dig[0] = 1;
@@ -103,7 +125,7 @@
}
}
- int sw = 0;
+ bool sw = false;
RECT rcPlus = {32, 48, 40, 56};
RECT rcMinus = {40, 48, 48, 56};
@@ -120,15 +142,12 @@
{
if (sw || !i || fig[i])
{
- sw = 1;
+ sw = true;
- RECT rect;
if (minus)
- rect = {fig[i] << 3, 64, (fig[i] + 1) << 3, 72};
- else
- rect = {fig[i] << 3, 56, (fig[i] + 1) << 3, 64};
+ fig[i] += 10;
- Surface2Surface(8 * (4 - i), gVV[index].rect.top, &rect, 29, 26);
+ Surface2Surface(8 * (4 - i), gVV[index].rect.top, &rect[fig[i]], 29, 26);
}
}
}
--- a/src/WindowsWrapper.h
+++ b/src/WindowsWrapper.h
@@ -1,4 +1,6 @@
#pragma once
+int rep_rand();
+void rep_srand(unsigned int seed);
typedef int BOOL;