Initial commit
This commit is contained in:
commit
294fd6e2ac
165
.cproject
Normal file
165
.cproject
Normal file
@ -0,0 +1,165 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
|
||||
<storageModule moduleId="org.eclipse.cdt.core.settings">
|
||||
<cconfiguration id="cdt.managedbuild.config.gnu.exe.debug.1767279125">
|
||||
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.debug.1767279125" moduleId="org.eclipse.cdt.core.settings" name="Debug">
|
||||
<externalSettings/>
|
||||
<extensions>
|
||||
<extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
</extensions>
|
||||
</storageModule>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.debug.1767279125" name="Debug" parent="cdt.managedbuild.config.gnu.exe.debug">
|
||||
<folderInfo id="cdt.managedbuild.config.gnu.exe.debug.1767279125." name="/" resourcePath="">
|
||||
<toolChain id="cdt.managedbuild.toolchain.gnu.exe.debug.263074825" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.debug">
|
||||
<targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.debug.361182110" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.debug"/>
|
||||
<builder buildPath="${workspace_loc:/Farmlands}/Debug" id="cdt.managedbuild.target.gnu.builder.exe.debug.756240966" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.debug"/>
|
||||
<tool id="cdt.managedbuild.tool.gnu.archiver.base.1607221000" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
|
||||
<tool command="g++" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.1808198807" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug">
|
||||
<option id="gnu.cpp.compiler.exe.debug.option.optimization.level.593370343" name="Optimization Level" superClass="gnu.cpp.compiler.exe.debug.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
|
||||
<option id="gnu.cpp.compiler.exe.debug.option.debugging.level.1975874858" name="Debug Level" superClass="gnu.cpp.compiler.exe.debug.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
|
||||
<option id="gnu.cpp.compiler.option.dialect.std.2087263669" name="Language standard" superClass="gnu.cpp.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.cpp.compiler.dialect.c++11" valueType="enumerated"/>
|
||||
<option id="gnu.cpp.compiler.option.preprocessor.def.954705469" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" useByScannerDiscovery="false"/>
|
||||
<option id="gnu.cpp.compiler.option.include.paths.1179839838" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/Farmlands/src}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/Farmlands/import/include}""/>
|
||||
</option>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1411957018" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
|
||||
</tool>
|
||||
<tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.debug.2048141090" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.debug">
|
||||
<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.exe.debug.option.optimization.level.343035103" name="Optimization Level" superClass="gnu.c.compiler.exe.debug.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
|
||||
<option id="gnu.c.compiler.exe.debug.option.debugging.level.1227887016" name="Debug Level" superClass="gnu.c.compiler.exe.debug.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.max" valueType="enumerated"/>
|
||||
<option id="gnu.c.compiler.option.dialect.std.1347456933" name="Language standard" superClass="gnu.c.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.c.compiler.dialect.c99" valueType="enumerated"/>
|
||||
<option id="gnu.c.compiler.option.include.paths.1506817800" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/Farmlands/src}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/Farmlands/import/include}""/>
|
||||
</option>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1905365757" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
|
||||
</tool>
|
||||
<tool id="cdt.managedbuild.tool.gnu.c.linker.exe.debug.1471902586" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.debug"/>
|
||||
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug.1826221303" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug">
|
||||
<option id="gnu.cpp.link.option.libs.656941493" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" useByScannerDiscovery="false" valueType="libs">
|
||||
<listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="SDL2"/>
|
||||
<listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="SDL2_ttf"/>
|
||||
<listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="SDL2_image"/>
|
||||
</option>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.753606673" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
|
||||
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
|
||||
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
|
||||
</inputType>
|
||||
</tool>
|
||||
<tool id="cdt.managedbuild.tool.gnu.assembler.exe.debug.103646753" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.exe.debug">
|
||||
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.168810547" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
|
||||
</tool>
|
||||
</toolChain>
|
||||
</folderInfo>
|
||||
<sourceEntries>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
|
||||
</sourceEntries>
|
||||
</configuration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
||||
</cconfiguration>
|
||||
<cconfiguration id="cdt.managedbuild.config.gnu.exe.release.1609929883">
|
||||
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.release.1609929883" moduleId="org.eclipse.cdt.core.settings" name="Release">
|
||||
<externalSettings/>
|
||||
<extensions>
|
||||
<extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
|
||||
</extensions>
|
||||
</storageModule>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.release.1609929883" name="Release" parent="cdt.managedbuild.config.gnu.exe.release">
|
||||
<folderInfo id="cdt.managedbuild.config.gnu.exe.release.1609929883." name="/" resourcePath="">
|
||||
<toolChain id="cdt.managedbuild.toolchain.gnu.exe.release.2003855563" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.release">
|
||||
<targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.release.2010013881" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.release"/>
|
||||
<builder buildPath="${workspace_loc:/Farmlands}/Release" id="cdt.managedbuild.target.gnu.builder.exe.release.1908151018" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.release"/>
|
||||
<tool id="cdt.managedbuild.tool.gnu.archiver.base.1727165317" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
|
||||
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.1249722811" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release">
|
||||
<option id="gnu.cpp.compiler.exe.release.option.optimization.level.1342166702" name="Optimization Level" superClass="gnu.cpp.compiler.exe.release.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
|
||||
<option id="gnu.cpp.compiler.exe.release.option.debugging.level.1515472655" name="Debug Level" superClass="gnu.cpp.compiler.exe.release.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/>
|
||||
<option id="gnu.cpp.compiler.option.dialect.std.1039507910" name="Language standard" superClass="gnu.cpp.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.cpp.compiler.dialect.c++11" valueType="enumerated"/>
|
||||
<option id="gnu.cpp.compiler.option.preprocessor.def.317772284" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" useByScannerDiscovery="false"/>
|
||||
<option id="gnu.cpp.compiler.option.include.paths.664997027" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/Farmlands/src}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/Farmlands/import/include}""/>
|
||||
</option>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1719824945" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
|
||||
</tool>
|
||||
<tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.release.495054087" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.release">
|
||||
<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.exe.release.option.optimization.level.450963560" name="Optimization Level" superClass="gnu.c.compiler.exe.release.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
|
||||
<option id="gnu.c.compiler.exe.release.option.debugging.level.696568339" name="Debug Level" superClass="gnu.c.compiler.exe.release.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.none" valueType="enumerated"/>
|
||||
<option id="gnu.c.compiler.option.dialect.std.1246534005" name="Language standard" superClass="gnu.c.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.c.compiler.dialect.c99" valueType="enumerated"/>
|
||||
<option id="gnu.c.compiler.option.include.paths.1574426438" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/Farmlands/src}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/Farmlands/import/include}""/>
|
||||
</option>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1918347020" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
|
||||
</tool>
|
||||
<tool id="cdt.managedbuild.tool.gnu.c.linker.exe.release.1752295375" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.release"/>
|
||||
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.release.45072670" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.release">
|
||||
<option id="gnu.cpp.link.option.libs.2082560821" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" valueType="libs">
|
||||
<listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="SDL2"/>
|
||||
<listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="SDL2_ttf"/>
|
||||
<listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="SDL2_image"/>
|
||||
</option>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1964167308" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
|
||||
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
|
||||
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
|
||||
</inputType>
|
||||
</tool>
|
||||
<tool id="cdt.managedbuild.tool.gnu.assembler.exe.release.2103062671" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.exe.release">
|
||||
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.916223047" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
|
||||
</tool>
|
||||
</toolChain>
|
||||
</folderInfo>
|
||||
<sourceEntries>
|
||||
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
|
||||
</sourceEntries>
|
||||
</configuration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
|
||||
</cconfiguration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<project id="Farmlands.cdt.managedbuild.target.gnu.exe.1704596634" name="Executable" projectType="cdt.managedbuild.target.gnu.exe"/>
|
||||
</storageModule>
|
||||
<storageModule moduleId="scannerConfiguration">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.debug.1767279125;cdt.managedbuild.config.gnu.exe.debug.1767279125.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.1808198807;cdt.managedbuild.tool.gnu.cpp.compiler.input.1411957018">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
</scannerConfigBuildInfo>
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.debug.1767279125;cdt.managedbuild.config.gnu.exe.debug.1767279125.;cdt.managedbuild.tool.gnu.c.compiler.exe.debug.2048141090;cdt.managedbuild.tool.gnu.c.compiler.input.1905365757">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
</scannerConfigBuildInfo>
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.release.1609929883;cdt.managedbuild.config.gnu.exe.release.1609929883.;cdt.managedbuild.tool.gnu.c.compiler.exe.release.495054087;cdt.managedbuild.tool.gnu.c.compiler.input.1918347020">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
</scannerConfigBuildInfo>
|
||||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.release.1609929883;cdt.managedbuild.config.gnu.exe.release.1609929883.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.1249722811;cdt.managedbuild.tool.gnu.cpp.compiler.input.1719824945">
|
||||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
</scannerConfigBuildInfo>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||
<storageModule moduleId="refreshScope" versionNumber="2">
|
||||
<configuration configurationName="Multiple configurations">
|
||||
<resource resourceType="PROJECT" workspacePath="/Farmlands"/>
|
||||
</configuration>
|
||||
<configuration configurationName="Debug">
|
||||
<resource resourceType="PROJECT" workspacePath="/Farmlands"/>
|
||||
</configuration>
|
||||
<configuration configurationName="Release">
|
||||
<resource resourceType="PROJECT" workspacePath="/Farmlands"/>
|
||||
</configuration>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
|
||||
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
|
||||
</cproject>
|
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
RemoteSystemsTempFiles
|
||||
.metadata
|
||||
.settings
|
||||
import
|
||||
Debug
|
||||
Release
|
27
.project
Normal file
27
.project
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Farmlands</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
|
||||
<triggers>clean,full,incremental,</triggers>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
|
||||
<triggers>full,incremental,</triggers>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.cdt.core.cnature</nature>
|
||||
<nature>org.eclipse.cdt.core.ccnature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
BIN
assets/fonts/DejaVuSans.ttf
Normal file
BIN
assets/fonts/DejaVuSans.ttf
Normal file
Binary file not shown.
BIN
assets/tilesets/ground.png
Normal file
BIN
assets/tilesets/ground.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
140
src/FarmlandsGame.cpp
Normal file
140
src/FarmlandsGame.cpp
Normal file
@ -0,0 +1,140 @@
|
||||
/*
|
||||
* FarmlandsGame.cpp
|
||||
*
|
||||
* Created on: Nov 7, 2016
|
||||
* Author: tibi
|
||||
*/
|
||||
|
||||
#include "FarmlandsGame.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace farmlands
|
||||
{
|
||||
|
||||
FarmlandsGame::FarmlandsGame() :
|
||||
m_running(true),
|
||||
m_sdlWindow(nullptr),
|
||||
m_sdlRenderer(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
bool FarmlandsGame::initialize()
|
||||
{
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||
std::cerr << "Failed to initialize SDL!\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
int imgFlags = IMG_INIT_PNG;
|
||||
if (IMG_Init(IMG_INIT_PNG) != imgFlags) {
|
||||
std::cerr << "Failed to initialize SDL_image!\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TTF_Init() != 0) {
|
||||
std::cerr << "Failed to initialize SDL_ttf!\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
m_sdlWindow = SDL_CreateWindow("Farmlands", 0, 0, 1024, 768, SDL_WINDOW_SHOWN);
|
||||
if (!m_sdlWindow) {
|
||||
std::cerr << "Failed to create main window!\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
m_sdlRenderer = SDL_CreateRenderer(m_sdlWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||
if (!m_sdlRenderer) {
|
||||
std::cerr << "Failed to create renderer!\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Load resources
|
||||
m_resourceManager.loadGame(m_sdlRenderer);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void FarmlandsGame::onLogicUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FarmlandsGame::onRender()
|
||||
{
|
||||
SDL_RenderClear(m_sdlRenderer);
|
||||
|
||||
SDL_Rect dest = { 0, 0, 0, 0};
|
||||
SDL_QueryTexture(m_resourceManager.texture(0), NULL, NULL, &dest.w, &dest.h);
|
||||
dest.w *= 2;
|
||||
|
||||
SDL_RenderCopy(m_sdlRenderer, m_resourceManager.texture(0), nullptr, &dest);
|
||||
// Render loading screen
|
||||
|
||||
SDL_Delay(10);
|
||||
|
||||
SDL_RenderPresent(m_sdlRenderer);
|
||||
}
|
||||
|
||||
void FarmlandsGame::onEvent(SDL_Event& event)
|
||||
{
|
||||
switch(event.type)
|
||||
{
|
||||
case SDL_QUIT:
|
||||
stop();
|
||||
break;
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.scancode == SDL_Scancode::SDL_SCANCODE_ESCAPE)
|
||||
stop();
|
||||
break;
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void FarmlandsGame::stop()
|
||||
{
|
||||
m_running = false;
|
||||
}
|
||||
|
||||
void FarmlandsGame::dispose()
|
||||
{
|
||||
if (m_sdlRenderer)
|
||||
SDL_DestroyRenderer(m_sdlRenderer);
|
||||
|
||||
if (m_sdlWindow)
|
||||
SDL_DestroyWindow(m_sdlWindow);
|
||||
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
int FarmlandsGame::run()
|
||||
{
|
||||
// Initialize game
|
||||
if (!initialize())
|
||||
{
|
||||
dispose();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Main loop
|
||||
while(m_running)
|
||||
{
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event))
|
||||
onEvent(event);
|
||||
|
||||
onLogicUpdate();
|
||||
onRender();
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
dispose();
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
49
src/FarmlandsGame.h
Normal file
49
src/FarmlandsGame.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* FarmlandsGame.h
|
||||
*
|
||||
* Created on: Nov 7, 2016
|
||||
* Author: tibi
|
||||
*/
|
||||
|
||||
#ifndef FARMLANDSGAME_H_
|
||||
#define FARMLANDSGAME_H_
|
||||
|
||||
#include "storage/ResourceManager.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
namespace farmlands
|
||||
{
|
||||
enum GameState
|
||||
{
|
||||
Splash,
|
||||
MainMenu,
|
||||
Playing
|
||||
};
|
||||
|
||||
class FarmlandsGame {
|
||||
|
||||
public:
|
||||
int run();
|
||||
FarmlandsGame();
|
||||
|
||||
protected:
|
||||
bool initialize();
|
||||
|
||||
void onLogicUpdate();
|
||||
void onRender();
|
||||
void onEvent(SDL_Event& event);
|
||||
|
||||
void stop();
|
||||
void dispose();
|
||||
|
||||
private:
|
||||
bool m_running;
|
||||
SDL_Window* m_sdlWindow;
|
||||
SDL_Renderer* m_sdlRenderer;
|
||||
enum GameState m_state;
|
||||
|
||||
storage::ResourceManager m_resourceManager;
|
||||
};
|
||||
}
|
||||
#endif /* FARMLANDSGAME_H_ */
|
7
src/Main.cpp
Normal file
7
src/Main.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
#include "FarmlandsGame.h"
|
||||
using namespace farmlands;
|
||||
|
||||
int main()
|
||||
{
|
||||
return FarmlandsGame().run();
|
||||
}
|
48
src/model/Level.cpp
Normal file
48
src/model/Level.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Level.cpp
|
||||
*
|
||||
* Created on: Nov 11, 2016
|
||||
* Author: tibi
|
||||
*/
|
||||
|
||||
#include "Level.h"
|
||||
#include <cassert>
|
||||
|
||||
namespace farmlands {
|
||||
namespace model {
|
||||
|
||||
Level::Level(size_t layerCount, size_t rowCount, size_t columnCount)
|
||||
: m_cells(new Cell[layerCount * rowCount * columnCount]),
|
||||
m_layers(layerCount),
|
||||
m_rows(rowCount),
|
||||
m_columns(columnCount)
|
||||
{
|
||||
}
|
||||
|
||||
Level::~Level()
|
||||
{
|
||||
delete[] m_cells;
|
||||
}
|
||||
|
||||
|
||||
Cell Level::cell(size_t layer, size_t row, size_t col) const
|
||||
{
|
||||
assert(layer < m_layers);
|
||||
assert(row < m_rows);
|
||||
assert(col < m_columns);
|
||||
|
||||
return m_cells[layer * m_rows * m_columns + row * m_columns + col];
|
||||
}
|
||||
|
||||
void Level::setCell(size_t layer, size_t row, size_t col, Cell value)
|
||||
{
|
||||
assert(layer < m_layers);
|
||||
assert(row < m_rows);
|
||||
assert(col < m_columns);
|
||||
|
||||
m_cells[layer * m_rows * m_columns + row * m_columns + col] = value;
|
||||
}
|
||||
|
||||
|
||||
} /* namespace model */
|
||||
} /* namespace farmlands */
|
45
src/model/Level.h
Normal file
45
src/model/Level.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Level.h
|
||||
*
|
||||
* Created on: Nov 11, 2016
|
||||
* Author: tibi
|
||||
*/
|
||||
|
||||
#ifndef MODEL_LEVEL_H_
|
||||
#define MODEL_LEVEL_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
namespace farmlands {
|
||||
namespace model {
|
||||
|
||||
typedef int16_t Cell;
|
||||
|
||||
class Level
|
||||
{
|
||||
public:
|
||||
Level(size_t layerCount, size_t rowCount, size_t columnCount);
|
||||
Level(const Level&) = delete;
|
||||
Level& operator= (const Level&) = delete;
|
||||
|
||||
virtual ~Level();
|
||||
|
||||
inline size_t layerCount() const { return m_layers; }
|
||||
inline size_t rowCount() const { return m_rows; }
|
||||
inline size_t columnCount() const { return m_columns; }
|
||||
|
||||
Cell cell(size_t layer, size_t row, size_t col) const;
|
||||
void setCell(size_t layer, size_t row, size_t col, Cell value);
|
||||
|
||||
private:
|
||||
Cell* m_cells;
|
||||
size_t m_layers;
|
||||
size_t m_rows;
|
||||
size_t m_columns;
|
||||
};
|
||||
|
||||
} /* namespace model */
|
||||
} /* namespace farmlands */
|
||||
|
||||
#endif /* MODEL_LEVEL_H_ */
|
92
src/storage/LoadLevel.cpp
Normal file
92
src/storage/LoadLevel.cpp
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* LoadLevel.cpp
|
||||
*
|
||||
* Created on: Nov 11, 2016
|
||||
* Author: tibi
|
||||
*/
|
||||
|
||||
#include <model/Level.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <json.hpp>
|
||||
|
||||
using namespace farmlands::model;
|
||||
using namespace nlohmann;
|
||||
|
||||
namespace farmlands {
|
||||
namespace storage {
|
||||
|
||||
namespace {
|
||||
|
||||
void loadLevelCells(std::shared_ptr<Level> level, size_t layer, std::string cellsFileName)
|
||||
{
|
||||
char buffer[1024 * 10];
|
||||
|
||||
// Open file
|
||||
std::ifstream in(cellsFileName);
|
||||
if (!in)
|
||||
throw 0; // TODO: replace with exception type
|
||||
|
||||
// Read CSV file line by line
|
||||
for (size_t row = 0; row < level->rowCount(); row++)
|
||||
{
|
||||
in.getline(buffer, sizeof(buffer));
|
||||
|
||||
if (in.eof())
|
||||
throw 0; // TODO: replace with exception type
|
||||
|
||||
// Separated by comma (or maybe semicolon)
|
||||
char* nextNum = strtok(buffer, ",;");
|
||||
for (size_t col = 0; col < level->columnCount() && nextNum != NULL; col++)
|
||||
{
|
||||
Cell cell = (Cell)strtol(nextNum, NULL, 10);
|
||||
level->setCell(layer, row, col, cell);
|
||||
|
||||
nextNum = strtok(NULL, ",;");
|
||||
}
|
||||
}
|
||||
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Level> loadLevel(std::string fileName)
|
||||
{
|
||||
// Open file
|
||||
std::ifstream levelIn(fileName);
|
||||
if (!levelIn)
|
||||
throw 0; // TODO: replace with exception type
|
||||
|
||||
// Parse file
|
||||
json levelJs;
|
||||
levelIn>>levelJs;
|
||||
|
||||
size_t layerCount = levelJs.value("layerCount", 0u);
|
||||
size_t rowCount = levelJs.value("height", 0u);
|
||||
size_t colCount = levelJs.value("width", 0u);
|
||||
|
||||
size_t cellWidth = levelJs.value("cellWidth", 0u);
|
||||
size_t cellHeight = levelJs.value("cellHeight", 0u);
|
||||
|
||||
std::shared_ptr<Level> level(new Level(layerCount, rowCount, colCount));
|
||||
|
||||
// Read layers
|
||||
json layersJs = levelJs["layers"];
|
||||
size_t layer = 0;
|
||||
|
||||
for (auto it = layersJs.begin(); it != layersJs.end(); it++, layer++)
|
||||
{
|
||||
std::string cellsFileName = it->value("cellsFile", std::string());
|
||||
loadLevelCells(level, layer, cellsFileName);
|
||||
|
||||
std::string textureFileName = it->value("textureFile", std::string());
|
||||
}
|
||||
return level;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
120
src/storage/ResourceManager.cpp
Normal file
120
src/storage/ResourceManager.cpp
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* ResourceManager.cpp
|
||||
*
|
||||
* Created on: Nov 7, 2016
|
||||
* Author: tibi
|
||||
*/
|
||||
|
||||
#include "ResourceManager.h"
|
||||
#include "Resources.h"
|
||||
|
||||
#define FONTID(id,size) (id * 1000 + size)
|
||||
#define FONTID_SIZE(fontid) (fontid % 1000)
|
||||
#define FONTID_ID(fontid) (fontid / 1000)
|
||||
|
||||
namespace farmlands
|
||||
{
|
||||
namespace storage
|
||||
{
|
||||
|
||||
ResourceManager::ResourceManager()
|
||||
{
|
||||
}
|
||||
|
||||
ResourceManager::~ResourceManager()
|
||||
{
|
||||
}
|
||||
|
||||
void ResourceManager::loadMainMenu()
|
||||
{
|
||||
}
|
||||
|
||||
void ResourceManager::loadGame(SDL_Renderer* renderer)
|
||||
{
|
||||
loadTextures(renderer);
|
||||
}
|
||||
|
||||
void ResourceManager::loadTextures(SDL_Renderer* renderer)
|
||||
{
|
||||
for (size_t i = 0; i < sizeof(Resources_Textures) / sizeof(Resources_Textures[0]); i++)
|
||||
{
|
||||
SDL_Surface* surface = IMG_Load(Resources_Textures[i]);
|
||||
m_surfaces.push_back(surface);
|
||||
|
||||
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||
m_textures.push_back(texture);
|
||||
}
|
||||
}
|
||||
|
||||
TTF_Font* ResourceManager::font(const char* name, int pointSize)
|
||||
{
|
||||
int id = fontId(name);
|
||||
|
||||
return font(id, pointSize);
|
||||
}
|
||||
|
||||
TTF_Font* ResourceManager::font(int id, int pointSize)
|
||||
{
|
||||
// Open from cache
|
||||
auto it = m_fontCache.find(FONTID(id, pointSize));
|
||||
if (it != m_fontCache.end())
|
||||
return it->second;
|
||||
|
||||
// Open font
|
||||
TTF_Font* font = TTF_OpenFont(Resources_Fonts[id], pointSize);
|
||||
m_fontCache.emplace(FONTID(id, pointSize), font);
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
int ResourceManager::fontId(const char* name)
|
||||
{
|
||||
// Find in cache
|
||||
auto it = m_fontIdCache.find(std::string(name));
|
||||
if (it != m_fontIdCache.end())
|
||||
return it->second;
|
||||
|
||||
for (size_t i = 0; i < sizeof(Resources_Fonts) / sizeof(Resources_Fonts[0]); i++)
|
||||
{
|
||||
// Extract name from file name
|
||||
std::string fontName = Resources_Fonts[i];
|
||||
size_t nameStart = fontName.find_last_of('/');
|
||||
|
||||
if (nameStart == std::string::npos)
|
||||
nameStart = 0;
|
||||
else
|
||||
++nameStart;
|
||||
|
||||
size_t nameEnd = fontName.find_last_of('.');
|
||||
size_t nameLen = (nameEnd != std::string::npos) ? nameEnd - nameStart : std::string::npos;
|
||||
|
||||
fontName = fontName.substr(nameStart, nameLen);
|
||||
|
||||
// Found?
|
||||
if (fontName == name) {
|
||||
m_fontIdCache.emplace(fontName, i);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_Texture* ResourceManager::texture(const char* name)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDL_Texture* ResourceManager::texture(int id)
|
||||
{
|
||||
return m_textures[id];
|
||||
}
|
||||
|
||||
int ResourceManager::textureId(const char* name)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
} /* namespace storage */
|
||||
} /* namespace farmlands */
|
54
src/storage/ResourceManager.h
Normal file
54
src/storage/ResourceManager.h
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* ResourceManager.h
|
||||
*
|
||||
* Created on: Nov 7, 2016
|
||||
* Author: tibi
|
||||
*/
|
||||
|
||||
#ifndef STORAGE_RESOURCEMANAGER_H_
|
||||
#define STORAGE_RESOURCEMANAGER_H_
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
|
||||
namespace farmlands
|
||||
{
|
||||
namespace storage
|
||||
{
|
||||
class ResourceManager
|
||||
{
|
||||
public:
|
||||
ResourceManager();
|
||||
virtual ~ResourceManager();
|
||||
|
||||
void loadMainMenu();
|
||||
void loadGame(SDL_Renderer* renderer);
|
||||
|
||||
TTF_Font* font(const char* name, int pointSize);
|
||||
TTF_Font* font(int id, int pointSize);
|
||||
int fontId(const char* name);
|
||||
|
||||
SDL_Texture* texture(const char* name);
|
||||
SDL_Texture* texture(int id);
|
||||
int textureId(const char* name);
|
||||
|
||||
private:
|
||||
void loadTextures(SDL_Renderer* renderer);
|
||||
|
||||
typedef int FontId;
|
||||
|
||||
std::map<FontId, TTF_Font*> m_fontCache;
|
||||
std::map<std::string, int> m_fontIdCache;
|
||||
|
||||
std::vector<SDL_Surface*> m_surfaces;
|
||||
std::vector<SDL_Texture*> m_textures;
|
||||
};
|
||||
|
||||
} /* namespace storage */
|
||||
} /* namespace farmlands */
|
||||
|
||||
#endif /* STORAGE_RESOURCEMANAGER_H_ */
|
28
src/storage/Resources.h
Normal file
28
src/storage/Resources.h
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Resources.h
|
||||
*
|
||||
* Created on: Nov 7, 2016
|
||||
* Author: tibi
|
||||
*/
|
||||
|
||||
#ifndef STORAGE_RESOURCES_H_
|
||||
#define STORAGE_RESOURCES_H_
|
||||
|
||||
namespace farmlands {
|
||||
namespace storage {
|
||||
|
||||
const char* const Resources_Fonts[] =
|
||||
{
|
||||
"assets/fonts/DejaVuSans.ttf",
|
||||
};
|
||||
|
||||
const char* const Resources_MainMenu_Textures[] = { };
|
||||
const char* const Resources_Textures[] =
|
||||
{
|
||||
"assets/tilesets/ground.png"
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* STORAGE_RESOURCES_H_ */
|
Loading…
Reference in New Issue
Block a user