Browse Source

finished mariokart

vlod 1 year ago
parent
commit
ff59679394

+ 1 - 1
Pika/core/coreConfig/pikaConfig.h

@@ -28,7 +28,7 @@
 #define PIKA_INTERNAL_CURRENT_ASSERT_FUNCTION pika::assert::assertFunctionDevelopment
 //#define PIKA_INTERNAL_CURRENT_ASSERT_FUNCTION pika::assert::assertFunctionToLog
 //#define PIKA_INTERNAL_CURRENT_ASSERT_FUNCTION pika::assert::terminate
-//#define PIKA_INTERNAL_CURRENT_ASSERT_FUNCTION //remove all asserts in production
+//#define PIKA_INTERNAL_CURRENT_ASSERT_FUNCTION //remove all asserts in production (I don't recommand this)
 
 
 

+ 2 - 2
Pika/gameplay/containers.h

@@ -21,7 +21,7 @@ Container *getContainer(const char* name, pika::memory::MemoryArena *memoryArena
 #include "pluggins/pikatextEditor.h"
 #include "pluggins/sushiViewer/sushiViewer.h"
 
-//#include "containers/mario/mario.h"
+#include "containers/mario/mario.h"
 //#include "containers/mario/marioEditor.h"
 //#include "containers/mario/marioNeuralVizualizer.h"
 //#include "containers/mario/marioNeuralTrainer.h"
@@ -63,13 +63,13 @@ Container *getContainer(const char* name, pika::memory::MemoryArena *memoryArena
 	PIKA_DECLARE_CONTAINER(MarioKartEditor) \
 	PIKA_DECLARE_CONTAINER(MarioKart) \
 	PIKA_DECLARE_CONTAINER(IsometricGameEditor) \
+	PIKA_DECLARE_CONTAINER(Mario) \
 	PIKA_DECLARE_CONTAINER(IsometricGame)
 	//PIKA_DECLARE_CONTAINER(McDungeonsGameplay) \
 	//PIKA_DECLARE_CONTAINER(McDungeonsEditor)
 	//PIKA_DECLARE_CONTAINER(McDungeonsMenu)
 
 	//PIKA_DECLARE_CONTAINER(Holloknight)\
-	//PIKA_DECLARE_CONTAINER(Mario) \
 	//PIKA_DECLARE_CONTAINER(MarioEditor) \
 	//PIKA_DECLARE_CONTAINER(MarioNeuralTrainer) \
 	//PIKA_DECLARE_CONTAINER(MarioNeuralVizualizer) \

+ 5 - 2
Pika/gameplay/containers/mario/mario.h

@@ -132,8 +132,8 @@ struct Mario: public Container
 		renderer.update(input, windowState, simulator);
 		renderer.followPlayer(player, input, windowState);
 		renderer.drawPlayer(player);
-		//renderer.render();
-
+		
+		
 		renderer.renderer.flushFBO(fbo);
 		renderer.renderer.pushCamera();
 		renderer.renderer.pushShader(postProcessShader);
@@ -142,6 +142,9 @@ struct Mario: public Container
 		renderer.renderer.popShader();
 		renderer.renderer.popCamera();
 
+		renderer.render();
+
+
 		return true;
 	}
 

+ 1 - 4
Pika/gameplay/containers/mario/marioCommon.h

@@ -253,14 +253,11 @@ struct GameplayRenderer
 				}
 		}
 
-		
-
 
 	}
 
 	void followPlayer(mario::Player &p, pika::Input &input, pika::WindowState &windowState)
 	{
-		//todo update gl2d this function
 		renderer.currentCamera.follow(p.position.getCenter(), input.deltaTime * 3, 0.0001, 0.2, windowState.windowW, windowState.windowH);
 
 
@@ -271,7 +268,7 @@ struct GameplayRenderer
 		glm::vec4 pos(p.position.position, 1, 1);
 		//pos.y -= 1 / 8.f;
 		pos.x -= 1 / 8.f;
-		renderer.renderRectangle(pos, marioTexture,
+		renderer.renderRectangle(pos, marioTexture, Colors_White, {}, 0.f, 
 			p.movingRight ? glm::vec4(0, 1, 1, 0) : glm::vec4(1, 1, 0, 0));
 	}
 

+ 107 - 6
Pika/gameplay/containers/marioKart/marioKart.h

@@ -41,6 +41,8 @@ struct MarioKart: public Container
 		glm::vec3 carPosition = {};
 		glm::vec3 moveDirection = glm::normalize(glm::vec3{0,0,-1});
 		int carMarker = 0;
+		float randomSpeed = 1;
+		float randomSpeedTimer = (rand()%10)/5.f;
 	};
 
 	struct GameplayData
@@ -52,6 +54,11 @@ struct MarioKart: public Container
 
 	Pilot player;
 
+	Pilot bowser;
+	Pilot boo;
+
+
+
 	//todo user can request imgui ids; shortcut manager context; allocators
 	static ContainerStaticInfo containerInfo()
 	{
@@ -163,6 +170,12 @@ struct MarioKart: public Container
 		player.car = renderer.createEntity(carModel, {}, false);
 		player.character = renderer.createEntity(marioModel, {}, false);
 
+		bowser.car = renderer.createEntity(carModel, {}, false);
+		bowser.character = renderer.createEntity(bowserModel, {}, false);
+
+		boo.car = renderer.createEntity(carModel, {}, false);
+		boo.character = renderer.createEntity(booModel, {}, false);
+
 		size_t size = 0;
 		if (requestedInfo.getFileSizeBinary(PIKA_RESOURCES_PATH "/marioKart/markers.bin", size))
 		{
@@ -209,12 +222,20 @@ struct MarioKart: public Container
 		for (int i = 0; i < 4; i++)
 		{
 			player.wheels[i] = renderer.createEntity(wheelModel, {}, false);
+			bowser.wheels[i] = renderer.createEntity(wheelModel, {}, false);
+			boo.wheels[i] = renderer.createEntity(wheelModel, {}, false);
 		}
 
 		if (markers.size() >= 2)
 		{
 			auto pos = markers[0].position;
 			player.carPosition = pos;
+
+
+			auto leftVector = -glm::normalize(glm::cross(markers[1].position - markers[0].position, glm::vec3(0, 1, 0)));
+
+			bowser.carPosition = pos + leftVector * 1.f;
+			boo.carPosition = pos - leftVector * 1.f;
 		}
 		else
 		{
@@ -384,7 +405,7 @@ struct MarioKart: public Container
 		float tilt = 0;
 
 		//input
-		if (markers.size() >= 2 && gameplayData.gameplayPhaze == 1)
+		if (markers.size() >= 2)
 		{
 
 			float moveForward = 0;
@@ -411,6 +432,12 @@ struct MarioKart: public Container
 				return isLeft2({a.x,a.z}, {b.x,b.z}, {c.x, c.z});
 			};
 
+			if (gameplayData.gameplayPhaze != 1)
+			{
+				moveForward = 0;
+				acceleration = 0;
+			}
+
 			if (!moveForward)
 			{
 				if (acceleration > 0)
@@ -519,14 +546,76 @@ struct MarioKart: public Container
 			}
 
 
-			auto updateCar = [&](Pilot &pilot)
+			auto updateCar = [&](Pilot &pilot, bool enemy, float enemySpeed = 0)
 			{
 				auto m1 = markers[pilot.carMarker];
 				auto m2 = markers[(pilot.carMarker + 1) % markers.size()];
 
+				if (enemy)
+				{
+
+					pilot.randomSpeedTimer -= input.deltaTime;
+					if (pilot.randomSpeedTimer < 0)
+					{
+						pilot.randomSpeedTimer = (rand() % 20) / 5.f;
+						pilot.randomSpeed = rand() % 5 + 6;
+					}
+
+
+					if (enemySpeed)
+					{
+						glm::vec3 roadLine = m2.position - m1.position;
+						glm::vec3 p = pilot.carPosition - m1.position;
+						p.y = 0;
+						roadLine.y = 0;
+						auto projPoint = glm::dot(p, roadLine) / glm::length(roadLine);
+						float l = glm::length(projPoint);
+						float final = l / glm::length(roadLine);
+
+						glm::vec3 direction = glm::normalize(roadLine);
+						//pilot.moveDirection = direction;
+
+
+						//auto oldPos = carPosition;
+						//carPosition += 
+						auto move = direction * enemySpeed;
+
+						//glm::vec2 newDelta = markerDelta + glm::vec2(move.x, move.y);
+
+						auto m1 = markers[pilot.carMarker];
+						auto m2 = markers[(pilot.carMarker + 1) % markers.size()];
+
+						if (!isLeft(getLeft(m1), getLeft(m2), pilot.carPosition + glm::vec3(move.x, 0, move.z)))
+						{
+							acceleration = -acceleration * 0.2;
+						}
+						else if (isLeft(getRight(m1), getRight(m2), pilot.carPosition + glm::vec3(move.x, 0, move.z)))
+						{
+							acceleration = -acceleration * 0.2;
+						}
+						else
+						{
+
+							if (!isLeft(getLeft(m2), getRight(m2), pilot.carPosition + glm::vec3(move.x, 0, move.z)))
+							{
+								pilot.carMarker++;
+								pilot.carMarker = pilot.carMarker % markers.size();
+							}
+							else if (isLeft(getLeft(m1), getRight(m1), pilot.carPosition + glm::vec3(move.x, 0, move.z)))
+							{
+								pilot.carMarker--;
+								if (pilot.carMarker < 0) { pilot.carMarker = markers.size() - 1; }
+							}
+
+							pilot.carPosition += glm::vec3(move.x, 0, move.z);
+						}
+					}
+
+				}
+
 				{
 					glm::vec3 roadLine = m2.position - m1.position;
-					glm::vec3 p = pilot.carPosition - m1.position; p.y = 0;
+					glm::vec3 p = pilot.carPosition - m1.position;
 					p.y = 0;
 					roadLine.y = 0;
 
@@ -554,7 +643,14 @@ struct MarioKart: public Container
 				renderer.setEntityTransform(pilot.character, t);
 
 				static float wheelTimer = 0;
-				wheelTimer += input.deltaTime * acceleration;
+				if (enemy)
+				{
+					wheelTimer += input.deltaTime * enemySpeed;
+				}
+				else
+				{
+					wheelTimer += input.deltaTime * acceleration;
+				}
 
 				t.scale *= glm::vec3(0.065);
 				for (int i = 0; i < 4; i++)
@@ -580,10 +676,15 @@ struct MarioKart: public Container
 				}
 			};
 
-			updateCar(player);
-			
+
+
+			updateCar(player, false);
+			updateCar(bowser, true, (gameplayData.gameplayPhaze == 1) * input.deltaTime * bowser.randomSpeed);
+			updateCar(boo, true, (gameplayData.gameplayPhaze == 1) * input.deltaTime * boo.randomSpeed);
+
 		}
 
+
 			
 		if (input.buttons[pika::Button::P].pressed())
 		{

+ 14 - 1
Pika/gameplay/containers/pikaGameplay.h

@@ -64,6 +64,20 @@ struct Gameplay : public Container
 	{
 		//todo keep window on top stuff
 
+
+
+
+
+		if (input.buttons[pika::Button::A].released())
+		{
+			//.. A button was released
+		}
+
+
+
+
+
+
 		glClear(GL_COLOR_BUFFER_BIT);
 
 		if (pika::shortcut(input, "Ctrl + S"))
@@ -83,7 +97,6 @@ struct Gameplay : public Container
 
 		requestedInfo.consoleWrite(input.typedInput);
 
-
 		if (input.buttons[pika::Button::P].held())
 		{
 			requestedInfo.consoleWrite(std::to_string(input.deltaTime).c_str());

+ 7 - 31
Pika/resources/logs.txt

@@ -1,31 +1,7 @@
-#2024-01-22 22:15:39: Created container: MarioKartEditor
-#2024-01-22 22:18:24: Destroyed continer: MarioKartEditor #1
-#2024-01-22 22:21:13: Reloaded dll
-#2024-01-22 22:21:19: Created container: MarioKart
-#2024-01-22 22:21:55: Destroyed continer: MarioKart #2
-#2024-01-22 22:22:02: Created container: MarioKartEditor
-#2024-01-22 22:27:25: Reloaded dll
-#2024-01-22 22:27:25: Destroyed continer: MarioKartEditor #3
-#2024-01-22 22:27:29: Created container: MarioKart
-#2024-01-22 22:27:49: Destroyed continer: MarioKart #4
-#2024-01-22 22:27:55: Created container: MarioKartEditor
-#2024-01-22 22:29:17: Destroyed continer: MarioKartEditor #5
-#2024-01-22 22:29:22: Reloaded dll
-#2024-01-22 22:29:26: Created container: MarioKart
-#2024-01-22 22:29:47: Destroyed continer: MarioKart #6
-#2024-01-22 22:29:51: Reloaded dll
-#2024-01-22 22:29:55: Created container: MarioKart
-#2024-01-22 22:30:23: Destroyed continer: MarioKart #7
-#2024-01-22 22:30:27: Reloaded dll
-#2024-01-22 22:30:30: Created container: MarioKart
-#2024-01-22 22:30:59: Destroyed continer: MarioKart #8
-#2024-01-22 22:31:03: Reloaded dll
-#2024-01-22 22:31:08: Created container: MarioKart
-#2024-01-22 22:31:28: Destroyed continer: MarioKart #9
-#2024-01-22 22:31:33: Created container: MarioKartEditor
-#2024-01-22 22:32:06: Destroyed continer: MarioKartEditor #10
-#2024-01-22 22:32:14: Reloaded dll
-#2024-01-22 22:32:18: Created container: MarioKart
-#2024-01-22 22:33:29: Destroyed continer: MarioKart #11
-#2024-01-22 22:33:32: Created container: MarioKart
-#2024-01-22 22:34:29: Destroyed continer: MarioKart #12
+#2024-02-21 10:42:57: Created container: MarioKart
+#2024-02-21 10:43:30: Destroyed continer: MarioKart #1
+#2024-02-21 10:43:40: Created container: MarioKart
+#2024-02-21 10:44:01: Destroyed continer: MarioKart #2
+#2024-02-21 10:46:07: Reloaded dll
+#2024-02-21 10:46:16: Created container: MarioKart
+#2024-02-21 10:47:18: Destroyed continer: MarioKart #3

+ 2 - 2
Pika/resources/mario/postProcess.frag

@@ -25,6 +25,6 @@ void main()
 
 	//color.rgb = vec3(length(color.rgb));
 
-	color = texture2D(u_sampler, v_texture);
-	color.a = 1;
+	//color = texture2D(u_sampler, v_texture);
+	//color.a = 1;
 }