Selaa lähdekoodia

added controller input

meemknight 2 vuotta sitten
vanhempi
sitoutus
a11fc565fa

+ 1 - 1
Pika/CMakeLists.txt

@@ -78,7 +78,7 @@ target_include_directories(pikaCore PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/pik
 target_include_directories(pikaCore PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/pikaRuntime/")
 target_include_directories(pikaCore PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/pikaSTD/")
 target_include_directories(pikaCore PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/sharedRuntime/")
-target_link_libraries(pikaCore PRIVATE glad glfw gl2d  gl3d glui glm stb_image stb_truetype imgui safeSave profilerLib box2d)
+target_link_libraries(pikaCore PRIVATE glad glfw gl2d  gl3d glui glm stb_image stb_truetype imgui safeSave profilerLib)
 #################^^^^^^^^#############################
 
 

+ 8 - 1
Pika/core/pikaRuntime/containerManager/containerManager.cpp

@@ -430,6 +430,13 @@ void pika::ContainerManager::update(pika::LoadedDll &loadedDll, pika::PikaWindow
 						{
 							windowInput.buttons[i] = {};
 						}
+
+						for (int i = 0; i < Input::MAX_CONTROLLERS_COUNT; i++)
+						{
+							windowInput.controllers[i].resetAllButtons();
+						}
+
+						windowInput.anyController.resetAllButtons();
 					}
 
 				}
@@ -488,7 +495,7 @@ void pika::ContainerManager::update(pika::LoadedDll &loadedDll, pika::PikaWindow
 				ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.f, 0.f, 0.f, 1.0f));
 				ImGui::SetNextWindowSize({200,200}, ImGuiCond_Once);
 				ImGui::Begin( (std::string("gameplay window id: ") + std::to_string(c.first)).c_str(),
-					&isOpen, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
+					&isOpen, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoNav);
 				
 				//mouse pos and focus
 				auto windowPos = ImGui::GetWindowPos();

+ 4 - 4
Pika/core/pikaSTD/engineLibraresSupport/engineGL2DSupport.cpp

@@ -84,7 +84,7 @@
 	return f;
 }
 
-void pika::gl2d::cameraController(::gl2d::Camera &c, Input &input, float speed)
+void pika::gl2d::cameraController(::gl2d::Camera &c, Input &input, float speed, float zoomSpeed)
 {
 	if (input.buttons[pika::Button::W].held())
 	{
@@ -104,12 +104,12 @@ void pika::gl2d::cameraController(::gl2d::Camera &c, Input &input, float speed)
 	}
 	if (input.buttons[pika::Button::Q].held())
 	{
-		c.zoom -= 1 * input.deltaTime;
+		c.zoom -= zoomSpeed * input.deltaTime;
 	}
 	if (input.buttons[pika::Button::E].held())
 	{
-		c.zoom += 1 * input.deltaTime;
+		c.zoom += zoomSpeed * input.deltaTime;
 	}
 
-	c.zoom = glm::clamp(c.zoom, 0.0001f, 1000.f);
+	c.zoom = glm::clamp(c.zoom, 0.001f, 1000.f);
 }

+ 1 - 1
Pika/core/pikaSTD/engineLibraresSupport/engineGL2DSupport.h

@@ -20,7 +20,7 @@ namespace pika
 		::gl2d::Font loadFont(const char *path, RequestedContainerInfo &info);
 
 		//speed without delta time
-		void cameraController(::gl2d::Camera &c, Input &input, float speed);
+		void cameraController(::gl2d::Camera &c, Input &input, float speed, float zoomSpeed);
 
 	}
 

+ 1 - 1
Pika/core/sharedRuntime/windowSystemm/callbacks.cpp

@@ -38,7 +38,7 @@ void windowFocusCallback(GLFWwindow *window, int focused)
 	}
 }
 
-static void processAButton(pika::Button &b, int action)
+void pika::processAButton(pika::Button &b, int action)
 {
 	if (action == GLFW_PRESS)
 	{

+ 55 - 5
Pika/core/sharedRuntime/windowSystemm/input.h

@@ -1,7 +1,6 @@
 #pragma once
 #include <cstdint>
 
-
 #define PIKA_ADD_FLAG(NAME, SETNAME, VALUE)	\
 	bool NAME() const {return (flags & ((std::uint32_t)1<<VALUE)); } \
 	void SETNAME(bool s) { \
@@ -18,7 +17,7 @@ namespace pika
 	{
 		//internal use only
 		float timer = 0;
-
+	
 		//internal use only
 		std::uint32_t flags = 0;
 
@@ -54,6 +53,54 @@ namespace pika
 
 	};
 
+	struct Controller
+	{
+		enum Buttons
+		{
+			A = 0,
+			B,
+			X,
+			Y,
+			LBumper,
+			RBumper,
+			Back,
+			Start,
+			Guide,
+			LThumb,
+			Rthumb,
+			Up,
+			Right,
+			Down,
+			Left,
+			ButtonsCount
+		};
+
+		Button buttons[Buttons::ButtonsCount] = {};
+		
+		float LT = 0.f;
+		float RT = 0.f;
+
+		struct
+		{
+			constexpr static float JOYSTICK_SENSITIVITY = 0.7f;
+
+			float x = 0.f, y = 0.f;
+
+			bool left() { return x < -JOYSTICK_SENSITIVITY; }
+			bool right() { return x > JOYSTICK_SENSITIVITY; }
+			bool up() { return y > JOYSTICK_SENSITIVITY; }
+			bool down() { return y < -JOYSTICK_SENSITIVITY; }
+
+		}LStick, RStick;
+
+		bool connected = 0;
+
+		void resetAllButtons() 
+		{
+			*this = {};
+		}
+	};
+
 	struct Input
 	{
 		//typed input doesn't work with mouse buttons
@@ -74,12 +121,15 @@ namespace pika
 		bool hasFocus = 0;
 		bool lastFrameHasFocus = 0;
 
-	};
-
-	
+		constexpr static int MAX_CONTROLLERS_COUNT = 4; //don't change
+		Controller controllers[MAX_CONTROLLERS_COUNT] = {};
 
+		//a logic or between all the controllers
+		Controller anyController = {};
+	};
 
 
+	void processAButton(pika::Button &b, int action);
 
 };
 

+ 84 - 2
Pika/core/sharedRuntime/windowSystemm/window.cpp

@@ -145,13 +145,19 @@ void pika::PikaWindow::update()
 
 	memset(input.typedInput, 0, sizeof(input.typedInput));
 
-#pragma endregion
+	for (int i = 0; i < Input::MAX_CONTROLLERS_COUNT; i++)
+	{
+		for (int j = 0; j < Controller::Buttons::ButtonsCount; j++)
+		{
+			processInputBefore(input.controllers[i].buttons[j]);
+		}
+	}
 
+#pragma endregion
 
 	glfwPollEvents();
 	glfwSwapBuffers(context.wind);
 
-
 #pragma region window state
 
 	{
@@ -172,6 +178,44 @@ void pika::PikaWindow::update()
 
 #pragma region input
 
+	#pragma region controller
+	for (int i = 0; i <= Input::MAX_CONTROLLERS_COUNT; i++)
+	{
+		if (glfwJoystickPresent(i) && glfwJoystickIsGamepad(i))
+		{
+			input.controllers[i].connected = true;
+
+			GLFWgamepadstate state;
+
+			if (glfwGetGamepadState(i, &state))
+			{
+				for (int b = 0; b <= GLFW_GAMEPAD_BUTTON_LAST; b++)
+				{
+					pika::processAButton(input.controllers[i].buttons[b], state.buttons[b]);
+
+					//updateButton(controllerButtons.buttons[i], deltaTime); //todo implement double epressed
+				}
+
+				input.controllers[i].LT = state.axes[GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER];
+				input.controllers[i].RT = state.axes[GLFW_GAMEPAD_AXIS_LEFT_TRIGGER];
+
+				input.controllers[i].LStick.x = state.axes[GLFW_GAMEPAD_AXIS_LEFT_X];
+				input.controllers[i].LStick.y = state.axes[GLFW_GAMEPAD_AXIS_LEFT_Y];
+
+				input.controllers[i].RStick.x = state.axes[GLFW_GAMEPAD_AXIS_RIGHT_X];
+				input.controllers[i].RStick.y = state.axes[GLFW_GAMEPAD_AXIS_RIGHT_Y];
+			}
+		}
+		else
+		{
+			input.controllers[i].resetAllButtons();
+		}
+
+	}
+
+	#pragma endregion
+
+
 	double mouseX = 0;
 	double mouseY = 0;
 	glfwGetCursorPos(context.wind, &mouseX, &mouseY);
@@ -212,6 +256,44 @@ void pika::PikaWindow::update()
 		processInput(input.buttons[i]);
 	}
 
+	#pragma region controller
+	for (int i = 0; i < Input::MAX_CONTROLLERS_COUNT; i++)
+	{
+		if(input.controllers[i].connected)
+		for (int b = 0; b <= GLFW_GAMEPAD_BUTTON_LAST; b++)
+		{
+			processInput(input.controllers[i].buttons[b]);
+		}
+	}
+
+	input.anyController.resetAllButtons();
+	for (int i = 0; i <= Input::MAX_CONTROLLERS_COUNT; i++)
+	{
+		input.controllers[i].connected = true;
+
+		if (input.controllers[i].connected)
+		{
+			input.anyController.connected = true;
+
+			for (int b = 0; b <= GLFW_GAMEPAD_BUTTON_LAST; b++)
+			{
+				input.anyController.buttons[b].flags
+					|= input.controllers[i].buttons[b].flags;
+			}
+
+			if (!input.anyController.LT) input.anyController.LT = input.controllers[i].LT;
+			if (!input.anyController.RT) input.anyController.RT = input.controllers[i].RT;
+
+			if (!input.anyController.LStick.x) input.anyController.LStick.x = input.controllers[i].LStick.x;
+			if (!input.anyController.LStick.y) input.anyController.LStick.y = input.controllers[i].LStick.y;
+
+			if (!input.anyController.RStick.x)  input.anyController.RStick.x = input.controllers[i].RStick.x;
+			if (!input.anyController.RStick.y) input.anyController.RStick.y = input.controllers[i].RStick.y;
+		}
+
+	}
+	#pragma endregion
+
 
 #pragma endregion
 

+ 0 - 1
Pika/core/sharedRuntime/windowSystemm/window.h

@@ -32,7 +32,6 @@ namespace pika
 		//on live code editing this will be recorded every frame
 		Input input = {};
 
-
 		WindowState windowState = {};
 
 		//this doesn't return error codes because it will do the asserts for you

+ 383 - 30
Pika/gameplay/containers/hollowknight/hollowknight.h

@@ -8,6 +8,7 @@
 #include <imgui_spinner.h>
 #include <box2d/box2d.h>
 #include <engineLibraresSupport/engineGL2DSupport.h>
+#include <pikaImgui/pikaImgui.h>
 
 struct Holloknight: public Container
 {
@@ -24,23 +25,71 @@ struct Holloknight: public Container
 		info.defaultHeapMemorySize = pika::MB(10);
 
 		info.requestImguiFbo = true; 
-
+		info.pushAnImguiIdForMe = true;
 
 		return info;
 	}
 
 	struct Block 
 	{
-		glm::vec4 dimensions = {};
+
 		b2Body *dynamicBody = 0;
-		float rotationRadians = 0;
+		glm::vec2 getPosCenter() 
+		{
+			auto pos = dynamicBody->GetPosition();
+			return {pos.x,pos.y};
+		};
+
+		glm::vec2 getSize()
+		{
+			auto f = dynamicBody->GetFixtureList(); if (!f) return {};
+			auto s = f->GetShape(); if (!s) return {};
+
+			if (s->GetType() == b2Shape::Type::e_polygon)
+			{
+				b2PolygonShape *poligon = dynamic_cast<b2PolygonShape *>(s);
+
+				if (poligon)
+				{
+					glm::vec2 min{999999,999999};
+					glm::vec2 max{-999999,-999999};
+
+					for (int i = 0; i < poligon->m_count; i++)
+					{
+						glm::vec2 p1 = {poligon->m_vertices[i].x,poligon->m_vertices[i].y};
+						
+						if (p1.x > max.x) { max.x = p1.x; }
+						if (p1.y > max.y) { max.y = p1.y; }
+
+						if (p1.x < min.x) { min.x = p1.x; }
+						if (p1.y < min.y) { min.y = p1.y; }
+					}
+
+					glm::vec2 size = max - min;
+
+					return size;
+				}
+
+			}
+
+			return {};
+		}
+
+		glm::vec2 getPosTopLeft()
+		{
+			auto pos = dynamicBody->GetPosition();
+			return glm::vec2(pos.x,pos.y) - getSize()/2.f;
+		};
+
+		float getRotation()
+		{
+			return dynamicBody->GetAngle();
+		}
 
 		void create(b2World &world, glm::vec4 dimensions, bool dynamic)
 		{
-			this->dimensions = dimensions;
-		
 			b2BodyDef myBodyDef;
-			if(dynamic)
+			if (dynamic)
 				myBodyDef.type = b2_dynamicBody; //this will be a dynamic body
 
 			dimensions.x += dimensions.z / 2.f;
@@ -52,7 +101,7 @@ struct Holloknight: public Container
 			dynamicBody = world.CreateBody(&myBodyDef);
 
 			b2PolygonShape boxShape;
-			boxShape.SetAsBox(dimensions.z/2, dimensions.w / 2);
+			boxShape.SetAsBox(dimensions.z / 2, dimensions.w / 2);
 
 			b2FixtureDef boxFixtureDef;
 			boxFixtureDef.shape = &boxShape;
@@ -60,20 +109,59 @@ struct Holloknight: public Container
 			dynamicBody->CreateFixture(&boxFixtureDef);
 		}
 
-		//remove
-		void updateMetrics(b2World &world) 
+		b2Fixture *addSensor(glm::vec4 dimensionsRelativeToCenter)
 		{
-			auto pos = dynamicBody->GetPosition();
-			dimensions.x = pos.x;
-			dimensions.y = pos.y;
+			b2PolygonShape boxShape;
+
+			b2Vec2 pos(dimensionsRelativeToCenter.x, dimensionsRelativeToCenter.y);
 
-			rotationRadians = dynamicBody->GetAngle();
+			b2Vec2 topLeft(-dimensionsRelativeToCenter.z / 2, dimensionsRelativeToCenter.w / 2);
+			b2Vec2 bottomLeft(-dimensionsRelativeToCenter.z / 2, -dimensionsRelativeToCenter.w / 2);
+			b2Vec2 bottomRight(dimensionsRelativeToCenter.z / 2, -dimensionsRelativeToCenter.w / 2);
+			b2Vec2 topRight(dimensionsRelativeToCenter.z / 2, dimensionsRelativeToCenter.w / 2);
+
+			b2Vec2 points[4] =
+			{
+				topLeft + pos,
+				bottomLeft + pos,
+				bottomRight + pos,
+				topRight + pos
+			};
+
+			boxShape.Set(points, 4);
+
+			b2FixtureDef boxFixtureDef;
+			boxFixtureDef.shape = &boxShape;
+			boxFixtureDef.density = 0;
+			boxFixtureDef.isSensor = true;
+
+			b2Fixture * f = dynamicBody->CreateFixture(&boxFixtureDef);
+			return f;
 		}
 
 		void render(gl2d::Renderer2D &renderer, glm::vec4 color) 
 		{
+			glm::vec4 dimensions(getPosCenter(), getSize());
 			renderer.renderRectangle({dimensions.x - dimensions.z / 2,dimensions.y - dimensions.w / 2,
-				dimensions.z,dimensions.w}, color, {}, -glm::degrees(rotationRadians));
+				dimensions.z,dimensions.w}, color, {}, -glm::degrees(getRotation()));
+		}
+	};
+
+	struct Entity
+	{
+		Block physicalBody;
+		
+		glm::vec4 spriteDimensions = {};
+
+		glm::vec4 getRenderPos() 
+		{
+			glm::vec4 centerPos = glm::vec4(physicalBody.getPosCenter() + glm::vec2(spriteDimensions),
+				glm::vec2(spriteDimensions.z, spriteDimensions.w));
+
+			centerPos.x -= centerPos.z / 2.f;
+			centerPos.y -= centerPos.w / 2.f;
+
+			return centerPos;
 		}
 	};
 
@@ -81,26 +169,53 @@ struct Holloknight: public Container
 	Block blocks[10];
 	b2Body *currentBodySelected = 0;
 
+	Entity character;
+	b2Fixture *characterJumpSensor;
+
 	glm::vec2 draggedStart = {};
 
+	bool followPlayer = true;
+
+	struct InputMetrict
+	{
+		float speed = 20;
+		float jump = 7;
+		float stopSpeed = 7;
+		float jumpTimer = 1.5;
+		float initialJumpImpulse = 1;
+	} inputMetrics = {};
+
 	bool create(RequestedContainerInfo &requestedInfo, pika::StaticString<256> commandLineArgument)
 	{
 
 		renderer.create(requestedInfo.requestedFBO.fbo);
+		renderer.currentCamera.zoom = 80.f;
+		renderer.currentCamera.position.x = -440;
+		renderer.currentCamera.position.y = -500;
 
-		sprites = pika::gl2d::loadTextureWithPixelPadding(PIKA_RESOURCES_PATH "holloknight/sprites.png", requestedInfo, 80);
+		if (!requestedInfo.readEntireFileBinary(PIKA_RESOURCES_PATH "hollowknight/inputMetrics.bin",
+			&inputMetrics, sizeof(inputMetrics)))
+		{
+			inputMetrics = {};
+		}
+
+		sprites = pika::gl2d::loadTextureWithPixelPadding(PIKA_RESOURCES_PATH "hollowknight/sprites.png", requestedInfo, 80);
 		atlas = gl2d::TextureAtlasPadding(12, 12, sprites.GetSize().x, sprites.GetSize().y);
 
 		world.SetAllowSleeping(true);
 		world.SetContinuousPhysics(true);
 
-		floor.create(world, {-100, 300, 1000, 30}, false);
+		floor.create(world, {-50, 10, 100, 1}, false);
 		
 		for (int i = 0; i < 10; i++) 
 		{
-			blocks[i].create(world, {100 + sin(i)*50, -51*i, 50,50}, true);
+			blocks[i].create(world, {1+ sin(i)*5, -1.5*i, 1,1}, true);
 		}
 
+		character.physicalBody.create(world, {10, 2, 0.6f,1}, true);
+		character.spriteDimensions = glm::vec4{0,0,1,1};
+		character.physicalBody.dynamicBody->SetFixedRotation(true);
+		characterJumpSensor = character.physicalBody.addSensor({0, 0.5, 0.55f, 0.1f});
 
 		return true;
 	}
@@ -114,27 +229,138 @@ struct Holloknight: public Container
 	#pragma endregion
 
 	#pragma region input
-		::pika::gl2d::cameraController(renderer.currentCamera, input, 200);
+
+		::pika::gl2d::cameraController(renderer.currentCamera, input, 60 * (!followPlayer), 4);
+
+		int direction = 0;
+
+		if (input.buttons[pika::Button::Left].held() 
+			|| input.anyController.buttons[pika::Controller::Left].held() 
+			|| input.anyController.LStick.left()
+			) { direction--; }
+
+		if (input.buttons[pika::Button::Right].held() 
+			|| input.anyController.buttons[pika::Controller::Right].held()
+			|| input.anyController.LStick.right()
+			) { direction++; }
+
+		{
+			b2Vec2 vel = character.physicalBody.dynamicBody->GetLinearVelocity();
+			float force = 0;
+
+
+			if (direction < 0)
+			{
+				if (vel.x > -5) force = -inputMetrics.speed;
+			}
+			else if (direction == 0)
+			{
+				force = vel.x * -inputMetrics.stopSpeed;
+			}
+			else
+			{
+				if (vel.x < 5) force = inputMetrics.speed;
+			}
+		
+			character.physicalBody.dynamicBody->ApplyForce(b2Vec2(force, 0), 
+				character.physicalBody.dynamicBody->GetWorldCenter(), true);
+		}
+
+		bool hitsGround = 0;
+		#pragma region jump
+		{
+			
+			auto b = character.physicalBody.dynamicBody;
+
+			for (b2ContactEdge *ce = b->GetContactList(); ce; ce = ce->next)
+			{
+				if (ce->contact->IsTouching())
+				{
+					if (
+						ce->contact->GetFixtureA() == characterJumpSensor ||
+						ce->contact->GetFixtureB() == characterJumpSensor
+						)
+					{
+						hitsGround = true;
+					}
+				}
+			}
+
+			static bool duringJump = 0;
+			static float jumpTimer = 0;
+			
+			if ((input.buttons[pika::Button::Space].pressed() ||
+				input.anyController.buttons[pika::Controller::A].pressed())
+				&& hitsGround
+				)
+			{
+				duringJump = true;
+				jumpTimer = inputMetrics.jumpTimer;
+
+				float impulse = character.physicalBody.dynamicBody->GetMass() * inputMetrics.initialJumpImpulse;
+				character.physicalBody.dynamicBody->ApplyLinearImpulse(b2Vec2(0, -impulse),
+					character.physicalBody.dynamicBody->GetWorldCenter(), true);
+			}
+
+			if ((input.buttons[pika::Button::Space].held() ||
+				input.anyController.buttons[pika::Controller::A].held()
+				) 
+					&& duringJump
+				)
+			{
+				jumpTimer -= input.deltaTime;
+
+				if (jumpTimer < 0) { jumpTimer = 0; duringJump = false; }
+				else
+				{
+					auto b = character.physicalBody.dynamicBody;
+
+					b->ApplyForce(b2Vec2(0, b->GetMass() * -inputMetrics.jump), b->GetWorldCenter(), true);
+				}
+
+				
+			}
+			else { duringJump = false; }
+	
+		}
+		#pragma endregion
+
+
 	#pragma endregion
 
-		int32 velocityIterations = 6;
-		int32 positionIterations = 2;
+		int32 velocityIterations = 8;
+		int32 positionIterations = 3;
 		world.Step(input.deltaTime, velocityIterations, positionIterations);
 
-		floor.updateMetrics(world);
-
-		for (int i = 0; i < 10; i++) 
+	#pragma region follow player
+		if (followPlayer)
 		{
-			blocks[i].updateMetrics(world);
+			renderer.currentCamera.follow(character.physicalBody.getPosCenter(), 2 * input.deltaTime, 0.f, 0.f,
+				windowState.frameBufferW, windowState.frameBufferH);
 		}
+	#pragma endregion
+
 
 		floor.render(renderer, Colors_White);
 
 		for (int i = 0; i < 10; i++)
 		{
-			blocks[i].render(renderer, Colors_Orange);
+			if (blocks[i].dynamicBody->GetType() == b2_dynamicBody)
+			{
+				blocks[i].render(renderer, Colors_Orange);
+			}
+			else if (blocks[i].dynamicBody->GetType() == b2_kinematicBody)
+			{
+				blocks[i].render(renderer, {0.5,0.7,0.1,1});
+			}
+			else
+			{
+				blocks[i].render(renderer, Colors_White);
+			}
 		}
 
+		renderer.renderRectangle(character.getRenderPos(), sprites, Colors_White, {}, 0, atlas.get(0, 0));
+
 		glm::vec2 mouseWorldpos(input.mouseX, input.mouseY);
 		{
 			auto viewRect = renderer.getViewRect();
@@ -150,12 +376,12 @@ struct Holloknight: public Container
 		{
 
 			glm::vec4 color = Colors_Red;
-			float thickness = 1;
+			float thickness = 0.01;
 
 			if (currentBodySelected == b) 
 			{
 				color = Colors_Blue;
-				thickness = 2;
+				thickness = 0.02;
 			}
 
 			auto centerOfMass = b->GetWorldCenter();
@@ -194,7 +420,14 @@ struct Holloknight: public Container
 							p1 = gl2d::rotateAroundPoint(p1, {centerOfMass.x,-centerOfMass.y}, angleDegrees);
 							p2 = gl2d::rotateAroundPoint(p2, {centerOfMass.x,-centerOfMass.y}, angleDegrees);
 
-							renderer.renderLine(p1, p2, color, thickness*2);
+							if (f->IsSensor())
+							{
+								renderer.renderLine(p1, p2, Colors_Green, thickness * 2);
+							}
+							else
+							{
+								renderer.renderLine(p1, p2, color, thickness * 2);
+							}
 						}
 
 					}
@@ -203,7 +436,6 @@ struct Holloknight: public Container
 			
 			}
 
-
 		}
 
 	#pragma endregion
@@ -223,6 +455,8 @@ struct Holloknight: public Container
 
 				glm::vec2 movement = dragEnd - draggedStart;
 
+				movement *= 0.01;
+
 				if (currentBodySelected)
 				{
 					currentBodySelected->SetLinearVelocity({movement.x,movement.y});
@@ -237,6 +471,126 @@ struct Holloknight: public Container
 
 		renderer.flush();
 
+	#pragma region imgui
+		{
+			ImGui::Begin("Game Editor");
+
+			ImGui::DragFloat2("Camera pos", &renderer.currentCamera.position[0], 0.001);
+			ImGui::DragFloat("Camera zoom", &renderer.currentCamera.zoom, 0.5, 10, 1000);
+		
+			ImGui::Checkbox("Follow player", &followPlayer);
+
+			ImGui::Separator();
+
+			ImGui::InputFloat("Speed", &inputMetrics.speed);
+			ImGui::InputFloat("Jump", &inputMetrics.jump);
+			ImGui::InputFloat("Stop speed", &inputMetrics.stopSpeed);
+			ImGui::InputFloat("Jump timer", &inputMetrics.jumpTimer);
+			ImGui::InputFloat("Initial jump", &inputMetrics.initialJumpImpulse);
+
+			ImGui::Separator();
+
+			if (hitsGround)
+			{
+				ImGui::PushStyleColor(ImGuiCol_Text, {0,1,0,1});
+				ImGui::Text("Hits ground: Yes");
+			}
+			else
+			{
+				ImGui::PushStyleColor(ImGuiCol_Text, {1,0,0,1});
+				ImGui::Text("Hits ground: No");
+			}
+
+			ImGui::PopStyleColor();
+
+
+			if (currentBodySelected)
+			{
+				ImGui::NewLine();
+				ImGui::Separator();
+				ImGui::Text("World editor");
+				ImGui::NewLine();
+
+
+				int item = currentBodySelected->GetType();
+				ImGui::Combo("Body type: ", &item, "static\0kinematic\0dynamic\0");
+
+				currentBodySelected->SetType((b2BodyType)item);
+
+				auto pos = currentBodySelected->GetPosition();
+
+				auto angle = currentBodySelected->GetAngle();
+
+				{
+					auto f = currentBodySelected->GetFixtureList();
+					
+					if (f)
+					{
+						auto s = f->GetShape();
+
+						if (s->GetType() == b2Shape::Type::e_polygon)
+						{
+							b2PolygonShape *poligon = dynamic_cast<b2PolygonShape *>(s);
+
+							glm::vec2 size = {};
+
+							if (poligon)
+							{
+								glm::vec2 min{999999,999999};
+								glm::vec2 max{-999999,-999999};
+
+								for (int i = 0; i < poligon->m_count; i++)
+								{
+									glm::vec2 p1 = {poligon->m_vertices[i].x,poligon->m_vertices[i].y};
+
+									if (p1.x > max.x) { max.x = p1.x; }
+									if (p1.y > max.y) { max.y = p1.y; }
+
+									if (p1.x < min.x) { min.x = p1.x; }
+									if (p1.y < min.y) { min.y = p1.y; }
+								}
+
+								size = max - min;
+							}
+
+							auto newSize = size;
+
+							ImGui::DragFloat2("Size: ", &newSize.x, 0.1);
+
+							if (newSize != size)
+							{
+								currentBodySelected->DestroyFixture(f);
+
+								b2PolygonShape boxShape;
+								boxShape.SetAsBox(newSize.x / 2, newSize.y / 2);
+
+								b2FixtureDef boxFixtureDef;
+								boxFixtureDef.shape = &boxShape;
+								boxFixtureDef.density = 1;
+								currentBodySelected->CreateFixture(&boxFixtureDef);
+							}
+
+						}
+					}
+				
+				}
+
+				ImGui::DragFloat2("Pos: ", &pos.x, 0.1);
+				ImGui::SliderAngle("Angle", &angle);
+
+				currentBodySelected->SetTransform(pos, angle);
+
+			}
+
+			ImGui::End();
+		}
+
+		requestedInfo.writeEntireFileBinary(PIKA_RESOURCES_PATH "hollowknight/inputMetrics.bin",
+			&inputMetrics, sizeof(inputMetrics));
+
+	#pragma endregion
+
+
 		
 		return true;
 	}
@@ -244,7 +598,6 @@ struct Holloknight: public Container
 	//optional
 	void destruct()
 	{
-
 	}
 
 };

BIN
Pika/resources/hollowknight/inputMetrics.bin


+ 0 - 0
Pika/resources/holloknight/sprites.png → Pika/resources/hollowknight/sprites.png


+ 2 - 12
Pika/resources/logs.txt

@@ -1,12 +1,2 @@
-#2023-07-12 12:14:18: Created container: Holloknight
-#2023-07-12 12:18:41[error]: Killed container because its static container info
-has changed: Holloknight #1
-#2023-07-12 12:18:41: Force terminated continer: Holloknight #1
-#2023-07-12 12:18:42: Reloaded dll
-#2023-07-12 12:18:47: Created container: Holloknight
-#2023-07-12 12:25:47[error]: Killed container because its static container info
-has changed: Holloknight #2
-#2023-07-12 12:25:47: Force terminated continer: Holloknight #2
-#2023-07-12 12:25:47: Reloaded dll
-#2023-07-12 12:25:52: Created container: Holloknight
-#2023-07-12 12:27:11: Reloaded dll
+#2023-07-14 18:32:01: Created container: Holloknight
+#2023-07-14 18:41:00: Destroyed continer: Holloknight #1

+ 0 - 2
Pika/thirdparty/gl2d/src/gl2d.cpp

@@ -1870,8 +1870,6 @@ namespace gl2d
 			else
 			{
 				position += delta * speed;
-
-
 			}
 
 			glm::vec2 delta2 = pos - position;