-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevelfruit.php
121 lines (107 loc) · 2.42 KB
/
levelfruit.php
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
<?php
include('Classes\Yogho.php');
include('Classes\Offsets.php');
include('Classes\Palette.php');
// Palette
$paletteModel = new \Yogho\Palette('1');
$palette = $paletteModel->palette;
$handle = fopen('YOGHODAT.DAT', 'rb');
fseek($handle, 13164);
$orderLevels1Through3 = [
0, 4, 8, 12, 16,
1, 5, 9, 13, 17,
2, 6, 10, 14, 18,
3, 7, 11, 15
];
$orderLevel4 = [
0, 4, 8, 12, 16,
1, 5, 9, 13, 17,
2, 6, 10, 14,
3, 7, 11, 15
];
$orderLevel5 = [
0, 4, 8, 12, 16,
1, 5, 9, 13, 17,
2, 6, 10, 14, 18,
3, 7, 11, 15
];
$orderLevel6 = [
0, 4, 8, 12,
1, 5, 9, 13,
2, 6, 10, 14,
3, 7, 11,
];
$levels = [
1 => [
'w' => 19,
'h' => 17,
'order' => $orderLevels1Through3,
],
2 => [
'w' => 19,
'h' => 17,
'order' => $orderLevels1Through3,
],
3 => [
'w' => 19,
'h' => 17,
'order' => $orderLevels1Through3,
],
4 => [
'w' => 18,
'h' => 16,
'order' => $orderLevel4,
],
5 => [
'w' => 19,
'h' => 16,
'order' => $orderLevel5,
],
6 => [
'w' => 16,
'h' => 17,
'order' => $orderLevel6,
],
];
$width = 0;
$height = 0;
foreach ($levels as $level) {
$width += $level['w'];
$height = max($height, $level['h']);
}
$plaatje = imagecreatetruecolor($width, $height);
imagecolortransparent($plaatje, imagecolorallocate($plaatje, $palette[0][0], $palette[0][1], $palette[0][2]));
$baseX = 0;
foreach ($levels as $level) {
foreach ($level['order'] as $x) {
for ($y = 0; $y < $level['h']; $y++) {
$n = ord(fread($handle, 1));
$col = imagecolorallocate($plaatje, $palette[$n][0], $palette[$n][1], $palette[$n][2]);
imagesetpixel($plaatje, $baseX + $x, $y, $col);
}
}
$baseX += $level['w'];
}
fclose($handle);
header("Content-type: image/png");
imagepng($plaatje);
/*
$baseX = 0;
foreach ($wh as list($w, $h)) {
$x = 0;
for ($i = 0; $i < $w; $i++) {
for ($y = 0; $y < $h; $y++) {
$n = ord(fread($handle, 1));
$col = imagecolorallocate($plaatje, $palette[$n][0], $palette[$n][1], $palette[$n][2]);
imagesetpixel($plaatje, $baseX + $x, $y, $col);
}
$x += 4;
if ($x >= $w) {
$x = $x % $w;
if ($x === 0) {
$x = 1;
}
}
}
$baseX += $w;
}*/