Browse Source

working at tema

meemknight 2 years ago
parent
commit
3f5e66c75a

+ 6 - 3
Pika/gameplay/containers.h

@@ -27,10 +27,11 @@ Container *getContainer(const char* name, pika::memory::MemoryArena *memoryArena
 //#include "containers/mario/marioNeuralTrainer.h"
 //#include "containers/mario/marioNeuralTrainer.h"
 #include "containers/minecraftDungeons/mcDungeonsEditor.h"
 #include "containers/minecraftDungeons/mcDungeonsEditor.h"
 #include "containers/minecraftDungeons/mcDungeonsgameplay.h"
 #include "containers/minecraftDungeons/mcDungeonsgameplay.h"
-//#include "containers/minecraftDungeons/mcDungeonsMenu.h"
+#include "containers/minecraftDungeons/mcDungeonsMenu.h"
 //#include "containers/hollowknight/hollowknight.h"
 //#include "containers/hollowknight/hollowknight.h"
 
 
 #include "containers/threeDGameExample/threeDGameExample.h"
 #include "containers/threeDGameExample/threeDGameExample.h"
+#include "containers/threeDGameExample/threeDGameMenu.h"
 
 
 #if PIKA_PRODUCTION == 1
 #if PIKA_PRODUCTION == 1
 
 
@@ -50,13 +51,15 @@ Container *getContainer(const char* name, pika::memory::MemoryArena *memoryArena
 	PIKA_DECLARE_CONTAINER(ThreeDEditor) \
 	PIKA_DECLARE_CONTAINER(ThreeDEditor) \
 	PIKA_DECLARE_CONTAINER(PikaTextEditor) \
 	PIKA_DECLARE_CONTAINER(PikaTextEditor) \
 	PIKA_DECLARE_CONTAINER(ThreeDGameExample) \
 	PIKA_DECLARE_CONTAINER(ThreeDGameExample) \
+	PIKA_DECLARE_CONTAINER(ThreeDGameMenu) \
 	PIKA_DECLARE_CONTAINER(McDungeonsGameplay) \
 	PIKA_DECLARE_CONTAINER(McDungeonsGameplay) \
-	PIKA_DECLARE_CONTAINER(McDungeonsEditor)
+	PIKA_DECLARE_CONTAINER(McDungeonsEditor) \
+	PIKA_DECLARE_CONTAINER(McDungeonsMenu)
+
 	//PIKA_DECLARE_CONTAINER(Holloknight)\
 	//PIKA_DECLARE_CONTAINER(Holloknight)\
 	//PIKA_DECLARE_CONTAINER(Mario) \
 	//PIKA_DECLARE_CONTAINER(Mario) \
 	//PIKA_DECLARE_CONTAINER(MarioEditor) \
 	//PIKA_DECLARE_CONTAINER(MarioEditor) \
 	//PIKA_DECLARE_CONTAINER(MarioNeuralTrainer) \
 	//PIKA_DECLARE_CONTAINER(MarioNeuralTrainer) \
 	//PIKA_DECLARE_CONTAINER(MarioNeuralVizualizer) \
 	//PIKA_DECLARE_CONTAINER(MarioNeuralVizualizer) \
-	//PIKA_DECLARE_CONTAINER(McDungeonsMenu) 
 
 
 #endif
 #endif

+ 0 - 3
Pika/gameplay/containers/threeDGameExample/threeDGameExample.cpp

@@ -1,3 +0,0 @@
-#pragma once 
-
-#include "threeDGameExample.h"

+ 289 - 206
Pika/gameplay/containers/threeDGameExample/threeDGameExample.h

@@ -13,21 +13,25 @@
 #include <sushi/sushi.h>
 #include <sushi/sushi.h>
 #include <engineLibraresSupport/sushi/engineSushiSupport.h>
 #include <engineLibraresSupport/sushi/engineSushiSupport.h>
 
 
-//animations
-//3 attack
-//5 walk
-//7 8 18 die
-//15 idle
 
 
 struct ThreeDGameExample: public Container
 struct ThreeDGameExample: public Container
 {
 {
-
+	enum Animations
+	{
+		attack,
+		idle,
+		run,
+		run2,
+		zombieAttack,
+		zombieIdle,
+		zombieRun,
+	};
 
 
 	//todo user can request imgui ids; shortcut manager context; allocators
 	//todo user can request imgui ids; shortcut manager context; allocators
 	static ContainerStaticInfo containerInfo()
 	static ContainerStaticInfo containerInfo()
 	{
 	{
 		ContainerStaticInfo info = {};
 		ContainerStaticInfo info = {};
-		info.defaultHeapMemorySize = pika::MB(1000); //todo option to use global allocator
+		info.defaultHeapMemorySize = pika::MB(1500); //todo option to use global allocator
 
 
 		info.extensionsSuported = {".gl3d"};
 		info.extensionsSuported = {".gl3d"};
 
 
@@ -37,17 +41,31 @@ struct ThreeDGameExample: public Container
 		return info;
 		return info;
 	}
 	}
 
 
+	struct Enemy
+	{
+		McDungeonsGameplay::PhysicsComponent physics;
+		gl3d::Entity entity;
+		float life = 1;
+		float attackCulldown = 0.f;
+
+		Enemy() {};
+		Enemy(int x, int z) { physics.position = {x,z}; physics.lastPos = {x,z}; };
+	};
+
+
+	std::vector<Enemy> enemies;
 
 
 	gl3d::Renderer3D renderer;
 	gl3d::Renderer3D renderer;
 	gl3d::Model groundModel;
 	gl3d::Model groundModel;
-	gl3d::Model treesModel;
-	gl3d::Model cabinModel;
-	gl3d::Model knightModel;
 	gl3d::Entity groundEntity;
 	gl3d::Entity groundEntity;
-	//gl3d::Entity treeEntity;
-	gl3d::Entity cabinEntity;
 	gl3d::Entity playerEntity;
 	gl3d::Entity playerEntity;
 	bool first = 1;
 	bool first = 1;
+	float health = 1;
+
+	int killed = 0;
+
+	float floatingPeriod = 0;
+	float killTimer = 1.5;
 
 
 	sushi::SushyContext sushyContext;
 	sushi::SushyContext sushyContext;
 
 
@@ -56,12 +74,44 @@ struct ThreeDGameExample: public Container
 	gl2d::Renderer2D renderer2d;
 	gl2d::Renderer2D renderer2d;
 	gl2d::Font font;
 	gl2d::Font font;
 
 
+
+	gl3d::Model createPlane(gl3d::Renderer3D &renderer)
+	{
+		float uv = 1;
+		float size = 200;
+		std::vector<unsigned int> ind = {0,   1,  2,  0,  2,  3};
+		std::vector<float> topVer = {
+				-1.0f * size, +0.0f, +1.0f * size, // 0
+				+0.0f, +1.0f, +0.0f, // Normal
+				0, 0,				 //uv
+
+				+1.0f * size, +0.0f, +1.0f * size, // 1
+				+0.0f, +1.0f, +0.0f, // Normal
+				1 * uv, 0,				 //uv
+
+				+1.0f * size, +0.0f, -1.0f * size, // 2
+				+0.0f, +1.0f, +0.0f, // Normal
+				1 * uv, 1 * uv,				 //uv
+
+				-1.0f * size, +0.0f, -1.0f * size, // 3
+				+0.0f, +1.0f, +0.0f, // Normal
+				0, 1 * uv,			 //uv
+		};
+
+		auto material =  renderer.createMaterial(0, {0.4,1,0.4,1}, 0, 1);
+
+		return renderer.createModelFromData(material, "plane",
+			topVer.size(), topVer.data(), ind.size(),
+			ind.data());
+	}
+
+
 	bool create(RequestedContainerInfo &requestedInfo, pika::StaticString<256> commandLineArgument)
 	bool create(RequestedContainerInfo &requestedInfo, pika::StaticString<256> commandLineArgument)
 	{
 	{
 		renderer2d.create(requestedInfo.requestedFBO.fbo);
 		renderer2d.create(requestedInfo.requestedFBO.fbo);
 		font = pika::gl2d::loadFont(PIKA_RESOURCES_PATH "arial.ttf", requestedInfo);
 		font = pika::gl2d::loadFont(PIKA_RESOURCES_PATH "arial.ttf", requestedInfo);
 
 
-
+		
 		renderer.setErrorCallback(&errorCallbackCustom, &requestedInfo);
 		renderer.setErrorCallback(&errorCallbackCustom, &requestedInfo);
 		renderer.fileOpener.userData = &requestedInfo;
 		renderer.fileOpener.userData = &requestedInfo;
 		renderer.fileOpener.readEntireFileBinaryCallback = readEntireFileBinaryCustom;
 		renderer.fileOpener.readEntireFileBinaryCallback = readEntireFileBinaryCustom;
@@ -75,23 +125,23 @@ struct ThreeDGameExample: public Container
 		//pika::gl3d::loadSettingsFromFileName(renderer, PIKA_RESOURCES_PATH "/threedgame/settings.gl3d", requestedInfo);
 		//pika::gl3d::loadSettingsFromFileName(renderer, PIKA_RESOURCES_PATH "/threedgame/settings.gl3d", requestedInfo);
 		editor.loadFromFile(renderer, PIKA_RESOURCES_PATH "/threedgame/settings.gl3d", requestedInfo);
 		editor.loadFromFile(renderer, PIKA_RESOURCES_PATH "/threedgame/settings.gl3d", requestedInfo);
 
 
+		auto zombieMat = renderer.loadMaterial(PIKA_RESOURCES_PATH "threedgame/zombie.mtl", 0);
+		if (zombieMat.size() != 1) { return false; }
+
+		auto playerModel = renderer.loadModel(PIKA_RESOURCES_PATH "mcDungeons/steve.glb", 0, 1);
+
 		renderer.getSSRdata().setLowQuality();
 		renderer.getSSRdata().setLowQuality();
 
 
 		renderer.getDirectionalShadowCascadesFrustumSplit(0) = 0.15;
 		renderer.getDirectionalShadowCascadesFrustumSplit(0) = 0.15;
 		renderer.getDirectionalShadowCascadesFrustumSplit(1) = 0.28;
 		renderer.getDirectionalShadowCascadesFrustumSplit(1) = 0.28;
 		renderer.getDirectionalShadowCascadesFrustumSplit(2) = 0.48;
 		renderer.getDirectionalShadowCascadesFrustumSplit(2) = 0.48;
 
 
-		groundModel = renderer.loadModel(PIKA_RESOURCES_PATH "threedgame/ground/GROUND_ON_BASE.obj", 
-			gl3d::TextureLoadQuality::maxQuality, 1);
 
 
-		treesModel = renderer.loadModel(PIKA_RESOURCES_PATH "threedgame/Tree_Red-spruce.glb",
-			gl3d::TextureLoadQuality::maxQuality, 1);
+		//renderer.
 
 
-		cabinModel = renderer.loadModel(PIKA_RESOURCES_PATH "threedgame/cabin/models/big_watchtower.obj",
-			gl3d::TextureLoadQuality::maxQuality,0.2);
+		groundModel = createPlane(renderer);
 
 
-		knightModel = renderer.loadModel(PIKA_RESOURCES_PATH "threedgame/knight/uploads_files_1950170_Solus_the_knight.gltf",
-			gl3d::TextureLoadQuality::maxQuality, 1);
+	
 
 
 		gl3d::Transform t;
 		gl3d::Transform t;
 		t.position = {0, -0.4, 0};
 		t.position = {0, -0.4, 0};
@@ -99,20 +149,13 @@ struct ThreeDGameExample: public Container
 
 
 		groundEntity = renderer.createEntity(groundModel, t);
 		groundEntity = renderer.createEntity(groundModel, t);
 
 
-		renderer.createEntity(treesModel, gl3d::Transform{{0,0,10}});
-		renderer.createEntity(treesModel, gl3d::Transform{{-5,0,7}});
-		renderer.createEntity(treesModel, gl3d::Transform{{-17,0,2}});
-		renderer.createEntity(treesModel, gl3d::Transform{{-13,0,-5}});
-		renderer.createEntity(treesModel, gl3d::Transform{{12,0,10}});
 
 
-		cabinEntity = renderer.createEntity(cabinModel, gl3d::Transform{{0,0,-25}});
-
-		playerEntity = renderer.createEntity(knightModel, gl3d::Transform{{0,0,-5}});
+		playerEntity = renderer.createEntity(playerModel, gl3d::Transform{{0,0,-5},{},glm::vec3{0.5f}}, false);
 
 
 		renderer.createDirectionalLight(glm::normalize(glm::vec3{-0.175,-0.577, -0.798}));
 		renderer.createDirectionalLight(glm::normalize(glm::vec3{-0.175,-0.577, -0.798}));
 	
 	
 		renderer.setEntityAnimate(playerEntity, 1);
 		renderer.setEntityAnimate(playerEntity, 1);
-		renderer.setEntityAnimationIndex(playerEntity, 15);
+		renderer.setEntityAnimationIndex(playerEntity, idle);
 
 
 
 
 		{
 		{
@@ -122,12 +165,42 @@ struct ThreeDGameExample: public Container
 			sushyContext.root.background.color = {0,0,0,0};
 			sushyContext.root.background.color = {0,0,0,0};
 		}
 		}
 
 
+		//if (0)
+		{
+			enemies.push_back(Enemy(18, 16));
+			enemies.push_back(Enemy(16, 16));
+		}
+
+		for (auto &i : enemies)
+		{
+			i.entity = renderer.createEntity(playerModel, 
+				gl3d::Transform{glm::vec3{i.physics.position.x, 0, i.physics.position.y}
+				,{},glm::vec3{0.5f}
+				}, false);
+
+
+			int count = renderer.getEntityMeshesCount(i.entity);
+			if (!count)return 0;
+			for (int j = 0; j < count; j++)
+			{
+				renderer.setEntityMeshMaterial(i.entity, j, zombieMat[0]);
+
+				auto m = renderer.getEntityMeshMaterialValues(i.entity, j);
+				m.kd = {1,0,0,1};
+				renderer.setEntityMeshMaterialValues(i.entity, j, m);
+			}
+
+			renderer.setEntityAnimationIndex(i.entity, 15); //idle
+			renderer.setEntityAnimationSpeed(i.entity, 1);
+			renderer.setEntityAnimate(i.entity, true);
+		}
+
 		return true;
 		return true;
 	}
 	}
 
 
 	float animationCulldown = 0;
 	float animationCulldown = 0;
 	float attackCulldown = 0;
 	float attackCulldown = 0;
-	float cameraYoffset = 4;
+	float cameraYoffset = 0;
 	bool freeCamera = 0;
 	bool freeCamera = 0;
 
 
 	McDungeonsGameplay::PhysicsComponent playerPhysics;
 	McDungeonsGameplay::PhysicsComponent playerPhysics;
@@ -171,110 +244,129 @@ struct ThreeDGameExample: public Container
 
 
 		#pragma region input
 		#pragma region input
 
 
-			//if (!diamonds.empty())
-			if (!freeCamera)
+			if (health <= 0)
 			{
 			{
-				glm::vec2 dir = {};
+				renderer.setEntityAnimationIndex(playerEntity, 18); //die
+				renderer.setEntityAnimationSpeed(playerEntity, 0.5);
+
+				killTimer -= input.deltaTime;
 
 
-				if (animationCulldown <= 0)
+				if (killTimer <= 0)
 				{
 				{
-					if (input.buttons[pika::Button::A].held() || input.buttons[pika::Button::Left].held())
-					{
-						dir -= glm::vec2(1, 1);
-					}
-					if (input.buttons[pika::Button::D].held() || input.buttons[pika::Button::Right].held())
+					requestedInfo.setNormalCursor(); //todo set by the engine on exit container
+					requestedInfo.createContainer("ThreeDGameMenu");
+					return 0;
+				}
+			}
+			else
+			{
+				if (!freeCamera)
+				{
+					glm::vec2 dir = {};
+
+					if (animationCulldown <= 0)
 					{
 					{
-						dir += glm::vec2(1, 1);
+						if (input.buttons[pika::Button::A].held() || input.buttons[pika::Button::Left].held())
+						{
+							dir -= glm::vec2(1, 1);
+						}
+						if (input.buttons[pika::Button::D].held() || input.buttons[pika::Button::Right].held())
+						{
+							dir += glm::vec2(1, 1);
+						}
+						if (input.buttons[pika::Button::W].held() || input.buttons[pika::Button::Up].held())
+						{
+							dir += glm::vec2(1, -1);
+						}
+						if (input.buttons[pika::Button::S].held() || input.buttons[pika::Button::Down].held())
+						{
+							dir -= glm::vec2(1, -1);
+						}
 					}
 					}
-					if (input.buttons[pika::Button::W].held() || input.buttons[pika::Button::Up].held())
+
+					if (dir.x != 0 || dir.y != 0)
 					{
 					{
-						dir += glm::vec2(1, -1);
+						dir = glm::normalize(dir);
+
+						auto lerp = [&](float x, float y, float a)
+						{
+							a = std::min(a, 1.f);
+							a = std::max(a, 0.f);
+							return x * (1 - a) + y * (a);
+						};
+
+						playerPhysics.desiredRotation = std::atan2(dir.x, dir.y);
+
+						if (animationCulldown <= 0)
+						{
+							renderer.setEntityAnimationIndex(playerEntity, run); //run 
+							renderer.setEntityAnimationSpeed(playerEntity, 1.5);
+						}
 					}
 					}
-					if (input.buttons[pika::Button::S].held() || input.buttons[pika::Button::Down].held())
+					else
 					{
 					{
-						dir -= glm::vec2(1, -1);
+						if (animationCulldown <= 0)
+						{
+							renderer.setEntityAnimationIndex(playerEntity, idle); //idle
+							renderer.setEntityAnimationSpeed(playerEntity, 1);
+						}
 					}
 					}
-				}
 
 
-				if (dir.x != 0 || dir.y != 0)
-				{
-					dir = glm::normalize(dir);
+					float speed = 3;
+					playerPhysics.position += dir * input.deltaTime * speed;
+
 
 
-					auto lerp = [&](float x, float y, float a)
+					if (input.buttons[pika::Button::Space].pressed() && attackCulldown <= 0)
 					{
 					{
-						a = std::min(a, 1.f);
-						a = std::max(a, 0.f);
-						return x * (1 - a) + y * (a);
-					};
+						renderer.setEntityAnimationIndex(playerEntity, attack); //attack
+						renderer.setEntityAnimationSpeed(playerEntity, 1.3);
+						animationCulldown = 1.2;
+						attackCulldown = 1.2;
 
 
-					playerPhysics.desiredRotation = std::atan2(dir.x, dir.y);
+						for (int i = 0; i < enemies.size(); i++)
+						{
+							float d = glm::distance(playerPhysics.position, enemies[i].physics.position);
+							if (d < 1.5f)
+							{
+								enemies[i].life -= 0.4;
+
+								if (enemies[i].life <= 0)
+								{
+									renderer.deleteEntity(enemies[i].entity);
+									enemies.erase(enemies.begin() + i);
+									killed++;
+									i--;
+									continue;
+								}
+
+								glm::vec2 dir(1, 0);
+
+								if (d != 0)
+								{
+									dir = (enemies[i].physics.position - playerPhysics.position) / d;
+								}
+
+								enemies[i].physics.position += dir * 4.0f;
+							}
+
+						}
 
 
-					if (animationCulldown <= 0)
-					{
-						renderer.setEntityAnimationIndex(playerEntity, 5); //run 
-						renderer.setEntityAnimationSpeed(playerEntity, 1.5);
 					}
 					}
+
 				}
 				}
-				else
+
+				if (animationCulldown > 0)
 				{
 				{
-					if (animationCulldown <= 0)
-					{
-						renderer.setEntityAnimationIndex(playerEntity, 15); //idle
-						renderer.setEntityAnimationSpeed(playerEntity, 1);
-					}
+					animationCulldown -= input.deltaTime;
 				}
 				}
 
 
-				float speed = 3;
-				playerPhysics.position += dir * input.deltaTime * speed;
-
-
-				if (input.buttons[pika::Button::Space].pressed() && attackCulldown <= 0)
+				if (attackCulldown > 0)
 				{
 				{
-					renderer.setEntityAnimationIndex(playerEntity, 3); //attack
-					renderer.setEntityAnimationSpeed(playerEntity, 1.3);
-					animationCulldown = 1.2;
-					attackCulldown = 1.2;
-
-					//for (int i = 0; i < enemies.size(); i++)
-					//{
-					//	float d = glm::distance(playerPhysics.position, enemies[i].physics.position);
-					//	if (d < 1.5f)
-					//	{
-					//		enemies[i].life -= 0.4;
-					//
-					//		if (enemies[i].life <= 0)
-					//		{
-					//			renderer.deleteEntity(enemies[i].entity);
-					//			enemies.erase(enemies.begin() + i);
-					//			i--;
-					//			continue;
-					//		}
-					//
-					//		glm::vec2 dir(1, 0);
-					//
-					//		if (d != 0)
-					//		{
-					//			dir = (enemies[i].physics.position - playerPhysics.position) / d;
-					//		}
-					//
-					//		enemies[i].physics.position += dir * 1.5f;
-					//	}
-					//
-					//}
-
+					attackCulldown -= input.deltaTime;
 				}
 				}
-
 			}
 			}
 
 
-			if (animationCulldown > 0)
-			{
-				animationCulldown -= input.deltaTime;
-			}
-
-			if (attackCulldown > 0)
-			{
-				attackCulldown -= input.deltaTime;
-			}
+			
 
 
 		#pragma endregion
 		#pragma endregion
 
 
@@ -338,7 +430,7 @@ struct ThreeDGameExample: public Container
 			{
 			{
 				gl3d::Transform t;
 				gl3d::Transform t;
 				t.rotation.y = p.rotation;
 				t.rotation.y = p.rotation;
-				t.position = glm::vec3(p.position.x, 0, p.position.y);
+				t.position = glm::vec3(p.position.x, -0.5, p.position.y);
 				t.scale = glm::vec3(1.f);
 				t.scale = glm::vec3(1.f);
 				renderer.setEntityTransform(e, t);
 				renderer.setEntityTransform(e, t);
 				return t;
 				return t;
@@ -347,55 +439,61 @@ struct ThreeDGameExample: public Container
 		#pragma region player position
 		#pragma region player position
 			auto t = setTransform(playerPhysics, playerEntity);
 			auto t = setTransform(playerPhysics, playerEntity);
 			glm::vec3 playerPos = t.position;
 			glm::vec3 playerPos = t.position;
-			glm::vec3 cameraViewDir = glm::normalize(glm::vec3(-1, 1.7, 1));
-			glm::vec3 cameraPos = playerPos + cameraViewDir * 12.f;
+			glm::vec3 cameraViewDir = glm::normalize(glm::vec3(-1, 0.8, 1));
+			glm::vec3 cameraPos = playerPos + cameraViewDir * 20.f;
 		#pragma endregion
 		#pragma endregion
 
 
-			//for (auto &e : enemies)
-			//{
-			//	float d = glm::distance(e.physics.position, playerPhysics.position);
-			//	if (d < 8.f)
-			//	{
-			//		if (d > 1.f)
-			//		{
-			//			glm::vec2 dir = glm::normalize(playerPhysics.position - e.physics.position);
-			//			float speed = 1.4;
-			//			e.physics.position += dir * input.deltaTime * speed;
-			//
-			//			e.physics.desiredRotation = std::atan2(dir.x, dir.y);
-			//
-			//			renderer.setEntityAnimationIndex(e.entity, Animations::zombieRun);
-			//
-			//		}
-			//		else
-			//		{
-			//			renderer.setEntityAnimationIndex(e.entity, Animations::zombieAttack);
-			//
-			//			if (e.attackCulldown <= 0.f)
-			//			{
-			//				health -= 0.2;
-			//				e.attackCulldown = 1.f;
-			//			}
-			//			//attack
-			//		}
-			//	}
-			//	else
-			//	{
-//		renderer.setEntityAnimationIndex(e.entity, Animations::zombieIdle);
-//	}
-//
-//	if (e.attackCulldown > 0)
-//	{
-//		e.attackCulldown -= input.deltaTime;
-//	}
-//
-//	solveRotation(e.physics);
-//
-//	resolveConstrains(e.physics);
-//	e.physics.updateMove();
-//
-//	setTransform(e.physics, e.entity);
-//}
+			for (auto &e : enemies)
+			{
+				float d = glm::distance(e.physics.position, playerPhysics.position);
+				if (d < 8.f)
+				{
+					if (d > 1.f)
+					{
+						glm::vec2 dir = glm::normalize(playerPhysics.position - e.physics.position);
+						float speed = 1.4;
+						e.physics.position += dir * input.deltaTime * speed;
+			
+						e.physics.desiredRotation = std::atan2(dir.x, dir.y);
+			
+						renderer.setEntityAnimationIndex(e.entity, zombieRun); //run 
+						renderer.setEntityAnimationSpeed(e.entity, 1.5);
+			
+					}
+					else
+					{
+						renderer.setEntityAnimationIndex(e.entity, zombieAttack); //attack
+						renderer.setEntityAnimationSpeed(e.entity, 1.3);
+			
+						if (e.attackCulldown <= 0.f)
+						{
+							//health -= 0.1;
+							e.attackCulldown = 1.f;
+						}
+						//attack
+					}
+				}
+				else
+				{
+					renderer.setEntityAnimationIndex(e.entity, zombieIdle); //idle
+					renderer.setEntityAnimationSpeed(e.entity, 1);
+				}
+			
+				if (e.attackCulldown > 0)
+				{
+					e.attackCulldown -= input.deltaTime;
+				}
+			
+				solveRotation(e.physics);
+			
+				//resolveConstrains(e.physics);
+				e.physics.updateMove();
+			
+				setTransform(e.physics, e.entity);
+
+				//requestedInfo.consoleWrite(std::to_string(e.physics.position.x) + " " +
+				//	std::to_string(e.physics.position.y) + "\n");
+			}
 
 
 
 
 #pragma region sword
 #pragma region sword
@@ -417,47 +515,15 @@ struct ThreeDGameExample: public Container
 
 
 #pragma region camera hover
 #pragma region camera hover
 			{
 			{
-			//cameraPos.y += cameraYoffset;
-
-			//auto checkHit = [&](glm::vec3 pos) -> bool
-			//{
-			//	for (int x = -2; x <= 2; x++)
-			//		for (int y = -2; y <= 2; y++)
-			//			for (int z = -2; z <= 2; z++)
-			//			{
-			//				glm::vec3 p = pos + glm::vec3(x, y, z);
-			//				if (getBlockSafe(p.x, p.y, p.z) != 0)
-			//				{
-			//					return true;
-			//				}
-			//			}
-			//	return false;
-			//};
-
-			//float hoverSpeed = 2;
-			//if (!diamonds.empty())
-			//{
-			//	if (checkHit(cameraPos))
-			//	{
-			//		cameraYoffset += input.deltaTime * hoverSpeed;
-			//	}
-			//	else
-			//	{
-			//		if (cameraYoffset > 0)
-			//			if (!checkHit(cameraPos -= glm::vec3(0, 0.1f, 0)))
-			//			{
-			//				cameraYoffset -= input.deltaTime * hoverSpeed;
-			//			}
-			//	}
-			//}
-			//else
-			//{
-			//	cameraYoffset += input.deltaTime;
-			//}
-			//
+			
+			if(health<=0)
+			{
+				cameraYoffset += input.deltaTime;
+			}
 			//
 			//
-			//cameraYoffset = std::max(cameraYoffset, 0.f);
 			//
 			//
+			cameraYoffset = std::max(cameraYoffset, 0.f);
+			cameraPos.y += cameraYoffset;
 			//cameraPos.x = std::max(cameraPos.x, 2.f);
 			//cameraPos.x = std::max(cameraPos.x, 2.f);
 
 
 			}
 			}
@@ -480,6 +546,10 @@ struct ThreeDGameExample: public Container
 	#pragma endregion
 	#pragma endregion
 
 
 
 
+
+		health = glm::clamp(health, 0.f, 1.f);
+
+
 	#pragma region render3d
 	#pragma region render3d
 
 
 		renderer.render(input.deltaTime);
 		renderer.render(input.deltaTime);
@@ -488,25 +558,37 @@ struct ThreeDGameExample: public Container
 
 
 
 
 	#pragma region ui
 	#pragma region ui
+		if(!freeCamera)
 		{
 		{
 			sushyContext.update(renderer2d, pika::toSushi(input), font);
 			sushyContext.update(renderer2d, pika::toSushi(input), font);
 			
 			
 			auto life = sushyContext.genUniqueParent("life");
 			auto life = sushyContext.genUniqueParent("life");
 			if (life)
 			if (life)
 			{
 			{
-				renderer2d.renderRectangle(life->outData.absTransform, {1,0,0,0.5});
+				auto t2 = life->outData.absTransform;
+				t2.z *= health;
+
+				renderer2d.renderRectangle(life->outData.absTransform, {0.5,0.5,0.5,0.1});
+				renderer2d.renderRectangle(t2, {1,0,0,0.5});
 			}
 			}
 			
 			
-			auto xp = sushyContext.genUniqueParent("xp");
-			if (xp)
-			{
-				renderer2d.renderRectangle(xp->outData.absTransform, {0,1,0,0.5});
-			}
+			//auto xp = sushyContext.genUniqueParent("xp");
+			//if (xp)
+			//{
+			//	renderer2d.renderRectangle(xp->outData.absTransform, {0,1,0,0.5});
+			//}
 			
 			
 			auto score = sushyContext.genUniqueParent("score");
 			auto score = sushyContext.genUniqueParent("score");
 			if (score)
 			if (score)
 			{
 			{
 				renderer2d.renderRectangle(score->outData.absTransform, {0.5,0.5,0.5,0.3});
 				renderer2d.renderRectangle(score->outData.absTransform, {0.5,0.5,0.5,0.3});
+
+				auto s = renderer2d.determineTextRescaleFit(std::to_string(killed).c_str(), font,
+					score->outData.absTransform);
+
+				renderer2d.renderText(glm::vec2(score->outData.absTransform) + glm::vec2{score->outData.absTransform.z,score->outData.absTransform.w} / 2.f,
+					std::to_string(killed).c_str(), font, Colors_White);
+
 			}
 			}
 			
 			
 			renderer2d.flush();
 			renderer2d.flush();
@@ -529,4 +611,5 @@ struct ThreeDGameExample: public Container
 //todo error popup
 //todo error popup
 //todo error popup disable in release
 //todo error popup disable in release
 
 
-//todo reset container button (keep same imgui id)
+//todo reset container button (keep same imgui id)
+

+ 104 - 0
Pika/gameplay/containers/threeDGameExample/threeDGameMenu.h

@@ -0,0 +1,104 @@
+#pragma once
+
+#include <gl2d/gl2d.h>
+#include <imgui.h>
+#include <baseContainer.h>
+#include <shortcutApi/shortcutApi.h>
+#include <pikaSizes.h>
+#include <imgui_spinner.h>
+#include <glui/glui.h>
+#include <engineLibraresSupport/engineGL2DSupport.h>
+
+struct ThreeDGameMenu : public Container
+{
+
+	gl2d::Renderer2D renderer;
+	gl2d::Font font;
+	gl2d::Texture logo;
+	gl2d::Texture button;
+	glui::RendererUi ui;
+
+	static ContainerStaticInfo containerInfo()
+	{
+		ContainerStaticInfo info = {};
+		info.defaultHeapMemorySize = pika::MB(100);
+
+		info.requestImguiFbo = true; 
+		//info.openOnApplicationStartup = true;
+		
+		
+
+		return info;
+	}
+
+
+	bool create(RequestedContainerInfo &requestedInfo, pika::StaticString<256> commandLineArgument)
+	{
+		renderer.create(requestedInfo.requestedFBO.fbo);
+		//pika::initShortcutApi(); //todo do this in dll load
+
+		font = pika::gl2d::loadFont(PIKA_RESOURCES_PATH "mcDungeons/CommodorePixeled.ttf", requestedInfo);
+		logo = pika::gl2d::loadTexture(PIKA_RESOURCES_PATH "threedgame/logo.png", requestedInfo);
+		button = pika::gl2d::loadTexture(PIKA_RESOURCES_PATH "mcDungeons/button.png", requestedInfo);
+
+
+		return true;
+	}
+
+	bool update(pika::Input input, pika::WindowState windowState,
+		RequestedContainerInfo &requestedInfo)
+	{
+
+		glClear(GL_COLOR_BUFFER_BIT);
+
+
+
+		renderer.updateWindowMetrics(windowState.windowW, windowState.windowH);
+
+		
+		ui.Begin(69);
+		{
+			
+			ui.Texture(1, logo);
+
+			if (ui.Button("Start game", Colors_White, button))
+			{
+				requestedInfo.createContainer("ThreeDGameExample");
+				return 0;
+			}
+
+			//ui.BeginMenu("Settings", Colors_White, button);
+			//{
+			//	if (ui.Button("Adaptive rezolution", Colors_White, button))
+			//	{
+			//
+			//	}
+			//}
+			//ui.EndMenu();
+
+		}
+		ui.End();
+
+
+		ui.renderFrame(renderer, font, {input.mouseX, input.mouseY},
+			input.lMouse.pressed(), input.lMouse.held(), input.lMouse.released(),
+			input.buttons[pika::Button::Escape].released(), input.typedInput, input.deltaTime);
+
+		renderer.flush();
+
+		
+
+		return true;
+	}
+
+	void destruct(RequestedContainerInfo &requestedInfo)
+	{
+
+		renderer.cleanup();
+		font.texture.cleanup();
+		logo.cleanup();
+		button.cleanup();
+
+	}
+
+};

BIN
Pika/resources/hollowknight/sprites.png


+ 2 - 2
Pika/resources/logs.txt

@@ -1,2 +1,2 @@
-#2023-10-18 16:26:43: Created container: ThreeDGameExample
-#2023-10-18 16:27:53: Destroyed continer: ThreeDGameExample #1
+#2023-12-18 12:43:56: Created container: ThreeDGameExample
+#2023-12-18 12:44:54: Destroyed continer: ThreeDGameExample #1

BIN
Pika/resources/threedgame/emissive.png


BIN
Pika/resources/threedgame/logo.png


BIN
Pika/resources/threedgame/normal.png


+ 1 - 1
Pika/resources/threedgame/settings.gl3d

@@ -1 +1 @@
-{"SSR":true,"SSRdata":{"maxRayDelta":0.6000000238418579,"maxRayStep":1.75,"maxSteps":20,"minRayStep":0.4000000059604645,"numBinarySearchSteps":7},"adaptiveResolution":false,"ambientb":1.7647058963775635,"ambientg":1.7647058963775635,"ambientr":1.7647058963775635,"chromaticAberation":false,"chromaticAberationData":{"strength":20.0,"unfocusDistance":5.0},"colorCorrection":false,"exposure":2.8289999961853027,"frustumCulling":false,"fxaa":true,"fxaaData":{"edgeDarkTreshold":0.24500000476837158,"edgeMinTreshold":0.004000000189989805,"iterations":30,"qualityMultiplyer":0.8240000009536743,"subPixelQuality":0.9259999990463257},"light subscatter":true,"normal mapping":true,"ssao":true,"ssaoData":{"bias":0.02500000037252903,"exponent":5.0,"radius":0.20000000298023224,"sampleCount":16}}
+{"SSR":true,"SSRdata":{"maxRayDelta":0.7940000295639038,"maxRayStep":1.75,"maxSteps":33,"minRayStep":0.35199999809265137,"numBinarySearchSteps":7},"adaptiveResolution":false,"ambientb":1.7647058963775635,"ambientg":1.7647058963775635,"ambientr":1.7647058963775635,"chromaticAberation":false,"chromaticAberationData":{"strength":20.0,"unfocusDistance":5.0},"colorCorrection":false,"exposure":2.8289999961853027,"frustumCulling":false,"fxaa":true,"fxaaData":{"edgeDarkTreshold":0.24500000476837158,"edgeMinTreshold":0.004000000189989805,"iterations":30,"qualityMultiplyer":0.8240000009536743,"subPixelQuality":0.9259999990463257},"light subscatter":true,"normal mapping":true,"ssao":true,"ssaoData":{"bias":0.02500000037252903,"exponent":5.0,"radius":0.20000000298023224,"sampleCount":16}}

+ 19 - 0
Pika/resources/threedgame/zombie.mtl

@@ -0,0 +1,19 @@
+# Blender MTL File: 'None'
+# Material Count: 1
+
+newmtl None
+
+Kd 1.000000 1.000000 1.000000
+Ke 0.000000 0.000000 0.000000
+Ni 1.000000
+d 1.000000
+Pm 0
+Pr 0.5
+Ao 1
+illum 2
+map_Kd zombie.png
+map_emissive emissive.png
+map_Kn normal.png
+
+# map_RMA rma.png
+# 

BIN
Pika/resources/threedgame/zombie.png


+ 8 - 6
Pika/thirdparty/gl3d/gl3d.cpp

@@ -36394,7 +36394,7 @@ namespace gl3d
 
 
 	
 	
 	Material Renderer3D::createMaterial(int quality, glm::vec4 kd,
 	Material Renderer3D::createMaterial(int quality, glm::vec4 kd,
-		float roughness, float metallic, float ao, std::string name,
+		float roughness, float metallic, float ao, float emissive, std::string name,
 		gl3d::Texture albedoTexture, gl3d::Texture normalTexture, gl3d::Texture roughnessTexture, gl3d::Texture metallicTexture,
 		gl3d::Texture albedoTexture, gl3d::Texture normalTexture, gl3d::Texture roughnessTexture, gl3d::Texture metallicTexture,
 		gl3d::Texture occlusionTexture, gl3d::Texture emmisiveTexture)
 		gl3d::Texture occlusionTexture, gl3d::Texture emmisiveTexture)
 	{
 	{
@@ -36406,6 +36406,7 @@ namespace gl3d
 		gpuMaterial.roughness = roughness;
 		gpuMaterial.roughness = roughness;
 		gpuMaterial.metallic = metallic;
 		gpuMaterial.metallic = metallic;
 		gpuMaterial.ao = ao;
 		gpuMaterial.ao = ao;
+		gpuMaterial.emmisive = emissive;
 
 
 		TextureDataForMaterial textureData{};
 		TextureDataForMaterial textureData{};
 
 
@@ -36446,7 +36447,7 @@ namespace gl3d
 		objl::Material &mat, const std::string &path, GLuint frameBuffer, int quality)
 		objl::Material &mat, const std::string &path, GLuint frameBuffer, int quality)
 	{
 	{
 		auto m = renderer.createMaterial(quality, mat.Kd, mat.roughness,
 		auto m = renderer.createMaterial(quality, mat.Kd, mat.roughness,
-			mat.metallic, mat.ao, mat.name);
+			mat.metallic, mat.ao, 0, mat.name);
 
 
 		stbi_set_flip_vertically_on_load(true);
 		stbi_set_flip_vertically_on_load(true);
 
 
@@ -37251,7 +37252,8 @@ namespace gl3d
 				}else
 				}else
 				{
 				{
 					//if no material loaded for this object create a new default one
 					//if no material loaded for this object create a new default one
-					gm.material = createMaterial(quality, glm::vec4{ 0.8f,0.8f,0.8f, 1.0f }, 0.5f, 0.f, 1.f, "default material");
+					gm.material = createMaterial(quality, glm::vec4{ 0.8f,0.8f,0.8f, 1.0f }, 0.5f, 0.f, 1.f, 0.f,
+						"default material");
 				}
 				}
 				
 				
 				gm.ownMaterial = true;
 				gm.ownMaterial = true;
@@ -38268,7 +38270,7 @@ namespace gl3d
 				if (mat != data)
 				if (mat != data)
 				{
 				{
 					Material newMat = this->createMaterial(TextureLoadQuality::dontSet, mat.kd, mat.roughness,
 					Material newMat = this->createMaterial(TextureLoadQuality::dontSet, mat.kd, mat.roughness,
-						mat.metallic, mat.ao, name);
+						mat.metallic, mat.ao, mat.emmisive, name);
 					int newMatIndex = internal.getMaterialIndex(newMat); //this should not fail
 					int newMatIndex = internal.getMaterialIndex(newMat); //this should not fail
 
 
 					internal.materialTexturesData[newMatIndex] = textures;
 					internal.materialTexturesData[newMatIndex] = textures;
@@ -38338,7 +38340,7 @@ namespace gl3d
 				if (name != oldName) //copy to new material
 				if (name != oldName) //copy to new material
 				{
 				{
 					Material newMat = this->createMaterial(TextureLoadQuality::dontSet, data.kd, data.roughness,
 					Material newMat = this->createMaterial(TextureLoadQuality::dontSet, data.kd, data.roughness,
-						data.metallic, data.ao, name);
+						data.metallic, data.ao, data.emmisive, name);
 					int newMatIndex = internal.getMaterialIndex(newMat); //this should not fail
 					int newMatIndex = internal.getMaterialIndex(newMat); //this should not fail
 					internal.materialTexturesData[newMatIndex] = textures;
 					internal.materialTexturesData[newMatIndex] = textures;
 
 
@@ -38433,7 +38435,7 @@ namespace gl3d
 				if (texture != oldTextures) //copy to new material
 				if (texture != oldTextures) //copy to new material
 				{
 				{
 					Material newMat = this->createMaterial(TextureLoadQuality::dontSet, data.kd, data.roughness,
 					Material newMat = this->createMaterial(TextureLoadQuality::dontSet, data.kd, data.roughness,
-						data.metallic, data.ao, oldName);
+						data.metallic, data.ao, data.emmisive, oldName);
 					int newMatIndex = internal.getMaterialIndex(newMat); //this should not fail
 					int newMatIndex = internal.getMaterialIndex(newMat); //this should not fail
 					internal.materialTexturesData[newMatIndex] = texture; //new textures
 					internal.materialTexturesData[newMatIndex] = texture; //new textures
 
 

+ 1 - 1
Pika/thirdparty/gl3d/gl3d.h

@@ -34592,7 +34592,7 @@ namespace gl3d
 	#pragma region material
 	#pragma region material
 		
 		
 		Material createMaterial(int quality, glm::vec4 kd = glm::vec4(1),
 		Material createMaterial(int quality, glm::vec4 kd = glm::vec4(1),
-			float roughness = 0.5f, float metallic = 0.1, float ao = 1.f, std::string name = "",
+			float roughness = 0.5f, float metallic = 0.1, float ao = 1.f, float emissive = 0.f, std::string name = "",
 			gl3d::Texture albedoTexture = {}, gl3d::Texture normalTexture = {}, gl3d::Texture roughnessTexture = {}, gl3d::Texture metallicTexture = {},
 			gl3d::Texture albedoTexture = {}, gl3d::Texture normalTexture = {}, gl3d::Texture roughnessTexture = {}, gl3d::Texture metallicTexture = {},
 			gl3d::Texture occlusionTexture = {}, gl3d::Texture emmisiveTexture = {});
 			gl3d::Texture occlusionTexture = {}, gl3d::Texture emmisiveTexture = {});