diff --git a/mario/.gitignore b/mario/.gitignore new file mode 100644 index 0000000..62ad6ab --- /dev/null +++ b/mario/.gitignore @@ -0,0 +1,4 @@ +sprites +*txt +mario +.DS_Store diff --git a/mario/Makefile b/mario/Makefile new file mode 100644 index 0000000..14aa676 --- /dev/null +++ b/mario/Makefile @@ -0,0 +1,80 @@ +PREFIX ?= /usr/local/bin + +ifeq ($(OS),Windows_NT) +UNAME_S := Windows +CXX = cl +CXXFLAGS = -MD -EHsc +OBJEXT = obj +LDFLAGS = +OUTPUTFLAG = -Fo +else +UNAME_S := $(shell uname -s) +CXX ?= g++ +CXXFLAGS = -std=c++14 -Wall -Wextra -pedantic -O2 -DDEBUG -DFEATURE #-g -fsanitize=address +OBJEXT = o +LDFLAGS ?= -lSDL2 -lSDL2_image -lSDL2_gfx -lSDL2_ttf -pthread +OUTPUTFLAG = -o +endif + +MARIO_OBJECTS = mario.${OBJEXT} blocks.${OBJEXT} global_vars.${OBJEXT} sprites.${OBJEXT} maploader.${OBJEXT} mario_visitor.${OBJEXT} + +ifeq ($(UNAME_S),Linux) +MARIO_OBJECTS += libsdlpp.so +endif +ifeq ($(UNAME_S),Darwin) +MARIO_OBJECTS += libsdlpp.dylib +endif +ifeq ($(UNAME_S),Windows) +MARIO_OBJECTS += ../sdlpp/SDL2/SDL2_framerate.c ../sdlpp/SDL2/SDL2_gfxPrimitives.c ../sdlpp/SDL2/SDL2_imageFilter.c ../sdlpp/SDL2/SDL2_rotozoom.c +SDLLIB = libsdlpp.dll +endif + +.PHONY: default +default: mario + +ifeq ($(UNAME_S),Windows) +mario: ${MARIO_OBJECTS} ${SDLLIB} + $(CXX) $(CXXFLAGS) -Fe"$@" ${MARIO_OBJECTS} /link ..\sdlpp\SDL2.lib ..\sdlpp\SDL2_ttf.lib ..\sdlpp\SDL2_image.lib libsdlpp.lib + +else +mario: ${MARIO_OBJECTS} + $(CXX) $(CXXFLAGS) -o $@ $^ ${LDFLAGS} -L $(shell pwd) -lsdlpp +endif + +mario.${OBJEXT}: main.cpp ../sdlpp/sdlpp.hpp sprites.hpp + $(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $< +blocks.${OBJEXT}: blocks.cpp ../sdlpp/sdlpp.hpp blocks.hpp sprites.hpp + $(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $< +global_vars.${OBJEXT}: global_vars.cpp ../sdlpp/sdlpp.hpp global_vars.hpp + $(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $< +sprites.${OBJEXT}: sprites.cpp ../sdlpp/sdlpp.hpp sprites.hpp + $(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $< +maploader.${OBJEXT}: maploader.cpp ../sdlpp/sdlpp.hpp maploader.hpp sprites.hpp blocks.hpp + $(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $< +mario_visitor.${OBJEXT}: mario_visitor.cpp ../sdlpp/sdlpp.hpp mario_visitor.hpp objectids.hpp + $(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $< +libsdlpp.so: ../sdlpp + $(MAKE) clean -C ../sdlpp + $(MAKE) -C ../sdlpp + cp ../sdlpp/libsdlpp.so . + ln -sf libsdlpp.so libsdlpp.so.1 +libsdlpp.dylib: ../sdlpp + $(MAKE) clean -C ../sdlpp + $(MAKE) -C ../sdlpp + cp ../sdlpp/libsdlpp.dylib . +libsdlpp.dll: ../sdlpp + $(MAKE) clean -C ../sdlpp + $(MAKE) -C ../sdlpp + cp ../sdlpp/libsdlpp.dll . + cp ../sdlpp/libsdlpp.lib . + +windows_release: ../Release/Tetris + cp mario.exe testfont.ttf libsdlpp.dll block.png ../Release/Tetris + rm ../Release/Tetris.zip + cd ../Release && zip -r Tetris.zip Tetris + +start: + LD_LIBRARY_PATH=$$(pwd) ./mario + +clean: + rm -Rf *.${OBJEXT} mario diff --git a/mario/blocks.cpp b/mario/blocks.cpp new file mode 100644 index 0000000..58d9f04 --- /dev/null +++ b/mario/blocks.cpp @@ -0,0 +1,65 @@ +#include "blocks.hpp" +#include "global_vars.hpp" +#include "objectids.hpp" +#include "sprites.hpp" +#include + +std::shared_ptr< SDLPP::RectangleRender > +createBlock( std::shared_ptr< SDLPP::Renderer > &renderer, double x, double y, + std::shared_ptr< SDLPP::Texture > &texture, const SDL_Rect &src, + uint64_t id, bool collision = false ) { + auto block = std::make_shared< SDLPP::RectangleRender >( + x, y, BLOCK_SIZE, BLOCK_SIZE, renderer, texture, src ); + block->setId( id ); + block->centerX(); + block->setStatic(); + if ( collision ) + block->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) ); + return block; +} + +SDL_Rect getSourceRectByID(uint64_t id) { + switch(id) { + case FLOOR_OVERWORLD_ID: + return FLOOR_OVERWORLD_SRC; + case HILL_OVERWORLD_INCLINE_ID: + return HILL_OVERWORLD_INCLINE_SRC; + case HILL_OVERWORLD_DECLINE_ID: + return HILL_OVERWORLD_DECLINE_SRC; + case HILL_OVERWORLD_DOTS_RIGHT_ID: + return HILL_OVERWORLD_DOTS_RIGHT_SRC; + case HILL_OVERWORLD_DOTS_LEFT_ID: + return HILL_OVERWORLD_DOTS_LEFT_SRC; + case HILL_OVERWORLD_FILL_ID: + return HILL_OVERWORLD_FILL_SRC; + case HILL_OVERWORLD_TOP_ID: + return HILL_OVERWORLD_TOP_SRC; + case BUSH_OVERWORLD_LEFT_ID: + return BUSH_OVERWORLD_LEFT_SRC; + case BUSH_OVERWORLD_MIDDLE_ID: + return BUSH_OVERWORLD_MIDDLE_SRC; + case BUSH_OVERWORLD_RIGHT_ID: + return BUSH_OVERWORLD_RIGHT_SRC; + case CLOUD_OVERWORLD_LEFT_BOTTOM_ID: + return CLOUD_OVERWORLD_LEFT_BOTTOM_SRC; + case CLOUD_OVERWORLD_MIDDLE_BOTTOM_ID: + return CLOUD_OVERWORLD_MIDDLE_BOTTOM_SRC; + case CLOUD_OVERWORLD_RIGHT_BOTTOM_ID: + return CLOUD_OVERWORLD_RIGHT_BOTTOM_SRC; + case CLOUD_OVERWORLD_LEFT_TOP_ID: + return CLOUD_OVERWORLD_LEFT_TOP_SRC; + case CLOUD_OVERWORLD_MIDDLE_TOP_ID: + return CLOUD_OVERWORLD_MIDDLE_TOP_SRC; + case CLOUD_OVERWORLD_RIGHT_TOP_ID: + return CLOUD_OVERWORLD_RIGHT_TOP_SRC; + } + return {}; +} + +std::shared_ptr createTerrainBlock( uint64_t block_id, std::shared_ptr &renderer, double x, double y, bool collision ) { + return createBlock(renderer, x, y, g_terrain_texture, getSourceRectByID(block_id), block_id, collision); +} + +std::shared_ptr createTerrainBlock( uint64_t block_id, std::shared_ptr &renderer, bool collision ) { + return createTerrainBlock(block_id, renderer, 0, 0, collision); +} diff --git a/mario/blocks.hpp b/mario/blocks.hpp new file mode 100644 index 0000000..101936a --- /dev/null +++ b/mario/blocks.hpp @@ -0,0 +1,10 @@ +#ifndef BLOCKS_H +#define BLOCKS_H + +#include "../sdlpp/sdlpp_rectrenderer.hpp" +#include + +std::shared_ptr createTerrainBlock( uint64_t block_id, std::shared_ptr &renderer, bool collision = false ); +std::shared_ptr createTerrainBlock( uint64_t block_id, std::shared_ptr &renderer, double x, double y, bool collision = false ); + +#endif diff --git a/mario/global_vars.cpp b/mario/global_vars.cpp new file mode 100644 index 0000000..149cd52 --- /dev/null +++ b/mario/global_vars.cpp @@ -0,0 +1,4 @@ +#include "global_vars.hpp" +#include "../sdlpp/sdlpp_texture.hpp" + +std::shared_ptr< SDLPP::Texture > g_terrain_texture{}; diff --git a/mario/global_vars.hpp b/mario/global_vars.hpp new file mode 100644 index 0000000..e551329 --- /dev/null +++ b/mario/global_vars.hpp @@ -0,0 +1,8 @@ +#ifndef GLOBAL_VARS_H +#define GLOBAL_VARS_H + +#include "../sdlpp/sdlpp.hpp" + +extern std::shared_ptr< SDLPP::Texture > g_terrain_texture; + +#endif diff --git a/mario/main.cpp b/mario/main.cpp new file mode 100644 index 0000000..b12912d --- /dev/null +++ b/mario/main.cpp @@ -0,0 +1,205 @@ +#include "../sdlpp/sdlpp.hpp" +#include "sprites.hpp" +#ifdef _WIN32 +#include "../sdlpp/SDL2/SDL2_framerate.h" +#include +#include +#include +#else +#include +#endif // UNIX + +#include +#include "global_vars.hpp" +#include "objectids.hpp" +#include "blocks.hpp" +#include "maploader.hpp" +#include "mario_visitor.hpp" + +#define SIDE_MOVEMENT 0.8 +#define FALL_MOVEMENT 1 + +bool quit = false; +std::shared_ptr mario = nullptr; +std::shared_ptr mario_texture = nullptr; + +void setMarioStanding() { + if(mario->getMovement().getX() == 0) { + mario->pauseAnimation(); +// mario->setTexture(mario_texture, MARIO_STANDING_SRC); + } +} + +void handleKeyDown( SDL_Keycode key, SDLPP::Scene &scene ) { + switch ( key ) { + case SDLK_ESCAPE: + quit = true; + break; + case SDLK_a: + mario->resumeAnimation(); + mario->addMovement( -SIDE_MOVEMENT, 0 ); + break; + case SDLK_d: + mario->resumeAnimation(); + mario->addMovement( SIDE_MOVEMENT, 0 ); + break; + case SDLK_SPACE: + case SDLK_w: + break; + case SDLK_s: + break; + case SDLK_r: + scene.getRenderer().setRenderColiders( + !scene.getRenderer().getRenderColiders() ); + default: + break; + } +} + +void handleKeyUp( SDL_Keycode key ) { + switch ( key ) { + case SDLK_a: + mario->resumeAnimation(); + mario->addMovement( SIDE_MOVEMENT, 0 ); + break; + case SDLK_d: + mario->resumeAnimation(); + mario->addMovement( -SIDE_MOVEMENT, 0 ); + break; + case SDLK_w: + case SDLK_s: + default: + break; + } +} + +void pollEvents( SDLPP::Scene &scene ) { + SDL_Event event; + while ( SDLPP::getSDLEvent( event ) ) { + switch ( event.type ) { + case SDL_QUIT: + quit = true; + break; + case SDL_KEYDOWN: + if ( !event.key.repeat ) + handleKeyDown( event.key.keysym.sym, scene ); + break; + case SDL_KEYUP: + handleKeyUp( event.key.keysym.sym ); + break; + case SDL_WINDOWEVENT: + if ( event.window.event == SDL_WINDOWEVENT_RESIZED ) + scene.updateSizeAndPosition(); + default: + break; + } + } +} + +void doInput( std::shared_ptr< SDLPP::Scene > scene ) { + FPSmanager gFPS; + SDL_initFramerate( &gFPS ); + SDL_setFramerate( &gFPS, 200 ); + while ( true ) { + SDL_framerateDelay( &gFPS ); + pollEvents( *scene ); + scene->updateScene(); + MarioVisitor mv{}; + scene->visitCollisions(*mario, mv); + if(mv.isDead()) { + quit = true; + } + if(!mv.isOnGround()) { + mario->setMovement(mario->getMovement().getX(), FALL_MOVEMENT); + } else { + mario->resetMovementY(); + } + auto playerX = mario->getRect().x; + auto width = scene->getWidth(); + auto rightBarrier = width * 0.7; + auto leftBarrier = width * 0.3; + auto rightmostX = + scene->rightmost()->getRect().x + scene->rightmost()->getRect().w; + auto leftmostX = scene->leftmost()->getRect().x; + scene->moveEverything( + ( playerX > rightBarrier && rightmostX > width ) * + ( rightBarrier - playerX ) / width, + 0 ); + scene->moveEverything( ( playerX < leftBarrier && leftmostX < 0 ) * + ( leftBarrier - playerX ) / width, + 0 ); + } +} + +#ifdef _WIN32 +int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, + PWSTR szCmdLine, int nCmdShow ) { +#else +int main() { +#endif + SDLPP::init(); + SDLPP::Window w( "Mario clone!" ); + w.setResizable( true ); + + auto renderer = std::make_shared< SDLPP::Renderer >( w ); + renderer->setBlendMode( SDL_BLENDMODE_BLEND ); + + // prepare global vars + g_terrain_texture = std::make_shared(renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY); + + auto scene = std::make_shared(renderer); + auto bg = std::make_shared(0,0,10,10,renderer, MARIO_OVERWORLD_COLORKEY, true); + bg->setPermanent(); + bg->setId(1); + scene->addObject(bg); + mario_texture = std::make_shared(renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY); + mario = std::make_shared( + 0, 0, BLOCK_SIZE, BLOCK_SIZE, renderer, mario_texture, MARIO_OVERWORLD_STANDING_SRC); + mario->setAnimationFrames( MARIO_OVERWORLD_WALK_ANIM ); + mario->setId(2); + mario->centerX(); + mario->setAnimationSpeed(12.5); + mario->pauseAnimation(); +// mario->setTexture(mario_texture, MARIO_STANDING_SRC); + mario->setMovement(0, FALL_MOVEMENT); + mario->setMovementSpeed(0.4); + mario->addCollision(SDLPP::RectColider(0.11,0,0.8,1)); + scene->addObject(mario); + + auto defeat = std::make_shared( + 0,1.01,0,0,renderer); + defeat->setId(DEATH_ID); + defeat->centerX(); + defeat->setStatic(); + auto defeatCol = SDLPP::RectColider(-1, 0, -1, -1); + defeatCol.setInfinite(); + defeat->addCollision(defeatCol); + + scene->addObject(defeat); + + loadMap(scene, mario, "testmap.txt", renderer); + + FPSmanager gFPS; + SDL_initFramerate( &gFPS ); + SDL_setFramerate( &gFPS, 60 ); + + auto base = SDL_GetTicks(); + int frames = 0; + std::thread inputThread( doInput, scene ); + inputThread.detach(); + while ( !quit ) { + SDL_PumpEvents(); + SDL_framerateDelay(&gFPS); + setMarioStanding(); + scene->renderScene(); + renderer->presentRenderer(); + frames++; + if ( SDL_GetTicks() - base >= 1000 ) { + std::cout << "FPS: " << frames << std::endl; + frames = 0; + base = SDL_GetTicks(); + } + } + + return 0; +} diff --git a/mario/maploader.cpp b/mario/maploader.cpp new file mode 100644 index 0000000..c260780 --- /dev/null +++ b/mario/maploader.cpp @@ -0,0 +1,74 @@ +#include "maploader.hpp" +#include "../sdlpp/sdlpp_rectrenderer.hpp" +#include +#include "sprites.hpp" +#include "blocks.hpp" +#include "objectids.hpp" + +std::shared_ptr decodeObject( char obj, double x, double y, std::shared_ptr &renderer) { + switch(obj) { + case 'F': + return createTerrainBlock(FLOOR_OVERWORLD_ID, renderer, x, y, true); + case 'I': + return createTerrainBlock(HILL_OVERWORLD_INCLINE_ID, renderer, x, y); + case 'R': + return createTerrainBlock(HILL_OVERWORLD_DOTS_RIGHT_ID, renderer, x, y); + case 'G': + return createTerrainBlock(HILL_OVERWORLD_FILL_ID, renderer, x, y); + case 'L': + return createTerrainBlock(HILL_OVERWORLD_DOTS_LEFT_ID, renderer, x, y); + case 'D': + return createTerrainBlock(HILL_OVERWORLD_DECLINE_ID, renderer, x, y); + case 'T': + return createTerrainBlock(HILL_OVERWORLD_TOP_ID, renderer, x, y); + case 'q': + return createTerrainBlock(BUSH_OVERWORLD_LEFT_ID, renderer, x, y); + case 'w': + return createTerrainBlock(BUSH_OVERWORLD_MIDDLE_ID, renderer, x, y); + case 'r': + return createTerrainBlock(BUSH_OVERWORLD_RIGHT_ID, renderer, x, y); + case 'a': + return createTerrainBlock(CLOUD_OVERWORLD_LEFT_BOTTOM_ID, renderer, x, y); + case 's': + return createTerrainBlock(CLOUD_OVERWORLD_MIDDLE_BOTTOM_ID, renderer, x, y); + case 'd': + return createTerrainBlock(CLOUD_OVERWORLD_RIGHT_BOTTOM_ID, renderer, x, y); + case 'z': + return createTerrainBlock(CLOUD_OVERWORLD_LEFT_TOP_ID, renderer, x, y); + case 'x': + return createTerrainBlock(CLOUD_OVERWORLD_MIDDLE_TOP_ID, renderer, x, y); + case 'c': + return createTerrainBlock(CLOUD_OVERWORLD_RIGHT_TOP_ID, renderer, x, y); + } + return nullptr; +} + +void loadMap(std::shared_ptr &scene, std::shared_ptr &mario, const std::string &file, std::shared_ptr &renderer) { + std::fstream mapFile; + mapFile.open(file, std::ios::in); + std::string buffer; + std::getline(mapFile, buffer); + auto cols = std::stoi(buffer); + std::getline(mapFile, buffer); + auto rows = std::stoi(buffer); + std::getline(mapFile, buffer); + auto mario_x = std::stoi(buffer); + std::getline(mapFile, buffer); + auto mario_y = std::stoi(buffer); + auto cur_y = 1 - rows * BLOCK_SIZE; + for(size_t i = 0; i < rows; i++) { + std::getline(mapFile, buffer); + auto cur_x = -BLOCK_SIZE; + for(size_t j = 0; j < cols; j++) { + cur_x += BLOCK_SIZE; + if(buffer[j] == ' ') + continue; + auto obj = decodeObject(buffer[j], cur_x, cur_y, renderer); + if(obj != nullptr) + scene->addObject(obj); + } + cur_y += BLOCK_SIZE; + } + mario->setPos(mario_x * BLOCK_SIZE, 1 - (rows - mario_y) * BLOCK_SIZE); + scene->moveZTop(mario); +} diff --git a/mario/maploader.hpp b/mario/maploader.hpp new file mode 100644 index 0000000..84e6228 --- /dev/null +++ b/mario/maploader.hpp @@ -0,0 +1,9 @@ +#ifndef MAPLOADER_H +#define MAPLOADER_H + +#include "../sdlpp/sdlpp_scene.hpp" +#include "../sdlpp/sdlpp_rectrenderer.hpp" + +void loadMap(std::shared_ptr &scene, std::shared_ptr &mario, const std::string &file, std::shared_ptr &renderer); + +#endif diff --git a/mario/mario_visitor.cpp b/mario/mario_visitor.cpp new file mode 100644 index 0000000..1874763 --- /dev/null +++ b/mario/mario_visitor.cpp @@ -0,0 +1,17 @@ +#include "mario_visitor.hpp" +#include "../sdlpp/sdlpp_renderobject.hpp" +#include "objectids.hpp" + +void MarioVisitor::visit( const SDLPP::RenderObject &obj ) { + auto id = obj.getId(); + switch(id) { + case FLOOR_OVERWORLD_ID: + onGround = true; + break; + case DEATH_ID: + death = true; + break; + default: + break; + } +} diff --git a/mario/mario_visitor.hpp b/mario/mario_visitor.hpp new file mode 100644 index 0000000..740c3d8 --- /dev/null +++ b/mario/mario_visitor.hpp @@ -0,0 +1,21 @@ +#ifndef MARIO_VISITOR_H +#define MARIO_VISITOR_H + +#include "../sdlpp/sdlpp_visitor.hpp" + +class MarioVisitor : public SDLPP::Visitor { +public: + MarioVisitor() {} + virtual void visit( const SDLPP::RenderObject &obj ); + bool isOnGround() { + return onGround; + } + bool isDead() { + return death; + } +private: + bool onGround = false; + bool death = false; +}; + +#endif diff --git a/mario/objectids.hpp b/mario/objectids.hpp new file mode 100644 index 0000000..86a3625 --- /dev/null +++ b/mario/objectids.hpp @@ -0,0 +1,23 @@ +#ifndef OBJECTIDS_H +#define OBJECTIDS_H + +#define FLOOR_OVERWORLD_ID 0x70000001 +#define HILL_OVERWORLD_INCLINE_ID 0x70000002 +#define HILL_OVERWORLD_DECLINE_ID 0x70000003 +#define HILL_OVERWORLD_DOTS_RIGHT_ID 0x70000004 +#define HILL_OVERWORLD_DOTS_LEFT_ID 0x70000005 +#define HILL_OVERWORLD_FILL_ID 0x70000006 +#define HILL_OVERWORLD_TOP_ID 0x70000007 +#define BUSH_OVERWORLD_LEFT_ID 0x70000008 +#define BUSH_OVERWORLD_MIDDLE_ID 0x70000009 +#define BUSH_OVERWORLD_RIGHT_ID 0x7000000A +#define CLOUD_OVERWORLD_LEFT_BOTTOM_ID 0x7000000B +#define CLOUD_OVERWORLD_MIDDLE_BOTTOM_ID 0x7000000C +#define CLOUD_OVERWORLD_RIGHT_BOTTOM_ID 0x7000000D +#define CLOUD_OVERWORLD_LEFT_TOP_ID 0x7000000E +#define CLOUD_OVERWORLD_MIDDLE_TOP_ID 0x7000000F +#define CLOUD_OVERWORLD_RIGHT_TOP_ID 0x70000010 + +#define DEATH_ID 0x10000001 + +#endif diff --git a/mario/sprites.cpp b/mario/sprites.cpp new file mode 100644 index 0000000..e0ccd41 --- /dev/null +++ b/mario/sprites.cpp @@ -0,0 +1,38 @@ +#include "sprites.hpp" + +extern const double BLOCK_SIZE = 0.0625; + +const std::string MARIO_OVERWORLD_COLORKEY = "#93bbec"; + +const SDL_Rect MARIO_OVERWORLD_STANDING_SRC = { 1, 9, 16, 16 }; +const SDL_Rect MARIO_OVERWORLD_DEATH_SRC = { 22, 9, 16, 16 }; +const std::vector< SDL_Rect > MARIO_OVERWORLD_WALK_ANIM = { { 43, 9, 16, 16 }, + { 60, 9, 16, 16 }, + { 77, 9, 16, 16 } }; +const SDL_Rect MARIO_OVERWORLD_CHANGE_DIR_SRC = { 98, 9, 16, 16 }; +const SDL_Rect MARIO_OVERWORLD_JUMP_SRC = { 119, 9, 16, 16 }; + +const SDL_Rect MARIO_OVERWORLD_STANDING_BIG_SRC = { 1, 26, 16, 32 }; +const SDL_Rect MARIO_OVERWORLD_DEATH_BIG_SRC = { 22, 26, 16, 32 }; +const std::vector< SDL_Rect > MARIO_OVERWORLD_WALK_BIG_ANIM = { + { 43, 26, 16, 32 }, { 60, 9, 16, 32 }, { 77, 9, 16, 32 } +}; +const SDL_Rect MARIO_OVERWORLD_CHANGE_DIR_BIG_SRC = { 98, 26, 16, 32 }; +const SDL_Rect MARIO_OVERWORLD_JUMP_BIG_SRC = { 119, 26, 16, 32 }; + +const SDL_Rect FLOOR_OVERWORLD_SRC = { 1, 131, 16, 16 }; +const SDL_Rect HILL_OVERWORLD_INCLINE_SRC = { 137, 97, 16, 16 }; +const SDL_Rect HILL_OVERWORLD_DECLINE_SRC = { 205, 97, 16, 16 }; +const SDL_Rect HILL_OVERWORLD_FILL_SRC = { 171, 97, 16, 16 }; +const SDL_Rect HILL_OVERWORLD_DOTS_RIGHT_SRC = { 154, 97, 16, 16 }; +const SDL_Rect HILL_OVERWORLD_DOTS_LEFT_SRC = { 188, 97, 16, 16 }; +const SDL_Rect HILL_OVERWORLD_TOP_SRC = { 171, 63, 16, 16 }; +extern const SDL_Rect BUSH_OVERWORLD_LEFT_SRC = {222,97,16,16}; +extern const SDL_Rect BUSH_OVERWORLD_MIDDLE_SRC = {239,97,16,16}; +extern const SDL_Rect BUSH_OVERWORLD_RIGHT_SRC = {256,97,16,16}; +extern const SDL_Rect CLOUD_OVERWORLD_LEFT_BOTTOM_SRC = {222,80,16,16}; +extern const SDL_Rect CLOUD_OVERWORLD_MIDDLE_BOTTOM_SRC = {239,80,16,16}; +extern const SDL_Rect CLOUD_OVERWORLD_RIGHT_BOTTOM_SRC = {256,80,16,16}; +extern const SDL_Rect CLOUD_OVERWORLD_LEFT_TOP_SRC = {222,63,16,16}; +extern const SDL_Rect CLOUD_OVERWORLD_MIDDLE_TOP_SRC = {239,63,16,16}; +extern const SDL_Rect CLOUD_OVERWORLD_RIGHT_TOP_SRC = {256,63,16,16}; diff --git a/mario/sprites.hpp b/mario/sprites.hpp new file mode 100644 index 0000000..cdd8b47 --- /dev/null +++ b/mario/sprites.hpp @@ -0,0 +1,43 @@ +#ifndef SPRITES_H +#define SPRITES_H + +#include +#include +#include + +extern const double BLOCK_SIZE; + +//------------------ OVERWORLD ---------------------- +extern const std::string MARIO_OVERWORLD_COLORKEY; +//------------------ MARIO -------------------------- +extern const SDL_Rect MARIO_OVERWORLD_STANDING_SRC; +extern const SDL_Rect MARIO_OVERWORLD_DEATH_SRC; +extern const std::vector MARIO_OVERWORLD_WALK_ANIM; +extern const SDL_Rect MARIO_OVERWORLD_CHANGE_DIR_SRC; +extern const SDL_Rect MARIO_OVERWORLD_JUMP_SRC; +//------------------ BIG MARIO ---------------------- +extern const SDL_Rect MARIO_OVERWORLD_STANDING_BIG_SRC; +extern const SDL_Rect MARIO_OVERWORLD_DEATH_BIG_SRC; +extern const std::vector MARIO_OVERWORLD_WALK_BIG_ANIM; +extern const SDL_Rect MARIO_OVERWORLD_CHANGE_DIR_BIG_SRC; +extern const SDL_Rect MARIO_OVERWORLD_JUMP_BIG_SRC; + +//------------------ TERRAIN ------------------------ +extern const SDL_Rect FLOOR_OVERWORLD_SRC; +extern const SDL_Rect HILL_OVERWORLD_INCLINE_SRC; +extern const SDL_Rect HILL_OVERWORLD_DECLINE_SRC; +extern const SDL_Rect HILL_OVERWORLD_FILL_SRC; +extern const SDL_Rect HILL_OVERWORLD_DOTS_RIGHT_SRC; +extern const SDL_Rect HILL_OVERWORLD_DOTS_LEFT_SRC; +extern const SDL_Rect HILL_OVERWORLD_TOP_SRC; +extern const SDL_Rect BUSH_OVERWORLD_LEFT_SRC; +extern const SDL_Rect BUSH_OVERWORLD_MIDDLE_SRC; +extern const SDL_Rect BUSH_OVERWORLD_RIGHT_SRC; +extern const SDL_Rect CLOUD_OVERWORLD_LEFT_BOTTOM_SRC; +extern const SDL_Rect CLOUD_OVERWORLD_MIDDLE_BOTTOM_SRC; +extern const SDL_Rect CLOUD_OVERWORLD_RIGHT_BOTTOM_SRC; +extern const SDL_Rect CLOUD_OVERWORLD_LEFT_TOP_SRC; +extern const SDL_Rect CLOUD_OVERWORLD_MIDDLE_TOP_SRC; +extern const SDL_Rect CLOUD_OVERWORLD_RIGHT_TOP_SRC; + +#endif