add ship
This commit is contained in:
+4
-4
@@ -1,11 +1,11 @@
|
|||||||
------------ Tyra's v2.0 roadmap to publish on GitHub ------------
|
------------ Tyra's v2.0 roadmap to publish on GitHub ------------
|
||||||
|
|
||||||
- [Demo] Animation table
|
- [Demo] Red screen on hit
|
||||||
|
- [Demo] Count of killed zombies
|
||||||
- [Demo] Crosshair
|
- [Demo] Crosshair
|
||||||
- [Demo] 2D Health bar
|
- [Demo] 2D Health bar
|
||||||
- [Demo] More monsters!
|
- [Demo] Game over screen
|
||||||
- [Demo] Add ship and other reality stuff
|
- [Demo] Game fadein with audio information about island
|
||||||
- [Demo] Game fadein
|
|
||||||
- [General] USB test
|
- [General] USB test
|
||||||
- [General] CI in Github via docker image
|
- [General] CI in Github via docker image
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "./renderer/game_renderer.hpp"
|
#include "./renderer/game_renderer.hpp"
|
||||||
#include "./terrain/terrain.hpp"
|
#include "./terrain/terrain.hpp"
|
||||||
#include "./skybox/skybox.hpp"
|
#include "./skybox/skybox.hpp"
|
||||||
|
#include "./ship/ship.hpp"
|
||||||
#include "./debug_object.hpp"
|
#include "./debug_object.hpp"
|
||||||
#include "./enemy/enemy_manager.hpp"
|
#include "./enemy/enemy_manager.hpp"
|
||||||
|
|
||||||
@@ -48,6 +49,7 @@ class GameState : public State<GlobalStateType> {
|
|||||||
EnemyManager* enemyManager;
|
EnemyManager* enemyManager;
|
||||||
Terrain* terrain;
|
Terrain* terrain;
|
||||||
Skybox* skybox;
|
Skybox* skybox;
|
||||||
|
Ship* ship;
|
||||||
DebugObject* dbgObj;
|
DebugObject* dbgObj;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
# _____ ____ ___
|
||||||
|
# | \/ ____| |___|
|
||||||
|
# | | | \ | |
|
||||||
|
#-----------------------------------------------------------------------
|
||||||
|
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||||
|
# Licensed under Apache License 2.0
|
||||||
|
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <renderer/3d/mesh/static/static_mesh.hpp>
|
||||||
|
#include <renderer/3d/pipeline/static/stapip_options.hpp>
|
||||||
|
#include "states/game/renderer/renderer_static_pair.hpp"
|
||||||
|
#include <renderer/renderer.hpp>
|
||||||
|
|
||||||
|
using Tyra::Renderer;
|
||||||
|
using Tyra::StaPipOptions;
|
||||||
|
using Tyra::StaticMesh;
|
||||||
|
using Tyra::TextureRepository;
|
||||||
|
using Tyra::Vec4;
|
||||||
|
|
||||||
|
namespace Demo {
|
||||||
|
|
||||||
|
class Ship {
|
||||||
|
public:
|
||||||
|
Ship(TextureRepository* repo);
|
||||||
|
~Ship();
|
||||||
|
|
||||||
|
StaticMesh* mesh;
|
||||||
|
StaPipOptions* options;
|
||||||
|
RendererStaticPair* pair;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void allocateOptions();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Demo
|
||||||
@@ -39,6 +39,7 @@ void GameState::onStart() {
|
|||||||
player = new Player(engine);
|
player = new Player(engine);
|
||||||
terrain = new Terrain(repository);
|
terrain = new Terrain(repository);
|
||||||
enemyManager = new EnemyManager(engine, terrain->heightmap);
|
enemyManager = new EnemyManager(engine, terrain->heightmap);
|
||||||
|
ship = new Ship(repository);
|
||||||
skybox = new Skybox(repository);
|
skybox = new Skybox(repository);
|
||||||
dbgObj = new DebugObject(repository);
|
dbgObj = new DebugObject(repository);
|
||||||
|
|
||||||
@@ -51,6 +52,7 @@ GlobalStateType GameState::onFinish() {
|
|||||||
delete player;
|
delete player;
|
||||||
delete enemyManager;
|
delete enemyManager;
|
||||||
delete terrain;
|
delete terrain;
|
||||||
|
delete ship;
|
||||||
delete skybox;
|
delete skybox;
|
||||||
delete dbgObj;
|
delete dbgObj;
|
||||||
initialized = false;
|
initialized = false;
|
||||||
@@ -60,7 +62,8 @@ GlobalStateType GameState::onFinish() {
|
|||||||
|
|
||||||
void GameState::update() {
|
void GameState::update() {
|
||||||
if (fpsChecker++ > 50) {
|
if (fpsChecker++ > 50) {
|
||||||
TYRA_LOG("FPS: ", engine->info.getFps());
|
TYRA_LOG("FPS: ", engine->info.getFps(),
|
||||||
|
" RAM: ", engine->info.getAvailableRAM());
|
||||||
fpsChecker = 0;
|
fpsChecker = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,11 +78,13 @@ void GameState::update() {
|
|||||||
|
|
||||||
renderer.clear();
|
renderer.clear();
|
||||||
{
|
{
|
||||||
renderer.add(skybox->pair);
|
renderer.add(skybox->pair); // First, because of ALLPASS
|
||||||
|
renderer.add(ship->pair);
|
||||||
|
renderer.add(dbgObj->pair);
|
||||||
|
|
||||||
renderer.add(player->pair);
|
renderer.add(player->pair);
|
||||||
renderer.add(enemyManager->getPairs());
|
renderer.add(enemyManager->getPairs());
|
||||||
renderer.add(terrain->pair);
|
renderer.add(terrain->pair);
|
||||||
renderer.add(dbgObj->pair);
|
|
||||||
}
|
}
|
||||||
renderer.render();
|
renderer.render();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
# _____ ____ ___
|
||||||
|
# | \/ ____| |___|
|
||||||
|
# | | | \ | |
|
||||||
|
#-----------------------------------------------------------------------
|
||||||
|
# Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||||
|
# Licensed under Apache License 2.0
|
||||||
|
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "states/game/ship/ship.hpp"
|
||||||
|
#include <loaders/3d/obj_loader/obj_loader.hpp>
|
||||||
|
#include <file/file_utils.hpp>
|
||||||
|
|
||||||
|
using Tyra::FileUtils;
|
||||||
|
using Tyra::ObjLoader;
|
||||||
|
using Tyra::ObjLoaderOptions;
|
||||||
|
|
||||||
|
namespace Demo {
|
||||||
|
|
||||||
|
Ship::Ship(TextureRepository* repo) {
|
||||||
|
ObjLoader loader;
|
||||||
|
|
||||||
|
ObjLoaderOptions objOptions;
|
||||||
|
objOptions.flipUVs = true;
|
||||||
|
objOptions.scale = 200.0F;
|
||||||
|
|
||||||
|
auto* data =
|
||||||
|
loader.load(FileUtils::fromCwd("game/models/ship/ship.obj"), objOptions);
|
||||||
|
mesh = new StaticMesh(*data);
|
||||||
|
delete data;
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < mesh->materials.size(); i++) {
|
||||||
|
mesh->materials[i]->ambient /= 2.0F;
|
||||||
|
mesh->materials[i]->ambient.a = 128.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
mesh->setPosition(Vec4(-800.0F, 10.0F, -2500.0F));
|
||||||
|
|
||||||
|
allocateOptions();
|
||||||
|
|
||||||
|
pair = new RendererStaticPair{mesh, options};
|
||||||
|
}
|
||||||
|
|
||||||
|
Ship::~Ship() {
|
||||||
|
delete mesh;
|
||||||
|
delete options;
|
||||||
|
delete pair;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ship::allocateOptions() { options = new StaPipOptions(); }
|
||||||
|
|
||||||
|
} // namespace Demo
|
||||||
@@ -23,22 +23,22 @@ Terrain::Terrain(TextureRepository* repo)
|
|||||||
Vec4(-750.0F, 0.0F, -1400.0F, 1.0F), // Left up
|
Vec4(-750.0F, 0.0F, -1400.0F, 1.0F), // Left up
|
||||||
Vec4(920.0F, 0.0F, 1520.0F, 1.0F) // Right down
|
Vec4(920.0F, 0.0F, 1520.0F, 1.0F) // Right down
|
||||||
) {
|
) {
|
||||||
// ObjLoader loader;
|
ObjLoader loader;
|
||||||
|
|
||||||
// ObjLoaderOptions objOptions;
|
ObjLoaderOptions objOptions;
|
||||||
// objOptions.flipUVs = true;
|
objOptions.flipUVs = true;
|
||||||
// objOptions.scale = 100.0F;
|
objOptions.scale = 100.0F;
|
||||||
|
|
||||||
// auto* data = loader.load(
|
auto* data = loader.load(
|
||||||
// FileUtils::fromCwd("game/models/terrain/terrain.obj"), objOptions);
|
FileUtils::fromCwd("game/models/terrain/terrain.obj"), objOptions);
|
||||||
// data->normalsEnabled = false;
|
data->normalsEnabled = false;
|
||||||
// mesh = new StaticMesh(*data);
|
mesh = new StaticMesh(*data);
|
||||||
// delete data;
|
delete data;
|
||||||
// repo->addByMesh(mesh, FileUtils::fromCwd("game/models/terrain/"), "png");
|
repo->addByMesh(mesh, FileUtils::fromCwd("game/models/terrain/"), "png");
|
||||||
|
|
||||||
// allocateOptions();
|
allocateOptions();
|
||||||
|
|
||||||
// pair = new RendererStaticPair{mesh, options};
|
pair = new RendererStaticPair{mesh, options};
|
||||||
}
|
}
|
||||||
|
|
||||||
float Terrain::getHeightOffset(const Vec4& playerPosition) {
|
float Terrain::getHeightOffset(const Vec4& playerPosition) {
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ class Color {
|
|||||||
explicit Color(const float* v) { copy(this, v); }
|
explicit Color(const float* v) { copy(this, v); }
|
||||||
|
|
||||||
void operator=(const Color& v);
|
void operator=(const Color& v);
|
||||||
|
void operator*=(const float& v);
|
||||||
|
void operator/=(const float& v);
|
||||||
|
|
||||||
inline void set(const Color& v) { copy(this, v.rgba); }
|
inline void set(const Color& v) { copy(this, v.rgba); }
|
||||||
inline void set(const float* v) { copy(this, v); }
|
inline void set(const float* v) { copy(this, v); }
|
||||||
|
|||||||
@@ -19,6 +19,18 @@ void Color::copy(Color* out, const float* in) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Color::operator=(const Color& v) { copy(this, v); }
|
void Color::operator=(const Color& v) { copy(this, v); }
|
||||||
|
void Color::operator*=(const float& v) {
|
||||||
|
r *= v;
|
||||||
|
g *= v;
|
||||||
|
b *= v;
|
||||||
|
a *= v;
|
||||||
|
}
|
||||||
|
void Color::operator/=(const float& v) {
|
||||||
|
r /= v;
|
||||||
|
g /= v;
|
||||||
|
b /= v;
|
||||||
|
a /= v;
|
||||||
|
}
|
||||||
|
|
||||||
void Color::set(const float& t_r, const float& t_g, const float& t_b,
|
void Color::set(const float& t_r, const float& t_g, const float& t_b,
|
||||||
const float& t_a) {
|
const float& t_a) {
|
||||||
|
|||||||
Reference in New Issue
Block a user