double-hit-balls/game/main_code.cpp

115 lines
2.5 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
2017-12-23 23:55:01 +00:00
ST::PathToResources = "../../../assets/";
2017-01-10 12:43:06 +00:00
#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-23 23:55:01 +00:00
ResourceManager->ShaderManager.AddShader("DefaultShader", "shaders/texture-shader.vertex", "shaders/texture-shader.fragment");
ResourceManager->ShaderManager.AddShader("ColorShader", "shaders/color-shader.vertex", "shaders/color-shader.fragment");
ResourceManager->ShaderManager.AddShader(ParticleEffect::PARTICLE_SHADER, "shaders/particle-shader.vertex", "shaders/particle-shader.fragment");
2017-12-22 18:35:11 +00:00
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-23 23:55:01 +00:00
Renderer->PushProjectionMatrix(width, height, -500, 500);
2017-12-22 18:35:11 +00:00
//Renderer->SetFullScreenViewport();
2017-01-10 12:43:06 +00:00
2017-12-22 18:35:11 +00:00
boost::property_tree::ptree JSONsource;
2017-12-23 23:55:01 +00:00
boost::property_tree::json_parser::read_json(ST::PathToResources + "config.json", JSONsource);
std::string effectJSON = JSONsource.get<std::string>("effect");
boost::property_tree::json_parser::read_json(ST::PathToResources + effectJSON, 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)
{
2017-12-23 23:55:01 +00:00
sparkler.setCoords({ (float)mouseState.X, Renderer->GetScreenHeight() - (float)mouseState.Y, 0 });
2017-12-22 18:35:11 +00:00
}
2017-12-25 00:44:14 +00:00
if (mouseState.RightButtonPressed)
2017-12-22 18:35:11 +00:00
{
if (sparkler.isSpawning())
{
sparkler.stopSpawn();
}
else
{
sparkler.startSpawn();
}
}
2017-02-26 23:07:37 +00:00
}
2017-11-14 17:04:04 +00:00
2017-12-25 00:44:14 +00:00
void TMyApplication::InnerOnMouseMove(TMouseState& mouseState)
2017-01-10 12:43:06 +00:00
{
2017-12-25 00:44:14 +00:00
if (mouseState.LeftButtonPressed)
2017-12-23 23:55:01 +00:00
{
2017-12-25 00:44:14 +00:00
sparkler.setCoords({ (float)mouseState.X, Renderer->GetScreenHeight() - (float)mouseState.Y, 0 });
2017-12-23 23:55:01 +00:00
}
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
}