tallscreen fix, replicated MSVC rand

This commit is contained in:
cuckydev 2019-02-09 22:02:18 -05:00
parent 378be5ae86
commit 767c2972ae
5 changed files with 72 additions and 35 deletions

View file

@ -52,6 +52,7 @@ void ActBack()
void PutBack(int fx, int fy)
{
RECT rect = {0, 0, gBack.partsW, gBack.partsH};
RECT rcSkyFiller = {106, 0, 255, 88};
switch (gBack.type)
{
@ -90,63 +91,63 @@ void PutBack(int fx, int fy)
case 6:
case 7:
//Sky
for (int y = 0; y < WINDOW_HEIGHT - 240 + 88; y += 88)
{
for (int x = -((y * 54) % 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;
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;
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;
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:

View file

@ -100,6 +100,10 @@ void ActionIllust()
{
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 +115,6 @@ void ActionIllust()
if (Illust.x < -0x14000)
Illust.x = -0x14000;
break;
case 0: //Off-screen to the left
Illust.x = -0x14000;
break;
}
}
@ -137,6 +137,7 @@ void ReloadIllust(int a)
//Initialize and release credits
void InitCreditScript()
{
//Clear script state and casts
memset(&Credit, 0, sizeof(CREDIT));
memset(Strip, 0, sizeof(Strip));
}
@ -145,6 +146,7 @@ void ReleaseCreditScript()
{
if (Credit.pData)
{
//Free script data
free(Credit.pData);
Credit.pData = NULL;
}
@ -179,7 +181,8 @@ bool StartCreditScript()
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,14 +206,16 @@ bool StartCreditScript()
//Clear casts
memset(Strip, 0, sizeof(Strip));
SDL_RWclose(fp);
return true;
}
//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 +223,7 @@ void ActionCredit_Read()
{
while (Credit.offset < Credit.size)
{
//Get character
uint8_t character = Credit.pData[Credit.offset];
int a, b, len;
@ -352,6 +358,7 @@ void ActionCredit()
{
if (Credit.offset < Credit.size)
{
//Update script, or if waiting, decrement the wait value
if (Credit.mode == 1)
{
ActionCredit_Read();
@ -379,23 +386,24 @@ void CutCreditIllust()
//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 +416,7 @@ int Scene_DownIsland(int mode)
switch (mode)
{
case 0:
//Move down
sprite.y += 0x33;
break;
@ -418,33 +427,38 @@ int Scene_DownIsland(int mode)
{
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);
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;

View file

@ -44,6 +44,21 @@ const char *lpWindowName = "洞窟物語エンジン2";
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 _rand()
{
next = ((next) * 214013 + 2531011);
return ((next) >> 16) & 0x7FFF;
}
void _srand(unsigned int seed)
{
next = seed;
}
//Framerate stuff
void PutFramePerSecound()
{
if (bFps)

View file

@ -5,6 +5,8 @@
#include <cstring>
#include <math.h>
#include "WindowsWrapper.h"
#include "CommonDefines.h"
#include "Tags.h"
#include "PixTone.h"

View file

@ -1,5 +1,10 @@
#pragma once
#define rand _rand
#define srand _srand
int _rand();
void _srand(unsigned int seed);
typedef int BOOL;
#ifndef FALSE