Skip to content

Commit

Permalink
Add Flag object
Browse files Browse the repository at this point in the history
It is only partially implemented yet
  • Loading branch information
enginmanap committed Apr 24, 2019
1 parent 4ddf1c1 commit ea13108
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ENDIF()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wnon-virtual-dtor -pedantic ${CMAKE_APPLE_FLAGS} ${CMAKE_WIN32_FLAGS}")

set(SOURCE_FILES src/main.cpp src/Objects/Mario.cpp src/Objects/Mario.h src/Utils.h src/Constants.h src/AABB.cpp src/AABB.h src/Objects/Brick.h src/Objects/CoinBox.h src/World.cpp src/World.h src/Objects/InteractiveObject.h src/Objects/Coin.cpp src/Objects/Coin.h src/Context.cpp src/Context.h src/Objects/CoinBox.cpp src/Objects/Goomba.cpp src/Objects/MushroomBox.cpp src/Objects/Mushroom.cpp src/Objects/HiddenCoinBox.cpp src/Objects/HiddenCoinBox.h src/Objects/Flower.cpp src/Objects/Fireball.cpp src/Objects/Koopa.cpp src/Objects/BoxBase.cpp src/Objects/BoxBase.h src/Objects/Star.cpp src/Objects/StarBrick.h src/HUD.cpp src/Objects/AnimatedScore.cpp src/InputHandler.cpp src/InputHandler.h)
set(SOURCE_FILES src/main.cpp src/Objects/Mario.cpp src/Objects/Mario.h src/Utils.h src/Constants.h src/AABB.cpp src/AABB.h src/Objects/Brick.h src/Objects/CoinBox.h src/World.cpp src/World.h src/Objects/InteractiveObject.h src/Objects/Coin.cpp src/Objects/Coin.h src/Context.cpp src/Context.h src/Objects/CoinBox.cpp src/Objects/Goomba.cpp src/Objects/MushroomBox.cpp src/Objects/Mushroom.cpp src/Objects/HiddenCoinBox.cpp src/Objects/HiddenCoinBox.h src/Objects/Flower.cpp src/Objects/Fireball.cpp src/Objects/Koopa.cpp src/Objects/BoxBase.cpp src/Objects/BoxBase.h src/Objects/Star.cpp src/Objects/StarBrick.h src/HUD.cpp src/Objects/AnimatedScore.cpp src/InputHandler.cpp src/InputHandler.h src/Objects/Flag.cpp src/Objects/Flag.h)
add_executable(mario ${SOURCE_FILES})


Expand Down
Binary file added res/flag/Flag.bmp
Binary file not shown.
Binary file modified res/levels/0101_bg.bmp
Binary file not shown.
4 changes: 2 additions & 2 deletions res/levels/0101_logic.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000G000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000B0B00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000400000000000000000000000000000000000000000000000000000000033333333000333400000000000000500000000000333000034430000000000000000000000000000000000000000000000000000000011000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111000000000000000000000000000000000
Expand All @@ -10,7 +10,7 @@
0000000000000000400035343000000000000000000000770000000009900000000000000000035300000000000000F000003w0000400400400000300000000003300000010010000000000110010000000000003343000000000000111111000000000000000000000000000000000
0000000000000000000000000000000000000077000000770000000009900000000000000000000000000000000000000000000000000000000000000000000000000000110011000000001110011000000000000000000000000001111111000000000000000000000000000000000
0000000000000000000000000000770000000077000000770000000009900000000000000000000000000000000000000000000000000000000000000000000000000001110011100000011110011100000770000000000000077011111111000000000000000000000000000000000
00z0000000000000000000B00000770000000077B0000077000B0B0009900000000000000000000000000000000000000B0B0000000C000000B0B0000000B0B0B0B0001111001111000011111001111000077000000000B0B0077111111111000000000000000000000000000000000
00z0000000000000000000B00000770000000077B0000077000B0B0009900000000000000000000000000000000000000B0B0000000C000000B0B0000000B0B0B0B0001111001111000011111001111000077000000000B0B0077111111111000000001000000000000000000000000
1111111111111111111111111111111111111111111111111111111111111111111110011111111111111100011111111111111111111111111111111111111111111111111111111111111110011111111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111111110011111111111111100011111111111111111111111111111111111111111111111111111111111111110011111111111111111111111111111111111111111111111111111111111111111111
[[Portals]]
Expand Down
2 changes: 2 additions & 0 deletions src/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
enum TileTypes {EMPTY = 0, GROUND = 1, COIN_TAKEN = 2, BRICK = 3, COIN_BOX=4, MUSHROOM_BOX=5, HIDDEN_MUSHROOM=6, PIPE_EMPTY=7,
PIPE_PORTAL=8, PIPE_ENEMY=9, FLOWER = 10, PIPE_ENEMY_PORTAL=17, GOOMBA=18, KOOPA=19, OUT_OF_MAP=20, MUSHROOM=21, HIDDEN_COIN_BOX=22,
// A B C D E F
FLAG = 23,
// G
COIN=69, TIME=70, STAR_BRICK=71, STAR=72, FIREBALL=73, PLAYER=74, };
// u v w x y z

Expand Down
45 changes: 45 additions & 0 deletions src/Objects/Flag.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// Created by engin on 24.04.2019.
//

#include "Flag.h"
#include "../Utils.h"


Flag::Flag(SDL_Renderer *ren, int x, int y) {
collisionBox = new AABB(
x * TILE_SIZE - TILE_SIZE, // 2 tiles width
x * TILE_SIZE + TILE_SIZE -1,
y * TILE_SIZE,
y * TILE_SIZE + TILE_SIZE -1); //-1 because 32 is not part of box. pixels 0 - TILE_SIZE, TILE_SIZE excluded


std::string flagImage = Utils::getResourcePath("flag") + "flag.bmp";
texture = Utils::loadTexture(ren, flagImage);

}

Flag::~Flag() {
SDL_DestroyTexture(texture);
delete(collisionBox);
}
void Flag::render(SDL_Renderer *renderer, int x, int y, long time) {
SDL_Rect screenPos;
screenPos.x = collisionBox->getLeftBorder() - x;
screenPos.y = collisionBox->getUpBorder() - y;
screenPos.w = TILE_SIZE * 2;
screenPos.h = TILE_SIZE;
SDL_RendererFlip flip = SDL_FLIP_NONE;
SDL_RenderCopyEx(renderer, getTexture(time), nullptr, &screenPos, 0, nullptr, flip);
}

TileTypes Flag::interactWithSide(std::shared_ptr<Context> context, std::shared_ptr<InteractiveObject> otherObject,
CollisionSide interactionSide, long time) {
return EMPTY;
}

void Flag::step(std::shared_ptr<Context> context, long time) {

}


46 changes: 46 additions & 0 deletions src/Objects/Flag.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Created by engin on 24.04.2019.
//

#ifndef MARIO_FLAG_H
#define MARIO_FLAG_H


#include "InteractiveObject.h"

class Flag : public InteractiveObject {
AABB* collisionBox;
SDL_Texture * texture;

public:

Flag(SDL_Renderer *ren, int x, int y);

~Flag();

AABB *getPosition() const override {
return collisionBox;
}

SDL_Texture *getTexture(long time) const override {
return texture;
}

TileTypes getTileType() const override {
return TileTypes::FLAG;
}

void render(SDL_Renderer *renderer, int x, int y, long time) override;

TileTypes interactWithSide(std::shared_ptr<Context> context, std::shared_ptr<InteractiveObject> otherObject,
CollisionSide interactionSide, long time) override;

void step(std::shared_ptr<Context> context, long time) override;

bool waitingForDestroy() const override {
return false;
}
};


#endif //MARIO_FLAG_H
9 changes: 9 additions & 0 deletions src/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "Objects/StarBrick.h"
#include "Objects/HiddenCoinBox.h"
#include "InputHandler.h"
#include "Objects/Flag.h"

TileTypes World::collide(int rightSpeed, int downSpeed, long time, std::shared_ptr<Context> context,
std::shared_ptr<InteractiveObject> interactiveObject) {
Expand Down Expand Up @@ -412,6 +413,14 @@ void World::load(std::string worldName, int &error, Mix_Music *&music) {
coinPos = getAndRemoveObject(TileTypes::COIN);
}

std::shared_ptr<Flag> flag;
SDL_Rect flagPos = getAndRemoveObject(TileTypes::FLAG);
while (flagPos.x != -1 && flagPos.y != -1) {
flag = std::make_shared<Flag>(ren, flagPos.x, flagPos.y);
addObject(flag);
flagPos = getAndRemoveObject(TileTypes::FLAG);
}

error = 0;
}

Expand Down

0 comments on commit ea13108

Please sign in to comment.