Add enemy class
This commit is contained in:
parent
6b60c55af7
commit
f1c3a1b57b
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
95
grk/project/Enemy.h
Normal file
95
grk/project/Enemy.h
Normal file
@ -0,0 +1,95 @@
|
||||
#include "glm.hpp"
|
||||
#include "ext.hpp"
|
||||
#include "src/Render_Utils.h"
|
||||
#include "Bullet.h"
|
||||
#include "Spaceship.h"
|
||||
|
||||
#pragma once
|
||||
class Enemy
|
||||
{
|
||||
private:
|
||||
std::list<Bullet*> bullets;
|
||||
float lastShootTime = 0.f;
|
||||
float shootInterval = 0.3f;
|
||||
|
||||
public:
|
||||
glm::mat4 modelMatrix;
|
||||
int hp;
|
||||
int dmg;
|
||||
float aggroRange;
|
||||
|
||||
Enemy(int initialHp, glm::mat4 initialModelMatrix, int initialDmg, float initialAggroRange)
|
||||
: hp(initialHp), modelMatrix(initialModelMatrix), dmg(initialDmg), aggroRange(initialAggroRange)
|
||||
{}
|
||||
|
||||
|
||||
virtual ~Enemy() = default;
|
||||
|
||||
virtual void attack(const glm::vec3& shipPos, float time) {
|
||||
|
||||
if (isInAggroRange(shipPos)) {
|
||||
requestShoot(time);
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool isAlive() const {
|
||||
if (this->hp < 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool isInAggroRange(const glm::vec3& shipPos) const {
|
||||
float distanceFromShip = glm::length(shipPos - glm::vec3(this->modelMatrix[3]));
|
||||
if (distanceFromShip > this->aggroRange) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void renderBullets(float time, GLuint program) {
|
||||
for (auto it = bullets.begin(); it != bullets.end();) {
|
||||
Bullet* bullet = *it;
|
||||
|
||||
if (bullet->shouldBeDestroyed(time, program)) {
|
||||
delete bullet;
|
||||
it = bullets.erase(it);
|
||||
}
|
||||
else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
}
|
||||
private:
|
||||
void requestShoot(float time) {
|
||||
if (canShoot(time)) {
|
||||
shoot(time);
|
||||
}
|
||||
}
|
||||
|
||||
bool canShoot(float time) {
|
||||
return this->lastShootTime == 0 || time - this->lastShootTime > this->shootInterval;
|
||||
}
|
||||
|
||||
void shoot(float time) {
|
||||
|
||||
|
||||
|
||||
glm::vec3 spaceshipPos = Spaceship::getInstance()->spaceshipPos;
|
||||
|
||||
// Przekszta³æ pozycjê statku do przestrzeni lokalnej obiektu Enemy
|
||||
glm::vec3 localSpaceshipPos = glm::inverse(glm::mat3(this->modelMatrix)) * (spaceshipPos - glm::vec3(this->modelMatrix[3]));
|
||||
|
||||
// Uzyskaj kierunek od obecnej pozycji obiektu Enemy do pozycji statku
|
||||
glm::vec3 localBulletDirection = glm::normalize(localSpaceshipPos);
|
||||
|
||||
// Przekszta³æ kierunek strza³u do przestrzeni œwiata, bior¹c pod uwagê macierz modelu
|
||||
glm::vec3 worldBulletDirection = glm::mat3(this->modelMatrix) * localBulletDirection;
|
||||
|
||||
// Dodaj nowy pocisk do listy pocisków
|
||||
this->bullets.push_back(Bullet::createSimpleBullet(worldBulletDirection, this->modelMatrix[3], time));
|
||||
|
||||
this->lastShootTime = time;
|
||||
}
|
||||
};
|
||||
|
@ -38,7 +38,7 @@ void Core::SpriteRenderer::DrawSprite(GLuint spriteTexture, const glm::mat4 mode
|
||||
glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * spaceship->createCameraMatrix();
|
||||
|
||||
// Kombinuj macierze transformacji
|
||||
glm::mat4 transformation = viewProjectionMatrix * billboardModelMatrix * modelMatrix;
|
||||
glm::mat4 transformation = viewProjectionMatrix * billboardModelMatrix;
|
||||
|
||||
// Przeka¿ macierze do shadera
|
||||
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, glm::value_ptr(transformation));
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "src/Render_Utils.h"
|
||||
#include "src/Texture.h"
|
||||
#include "Spaceship.h"
|
||||
#include "./Enemy.h"
|
||||
|
||||
#pragma once
|
||||
namespace Core {
|
||||
|
@ -118,6 +118,6 @@ void main()
|
||||
vec3 attenuatedlightColor = angle_atenuation*spotlightColor/pow(length(spotlightPos-worldPos),2);
|
||||
ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor,normal,viewDir);
|
||||
|
||||
|
||||
|
||||
outColor = vec4(vec3(1.0) - exp(-ilumination*exposition),1);
|
||||
}
|
||||
|
129
grk/project/shaders/shader_9_1.frag.orig
Normal file
129
grk/project/shaders/shader_9_1.frag.orig
Normal file
@ -0,0 +1,129 @@
|
||||
#version 430 core
|
||||
|
||||
float AMBIENT = 0.03;
|
||||
float PI = 3.14;
|
||||
|
||||
uniform sampler2D depthMap;
|
||||
|
||||
uniform vec3 cameraPos;
|
||||
|
||||
uniform vec3 color;
|
||||
|
||||
uniform vec3 lightPositions[100];
|
||||
uniform vec3 lightColors[100];
|
||||
|
||||
uniform vec3 spotlightPos;
|
||||
uniform vec3 spotlightColor;
|
||||
uniform vec3 spotlightConeDir;
|
||||
uniform vec3 spotlightPhi;
|
||||
|
||||
uniform float metallic;
|
||||
uniform float roughness;
|
||||
|
||||
uniform float exposition;
|
||||
|
||||
in vec3 vecNormal;
|
||||
in vec3 worldPos;
|
||||
|
||||
out vec4 outColor;
|
||||
|
||||
|
||||
in vec3 viewDirTS;
|
||||
in vec3 lightDirTS[4];
|
||||
in vec3 spotlightDirTS;
|
||||
in vec3 sunDirTS;
|
||||
|
||||
in vec3 test;
|
||||
|
||||
float DistributionGGX(vec3 normal, vec3 H, float roughness){
|
||||
float a = roughness*roughness;
|
||||
float a2 = a*a;
|
||||
float NdotH = max(dot(normal, H), 0.0);
|
||||
float NdotH2 = NdotH*NdotH;
|
||||
|
||||
float num = a2;
|
||||
float denom = (NdotH2 * (a2 - 1.0) + 1.0);
|
||||
denom = PI * denom * denom;
|
||||
|
||||
return num / denom;
|
||||
}
|
||||
float GeometrySchlickGGX(float NdotV, float roughness){
|
||||
float r = (roughness + 1.0);
|
||||
float k = (r*r) / 8.0;
|
||||
|
||||
float num = NdotV;
|
||||
float denom = NdotV * (1.0 - k) + k;
|
||||
|
||||
return num / denom;
|
||||
}
|
||||
float GeometrySmith(vec3 normal, vec3 V, vec3 lightDir, float roughness){
|
||||
float NdotV = max(dot(normal, V), 0.0);
|
||||
float NdotL = max(dot(normal, lightDir), 0.0);
|
||||
float ggx2 = GeometrySchlickGGX(NdotV, roughness);
|
||||
float ggx1 = GeometrySchlickGGX(NdotL, roughness);
|
||||
|
||||
return ggx1 * ggx2;
|
||||
}
|
||||
vec3 fresnelSchlick(float cosTheta, vec3 F0){
|
||||
return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
|
||||
}
|
||||
|
||||
vec3 PBRLight(vec3 lightDir, vec3 radiance, vec3 normal, vec3 V){
|
||||
float diffuse=max(0,dot(normal,lightDir));
|
||||
|
||||
vec3 F0 = vec3(0.04);
|
||||
F0 = mix(F0, color, metallic);
|
||||
|
||||
vec3 H = normalize(V + lightDir);
|
||||
|
||||
float NDF = DistributionGGX(normal, H, roughness);
|
||||
float G = GeometrySmith(normal, V, lightDir, roughness);
|
||||
vec3 F = fresnelSchlick(max(dot(H, V), 0.0), F0);
|
||||
|
||||
vec3 kS = F;
|
||||
vec3 kD = vec3(1.0) - kS;
|
||||
kD *= 1.0 - metallic;
|
||||
|
||||
vec3 numerator = NDF * G * F;
|
||||
float denominator = 4.0 * max(dot(normal, V), 0.0) * max(dot(normal, lightDir), 0.0) + 0.0001;
|
||||
vec3 specular = numerator / denominator;
|
||||
|
||||
float NdotL = max(dot(normal, lightDir), 0.0);
|
||||
return (kD * color / PI + specular) * radiance * NdotL;
|
||||
}
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 normal = normalize(vecNormal);
|
||||
|
||||
vec3 viewDir = normalize(cameraPos-worldPos);
|
||||
|
||||
vec3 lightDirs[4];
|
||||
vec3 ambient = AMBIENT * color;
|
||||
vec3 ilumination = ambient;
|
||||
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
lightDirs[i] = normalize(lightPositions[i] - worldPos);
|
||||
vec3 attenuatedlightColor = lightColors[i] / pow(length(lightPositions[i] - worldPos), 2);
|
||||
ilumination = ilumination+PBRLight(lightDirs[i], attenuatedlightColor * 300, normal, viewDir);
|
||||
}
|
||||
|
||||
|
||||
|
||||
vec3 spotlightDir= normalize(spotlightPos-worldPos);
|
||||
|
||||
|
||||
float angle_atenuation = clamp((dot(-normalize(spotlightPos-worldPos),spotlightConeDir)-0.5)*3,0,1);
|
||||
vec3 attenuatedlightColor = angle_atenuation*spotlightColor/pow(length(spotlightPos-worldPos),2);
|
||||
ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor,normal,viewDir);
|
||||
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
//sun
|
||||
//ilumination=ilumination+PBRLight(sunDir,sunColor,normal,viewDir);
|
||||
|
||||
>>>>>>> c0971c9 (Add enemy class)
|
||||
outColor = vec4(vec3(1.0) - exp(-ilumination*exposition),1);
|
||||
}
|
@ -17,7 +17,6 @@ GLuint Core::LoadTexture( const char * filepath )
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
|
||||
int w, h;
|
||||
unsigned char* image = SOIL_load_image(filepath, &w, &h, 0, SOIL_LOAD_RGBA);
|
||||
|
||||
|
@ -21,6 +21,9 @@
|
||||
#include "../Planet.h"
|
||||
#include "../GameObject.h"
|
||||
#include "../GameUtils.h"
|
||||
#include "../SpriteRenderer.h"
|
||||
#include "../Enemy.h"
|
||||
|
||||
|
||||
const unsigned int SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024;
|
||||
|
||||
@ -34,6 +37,7 @@ namespace models {
|
||||
}
|
||||
namespace texture {
|
||||
GLuint cubemapTexture;
|
||||
GLuint spriteTexture;
|
||||
}
|
||||
|
||||
void createGalaxy(glm::vec3 galaxyPosition);
|
||||
@ -44,13 +48,16 @@ GLuint depthMap;
|
||||
GLuint program;
|
||||
GLuint programSun;
|
||||
GLuint programTest;
|
||||
GLuint programTex;
|
||||
GLuint programSprite;
|
||||
GLuint programCubemap;
|
||||
|
||||
std::list<Planet*> planets;
|
||||
Sun* sun;
|
||||
GLuint VAO,VBO;
|
||||
|
||||
std::vector<Enemy*> enemies;
|
||||
|
||||
|
||||
float exposition = 1.f;
|
||||
|
||||
glm::vec3 pointlightPos = glm::vec3(0, 2, 0);
|
||||
@ -61,6 +68,8 @@ float deltaTime = 0.f;
|
||||
|
||||
Spaceship* spaceship = Spaceship::getInstance();
|
||||
void createSolarSystem(glm::vec3 sunPos, float sunScale, float* planetSizes, int numberOfPlanets, float planetsDistance, float planetSpeedCoef);
|
||||
Core::SpriteRenderer* spriteRenderer;
|
||||
|
||||
void updateDeltaTime(float time) {
|
||||
if (lastTime < 0) {
|
||||
lastTime = time;
|
||||
@ -107,8 +116,6 @@ void renderScene(GLFWwindow* window)
|
||||
|
||||
spaceship->renderBullets(glfwGetTime(), program);
|
||||
|
||||
//drawObjectPBR(sphereContext, glm::translate(pointlightPos) * glm::scale(glm::vec3(1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(10.f, 0, 0)) * glm::scale(glm::vec3(0.3f)), glm::vec3(0.2, 0.7, 0.3), 0.3, 0.0, program);
|
||||
|
||||
drawObjectPBR(models::sphereContext,
|
||||
glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f)),
|
||||
glm::vec3(0.5, 0.5, 0.5), 0.7, 0.0, program);
|
||||
@ -118,6 +125,26 @@ void renderScene(GLFWwindow* window)
|
||||
spaceship->color,
|
||||
spaceship->roughness, spaceship->metallic, program
|
||||
);
|
||||
glUseProgram(programSprite);
|
||||
for (const auto& enemy : enemies) {
|
||||
if (enemy->isAlive()) {
|
||||
spriteRenderer->DrawSprite(texture::spriteTexture, enemy->modelMatrix, programSprite);
|
||||
}
|
||||
|
||||
}
|
||||
glUseProgram(program);
|
||||
for (const auto& enemy : enemies) {
|
||||
if (enemy->isAlive()) {
|
||||
enemy->attack(spaceship->spaceshipPos, glfwGetTime());
|
||||
enemy->renderBullets(glfwGetTime(), program);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//drawObjectPBR(sphereContext, glm::translate(pointlightPos) * glm::scale(glm::vec3(1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(10.f, 0, 0)) * glm::scale(glm::vec3(0.3f)), glm::vec3(0.2, 0.7, 0.3), 0.3, 0.0, program);
|
||||
|
||||
|
||||
glUseProgram(0);
|
||||
glfwSwapBuffers(window);
|
||||
@ -158,9 +185,18 @@ void createSolarSystem(glm::vec3 sunPos, float sunScale, float* planetSizes, int
|
||||
}
|
||||
}
|
||||
|
||||
void createEnemies() {
|
||||
|
||||
enemies.push_back(new Enemy(100, glm::mat4(1.0f), 20, 5.0f));
|
||||
enemies.push_back(new Enemy(100, glm::translate(glm::mat4(1.0f) , glm::vec3(1.f,1.f,1.f)), 15, 5.0f));
|
||||
enemies.push_back(new Enemy(100, glm::translate(glm::mat4(1.0f), glm::vec3(-1.f, 2.f, -0.9f)), 25, 5.0f));
|
||||
|
||||
}
|
||||
|
||||
void init(GLFWwindow* window)
|
||||
{
|
||||
GameUtils* gameUtils = GameUtils::getInstance();
|
||||
spriteRenderer = new Core::SpriteRenderer();
|
||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
@ -169,12 +205,15 @@ void init(GLFWwindow* window)
|
||||
programTest = gameUtils->shaderLoader->CreateProgram("shaders/test.vert", "shaders/test.frag");
|
||||
programSun = gameUtils->shaderLoader->CreateProgram("shaders/shader_8_sun.vert", "shaders/shader_8_sun.frag");
|
||||
programCubemap = gameUtils->shaderLoader->CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
|
||||
|
||||
programSprite = gameUtils->shaderLoader->CreateProgram("shaders/shader_sprite.vert", "shaders/shader_sprite.frag");
|
||||
|
||||
loadModelToContext("./models/marbleBust.obj", models::marbleBustContext);
|
||||
loadModelToContext("./models/spaceship.obj", models::spaceshipContext);
|
||||
loadModelToContext("./models/sphere.obj", models::sphereContext);
|
||||
loadModelToContext("./models/cube.obj", models::cubeContext);
|
||||
Core::loadModelToContext("./models/sphere.obj", GameUtils::getInstance()->sphereContext);
|
||||
|
||||
texture::spriteTexture = Core::LoadTexture("textures/blinky1.png");
|
||||
|
||||
std::vector<std::string> cubeFaces = {
|
||||
"bkg2_right1.png",
|
||||
@ -188,11 +227,18 @@ void init(GLFWwindow* window)
|
||||
texture::cubemapTexture = Core::LoadCubemap(cubeFaces);
|
||||
|
||||
createSuns();
|
||||
createEnemies();
|
||||
}
|
||||
|
||||
void shutdown(GLFWwindow* window)
|
||||
{
|
||||
GameUtils::getInstance()->shaderLoader->DeleteProgram(program);
|
||||
delete spriteRenderer;
|
||||
|
||||
// Dealokacja pamięci po obiektach Enemy
|
||||
for (const auto& enemy : enemies) {
|
||||
delete enemy;
|
||||
}
|
||||
}
|
||||
|
||||
//obsluga wejscia
|
||||
|
@ -21,6 +21,9 @@
|
||||
#include "../Planet.h"
|
||||
#include "../GameObject.h"
|
||||
#include "../GameUtils.h"
|
||||
#include "../SpriteRenderer.h"
|
||||
#include "../Enemy.h"
|
||||
|
||||
|
||||
const unsigned int SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024;
|
||||
|
||||
@ -34,21 +37,27 @@ namespace models {
|
||||
}
|
||||
namespace texture {
|
||||
GLuint cubemapTexture;
|
||||
GLuint spriteTexture;
|
||||
}
|
||||
|
||||
void createGalaxy(glm::vec3 galaxyPosition);
|
||||
|
||||
GLuint depthMapFBO;
|
||||
GLuint depthMap;
|
||||
|
||||
GLuint program;
|
||||
GLuint programSun;
|
||||
GLuint programTest;
|
||||
GLuint programTex;
|
||||
GLuint programSprite;
|
||||
GLuint programCubemap;
|
||||
|
||||
std::list<Planet*> planets;
|
||||
Sun* sun;
|
||||
GLuint VAO,VBO;
|
||||
|
||||
std::vector<Enemy*> enemies;
|
||||
|
||||
|
||||
float exposition = 1.f;
|
||||
|
||||
glm::vec3 pointlightPos = glm::vec3(0, 2, 0);
|
||||
@ -58,7 +67,12 @@ float lastTime = -1.f;
|
||||
float deltaTime = 0.f;
|
||||
|
||||
Spaceship* spaceship = Spaceship::getInstance();
|
||||
<<<<<<< HEAD
|
||||
void createSolarSystem(glm::vec3 sunPos, float sunScale, float* planetSizes, int numberOfPlanets, float planetsDistance, float planetSpeedCoef);
|
||||
=======
|
||||
Core::SpriteRenderer* spriteRenderer;
|
||||
|
||||
>>>>>>> c0971c9 (Add enemy class)
|
||||
void updateDeltaTime(float time) {
|
||||
if (lastTime < 0) {
|
||||
lastTime = time;
|
||||
@ -105,8 +119,6 @@ void renderScene(GLFWwindow* window)
|
||||
|
||||
spaceship->renderBullets(glfwGetTime(), program);
|
||||
|
||||
//drawObjectPBR(sphereContext, glm::translate(pointlightPos) * glm::scale(glm::vec3(1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(10.f, 0, 0)) * glm::scale(glm::vec3(0.3f)), glm::vec3(0.2, 0.7, 0.3), 0.3, 0.0, program);
|
||||
|
||||
drawObjectPBR(models::sphereContext,
|
||||
glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f)),
|
||||
glm::vec3(0.5, 0.5, 0.5), 0.7, 0.0, program);
|
||||
@ -116,6 +128,26 @@ void renderScene(GLFWwindow* window)
|
||||
spaceship->color,
|
||||
spaceship->roughness, spaceship->metallic, program
|
||||
);
|
||||
glUseProgram(programSprite);
|
||||
for (const auto& enemy : enemies) {
|
||||
if (enemy->isAlive()) {
|
||||
spriteRenderer->DrawSprite(texture::spriteTexture, enemy->modelMatrix, programSprite);
|
||||
}
|
||||
|
||||
}
|
||||
glUseProgram(program);
|
||||
for (const auto& enemy : enemies) {
|
||||
if (enemy->isAlive()) {
|
||||
enemy->attack(spaceship->spaceshipPos, glfwGetTime());
|
||||
enemy->renderBullets(glfwGetTime(), program);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//drawObjectPBR(sphereContext, glm::translate(pointlightPos) * glm::scale(glm::vec3(1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(10.f, 0, 0)) * glm::scale(glm::vec3(0.3f)), glm::vec3(0.2, 0.7, 0.3), 0.3, 0.0, program);
|
||||
|
||||
|
||||
glUseProgram(0);
|
||||
glfwSwapBuffers(window);
|
||||
@ -130,60 +162,63 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||
|
||||
|
||||
void createSuns() {
|
||||
GameUtils* gu = GameUtils::getInstance();
|
||||
sun = new Sun(programSun, models::sphereContext, glm::vec3(0, 2, 0), glm::vec3(-0.93633f, 0.351106, 0.003226f), glm::vec3(0.9f, 0.9f, 0.7f) * 5, 1);
|
||||
Planet* planet = new Planet(sun, 20.f, 0.25f, 1.f, models::sphereContext);
|
||||
planets.push_back(planet);
|
||||
Planet* moon = new Planet(planet, 5.f, 1.f, 0.2f, models::sphereContext);
|
||||
planets.push_back(moon);
|
||||
gu->getSuns()->push_back(sun);
|
||||
Planet* planet2 = new Planet(sun, 50.f, 0.5f, 1.5f, models::sphereContext);
|
||||
planets.push_back(planet2);
|
||||
/*suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-80, 20, 50), glm::vec3(-0.93633f, 0.351106, 0.003226f), glm::vec3(1.0f, 0.8f, 0.2f), 4.0));
|
||||
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(50, 40, -30), glm::vec3(-0.73633f, 0.451106, 0.023226f), glm::vec3(0.9f, 0.5f, 0.1f), 3.5));
|
||||
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(0, -60, 100), glm::vec3(-0.53633f, 0.551106, 0.043226f), glm::vec3(0.8f, 0.2f, 0.2f), 4.5));
|
||||
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(20, 80, -70), glm::vec3(0.33633f, 0.651106, 0.063226f), glm::vec3(0.5f, 0.7f, 0.9f), 3.8));
|
||||
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-60, -20, 30), glm::vec3(-0.23633f, 0.751106, 0.083226f), glm::vec3(0.7f, 0.2f, 0.7f), 4.2));
|
||||
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(70, -50, -80), glm::vec3(-0.03633f, 0.851106, 0.103226f), glm::vec3(0.1f, 0.3f, 0.9f), 3.9));
|
||||
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(10, 30, 60), glm::vec3(0.13633f, -0.951106, -0.123226f), glm::vec3(0.6f, 0.9f, 0.4f), 4.3));
|
||||
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-40, -80, -50), glm::vec3(0.33633f, -0.851106, -0.143226f), glm::vec3(0.7f, 0.5f, 0.2f), 3.7));
|
||||
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(90, 70, 20), glm::vec3(0.53633f, -0.751106, -0.163226f), glm::vec3(0.4f, 0.1f, 0.9f), 4.1));
|
||||
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-30, 10, -40), glm::vec3(0.73633f, -0.651106, -0.183226f), glm::vec3(0.8f, 0.4f, 0.1f), 4.4));
|
||||
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(150, -100, 80), glm::vec3(0.33633f, -0.951106, -0.143226f), glm::vec3(0.2f, 0.8f, 0.5f), 3.9));
|
||||
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-120, 50, -60), glm::vec3(0.73633f, 0.551106, 0.103226f), glm::vec3(0.9f, 0.2f, 0.7f), 3.6));
|
||||
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(0, 120, -150), glm::vec3(-0.23633f, -0.751106, 0.083226f), glm::vec3(0.5f, 0.6f, 0.9f), 3.4));
|
||||
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-180, -50, 120), glm::vec3(0.13633f, 0.351106, -0.003226f), glm::vec3(0.7f, 0.9f, 0.2f), 4.2));
|
||||
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(60, -150, 180), glm::vec3(-0.93633f, -0.451106, -0.023226f), glm::vec3(0.3f, 0.7f, 0.8f), 3.8));
|
||||
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(100, 80, -120), glm::vec3(0.53633f, -0.651106, 0.163226f), glm::vec3(0.8f, 0.1f, 0.4f), 4.5));
|
||||
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-50, -180, 150), glm::vec3(-0.33633f, 0.951106, -0.083226f), glm::vec3(0.4f, 0.8f, 0.6f), 3.5));
|
||||
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(200, 150, -100), glm::vec3(0.03633f, 0.151106, 0.103226f), glm::vec3(0.6f, 0.2f, 0.9f), 3.9));
|
||||
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-150, -100, -50), glm::vec3(0.83633f, -0.251106, -0.123226f), glm::vec3(0.7f, 0.5f, 0.8f), 4.1));*/
|
||||
createGalaxy(glm::vec3(0.f));
|
||||
createGalaxy(glm::vec3(0.f, 50.f, 200.f));
|
||||
}
|
||||
|
||||
void createGalaxy(glm::vec3 galaxyPosition) {
|
||||
float planetsSizes[] = { 1.f, 1.5f, 0.8f, 1.2f, 0.2f };
|
||||
createSolarSystem(galaxyPosition + glm::vec3(0, 2, 0), 3, planetsSizes, 5, 15.f, 0.2f);
|
||||
float planetsSizes2[] = { 0.6f, 1.1f, 0.9f };
|
||||
createSolarSystem(galaxyPosition + glm::vec3(150, 5, 0), 2, planetsSizes2, 3, 15.f, 0.2f);
|
||||
float planetsSizes3[] = { 0.7f, 1.5f, 1.2f, 1.f };
|
||||
createSolarSystem(galaxyPosition + glm::vec3(-20, -30, 50), 4, planetsSizes3, 4, 20.f, 0.2f);
|
||||
float planetSizes4[] = { 1.f, 0.5f };
|
||||
createSolarSystem(galaxyPosition + glm::vec3(100, 20, -50), 5, planetsSizes3, 2, 25.f, 0.2f);
|
||||
}
|
||||
|
||||
void createSolarSystem(glm::vec3 sunPos, float sunScale, float* planetSizes, int numberOfPlanets, float planetsDistance, float planetSpeedCoef) {
|
||||
GameUtils* gu = GameUtils::getInstance();
|
||||
sun = new Sun(programSun, models::sphereContext, sunPos, glm::vec3(-0.93633f, 0.351106, 0.003226f), glm::vec3(0.9f, 0.9f, 0.7f) * 5, sunScale);
|
||||
gu->getSuns()->push_back(sun);
|
||||
for (int i = 0; i < numberOfPlanets; i++) {
|
||||
float distanceFromSum = (i + 1) * planetsDistance;
|
||||
Planet* planet = new Planet(sun, distanceFromSum, i * 0.1f + planetSpeedCoef, planetSizes[i], models::sphereContext);
|
||||
planets.push_back(planet);
|
||||
}
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
void createEnemies() {
|
||||
|
||||
enemies.push_back(new Enemy(100, glm::mat4(1.0f), 20, 5.0f));
|
||||
enemies.push_back(new Enemy(100, glm::translate(glm::mat4(1.0f) , glm::vec3(1.f,1.f,1.f)), 15, 5.0f));
|
||||
enemies.push_back(new Enemy(100, glm::translate(glm::mat4(1.0f), glm::vec3(-1.f, 2.f, -0.9f)), 25, 5.0f));
|
||||
|
||||
}
|
||||
>>>>>>> c0971c9 (Add enemy class)
|
||||
void init(GLFWwindow* window)
|
||||
{
|
||||
GameUtils* gameUtils = GameUtils::getInstance();
|
||||
spriteRenderer = new Core::SpriteRenderer();
|
||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
<<<<<<< HEAD
|
||||
program = shaderLoader.CreateProgram("shaders/shader_9_1.vert", "shaders/shader_9_1.frag");
|
||||
programTest = shaderLoader.CreateProgram("shaders/test.vert", "shaders/test.frag");
|
||||
programSun = shaderLoader.CreateProgram("shaders/shader_8_sun.vert", "shaders/shader_8_sun.frag");
|
||||
programCubemap = shaderLoader.CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
|
||||
|
||||
|
||||
program = gameUtils->shaderLoader->CreateProgram("shaders/shader_9_1.vert", "shaders/shader_9_1.frag");
|
||||
programTest = gameUtils->shaderLoader->CreateProgram("shaders/test.vert", "shaders/test.frag");
|
||||
programSun = gameUtils->shaderLoader->CreateProgram("shaders/shader_8_sun.vert", "shaders/shader_8_sun.frag");
|
||||
programCubemap = gameUtils->shaderLoader->CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
|
||||
programSprite = gameUtils->shaderLoader->CreateProgram("shaders/shader_sprite.vert", "shaders/shader_sprite.frag");
|
||||
|
||||
loadModelToContext("./models/marbleBust.obj", models::marbleBustContext);
|
||||
loadModelToContext("./models/spaceship.obj", models::spaceshipContext);
|
||||
loadModelToContext("./models/sphere.obj", models::sphereContext);
|
||||
loadModelToContext("./models/cube.obj", models::cubeContext);
|
||||
|
||||
/*std::vector<std::string> cubeFaces = {
|
||||
"space_rt.png",
|
||||
"space_lf.png",
|
||||
"space_up.png",
|
||||
"space_dn.png",
|
||||
"space_bk.png",
|
||||
"space_ft.png"
|
||||
};*/
|
||||
Core::loadModelToContext("./models/sphere.obj", GameUtils::getInstance()->sphereContext);
|
||||
|
||||
texture::spriteTexture = Core::LoadTexture("textures/blinky1.png");
|
||||
|
||||
std::vector<std::string> cubeFaces = {
|
||||
"bkg2_right1.png",
|
||||
@ -196,28 +231,19 @@ void init(GLFWwindow* window)
|
||||
|
||||
texture::cubemapTexture = Core::LoadCubemap(cubeFaces);
|
||||
|
||||
=======
|
||||
program = gameUtils->shaderLoader->CreateProgram("shaders/shader_9_1.vert", "shaders/shader_9_1.frag");
|
||||
programTest = gameUtils->shaderLoader->CreateProgram("shaders/test.vert", "shaders/test.frag");
|
||||
programSun = gameUtils->shaderLoader->CreateProgram("shaders/shader_8_sun.vert", "shaders/shader_8_sun.frag");
|
||||
|
||||
//loadModelToContext("./models/sphere.obj", sphereContext);
|
||||
//loadModelToContext("./models/spaceship.obj", spaceship.context);
|
||||
|
||||
|
||||
|
||||
Core::loadModelToContext("./models/marbleBust.obj", models::marbleBustContext);
|
||||
Core::loadModelToContext("./models/spaceship.obj", models::spaceshipContext);
|
||||
Core::loadModelToContext("./models/sphere.obj", models::sphereContext);
|
||||
Core::loadModelToContext("./models/sphere.obj", GameUtils::getInstance()->sphereContext);
|
||||
>>>>>>> 62afe67 (add shooting)
|
||||
|
||||
createSuns();
|
||||
createEnemies();
|
||||
}
|
||||
|
||||
void shutdown(GLFWwindow* window)
|
||||
{
|
||||
GameUtils::getInstance()->shaderLoader->DeleteProgram(program);
|
||||
delete spriteRenderer;
|
||||
|
||||
// Dealokacja pamięci po obiektach Enemy
|
||||
for (const auto& enemy : enemies) {
|
||||
delete enemy;
|
||||
}
|
||||
}
|
||||
|
||||
//obsluga wejscia
|
||||
|
Loading…
Reference in New Issue
Block a user