Skip to content

Commit ed447a3

Browse files
committed
Fix using wrong color for keys somestimes
- Also general Sprite tweaks - Fixes #1
1 parent 1a1677e commit ed447a3

7 files changed

Lines changed: 68 additions & 26 deletions

File tree

include/kbd.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Kbd {
4040
Kbd &show(void) { _visible = true; for(Sprite &sprite : _sprites) sprite.visible(true); Sprite::update(false); return *this; }
4141
Kbd &hide(void) { _visible = false; for(Sprite &sprite : _sprites) sprite.visible(false); Sprite::update(false); return *this; }
4242

43+
TilePalette palette(char c);
4344
Kbd &palette(char c, TilePalette pal);
4445
};
4546

include/sprite.hpp

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,18 @@ class Sprite {
1111
bool _top;
1212
OamState *_oam;
1313
int _id = -1;
14-
int _rotId = -1;
15-
bool _visible = true;
1614
SpriteSize _size;
1715
SpriteColorFormat _format;
1816

17+
u16 *_gfx = nullptr;
18+
int _affineIndex = -1;
19+
int _paletteAlpha = 0;
20+
int _priority = 0;
21+
int _x = 0, _y = 0;
22+
bool _hFlip = false, _vFlip = false;
23+
bool _sizeDouble = false;
24+
bool _visible = true;
25+
1926
public:
2027
Sprite(bool top, SpriteSize size, SpriteColorFormat format);
2128
Sprite(const Sprite &sprite);
@@ -27,18 +34,28 @@ class Sprite {
2734
Sprite &update(void) { oamUpdate(_oam); return *this; }
2835

2936
int id(void) const { return _id; }
37+
38+
u16 *gfx(void) const { return _gfx; }
39+
int affineIndex(void) const { return _affineIndex; }
40+
int paletteAlpha(void) const { return _paletteAlpha; }
41+
int priority(void) const { return _priority; }
42+
int x(void) const { return _x; }
43+
int y(void) const { return _y; }
44+
bool hFlip(void) const { return _hFlip; }
45+
bool vFlip(void) const { return _vFlip; }
46+
bool sizeDouble(void) const { return _sizeDouble; }
3047
bool visible(void) const { return _visible; }
3148

32-
Sprite &affineIndex(int affineIndex, bool sizeDouble) { _rotId = affineIndex; oamSetAffineIndex(_oam, _id, _rotId, sizeDouble); return *this; }
33-
Sprite &affineTransform(float hdx, float hdy, float vdx, float vdy) { if(_rotId >= 0 && _rotId <= 31) oamAffineTransformation(_oam, _rotId, FLOAT_TO_FIXED(hdx), FLOAT_TO_FIXED(hdy), FLOAT_TO_FIXED(vdx), FLOAT_TO_FIXED(vdy)); return *this; }
34-
Sprite &alpha(int alpha) { oamSetAlpha(_oam, _id, alpha); return *this; }
35-
Sprite &flip(bool hflip, bool vflip) { oamSetFlip(_oam, _id, hflip, vflip); return *this; }
36-
Sprite &gfx(u16 *gfx) { oamSetGfx(_oam, _id, _size, _format, gfx); return *this; }
37-
Sprite &palette(int palette) { oamSetPalette(_oam, _id, palette); return *this; }
38-
Sprite &priority(int priority) { oamSetPriority(_oam, _id, priority); return *this; }
39-
Sprite &rotateScale(int angle, float sx, float sy) { if(_rotId >= 0 && _rotId <= 31) oamRotateScale(_oam, _rotId, angle, FLOAT_TO_FIXED(sx), FLOAT_TO_FIXED(sy)); return *this; }
49+
Sprite &affineIndex(int affineIndex, bool sizeDouble) { _affineIndex = affineIndex, _sizeDouble = sizeDouble; oamSetAffineIndex(_oam, _id, _affineIndex, _sizeDouble); return *this; }
50+
Sprite &affineTransform(float hdx, float hdy, float vdx, float vdy) { if(_affineIndex >= 0 && _affineIndex <= 31) oamAffineTransformation(_oam, _affineIndex, FLOAT_TO_FIXED(hdx), FLOAT_TO_FIXED(hdy), FLOAT_TO_FIXED(vdx), FLOAT_TO_FIXED(vdy)); return *this; }
51+
Sprite &alpha(int alpha) { _paletteAlpha = alpha; oamSetAlpha(_oam, _id, _paletteAlpha); return *this; }
52+
Sprite &flip(bool hFlip, bool vFlip) { _hFlip = hFlip, _vFlip = vFlip; oamSetFlip(_oam, _id, _hFlip, _vFlip); return *this; }
53+
Sprite &gfx(u16 *gfx) { _gfx = gfx; oamSetGfx(_oam, _id, _size, _format, _gfx); return *this; }
54+
Sprite &move(int x, int y) { _x = x, _y = y; oamSetXY(_oam, _id, _x, _y); return *this; }
55+
Sprite &palette(int palette) { _paletteAlpha = palette; oamSetPalette(_oam, _id, _paletteAlpha); return *this; }
56+
Sprite &priority(int priority) { _priority = priority; oamSetPriority(_oam, _id, _priority); return *this; }
57+
Sprite &rotateScale(int angle, float sx, float sy) { if(_affineIndex >= 0 && _affineIndex <= 31) oamRotateScale(_oam, _affineIndex, angle, FLOAT_TO_FIXED(sx), FLOAT_TO_FIXED(sy)); return *this; }
4058
Sprite &visible(bool visible) { _visible = visible; oamSetHidden(_oam, _id, !visible); return *this; }
41-
Sprite &xy(int x, int y) { oamSetXY(_oam, _id, x, y); return *this; }
4259
};
4360

4461
#endif // SPRITE_HPP

source/gfx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void initGraphics(bool altPalette) {
6868

6969
for(int i = 0; i < WORD_LEN * MAX_GUESSES; i++) {
7070
letterSprites.emplace_back(true, SpriteSize_32x32, SpriteColorFormat_16Color);
71-
letterSprites.back().xy((((256 - (WORD_LEN * 24 + (WORD_LEN - 1) * 2)) / 2) - 4) + (i % WORD_LEN) * 26, (25 + (167 - (MAX_GUESSES * 24 + (MAX_GUESSES - 1) * 2)) / 2 - 4) + (i / WORD_LEN) * 26).gfx(letterGfx[0]);
71+
letterSprites.back().move((((256 - (WORD_LEN * 24 + (WORD_LEN - 1) * 2)) / 2) - 4) + (i % WORD_LEN) * 26, (25 + (167 - (MAX_GUESSES * 24 + (MAX_GUESSES - 1) * 2)) / 2 - 4) + (i / WORD_LEN) * 26).gfx(letterGfx[0]);
7272
}
7373
Sprite::update(true);
7474
}

source/howto.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void howtoMenu() {
3131
std::vector<Sprite> howtoSprites;
3232
for(uint i = 0; i < words.length(); i++) {
3333
howtoSprites.emplace_back(false, SpriteSize_32x32, SpriteColorFormat_16Color);
34-
howtoSprites.back().xy(1 + (i % 5) * 26, 22 + (i / 5 * 60)).gfx(letterGfxSub[words[i] - 'a' + 1]);
34+
howtoSprites.back().move(1 + (i % 5) * 26, 22 + (i / 5 * 60)).gfx(letterGfxSub[words[i] - 'a' + 1]);
3535
}
3636

3737
std::array<Sprite, 3> toFlip = {howtoSprites[0], howtoSprites[6], howtoSprites[13]};

source/kbd.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Kbd::Kbd() {
1919
tonccpy(_gfx.back(), enterKeyTiles, enterKeyTilesLen);
2020
for(Key &key : _keys) {
2121
_sprites.emplace_back(false, (key.c == '\b' || key.c == '\n') ? SpriteSize_32x16 : SpriteSize_16x16, SpriteColorFormat_16Color);
22-
_sprites.back().xy(key.x, key.y).gfx(_gfx[key.c == '\b' ? 26 : (key.c == '\n' ? 27 : key.c - 'a')]).visible(false);
22+
_sprites.back().move(key.x, key.y).gfx(_gfx[key.c == '\b' ? 26 : (key.c == '\n' ? 27 : key.c - 'a')]).visible(false);
2323
}
2424
Sprite::update(false);
2525
}
@@ -41,10 +41,21 @@ char Kbd::get() {
4141
return SpecialKey::NOKEY;
4242
}
4343

44+
TilePalette Kbd::palette(char c) {
45+
for(uint i = 0; i < _keys.size(); i++) {
46+
if(_keys[i].c == c) {
47+
return TilePalette(_sprites[i].paletteAlpha());
48+
}
49+
}
50+
51+
return TilePalette::white;
52+
}
53+
4454
Kbd &Kbd::palette(char c, TilePalette pal) {
4555
for(uint i = 0; i < _keys.size(); i++) {
4656
if(_keys[i].c == c) {
4757
_sprites[i].palette(pal);
58+
break;
4859
}
4960
}
5061

source/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ std::vector<TilePalette> check(const std::string &guess, const std::string &answ
4242
continue;
4343
} else if(letters[guess[i]] > 0) {
4444
res[i] = TilePalette::yellow;
45-
if(kbd)
45+
if(kbd && kbd->palette(guess[i]) != TilePalette::green)
4646
kbd->palette(guess[i], TilePalette::yellow);
4747
letters[guess[i]]--;
4848
} else {
4949
res[i] = TilePalette::gray;
50-
if(kbd)
50+
if(kbd && (kbd->palette(guess[i]) != TilePalette::yellow && kbd->palette(guess[i]) != TilePalette::green))
5151
kbd->palette(guess[i], TilePalette::gray);
5252
}
5353
}
@@ -292,7 +292,7 @@ int main(void) {
292292
for(uint i = 0; i < answer.length(); i++) {
293293
answerSprites.emplace_back(false, SpriteSize_32x32, SpriteColorFormat_16Color);
294294
answerSprites.back()
295-
.xy((((256 - (WORD_LEN * 24 + (WORD_LEN - 1) * 2)) / 2) - 4) + (i % WORD_LEN) * 26, 96)
295+
.move((((256 - (WORD_LEN * 24 + (WORD_LEN - 1) * 2)) / 2) - 4) + (i % WORD_LEN) * 26, 96)
296296
.palette(TilePalette::white)
297297
.gfx(letterGfxSub[answer[i] - 'a' + 1])
298298
.visible(false);

source/sprite.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ Sprite::Sprite(bool top, SpriteSize size, SpriteColorFormat format) : _top(top),
1717
if(_id == -1)
1818
return;
1919

20-
oamSet(_oam, _id, 0, 0, 0, 0, _size, _format, nullptr, _rotId, false, false, false, false, false);
20+
oamSet(_oam, _id, _x, _y, _priority, _paletteAlpha, _size, _format, nullptr, _affineIndex, _sizeDouble, !_visible, _hFlip, _vFlip, false);
2121
}
2222

23-
Sprite::Sprite(const Sprite &sprite) : _top(sprite._top), _oam(sprite._oam), _id(sprite._id), _rotId(sprite._rotId), _visible(sprite._visible), _size(sprite._size), _format(sprite._format) {
23+
Sprite::Sprite(const Sprite &sprite) :
24+
_top(sprite._top), _oam(sprite._oam), _id(sprite._id), _size(sprite._size), _format(sprite._format),
25+
_gfx(sprite._gfx), _affineIndex(sprite._affineIndex), _paletteAlpha(sprite._paletteAlpha),
26+
_priority(sprite._priority), _x(sprite._x), _y(sprite._y), _hFlip(sprite._hFlip), _vFlip(sprite._vFlip),
27+
_sizeDouble(sprite._sizeDouble), _visible(sprite._visible) {
2428
activeIds[_top][_id]++;
2529
}
2630

@@ -33,13 +37,22 @@ Sprite::~Sprite() {
3337
}
3438

3539
Sprite &Sprite::operator=(const Sprite &sprite) {
36-
_top = sprite._top;
37-
_oam = sprite._oam;
38-
_id = sprite._id;
39-
_rotId = sprite._rotId;
40-
_visible = sprite._visible;
41-
_size = sprite._size;
42-
_format = sprite._format;
40+
_top = sprite._top;
41+
_oam = sprite._oam;
42+
_id = sprite._id;
43+
_size = sprite._size;
44+
_format = sprite._format;
45+
46+
_gfx = sprite._gfx;
47+
_affineIndex = sprite._affineIndex;
48+
_paletteAlpha = sprite._paletteAlpha;
49+
_priority = sprite._priority;
50+
_x = sprite._x;
51+
_y = sprite._y;
52+
_hFlip = sprite._hFlip;
53+
_vFlip = sprite._vFlip;
54+
_sizeDouble = sprite._sizeDouble;
55+
_visible = sprite._visible;
4356

4457
activeIds[_top][_id]++;
4558

0 commit comments

Comments
 (0)