Sprite toggeling for missiles.

This commit is contained in:
Christian Speckner 2016-12-02 01:11:54 +01:00
parent 042dc72e66
commit 920787aa9f
4 changed files with 96 additions and 16 deletions

View File

@ -28,7 +28,9 @@ namespace TIA6502tsCore {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Missile::Missile(uInt32 collisionMask)
: myCollisionMask(collisionMask)
: myCollisionMaskDisabled(collisionMask),
myCollisionMaskEnabled(0x8000),
mySupressed(false)
{
reset();
}
@ -47,14 +49,14 @@ void Missile::reset()
myIsRendering = false;
myRenderCounter = 0;
myColor = 0;
collision = myCollisionMask;
collision = myCollisionMaskDisabled;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Missile::enam(uInt8 value)
{
myEnam = (value & 0x02) > 0;
myEnabled = myEnam && (myResmp == 0);
updateEnabled();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -78,12 +80,21 @@ void Missile::resmp(uInt8 value, const Player& player)
myResmp = resmp;
if (myResmp) {
myEnabled = false;
} else {
myEnabled = myEnam;
myCounter = player.getRespClock();
}
if (!myResmp) myCounter = player.getRespClock();
updateEnabled();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Missile::toggleCollisions(bool enabled)
{
myCollisionMaskEnabled = enabled ? 0x8000 : (0x8000 | myCollisionMaskDisabled);
}
void Missile::toggleEnabled(bool enabled)
{
mySupressed = !enabled;
updateEnabled();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -120,7 +131,9 @@ bool Missile::movementTick(uInt32 clock, bool apply)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Missile::render()
{
collision = (myIsRendering && myRenderCounter >= 0 && myEnabled) ? 0 : myCollisionMask;
collision = (myIsRendering && myRenderCounter >= 0 && myEnabled) ?
myCollisionMaskEnabled :
myCollisionMaskDisabled;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -142,6 +155,12 @@ void Missile::setColor(uInt8 color)
myColor = color;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Missile::updateEnabled()
{
myEnabled = !mySupressed && myEnam && !myResmp;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// TODO: implement this once the class is finalized
bool Missile::save(Serializer& out) const

View File

@ -55,8 +55,12 @@ class Missile : public Serializable
void setColor(uInt8 color);
void toggleCollisions(bool enabled);
void toggleEnabled(bool enabled);
uInt8 getPixel(uInt8 colorIn) const {
return collision ? colorIn : myColor;
return (collision & 0x8000) ? myColor : colorIn;
}
/**
@ -72,9 +76,15 @@ class Missile : public Serializable
private:
uInt32 myCollisionMask;
void updateEnabled();
private:
uInt32 myCollisionMaskDisabled;
uInt32 myCollisionMaskEnabled;
bool myEnabled;
bool mySupressed;
bool myEnam;
uInt8 myResmp;

View File

@ -56,6 +56,8 @@ TIA::TIA(Console& console, Sound& sound, Settings& settings)
mySound(sound),
mySettings(settings),
myDelayQueue(10, 20),
mySpriteEnabledBits(0xFF),
myCollisionsEnabledBits(0xFF),
myPlayfield(CollisionMask::playfield),
myMissile0(CollisionMask::missile0),
myMissile1(CollisionMask::missile1),
@ -650,28 +652,74 @@ bool TIA::scanlinePos(uInt16& x, uInt16& y) const
// TODO: stub
bool TIA::toggleBit(TIABit b, uInt8 mode)
{
return false;
uInt8 mask;
switch (mode) {
case 0:
mask = 0;
break;
case 1:
mask = b;
break;
default:
mask = (~mySpriteEnabledBits & b);
break;
}
mySpriteEnabledBits = (mySpriteEnabledBits & ~b) | mask;
myMissile0.toggleEnabled(mySpriteEnabledBits & TIABit::M0Bit);
myMissile1.toggleEnabled(mySpriteEnabledBits & TIABit::M1Bit);
return mask;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// TODO: stub
bool TIA::toggleBits()
{
return false;
toggleBit(TIABit(0xFF), mySpriteEnabledBits > 0 ? 0 : 1);
return mySpriteEnabledBits;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// TODO: stub
bool TIA::toggleCollision(TIABit b, uInt8 mode)
{
return false;
uInt8 mask;
switch (mode) {
case 0:
mask = 0;
break;
case 1:
mask = b;
break;
default:
mask = (~myCollisionsEnabledBits & b);
break;
}
myCollisionsEnabledBits = (myCollisionsEnabledBits & ~b) | mask;
myMissile0.toggleCollisions(myCollisionsEnabledBits & TIABit::M0Bit);
myMissile1.toggleCollisions(myCollisionsEnabledBits & TIABit::M1Bit);
return mask;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// TODO: stub
bool TIA::toggleCollisions()
{
return false;
toggleCollision(TIABit(0xFF), myCollisionsEnabledBits > 0 ? 0 : 1);
return myCollisionsEnabledBits;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -210,6 +210,9 @@ class TIA : public AbstractTIA
uInt8 mySubClock;
uInt32 myLastCycle;
uInt8 mySpriteEnabledBits;
uInt8 myCollisionsEnabledBits;
uInt8 myColorBk;
double myTimestamp;