-
Notifications
You must be signed in to change notification settings - Fork 1
/
Screen.cpp
124 lines (121 loc) · 3.78 KB
/
Screen.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//---------------------------------------------------------------------------
#include "agdv.pch.h"
#include "Screen.h"
#include "ErrorReporter.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
__fastcall GameScreen::GameScreen(const String& data, unsigned int screenIndex)
{
try
{
// convert the SPRITEPOSITION commands
auto ld = data.LowerCase();
auto sp = ld.Pos("spriteposition");
auto sprites = sp != 0 ? data.SubString(sp, data.Length()) : "";
auto blocks = sp != 0 ? data.SubString(1, sp - 1) : data;
auto spTokens = SplitString(sprites.Trim(), " ");
String prevToken = "";
SpritePosition spritePos;
spritePos.ScreenIndex = screenIndex;
int i = 0;
for (auto token : spTokens)
{
token = token.Trim();
if (token != "")
{
if (prevToken.LowerCase() == "spriteposition")
{
i = 1;
spritePos.Type = StrToInt(token);
}
else if (i == 1)
{
spritePos.Index = StrToInt(token);
if (spritePos.Index == 90)
{
spritePos.Index = 0;
}
i = 2;
}
else if (i == 2)
{
spritePos.Position.Y = StrToInt(token);
i = 3;
}
else if (i == 3)
{
spritePos.Position.X = StrToInt(token);
i = 0;
m_Sprites.push_back(spritePos);
}
prevToken = token;
}
}
// Convert the block data
auto tokens = SplitString(blocks.Trim(), " ");
for (auto token : tokens)
{
if (token.Trim() != "")
{
m_Blocks.push_back(StrToInt(token.Trim()));
}
}
}
catch(...)
{
g_ErrorReporter.Add("Error: Exception caught while converting Screen data. [" + data + "]");
throw;
}
}
//---------------------------------------------------------------------------
void __fastcall GameScreen::Draw(int room, int x, int y, TBitmap* bitmap, int scalar, const ImageList& blocks, const ImageList& objects, const ImageList& sprites, const Window& window)
{
auto sx = x;
auto sy = y;
auto bx = 0;
auto by = 0;
auto wx = window.x * 8;
auto wy = window.y * 8;
auto bw = blocks[0]->Width * scalar;
auto bh = blocks[0]->Height * scalar;
for (const auto& block : m_Blocks)
{
blocks[block]->Draw(x, y, bitmap, scalar, 0);
x += bw;
if (++bx >= window.w)
{
x = sx;
y += bh;
bx = 0;
if (++by == window.h)
{
break;
}
}
}
for (auto& sprite : m_Sprites)
{
if (sprite.Index >= sprites.size())
{
sprite.Index = 0;
}
if (sprite.Index < sprites.size())
{
sprites[sprite.Index]->Draw(sx + ((sprite.Position.X - wx) * scalar), sy + ((sprite.Position.Y - wy) * scalar), bitmap, scalar, 0);
}
else
{
g_ErrorReporter.Add("Error: Invalid Sprite index referenced in screen data. Room: " + IntToStr(room) + ", SpriteIndex: " + IntToStr(sprite.Index));
}
}
for (const auto& object : objects)
{
auto image = dynamic_cast<ImageObject*>(object.get());
if (image != nullptr && image->Room == room && image->Room != -1)
{
image->Draw(sx + ((image->Position.X - wx) * scalar), sy + ((image->Position.Y - wy) * scalar), bitmap, scalar, 0);
}
}
}
//---------------------------------------------------------------------------