Skip to content

Commit

Permalink
Replaced the raw block type with a modern enum
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatyas committed Mar 29, 2024
1 parent ce4f952 commit f9794b5
Show file tree
Hide file tree
Showing 15 changed files with 262 additions and 302 deletions.
31 changes: 14 additions & 17 deletions src/common/BlockTypes.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
#ifndef BLOCKTYPES_H
#define BLOCKTYPES_H
#pragma once

enum BlockType {
block_none,
block_powerup,
block_view,
block_breakable,
block_note,
block_donut,
block_flip,
block_bounce,
block_throw,
block_onoff_switch,
block_onoff,
block_weaponbreakable
enum class BlockType: unsigned char {
None,
Powerup,
View,
Breakable,
Note,
Donut,
Flip,
Bounce,
Throw,
OnOffSwitch,
OnOff,
WeaponBreakable,
};

#endif // BLOCKTYPES_H
2 changes: 1 addition & 1 deletion src/common/IO_Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class IO_Block : public CObject
virtual bool collide(CPlayer * player, short direction, bool useBehavior);
virtual bool collide(IO_MovingObject * object, short direction);

virtual BlockType getBlockType() = 0;
virtual BlockType getBlockType() const = 0;

virtual bool isTransparent() {
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/smw/objectgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ void MO_Hammer::update()
IO_Block * blocks[4];
GetCollisionBlocks(blocks);
for (short iBlock = 0; iBlock < 4; iBlock++) {
if (blocks[iBlock] && blocks[iBlock]->getBlockType() == block_weaponbreakable) {
if (blocks[iBlock] && blocks[iBlock]->getBlockType() == BlockType::WeaponBreakable) {
B_WeaponBreakableBlock * weaponbreakableblock = (B_WeaponBreakableBlock*)blocks[iBlock];
if (weaponbreakableblock->iType == 5) {
weaponbreakableblock->triggerBehavior(iPlayerID, iTeamID);
Expand Down Expand Up @@ -1743,7 +1743,7 @@ void MO_Boomerang::update()
IO_Block * blocks[4];
GetCollisionBlocks(blocks);
for (short iBlock = 0; iBlock < 4; iBlock++) {
if (blocks[iBlock] && blocks[iBlock]->getBlockType() == block_weaponbreakable) {
if (blocks[iBlock] && blocks[iBlock]->getBlockType() == BlockType::WeaponBreakable) {
B_WeaponBreakableBlock * weaponbreakableblock = (B_WeaponBreakableBlock*)blocks[iBlock];
if (weaponbreakableblock->iType == 4) {
weaponbreakableblock->triggerBehavior(iPlayerID, iTeamID);
Expand Down
2 changes: 1 addition & 1 deletion src/smw/objecthazard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ void MO_Explosion::update()
short iTestRow = iTestY / TILESIZE;
for (short iCol = 0; iCol < 7; iCol++) {
IO_Block * block = g_map->block(iTestX / TILESIZE, iTestRow);
if (block && block->getBlockType() == block_weaponbreakable) {
if (block && block->getBlockType() == BlockType::WeaponBreakable) {
B_WeaponBreakableBlock * weaponbreakableblock = (B_WeaponBreakableBlock*)block;
if (weaponbreakableblock->iType == 3) {
weaponbreakableblock->triggerBehavior(iPlayerID, iTeamID);
Expand Down
37 changes: 17 additions & 20 deletions src/smw/objects/blocks/BounceBlock.h
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
#ifndef SMW_GAMEOBJECT_BLOCK_BOUNCE_H
#define SMW_GAMEOBJECT_BLOCK_BOUNCE_H
#pragma once

#include "IO_Block.h"

class B_BounceBlock : public IO_Block
{
public:
B_BounceBlock(gfxSprite *nspr, short x, short y, bool fHidden);
~B_BounceBlock(){};

BlockType getBlockType() {
return block_bounce;
class B_BounceBlock : public IO_Block {
public:
B_BounceBlock(gfxSprite *nspr, short x, short y, bool fHidden);
~B_BounceBlock(){};

BlockType getBlockType() const override {
return BlockType::Bounce;
}

void update();
void draw();
void reset();
void update();
void draw();
void reset();

bool collide(CPlayer * player, short direction, bool useBehavior);
bool collide(IO_MovingObject * object, short direction);
bool collide(CPlayer * player, short direction, bool useBehavior);
bool collide(IO_MovingObject * object, short direction);

bool hittop(CPlayer * player, bool useBehavior);
bool hitbottom(CPlayer * player, bool useBehavior);
bool hittop(CPlayer * player, bool useBehavior);
bool hitbottom(CPlayer * player, bool useBehavior);

bool hittop(IO_MovingObject * object);
bool hittop(IO_MovingObject * object);

void triggerBehavior();
void triggerBehavior();
};

#endif // SMW_GAMEOBJECT_BLOCK_BOUNCE_H
47 changes: 22 additions & 25 deletions src/smw/objects/blocks/BreakableBlock.h
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
#ifndef SMW_GAMEOBJECT_BLOCK_BREAKABLE_H
#define SMW_GAMEOBJECT_BLOCK_BREAKABLE_H
#pragma once

#include "IO_Block.h"

class gfxSprite;
class CPlayer;
class IO_MovingObject;

class B_BreakableBlock : public IO_Block
{
public:
B_BreakableBlock(gfxSprite *nspr, short x, short y, short iNumSpr, short aniSpeed);
~B_BreakableBlock(){};

BlockType getBlockType() {
return block_breakable;
class B_BreakableBlock : public IO_Block {
public:
B_BreakableBlock(gfxSprite *nspr, short x, short y, short iNumSpr, short aniSpeed);
~B_BreakableBlock(){};

BlockType getBlockType() const override {
return BlockType::Breakable;
}

void draw();
void update();
void draw();
void update();

bool hittop(CPlayer * player, bool useBehavior);
bool hitbottom(CPlayer * player, bool useBehavior);
bool hittop(CPlayer * player, bool useBehavior);
bool hitbottom(CPlayer * player, bool useBehavior);

bool hittop(IO_MovingObject * object);
bool hitright(IO_MovingObject * object);
bool hitleft(IO_MovingObject * object);
bool hittop(IO_MovingObject * object);
bool hitright(IO_MovingObject * object);
bool hitleft(IO_MovingObject * object);

void triggerBehavior();
void triggerBehavior();

private:
short iNumSprites;
short animationSpeed;
short drawFrame;
short animationTimer;
short animationWidth;
private:
short iNumSprites;
short animationSpeed;
short drawFrame;
short animationTimer;
short animationWidth;
};

#endif // SMW_GAMEOBJECT_BLOCK_BREAKABLE_H
34 changes: 15 additions & 19 deletions src/smw/objects/blocks/DonutBlock.h
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
#ifndef SMW_GAMEOBJECT_BLOCK_B_DONUT_H
#define SMW_GAMEOBJECT_BLOCK_B_DONUT_H
#pragma once

#include "IO_Block.h"

class B_DonutBlock : public IO_Block
{
public:
B_DonutBlock(gfxSprite *nspr, short x, short y);
~B_DonutBlock(){};
class B_DonutBlock : public IO_Block {
public:
B_DonutBlock(gfxSprite *nspr, short x, short y);
~B_DonutBlock(){};

BlockType getBlockType() {
return block_donut;
BlockType getBlockType() const override {
return BlockType::Donut;
}

void draw();
void update();
void draw();
void update();

bool hittop(CPlayer * player, bool useBehavior);
bool hittop(CPlayer * player, bool useBehavior);

void triggerBehavior(short iPlayerId);
void triggerBehavior(short iPlayerId);

private:
short counter;
short jigglex;
short jigglecounter;
private:
short counter;
short jigglex;
short jigglecounter;
};

#endif // SMW_GAMEOBJECT_BLOCK_B_DONUT_H
59 changes: 27 additions & 32 deletions src/smw/objects/blocks/FlipBlock.h
Original file line number Diff line number Diff line change
@@ -1,49 +1,44 @@
#ifndef SMW_GAMEOBJECT_BLOCK_FLIP_H
#define SMW_GAMEOBJECT_BLOCK_FLIP_H
#pragma once

#include "IO_Block.h"

class B_FlipBlock : public IO_Block
{
public:
B_FlipBlock(gfxSprite *nspr, short x, short y, bool fHidden);
~B_FlipBlock(){};
class B_FlipBlock : public IO_Block {
public:
B_FlipBlock(gfxSprite *nspr, short x, short y, bool fHidden);
~B_FlipBlock(){};

BlockType getBlockType() {
return block_flip;
BlockType getBlockType() const override {
return BlockType::Flip;
}

void draw();
void update();
void reset();
void draw();
void update();
void reset();

bool collide(CPlayer * player, short direction, bool useBehavior);
bool collide(IO_MovingObject * object, short direction);
bool collide(CPlayer * player, short direction, bool useBehavior);
bool collide(IO_MovingObject * object, short direction);

bool isTransparent() {
return state == 1;
}

bool hittop(CPlayer * player, bool useBehavior);
bool hitbottom(CPlayer * player, bool useBehavior);
bool hitright(CPlayer * player, bool useBehavior);
bool hitleft(CPlayer * player, bool useBehavior);
bool hittop(CPlayer * player, bool useBehavior);
bool hitbottom(CPlayer * player, bool useBehavior);
bool hitright(CPlayer * player, bool useBehavior);
bool hitleft(CPlayer * player, bool useBehavior);

bool hittop(IO_MovingObject * object);
bool hitbottom(IO_MovingObject * object);
bool hitright(IO_MovingObject * object);
bool hitleft(IO_MovingObject * object);
bool hittop(IO_MovingObject * object);
bool hitbottom(IO_MovingObject * object);
bool hitright(IO_MovingObject * object);
bool hitleft(IO_MovingObject * object);

void triggerBehavior();
void triggerBehavior();

private:
private:
void explode();

void explode();

short counter;
short frame;
short timer;
short animationWidth;
short counter;
short frame;
short timer;
short animationWidth;
};

#endif // SMW_GAMEOBJECT_BLOCK_FLIP_H
54 changes: 25 additions & 29 deletions src/smw/objects/blocks/NoteBlock.h
Original file line number Diff line number Diff line change
@@ -1,40 +1,36 @@
#ifndef SMW_GAMEOBJECT_BLOCK_NOTE_H
#define SMW_GAMEOBJECT_BLOCK_NOTE_H
#pragma once

#include "IO_Block.h"

class B_NoteBlock : public IO_Block
{
public:
B_NoteBlock(gfxSprite *nspr, short x, short y, short iNumSpr, short aniSpeed, short type, bool fHidden);
~B_NoteBlock(){};
class B_NoteBlock : public IO_Block {
public:
B_NoteBlock(gfxSprite *nspr, short x, short y, short iNumSpr, short aniSpeed, short type, bool fHidden);
~B_NoteBlock(){};

BlockType getBlockType() {
return block_note;
BlockType getBlockType() const override {
return BlockType::Note;
}

void draw();
void update();
void reset();
void draw();
void update();
void reset();

bool collide(CPlayer * player, short direction, bool useBehavior);
bool collide(IO_MovingObject * object, short direction);
bool collide(CPlayer * player, short direction, bool useBehavior);
bool collide(IO_MovingObject * object, short direction);

bool hittop(CPlayer * player, bool useBehavior);
bool hitbottom(CPlayer * player, bool useBehavior);
bool hitright(CPlayer * player, bool useBehavior);
bool hitleft(CPlayer * player, bool useBehavior);
bool hittop(CPlayer * player, bool useBehavior);
bool hitbottom(CPlayer * player, bool useBehavior);
bool hitright(CPlayer * player, bool useBehavior);
bool hitleft(CPlayer * player, bool useBehavior);

bool hittop(IO_MovingObject * object);
bool hittop(IO_MovingObject * object);

private:
short iNumSprites;
short animationSpeed;
short drawFrame;
short animationTimer;
short animationWidth;
short iType;
short iTypeOffsetY;
private:
short iNumSprites;
short animationSpeed;
short drawFrame;
short animationTimer;
short animationWidth;
short iType;
short iTypeOffsetY;
};

#endif // SMW_GAMEOBJECT_BLOCK_NOTE_H
Loading

0 comments on commit f9794b5

Please sign in to comment.