Various Works.
This commit is contained in:
@@ -143,6 +143,7 @@ protected:
|
||||
tile.quad = quads[i];
|
||||
tile.name = std::format("tile_{}", i);
|
||||
tile.metadata = json::value();
|
||||
tile.collides = true;
|
||||
tiles.emplace(tiles.begin() + i, tile);
|
||||
}
|
||||
}
|
||||
|
@@ -3,9 +3,16 @@
|
||||
|
||||
|
||||
namespace TestGame {
|
||||
|
||||
class GameEntity : public Entity
|
||||
{
|
||||
|
||||
public:
|
||||
float gravity = 9.8f;
|
||||
float mass = 12.f;
|
||||
float air_resistance = 8.f;
|
||||
float friction = 0.001f;
|
||||
float acceleration = 1200;
|
||||
|
||||
GameEntity(const Vector2& spawn_pos) {
|
||||
pos = spawn_pos;
|
||||
|
@@ -1,3 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <JUI/Widgets/Window.hpp>
|
||||
|
||||
namespace TestGame {
|
||||
|
||||
class PhysicsTweaker : public JUI::Window {
|
||||
public:
|
||||
PhysicsTweaker() : JUI::Window() {
|
||||
|
||||
}
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
}
|
@@ -1,54 +1,20 @@
|
||||
#pragma once
|
||||
#include "GameEntity.hpp"
|
||||
#include <JGL/JGL.h>
|
||||
|
||||
|
||||
namespace TestGame {
|
||||
|
||||
class Player : public GameEntity
|
||||
{
|
||||
public:
|
||||
Player(const Vector2& spawn_pos) : GameEntity(spawn_pos) {
|
||||
bbox = {16, 24};
|
||||
}
|
||||
inline static JGL::Texture* sprite = nullptr;
|
||||
Player(const Vector2& spawn_pos);
|
||||
|
||||
~Player() {
|
||||
~Player();
|
||||
|
||||
}
|
||||
void Update(float elapsed) override;
|
||||
|
||||
void Update(float elapsed) override {
|
||||
// Update current position to our next_position, which was computed on the last frame.
|
||||
// This means we can collision solve our next_pos in between calls to entity->Update();
|
||||
pos = next_pos;
|
||||
|
||||
velocity.x *= 1 - (elapsed * air_resistance);
|
||||
//velocity.y *= 1 - (elapsed * air_resistance);
|
||||
|
||||
//if (on_ground)
|
||||
//velocity.x *= friction;
|
||||
|
||||
velocity.y += (elapsed*gravity*mass);
|
||||
|
||||
next_pos += velocity * elapsed;
|
||||
|
||||
if (Math::Abs(velocity.y) > 2)
|
||||
on_ground = false;
|
||||
|
||||
|
||||
if (InputService::IsKeyDown(Keys::A))
|
||||
velocity.x -= acceleration * elapsed;
|
||||
|
||||
if (InputService::IsKeyDown(Keys::D))
|
||||
velocity.x += acceleration * elapsed;
|
||||
|
||||
if (InputService::IsKeyDown(Keys::W))
|
||||
velocity.y -= acceleration * elapsed;
|
||||
|
||||
if (InputService::IsKeyDown(Keys::S))
|
||||
velocity.y += acceleration * elapsed;
|
||||
}
|
||||
|
||||
void Draw() override {
|
||||
J2D::FillRect(Colors::Blue, pos, bbox);
|
||||
J2D::DrawPartialSprite(player_tex, pos, {0,0}, bbox);
|
||||
}
|
||||
void Draw() override;
|
||||
};
|
||||
}
|
||||
|
@@ -5,6 +5,9 @@
|
||||
#include "JUI/Widgets/Scene.hpp"
|
||||
#include "ReWindow/types/Window.h"
|
||||
|
||||
#include <JUI/Widgets/Slider.hpp>
|
||||
#include <JUI/Base/TextBase.hpp>
|
||||
|
||||
namespace TestGame
|
||||
{
|
||||
constexpr int GL_MAJOR = 2;
|
||||
@@ -14,6 +17,39 @@ namespace TestGame
|
||||
constexpr int START_APP_HEIGHT = 768;
|
||||
static const std::string START_APP_TITLE = "Redacted Software 2D Level Editor - Map Testing Game";
|
||||
|
||||
// Implemented in next version of JUI.
|
||||
class LabeledSlider : public JUI::Slider, public JUI::TextBase {
|
||||
public:
|
||||
LabeledSlider() : Slider(), TextBase() {
|
||||
|
||||
}
|
||||
explicit LabeledSlider(Widget* parent) : LabeledSlider()
|
||||
{
|
||||
this->Parent(parent);
|
||||
}
|
||||
|
||||
void Draw() override {
|
||||
Slider::Draw();
|
||||
|
||||
auto abs_pos = this->GetAbsolutePosition();
|
||||
auto abs_size = this->GetAbsoluteSize();
|
||||
|
||||
auto pos_pad = GetAbsolutePaddingTopLeft();
|
||||
auto size_pad = GetAbsolutePaddingBottomRight();
|
||||
|
||||
TextBase::Draw(abs_pos + pos_pad, abs_size - size_pad);
|
||||
}
|
||||
|
||||
void Update(float elapsed) override {
|
||||
Slider::Update(elapsed);
|
||||
TextBase::Update(elapsed);
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
|
||||
class TestGameAppWindow : public ReWindow::OpenGLWindow
|
||||
{
|
||||
public:
|
||||
@@ -58,16 +94,12 @@ namespace TestGame
|
||||
void DrawLayer(const Layer* layer) const;
|
||||
|
||||
|
||||
void ApplyOriginTransformation() {
|
||||
glTranslatef(GetWidth() / 2.f, GetHeight() / 2.f, 0);
|
||||
}
|
||||
/// Translates the coordinate-space origin {0,0} to be at the center of the screen.
|
||||
void ApplyOriginTransformation();
|
||||
|
||||
void ApplyCameraTransformation() {
|
||||
ApplyOriginTransformation();
|
||||
glRotatef(camera.rotation.current, 0, 0, 1);
|
||||
glScalef(camera.scale.current, camera.scale.current, 1);
|
||||
glTranslatef(-camera.translation.current.x, -camera.translation.current.y, 0);
|
||||
}
|
||||
/// Applies the camera's rotation, scale, and translation to the coordinate system.
|
||||
/// This is performed after translating the origin to the center of the screen.
|
||||
void ApplyCameraTransformation();
|
||||
|
||||
void DrawLevel(const Level* level) const
|
||||
{
|
||||
@@ -77,6 +109,7 @@ namespace TestGame
|
||||
}
|
||||
}
|
||||
|
||||
/// Draw objects with the camera projection, as if they are in world-space.
|
||||
void DrawWorldSpace() {
|
||||
|
||||
if (!data_ready) return; // Don't try to draw the level if not loaded.
|
||||
@@ -159,4 +192,5 @@ namespace TestGame
|
||||
#pragma endregion
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user