~ndiddy/libremo

cbb57c68bda7ecf967b262d0046eab31e31943bb — Nathan Misner 2 years ago e27c322
improved makefile, kept working on between level transition
8 files changed, 105 insertions(+), 90 deletions(-)

M .gitignore
M Makefile
M ball.h
M block.cpp
M block.h
M game.cpp
M level.cpp
M level.h
M .gitignore => .gitignore +1 -0
@@ 1,4 1,5 @@
*.o
*.d
*.swp
.DS_Store
.vs/

M Makefile => Makefile +7 -3
@@ 6,8 6,8 @@ TARGET = libremo
SDL2_CFLAGS = $(shell sdl2-config --cflags)
SDL2_LDFLAGS = $(shell sdl2-config --libs)

CFLAGS = -g -std=c11 -Wall -Wvla -Wformat=2 -O0 $(SDL2_CFLAGS)
CXXFLAGS = -g -std=c++20 -Wall -Wvla -O0 $(SDL2_CFLAGS)
CFLAGS = -g -std=c11 -Wall -Wvla -Wformat=2 -O0 -MMD $(SDL2_CFLAGS)
CXXFLAGS = -g -std=c++20 -Wall -Wvla -O0 -MMD $(SDL2_CFLAGS)
LDFLAGS = $(SDL2_LDFLAGS) -lSDL2_image -lm

OBJECTS =	main.o \


@@ 53,13 53,15 @@ OBJECTS =	main.o \
			ymfm_ssg.o \
			ymfm_opn.o

DEPENDS = $(OBJECTS:.o=.d)

all: $(TARGET)

run: $(TARGET)
	./$(TARGET) ../moexconv/out/ ./music

clean:
	rm *.o
	rm *.o *.d

$(TARGET): $(OBJECTS)
	$(CXX) $(CXXFLAGS) -o $@ $(OBJECTS) $(LDFLAGS) 


@@ 69,3 71,5 @@ $(TARGET): $(OBJECTS)

%.o: %.cpp
	$(CXX) -c $(CXXFLAGS) -o $@ $<

-include $(DEPENDS)
\ No newline at end of file

M ball.h => ball.h +1 -1
@@ 58,7 58,7 @@ typedef enum {
    DIR_UP = 0,
    DIR_DOWN,
    DIR_LEFT,
    DIR_RIGHT
    DIR_RIGHT,
} DIRECTION;

class Ball: public SpriteInfo {

M block.cpp => block.cpp +3 -26
@@ 160,37 160,14 @@ int Block::collide(int power) {
    }
}

void Block::setAlpha(int alpha) {
void Block::setAlpha(uint8_t alpha) {
    // small optimization so i can call this function every frame in level.cpp
    if (alpha != this->alpha) {
        SpriteInfo::setAlpha(alpha);
        printf("old: %u new: %u\n", alpha, this->alpha);
        printf("result: %d\n", SDL_SetTextureAlphaMod(texture, alpha));
    }
}

void Block::draw() {
    if (type != INV) {
        if (mode == BLOCK_MODE_NORMAL) {
            texture = blockTextures[type]->texture;
        }
    }
    if (type == INV) {
        // don't draw invisible blocks
        return;
    }
    SpriteInfo spr;

    if (mode == BLOCK_MODE_NORMAL) {
        spr = SpriteInfo(blockTextures[type]->texture, NULL, &blockRect);
    }
    else if (mode == BLOCK_MODE_TUTORIAL) {
        spr = SpriteInfo(tutorialBlockTextures[type]->texture, NULL, &blockRect);
    }
    spr.x = x;
    spr.y = y;
    spr.setAlpha(alpha);
    spr.draw();
}

void Block_Init() {
    blockTextures = Sprite_LoadPak("block.pak");
    tutorialBlockTextures = Sprite_LoadPak("tutorialblock.pak");

M block.h => block.h +2 -3
@@ 66,7 66,7 @@ class Level;

class Block : public SpriteInfo{
public:
    int alpha;
    uint8_t alpha;
    int type;
    int mode;
    Level *parent;


@@ 80,8 80,7 @@ public:
    int shouldBounce(int power);
    int collide(int power);
    // makes the block partially transparent. alpha should be between 0 and 255
    void setAlpha(int alpha);
    void draw();
    void setAlpha(uint8_t alpha);
};

void Block_Init();

M game.cpp => game.cpp +78 -54
@@ 41,6 41,7 @@ typedef enum {
    STATE_GAME_PLAY,
    STATE_GAME_PAUSE,
    STATE_GAME_LOSS,
    STATE_GAME_FADELEVEL,
    STATE_GAME_CENTERSHIP,
    STATE_GAME_FLYUP,
    STATE_GAME_FLYDOWN,


@@ 339,12 340,60 @@ int Game_Playing() {
    return state == STATE_GAME_PLAY;
}

void Game_DrawShip() {
    // if illusion is active, draw those ships back to front
    if (illusion) {
        SpriteInfo illusionSprite = shipSprite;
        int topIndex = illusionCursor - ILLUSION_FRAMEDELAY; // top
        if (topIndex < 0) { topIndex += ILLUSION_ARRLEN; }
        int midIndex = topIndex - ILLUSION_FRAMEDELAY;       // middle
        if (midIndex < 0) { midIndex += ILLUSION_ARRLEN; }
        int botIndex = midIndex - ILLUSION_FRAMEDELAY;       // bottom
        if (botIndex < 0) { botIndex += ILLUSION_ARRLEN; }

        // bottom
        illusionSprite.x = illusionArr[botIndex].x;
        illusionSprite.y = illusionArr[botIndex].y;
        illusionSprite.setAlpha(96);
        illusionSprite.draw();

        // middle
        illusionSprite.x = illusionArr[midIndex].x;
        illusionSprite.y = illusionArr[midIndex].y;
        illusionSprite.setAlpha(128);
        illusionSprite.draw();

        // top
        illusionSprite.x = illusionArr[topIndex].x;
        illusionSprite.y = illusionArr[topIndex].y;
        illusionSprite.setAlpha(160);
        illusionSprite.draw();
        illusionSprite.setAlpha(255);
    }

    shipSprite.draw();
    if (bitShip) {
        Game_BitAnim();
        bitSprite.x = bitLeft;
        bitSprite.y = SHIP_POS + SHIP_YMARGIN;
        bitSprite.draw();
        bitSprite.x = bitRight;
        bitSprite.draw();
    }

    // draw barrels if ship is done animating in
    if (shipSprite.source.y == SHIP_SPRITESHEET_LAST){
        barrelSprite.x = shipSprite.x;
        barrelSprite.y = shipSprite.y + BARREL_YOFFSET;
        barrelSprite.draw();
        barrelSprite.x = shipSprite.x + BARREL_XOFFSET;
        barrelSprite.mirror = SDL_FLIP_HORIZONTAL;
        barrelSprite.draw();
        barrelSprite.mirror = SDL_FLIP_NONE;
    }
}

int Game_Run() {
    // for illusion
    int topIndex = 0;
    int midIndex = 0;
    int botIndex = 0;
    
    float speed;

    switch (state) {


@@ 414,11 463,11 @@ int Game_Run() {
            }
            // calculate array indexes for each trailing ship, as well as "true" shipLeft/shipRight
            if (illusion) {
                topIndex = illusionCursor - ILLUSION_FRAMEDELAY; // top
                int topIndex = illusionCursor - ILLUSION_FRAMEDELAY; // top
                if (topIndex < 0) { topIndex += ILLUSION_ARRLEN; }
                midIndex = topIndex - ILLUSION_FRAMEDELAY;       // middle
                int midIndex = topIndex - ILLUSION_FRAMEDELAY;       // middle
                if (midIndex < 0) { midIndex += ILLUSION_ARRLEN; }
                botIndex = midIndex - ILLUSION_FRAMEDELAY;       // bottom
                int botIndex = midIndex - ILLUSION_FRAMEDELAY;       // bottom
                if (botIndex < 0) { botIndex += ILLUSION_ARRLEN; }
                // left
                shipLeft = MIN(shipLeft, illusionArr[topIndex].x);


@@ 450,7 499,9 @@ int Game_Run() {
                gameLevelNum++;
                // show the "ship flying off the screen" animation
                if (gameLevelNum >= gameLevelMax) {
                    state = STATE_GAME_CENTERSHIP;
                    frames = 0;
                    state = STATE_GAME_FADELEVEL;
                    break;
                }

                // load new level


@@ 501,6 552,18 @@ int Game_Run() {
            }
            break;

        // beginning of "ship flying out"
        case STATE_GAME_FADELEVEL:
            if (frames < 60) {
                frames += Speed_Multiplier();
                gameLevel->setAlpha((uint8_t)((255.0 / 60.0) * (60.0 - frames)));
            }
            else {
                frames = 0;
                state = STATE_GAME_CENTERSHIP;
            }
            break;

        case STATE_GAME_CENTERSHIP:
            if (shipSprite.x < SHIP_STARTX) {
                shipSprite.x += 3;


@@ 657,59 720,20 @@ int Game_Run() {
        gameLevel->disp(); // draw blocks
        Enemy_Run();
        Capsule_Draw();
        Game_DrawShip();
        Ball_Draw(); // draw balls
        Laser_Draw();

        Capsule_FlushRemoveQueue();
        Enemy_FlushRemoveQueue();
        if (state != STATE_GAME_LOSS) {

        // this function will trigger a state change to STATE_GAME_LOSS
        // if there's no balls, so we only want it to run when the game
        // is playing
        if (state == STATE_GAME_PLAY) {
            Ball_FlushRemoveQueue();
        }
        gameLevel->flushRemoveQueue();

        // if illusion is active, draw those ships back to front
        if (illusion) {
            SpriteInfo illusionSprite = shipSprite;
            // bottom
            illusionSprite.x = illusionArr[botIndex].x;
            illusionSprite.y = illusionArr[botIndex].y;
            illusionSprite.setAlpha(96);
            illusionSprite.draw();

            // middle
            illusionSprite.x = illusionArr[midIndex].x;
            illusionSprite.y = illusionArr[midIndex].y;
            illusionSprite.setAlpha(128);
            illusionSprite.draw();

            // top
            illusionSprite.x = illusionArr[topIndex].x;
            illusionSprite.y = illusionArr[topIndex].y;
            illusionSprite.setAlpha(160);
            illusionSprite.draw();
            illusionSprite.setAlpha(255);
        }

        shipSprite.draw();
        if (bitShip) {
            Game_BitAnim();
            bitSprite.x = bitLeft;
            bitSprite.y = SHIP_POS + SHIP_YMARGIN;
            bitSprite.draw();
            bitSprite.x = bitRight;
            bitSprite.draw();
        }

        // draw barrels if ship is done animating in
        if (shipSprite.source.y == SHIP_SPRITESHEET_LAST){
            barrelSprite.x = shipSprite.x;
            barrelSprite.y = shipSprite.y + BARREL_YOFFSET;
            barrelSprite.draw();
            barrelSprite.x = shipSprite.x + BARREL_XOFFSET;
            barrelSprite.mirror = SDL_FLIP_HORIZONTAL;
            barrelSprite.draw();
            barrelSprite.mirror = SDL_FLIP_NONE;
        }
    }
    
    Hud_Disp(score, lives, powerupCursor, turbo);

M level.cpp => level.cpp +8 -0
@@ 224,8 224,16 @@ void Level::animate() {
    }
}

void Level::setAlpha(uint8_t alpha) {
    this->alpha = alpha;
}

void Level::disp() {
    SpriteInfo spr;

    if (alpha == 0) {
        return;
    }
    
    // scroll each row down, then move to the next row until we've put all rows onscreen
    if (rowNum >= 0) {

M level.h => level.h +5 -3
@@ 49,9 49,7 @@ private:
	// where the level is on the screen
	int xPos;
	int yPos;
	// transparency on the level, should be between 0 and 255. Used for fade-outs
	// at the end of a stage
	int alpha;
	uint8_t alpha;
	// how fast the blocks move during animations
	float blockSpeed;
	// mover blocks


@@ 80,6 78,10 @@ public:
	// explode: 1 if we want to add an explosion, capsule, score, etc
	void removeBlock(Block *block, int explode);

	// sets the alpha transparency for the level (used for end-of-level fadeouts).
	// alpha should be between 0 and 255
	void setAlpha(uint8_t alpha);

	// shows level
	void disp();