double-hit-balls/game/main_code.cpp

107 lines
2.1 KiB
C++
Raw Normal View History

2017-01-10 12:43:06 +00:00
#include "main_code.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "include/Engine.h"
2017-12-22 18:35:11 +00:00
#include <boost/property_tree/json_parser.hpp>
2017-11-14 17:04:04 +00:00
TMyApplication* Application;
2017-01-10 12:43:06 +00:00
2017-11-14 17:04:04 +00:00
void TMyApplication::InnerInit()
2017-01-10 12:43:06 +00:00
{
Application = this;
#ifdef TARGET_WIN32
#ifdef NDEBUG
ST::PathToResources = "resources/";
#else
ST::PathToResources = "../../../assets/";
#endif
#endif
#ifdef TARGET_IOS
ST::PathToResources = "assets/";
#endif
if (Console != NULL)
{
*Console<<"APP INIT\n";
}
2017-11-14 17:04:04 +00:00
srand (static_cast<size_t>(time(NULL)));
2017-01-10 12:43:06 +00:00
2017-12-19 10:54:34 +00:00
ResourceManager->ShaderManager.AddShader("DefaultShader", "texture-shader.vertex", "texture-shader.fragment");
2017-12-22 18:35:11 +00:00
ResourceManager->ShaderManager.AddShader("ColorShader", "color-shader.vertex", "color-shader.fragment");
ResourceManager->ShaderManager.AddShader(ParticleEffect::PARTICLE_SHADER, "particle-shader.vertex", "particle-shader.fragment");
Renderer->PushShader("ColorShader");
2017-11-14 17:04:04 +00:00
2017-12-22 18:35:11 +00:00
float width = Renderer->GetScreenWidth();
float height = Renderer->GetScreenHeight();
2017-01-10 12:43:06 +00:00
Renderer->SetOrthoProjection();
2017-12-22 18:35:11 +00:00
Renderer->PushProjectionMatrix(width, height, -1, 1);
//Renderer->SetFullScreenViewport();
2017-01-10 12:43:06 +00:00
2017-12-22 18:35:11 +00:00
boost::property_tree::ptree JSONsource;
boost::property_tree::json_parser::read_json(ST::PathToResources + "test.json", JSONsource);
2017-01-10 12:43:06 +00:00
2017-12-22 18:35:11 +00:00
sparkler.parse(JSONsource); // parse JSON
sparkler.load(); // load textures
sparkler.setCoords({ width / 2, height / 2, 0 });
2017-01-10 12:43:06 +00:00
}
2017-11-14 17:04:04 +00:00
2017-12-22 18:35:11 +00:00
void TMyApplication::InnerDeinit()
2017-11-14 17:04:04 +00:00
{
2017-01-10 12:43:06 +00:00
}
2017-02-26 23:07:37 +00:00
2017-12-22 18:35:11 +00:00
void TMyApplication::InnerOnMouseDown(TMouseState& mouseState)
2017-02-26 23:07:37 +00:00
{
2017-12-22 18:35:11 +00:00
if (mouseState.LeftButtonPressed)
{
sparkler.setCoords({ (float)mouseState.X, (float)mouseState.Y, 0 });
}
else if (mouseState.RightButtonPressed)
{
if (sparkler.isSpawning())
{
sparkler.stopSpawn();
}
else
{
sparkler.startSpawn();
}
}
2017-02-26 23:07:37 +00:00
}
2017-11-14 17:04:04 +00:00
void TMyApplication::InnerOnMove(Vector2f p, Vector2f shift)
2017-01-10 12:43:06 +00:00
{
2017-12-22 18:35:11 +00:00
sparkler.setCoords({ p[0], p[1], 0 });
2017-01-10 12:43:06 +00:00
}
2017-11-14 17:04:04 +00:00
void TMyApplication::InnerDraw()
2017-01-10 12:43:06 +00:00
{
glDisable(GL_DEPTH_TEST);
2017-12-19 10:54:34 +00:00
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
2017-01-10 12:43:06 +00:00
2017-12-22 18:35:11 +00:00
sparkler.draw();
2017-01-10 12:43:06 +00:00
}
2017-11-14 17:04:04 +00:00
void TMyApplication::InnerUpdate(size_t dt)
2017-01-10 12:43:06 +00:00
{
2017-12-22 18:35:11 +00:00
if (dt > 50)
{
dt = 50;
}
sparkler.update(dt / 1000.f);
2017-12-19 10:54:34 +00:00
}