-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZObject.cs
More file actions
210 lines (198 loc) · 7.13 KB
/
ZObject.cs
File metadata and controls
210 lines (198 loc) · 7.13 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// ZObject / ZTeacher for HHSAdvSDL
using System.Data.Common;
using System.IO;
namespace HHSAdvWin
{
public class ZObjects
{
private const int blockSize = 0x200;
public int Id
{
get
{
return id;
}
set
{
using (var fs = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
fs.Seek((value + 1) * blockSize, System.IO.SeekOrigin.Begin);
byte[] b = new byte[blockSize];
using (var br = new BinaryReader(fs))
{
b = br.ReadBytes(b.Length);
}
obj = (value == 14) ? new ZTeacher(b) : new ZObject(b);
id = value;
}
}
}
private string fileName = string.Empty;
public ZObjects(string f)
{
fileName = f;
}
public void Draw(Canvas cv, bool shift = false)
{
obj.Draw(cv, shift);
}
private int id = -1;
private ZObject obj = new ZObject();
private class ZObject
{
protected byte[] buf;
public ZObject()
{
buf = new byte[blockSize];
}
public ZObject(byte[] b)
{
buf = new byte[blockSize];
Array.Copy(b, buf, blockSize);
}
public virtual void Draw(Canvas cv, bool shift = false)
{
int offset = (shift) ? 256 : 0;
draw(cv, true, offset);
draw(cv, false, offset);
}
private void draw(Canvas cv, bool draft, int offset)
{
int o = offset;
UInt32 b = cv.GetPaletteColor(buf[o++]);
if (draft) b = 0xffc0c000; //new SDL.SDL_Color { r = 192, g = 192, b = 0, a = 255 };
int xs = buf[o++] / 2;
int ys = buf[o++];
o = OutLine(cv, o, b, xs, ys);
int x0 = buf[o++];
int y0 = buf[o++];
while (x0 != 0xff || y0 != 0xff)
{
UInt32 c = cv.GetPaletteColor(buf[o++]);
if (draft) c = b;
cv.paint(xs + x0, ys + y0, c, b);
x0 = buf[o++];
y0 = buf[o++];
}
}
private int OutLine(Canvas cv, int offset,UInt32 col, int ox, int oy)
{
int x0, y0, x1, y1;
x0 = buf[offset++];
y0 = buf[offset++];
while (true)
{
x1 = buf[offset++];
y1 = buf[offset++];
if (y1 == 0xff)
{
if (x1 == 0xff) break;
x0 = buf[offset++];
y0 = buf[offset++];
continue;
}
cv.line(x0 + ox, y0 + oy, x1 + ox, y1 + oy, col);
y0 = y1;
x0 = x1;
}
return offset;
}
}
private class ZTeacher : ZObject
{
public ZTeacher() : base()
{
}
public ZTeacher(byte[] b) : base(b)
{
}
public override void Draw(Canvas cv, bool shift = false)
{
const int ox = -32;
int x0, y0, x1, y1;
int[] r1 = new int [] { 18, 24, 2, 2, 2, 22, 9, 0xffff };
int[] r2 = new int [] { 148,14, 126, 6, 0, 0 };
y0 = 63;
int i = 0;
for (i = 0 ; i <= 172 ; i += 2)
{
x0 = buf[i];
x1 = buf[i + 1];
cv.line(ox + x0, y0, ox + x1, y0, 1);
++y0;
}
int c = 0;
for (int j = 0 ; r1[j] != 0xffff ; j++)
{
c = buf[i++];
//if (c == TFT_RED) c = 0xf81f; //MAROON;
x0 = buf[i++];
y0 = buf[i++];
for (int k = 0 ; k <= r1[j] + 1 ; k++)
{
x1 = buf[i++];
y1 = buf[i++];
cv.line(ox + x0, y0, ox + x1, y1, c);
x0 = x1;
y0 = y1;
}
x0 = buf[i++];
y0 = buf[i++];
cv.paint(ox + x0, y0, c, c);
}
x0 = buf[i++];
y0 = buf[i++];
cv.paint(ox + x0, y0, c, c);
for (int j = 120 ; j < 124 ; j++)
{
cv.line(ox + j, 64, ox + j + 8, 110, 6);
cv.line(ox + j + 9, 110, ox + j + 11, 126, 7);
}
cv.line(ox + 125, 111, ox + 133, 109, 2);
cv.line(ox + 133, 109, ox + 134, 110, 2);
cv.line(ox + 134, 110, ox + 125, 112, 2);
cv.line(ox + 125, 112, ox + 125, 111, 2);
cv.line(ox + 120, 65, ox + 123, 64, 7);
cv.line(ox + 123, 64, ox + 121, 62, 7);
cv.line(ox + 121, 62, ox + 120, 65, 7);
cv.paint(ox + 122, 63, 7, 7);
for(int k = 0 ; r2[k + 1] != 0 ; k += 2)
{
x0 = r2[k];
UInt32 col = 0xffffc0c0; // { 255, 192, 192 }
for (int j = 0 ; j < r2[k + 1] ; j += 2)
{
y0 = buf[i++];
y1 = buf[i++];
cv.line(ox + x0, y0, ox + x0, y1, col);
++x0;
cv.line(ox + x0, y0, ox + x0, y1, col);
++x0;
y0 = buf[i++];
y1 = buf[i++];
cv.line(ox + x0, y0, ox + x0, y1, col);
++x0;
}
}
cv.drawRect(ox + 148, 78, ox + 164, 84, cv.GetPaletteColor(0));
cv.fillRect(ox + 149, 79, ox + 163, 83, cv.GetPaletteColor(7));
cv.fillRect(ox + 155, 78, ox + 156, 84, cv.GetPaletteColor(0));
while(true)
{
x1 = buf[i++];
y1 = buf[i++];
if (y1 == 0xff)
{
if (x1 == 0xff) break;
x0 = buf[i++];
y0 = buf[i++];
continue;
}
cv.line(ox + x0, y0, ox + x1, y1, 0);
x0 = x1;
y0 = y1;
}
}
}
}
}