-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColBitMap.cs
151 lines (135 loc) · 5.52 KB
/
ColBitMap.cs
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
using System.Drawing;
namespace ScreenSaver
{
internal class ColBitMap
{
public Bitmap ColumnBitMap { get; set; }
public bool IsModified { get; set; }
private readonly int ColumnIndex;
private readonly int ScrNumber;
public ColBitMap(int columnIndex, int scrNumber)
{
ScrNumber = scrNumber;
ColumnIndex = columnIndex;
ColumnBitMap = new Bitmap(16, ScreenInstances.ScrForms[ScrNumber].SSBitmap.Height);
IsModified = false;
}
public void InPlaceMutation()
{
var movesdown = ScreenInstances.EntropySrc.Next(0,4);
for (int i = 0; i < movesdown; i++)
{
MoveDown(true);
}
using (Graphics graphics = Graphics.FromImage(ColumnBitMap))
{
for (int i = 0; i < ScreenInstances.ScrForms[ScrNumber].SpriteRows; i++)
{
var mutationdice = ScreenInstances.EntropySrc.Next(4);
if (!ScreenInstances.CheckIndexEmptySprite(ScreenInstances.ScrForms[ScrNumber].UsedKatakanaIndexes[ColumnIndex, i]))
{
switch (mutationdice)
{
case 0:
{
ScreenInstances.ScrForms[ScrNumber].UsedKatakanaIndexes[ColumnIndex, i] = ScreenInstances.EntropySrc.Next(480);
}
break;
default:
{
ScreenInstances.ScrForms[ScrNumber].UsedKatakanaIndexes[ColumnIndex, i] = (ScreenInstances.ScrForms[ScrNumber].UsedKatakanaIndexes[ColumnIndex, i] + 120) % 480;
}
break;
}
Bitmap resbitmap = ScreenInstances.GetKatakanaSprite(ScreenInstances.ScrForms[ScrNumber].UsedKatakanaIndexes[ColumnIndex, i]);
Point destp = new Point(0, i * 24);
graphics.DrawImageUnscaled(resbitmap, destp);
}
}
}
}
public void MoveDown(bool clearfisrst = false)
{
Bitmap sprites = null;
var findex = FirstSpriteIndex;
if (findex == -1)
{
return;
}
var spritesheight = ScreenInstances.ScrForms[ScrNumber].SSBitmap.Height - (findex + 1) * 24;
using (var cbm = new Bitmap(ColumnBitMap))
{
using (Graphics graphics = Graphics.FromImage(ColumnBitMap))
{
Rectangle cloneRect = new Rectangle(0, findex * 24, 16, spritesheight);
sprites = cbm.Clone(cloneRect, ScreenInstances.ScrForms[ScrNumber].SSBitmap.PixelFormat);
Point clearp = new Point(0, findex * 24);
Point destp = new Point(0, (findex + 1) * 24);
graphics.DrawImageUnscaled(ScreenInstances.katakana[119], clearp);
graphics.DrawImageUnscaled(sprites, destp);
ScreenInstances.ScrForms[ScrNumber].ReorderColumnIndexesDownMove(ColumnIndex, clearfisrst);
}
}
IsModified = true;
}
public void AddTopSprite(int index = -1)
{
MoveDown(false);
using (Graphics graphics = Graphics.FromImage(ColumnBitMap))
{
Point sp = new Point(0, 0);
var selectedindex = index == -1 ? ScreenInstances.EntropySrc.Next(ScreenInstances.katakana.Length) : index;
Bitmap resbitmap = ScreenInstances.GetKatakanaSprite(selectedindex);
graphics.DrawImageUnscaled(resbitmap, sp);
ScreenInstances.ScrForms[ScrNumber].UsedKatakanaIndexes[ColumnIndex, 0] = selectedindex;
}
}
public int FirstSpriteIndex
{
get
{
var res = -1;
for (int crow = 0; crow < ScreenInstances.ScrForms[ScrNumber].SpriteRows; crow++)
{
if (!ScreenInstances.CheckIndexEmptySprite(ScreenInstances.ScrForms[ScrNumber].UsedKatakanaIndexes[ColumnIndex, crow]))
{
res = crow;
break;
}
}
return res;
}
}
public int LastSpriteIndex
{
get
{
var res = -1;
for (int crow = ScreenInstances.ScrForms[ScrNumber].SpriteRows - 1; crow >= 0; crow--)
{
if (!ScreenInstances.CheckIndexEmptySprite(ScreenInstances.ScrForms[ScrNumber].UsedKatakanaIndexes[ColumnIndex, crow]))
{
res = crow;
break;
}
}
return res;
}
}
public int SpriteCount
{
get
{
var res = 0;
for (int crow = 0; crow < ScreenInstances.ScrForms[ScrNumber].SpriteRows; crow++)
{
if (!ScreenInstances.CheckIndexEmptySprite(ScreenInstances.ScrForms[ScrNumber].UsedKatakanaIndexes[ColumnIndex, crow]))
{
res++;
}
}
return res;
}
}
}
}