Starting Mario Editor project
This commit is contained in:
parent
1927b71629
commit
d4991ea3a7
1
mario/.gitignore
vendored
1
mario/.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
sprites
|
||||
*txt
|
||||
mario
|
||||
editor
|
||||
.DS_Store
|
||||
|
@ -16,7 +16,9 @@ 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}
|
||||
COMMON_OBJECTS = blocks.${OBJEXT} global_vars.${OBJEXT} sprites.${OBJEXT} maploader.${OBJEXT}
|
||||
MARIO_OBJECTS = mario.${OBJEXT} mario_visitor.${OBJEXT} ${COMMON_OBJECTS}
|
||||
EDITOR_OBJECTS = editor.${OBJEXT} ${COMMON_OBJECTS}
|
||||
|
||||
ifeq ($(UNAME_S),Linux)
|
||||
MARIO_OBJECTS += libsdlpp.so
|
||||
@ -35,10 +37,14 @@ 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
|
||||
editor: ${EDITOR_OBJECTS} ${SDLLIB}
|
||||
$(CXX) $(CXXFLAGS) -Fe"$@" ${EDITOR_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
|
||||
editor: ${EDITOR_OBJECTS}
|
||||
$(CXX) $(CXXFLAGS) -o $@ $^ ${LDFLAGS} -L $(shell pwd) -lsdlpp
|
||||
endif
|
||||
|
||||
mario.${OBJEXT}: main.cpp ../sdlpp/sdlpp.hpp sprites.hpp
|
||||
@ -53,6 +59,8 @@ maploader.${OBJEXT}: maploader.cpp ../sdlpp/sdlpp.hpp maploader.hpp sprites.hpp
|
||||
$(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $<
|
||||
mario_visitor.${OBJEXT}: mario_visitor.cpp ../sdlpp/sdlpp.hpp mario_visitor.hpp objectids.hpp
|
||||
$(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $<
|
||||
editor.${OBJEXT}: editor.cpp ../sdlpp/sdlpp.hpp sprites.hpp
|
||||
$(CXX) $(CXXFLAGS) -c ${OUTPUTFLAG}$@ $<
|
||||
libsdlpp.so: ../sdlpp
|
||||
$(MAKE) clean -C ../sdlpp
|
||||
$(MAKE) -C ../sdlpp
|
||||
@ -75,6 +83,8 @@ windows_release: ../Release/Tetris
|
||||
|
||||
start:
|
||||
LD_LIBRARY_PATH=$$(pwd) ./mario
|
||||
start_edit:
|
||||
LD_LIBRARY_PATH=$$(pwd) ./editor
|
||||
|
||||
clean:
|
||||
rm -Rf *.${OBJEXT} mario
|
||||
rm -Rf *.${OBJEXT} mario editor
|
||||
|
140
mario/editor.cpp
Normal file
140
mario/editor.cpp
Normal file
@ -0,0 +1,140 @@
|
||||
#include "../sdlpp/sdlpp.hpp"
|
||||
#include "sprites.hpp"
|
||||
#ifdef _WIN32
|
||||
#include "../sdlpp/SDL2/SDL2_framerate.h"
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <SDL2/SDL2_framerate.h>
|
||||
#endif // UNIX
|
||||
|
||||
#include <thread>
|
||||
#include "global_vars.hpp"
|
||||
#include "objectids.hpp"
|
||||
#include "blocks.hpp"
|
||||
#include "maploader.hpp"
|
||||
|
||||
std::shared_ptr< SDLPP::Renderer > renderer = nullptr;
|
||||
bool quit = false;
|
||||
|
||||
void handleKeyDown( SDL_Keycode key, SDLPP::Scene &scene ) {
|
||||
switch ( key ) {
|
||||
case SDLK_ESCAPE:
|
||||
quit = true;
|
||||
break;
|
||||
case SDLK_a:
|
||||
break;
|
||||
case SDLK_d:
|
||||
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:
|
||||
break;
|
||||
case SDLK_d:
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
#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 );
|
||||
BLOCK_SIZE = 1.0 / 20;
|
||||
|
||||
renderer = std::make_shared< SDLPP::Renderer >( w );
|
||||
renderer->setBlendMode( SDL_BLENDMODE_BLEND );
|
||||
|
||||
// prepare global vars
|
||||
g_terrain_texture = std::make_shared< SDLPP::Texture >(
|
||||
renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY );
|
||||
|
||||
auto scene = std::make_shared< SDLPP::Scene >( renderer );
|
||||
auto bg = std::make_shared< SDLPP::RectangleRender >(
|
||||
0, 0, 10, 10, renderer, MARIO_OVERWORLD_COLORKEY, true );
|
||||
bg->setStatic();
|
||||
bg->setId( 1 );
|
||||
scene->addObject( bg );
|
||||
|
||||
loadMap( scene, nullptr, "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 );
|
||||
scene->renderScene();
|
||||
renderer->presentRenderer();
|
||||
frames++;
|
||||
if ( SDL_GetTicks() - base >= 1000 ) {
|
||||
std::cout << "FPS: " << frames << std::endl;
|
||||
frames = 0;
|
||||
base = SDL_GetTicks();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -71,8 +71,8 @@ void loadMap(std::shared_ptr<SDLPP::Scene> &scene, std::shared_ptr<SDLPP::Rectan
|
||||
}
|
||||
if(mario != nullptr) {
|
||||
mario->setPos(mario_x * BLOCK_SIZE, 1 - (rows - mario_y) * BLOCK_SIZE);
|
||||
scene->moveZTop(mario);
|
||||
} else {
|
||||
//createMarioBlock
|
||||
}
|
||||
scene->moveZTop(mario);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "sprites.hpp"
|
||||
|
||||
extern const double BLOCK_SIZE = 0.0625;
|
||||
double BLOCK_SIZE = 1.0 / 16;
|
||||
|
||||
const std::string MARIO_OVERWORLD_COLORKEY = "#93bbec";
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <vector>
|
||||
#include "../sdlpp/sdlpp_vector.hpp"
|
||||
|
||||
extern const double BLOCK_SIZE;
|
||||
extern double BLOCK_SIZE;
|
||||
|
||||
//------------------ COLORS -------------------------
|
||||
extern const std::string MARIO_OVERWORLD_COLORKEY;
|
||||
|
Loading…
Reference in New Issue
Block a user