add welcome stage and a little gui
This commit is contained in:
parent
5dcf222a0a
commit
fd0bcce5c7
Binary file not shown.
After Width: | Height: | Size: 542 B |
Binary file not shown.
After Width: | Height: | Size: 837 B |
|
@ -70,6 +70,8 @@ public:
|
|||
FreeRotation = 0x02,
|
||||
};
|
||||
|
||||
static constexpr int InfBullet = -1;
|
||||
|
||||
void Init(const std::string& name,
|
||||
Type type,
|
||||
BulletCmpt::Type bulletType,
|
||||
|
@ -77,7 +79,8 @@ public:
|
|||
int damage,
|
||||
float shootSpeed,
|
||||
float maxSpeed,
|
||||
float duration) {
|
||||
float duration,
|
||||
int bulletAmount = InfBullet) {
|
||||
this->name = name;
|
||||
this->type = type;
|
||||
this->bulletType = bulletType;
|
||||
|
@ -87,6 +90,7 @@ public:
|
|||
this->shootDuration = duration;
|
||||
this->coolDown = 0;
|
||||
this->maxSpeed = maxSpeed;
|
||||
this->bulletAmount = bulletAmount;
|
||||
}
|
||||
|
||||
void Release() {}
|
||||
|
@ -103,6 +107,7 @@ public:
|
|||
float coolDown;
|
||||
float maxSpeed;
|
||||
Entity* owner;
|
||||
int bulletAmount;
|
||||
};
|
||||
|
||||
class SpaceshipArmorCmpt: public Component {
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include "tinyengine/tinyengine.hpp"
|
||||
|
||||
bool Button(Texture* texture, const Point& pos, const Size& size);
|
|
@ -1,26 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "tinyengine/pch.hpp"
|
||||
#include "tinyengine/libmath.hpp"
|
||||
|
||||
class Sprite {
|
||||
public:
|
||||
virtual ~Sprite() = default;
|
||||
|
||||
void Move(const Point& offset) { position_ += offset; dirty_ = true; }
|
||||
void MoveTo(const Point& p) { position_ = p; dirty_ = true; }
|
||||
void Rotate(const float degreeDelta) { rotation_ += degreeDelta; dirty_ = true; }
|
||||
void RotateTo(const float degree) { rotation_ = degree; dirty_ = true; }
|
||||
|
||||
bool TryCalcView();
|
||||
const Mat44& GetModel() const { return modelMat_; }
|
||||
|
||||
virtual void Update() { oldPosition_ = position_; }
|
||||
|
||||
private:
|
||||
Point position_ = {0, 0};
|
||||
Point oldPosition_;
|
||||
float rotation_ = 0;
|
||||
bool dirty_ = false;
|
||||
Mat44 modelMat_;
|
||||
};
|
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include "tinyengine/tinyengine.hpp"
|
||||
|
||||
class WelcomeScence: public Scence {
|
||||
public:
|
||||
void OnInit() override;
|
||||
void OnRender() override;
|
||||
|
||||
private:
|
||||
Unique<Texture> startImage_;
|
||||
Unique<Texture> exitImage_;
|
||||
Camera camera_;
|
||||
};
|
|
@ -14,7 +14,7 @@ public:
|
|||
void Init(const std::string& title, const Size& size, Scence* scence);
|
||||
void Shutdown();
|
||||
|
||||
void Exit() { shouldExit_ = true; }
|
||||
void Exit() { glfwSetWindowShouldClose(window_, 1); }
|
||||
bool ShouldExit() const { return glfwWindowShouldClose(window_); }
|
||||
|
||||
void Update(float deltaTime);
|
||||
|
|
|
@ -9,11 +9,11 @@ void Shoot(SpaceshipWeaponCmpt& weapon, const Point& dir) {
|
|||
|
||||
Entity* bullet;
|
||||
bullet = weapon.ShootBullet(dir);
|
||||
Bullets.Add(bullet);
|
||||
|
||||
weapon.coolDown = weapon.shootDuration;
|
||||
|
||||
Sounds["shoot"]->Play();
|
||||
if (bullet) {
|
||||
Bullets.Add(bullet);
|
||||
weapon.coolDown = weapon.shootDuration;
|
||||
Sounds["shoot"]->Play();
|
||||
}
|
||||
}
|
||||
|
||||
void Shoot(SpaceshipWeaponCmpt& weapon, const Point& dir, Entity* target) {
|
||||
|
@ -25,14 +25,12 @@ void Shoot(SpaceshipWeaponCmpt& weapon, const Point& dir, Entity* target) {
|
|||
|
||||
Entity* bullet;
|
||||
bullet = weapon.ShootMissile(dir, target);
|
||||
|
||||
// FIXME the rotation have some bugs
|
||||
bullet->Use<BulletCmpt>()->rotation = Degrees(std::acos(-Normalize(dir).y));
|
||||
|
||||
Bullets.Add(bullet);
|
||||
|
||||
weapon.coolDown = weapon.shootDuration;
|
||||
|
||||
Sounds["shoot"]->Play();
|
||||
if (bullet) {
|
||||
// FIXME the rotation have some bugs
|
||||
bullet->Use<BulletCmpt>()->rotation = Degrees(std::acos(-Normalize(dir).y));
|
||||
Bullets.Add(bullet);
|
||||
weapon.coolDown = weapon.shootDuration;
|
||||
Sounds["shoot"]->Play();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
#include "game/entity.hpp"
|
||||
|
||||
Entity* SpaceshipWeaponCmpt::ShootBullet(const Point& dir) {
|
||||
if (bulletAmount == 0) return nullptr;
|
||||
if (bulletAmount != InfBullet) {
|
||||
bulletAmount --;
|
||||
}
|
||||
Entity* bullet = CreateBullet(damage, owner, maxSpeed);
|
||||
bullet->Use<MotionCmpt>()->speed = Normalize(dir) * shootSpeed;
|
||||
bullet->Use<MoveCmpt>()->position = owner->Get<MoveCmpt>()->position;
|
||||
|
@ -9,9 +13,13 @@ Entity* SpaceshipWeaponCmpt::ShootBullet(const Point& dir) {
|
|||
}
|
||||
|
||||
Entity* SpaceshipWeaponCmpt::ShootMissile(const Point& dir, Entity* target) {
|
||||
if (bulletAmount == 0) return nullptr;
|
||||
if (bulletAmount != InfBullet) {
|
||||
bulletAmount --;
|
||||
}
|
||||
Entity* bullet = CreateMissile(damage, owner, maxSpeed, target);
|
||||
if (target) {
|
||||
bullet->Use<BulletCmpt>()->rotation = Degrees(std::acos(Dot(dir, Normalize(target->Get<MoveCmpt>()->position - owner->Get<MoveCmpt>()->position))));
|
||||
bullet->Use<BulletCmpt>()->rotation = Degrees(std::acos(Dot(dir, Normalize(target->Get<MoveCmpt>()->position - owner->Get<MoveCmpt>()->position))));
|
||||
}
|
||||
bullet->Use<MotionCmpt>()->speed = Normalize(dir) * shootSpeed;
|
||||
bullet->Use<MoveCmpt>()->position = owner->Get<MoveCmpt>()->position;
|
||||
|
|
|
@ -41,7 +41,8 @@ Entity* CreateFightShip() {
|
|||
LazerDamage,
|
||||
LazerShooterSpeed,
|
||||
LazerShooterMaxSpeed,
|
||||
LazerShooterCooldown);
|
||||
LazerShooterCooldown,
|
||||
10);
|
||||
|
||||
entity->Add<CollisionCmpt>(Size{16, 16});
|
||||
entity->Add<LifeCmpt>(FreightLife);
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
#include "game/gui.hpp"
|
||||
#include "tinyengine/event.hpp"
|
||||
|
||||
bool Button(Texture* texture, const Point& pos, const Size& size) {
|
||||
Renderer::DrawTexture(texture, nullptr, pos, size);
|
||||
if (IsLeftPressing() &&
|
||||
IsPointInRect(GetMousePosition(), Rect{pos.x - size.w / 2, pos.y - size.h / 2, size.w, size.h})) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
#include "game/stages/gamelogo.hpp"
|
||||
#include "game/stages/space.hpp"
|
||||
#include "game/stages/welcome.hpp"
|
||||
#include "game/constants.hpp"
|
||||
|
||||
RUN_WINDOW("Space Sector", GameWindowSize.w, GameWindowSize.h, SpaceScence)
|
||||
RUN_WINDOW("Space Sector", GameWindowSize.w, GameWindowSize.h, WelcomeScence)
|
||||
// RUN_WINDOW("Space Sector", GameWindowSize.w, GameWindowSize.h, SpaceScence)
|
||||
// RUN_WINDOW("Space Sector", GameWindowSize.w, GameWindowSize.h, GameLogoScence)
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
#include "game/sprite.hpp"
|
||||
|
||||
bool Sprite::TryCalcView() {
|
||||
if (dirty_) {
|
||||
float theta = Radians(rotation_);
|
||||
float sinTheta = std::sin(theta);
|
||||
float cosTheta = std::cos(theta);
|
||||
modelMat_ = Mat44({
|
||||
cosTheta, -sinTheta, 0, position_.x,
|
||||
sinTheta, cosTheta, 0, position_.y,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1,
|
||||
});
|
||||
dirty_ = false;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -98,14 +98,14 @@ void SpaceScence::renderMiniMap() {
|
|||
}
|
||||
|
||||
void SpaceScence::renderWeapons(SpaceshipWeaponCmpt* weapon1, SpaceshipWeaponCmpt* weapon2) {
|
||||
Rect mapRect = {0, 0, 200, 100};
|
||||
mapRect.y = GameWindowSize.h - mapRect.h;
|
||||
mapRect.x = GameWindowSize.w - mapRect.w - 1;
|
||||
Rect weaponInfoRect = {0, 0, 300, 100};
|
||||
weaponInfoRect.y = GameWindowSize.h - weaponInfoRect.h;
|
||||
weaponInfoRect.x = GameWindowSize.w - weaponInfoRect.w - 1;
|
||||
|
||||
Renderer::SetDrawColor(Color{0, 0, 0, 255});
|
||||
Renderer::FillRect(mapRect);
|
||||
Renderer::SetDrawColor(Color{255, 255, 255, 255});
|
||||
Renderer::DrawRect(mapRect);
|
||||
Renderer::SetDrawColor(Color{0, 0, 0, 1});
|
||||
Renderer::FillRect(weaponInfoRect);
|
||||
Renderer::SetDrawColor(Color{1, 1, 1, 1});
|
||||
Renderer::DrawRect(weaponInfoRect);
|
||||
|
||||
Point offset = {10, 10};
|
||||
auto& font = engine.GetInnerBmpFont();
|
||||
|
@ -113,15 +113,28 @@ void SpaceScence::renderWeapons(SpaceshipWeaponCmpt* weapon1, SpaceshipWeaponCmp
|
|||
if (weapon1) {
|
||||
font.Render(weapon1->name,
|
||||
20,
|
||||
Point{mapRect.x, mapRect.y} + offset,
|
||||
Color{0, 200, 0, 255});
|
||||
Point{weaponInfoRect.x, weaponInfoRect.y} + offset,
|
||||
Color{0, 0.8, 0, 1});
|
||||
if (weapon1->bulletAmount != SpaceshipWeaponCmpt::InfBullet) {
|
||||
font.Render("[" + std::to_string(weapon1->bulletAmount) + "]",
|
||||
20,
|
||||
Point{weaponInfoRect.x + weaponInfoRect.w - 50, weaponInfoRect.y} + offset,
|
||||
Color{0, 0.8, 0, 1});
|
||||
}
|
||||
offset.y += 20;
|
||||
}
|
||||
if (weapon2) {
|
||||
font.Render(weapon2->name,
|
||||
20,
|
||||
Point{mapRect.x, mapRect.y} + offset,
|
||||
Color{0, 50, 0, 255});
|
||||
Point{weaponInfoRect.x, weaponInfoRect.y} + offset,
|
||||
Color{0, 0.8, 0, 1});
|
||||
|
||||
if (weapon2->bulletAmount != SpaceshipWeaponCmpt::InfBullet) {
|
||||
font.Render("[" + std::to_string(weapon2->bulletAmount) + "]",
|
||||
20,
|
||||
Point{weaponInfoRect.x + weaponInfoRect.w - 100, weaponInfoRect.y} + offset,
|
||||
Color{0, 0.8, 0, 1});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
#include "game/stages/welcome.hpp"
|
||||
#include "game/gui.hpp"
|
||||
#include "game/stages/space.hpp"
|
||||
|
||||
void WelcomeScence::OnInit() {
|
||||
startImage_.reset(new Texture("assets/start_btn.png"));
|
||||
exitImage_.reset(new Texture("assets/exit_btn.png"));
|
||||
}
|
||||
|
||||
void WelcomeScence::OnRender() {
|
||||
Renderer::SetCamera(camera_);
|
||||
auto& font = engine.GetInnerBmpFont();
|
||||
std::string title = "SPACE SECTOR";
|
||||
int pt = 70;
|
||||
font.Render(title, pt,
|
||||
Point{(GameWindowSize.w - title.size() * pt) / 2, 100},
|
||||
Color{0.39, 0.6, 1, 1});
|
||||
|
||||
title = "-------MADE FOR 1M GAMES-------";
|
||||
pt = 20;
|
||||
font.Render(title, pt,
|
||||
Point{(GameWindowSize.w - title.size() * pt) / 2, 200},
|
||||
Color{0.8, 0.8, 1, 1});
|
||||
|
||||
if (Button(exitImage_.get(), Point{(GameWindowSize.w) / 2, 550}, Size{100, 100})) {
|
||||
engine.Exit();
|
||||
}
|
||||
|
||||
if (Button(startImage_.get(), Point{(GameWindowSize.w) / 2, 400}, Size{100, 100})) {
|
||||
engine.ChangeScence(new SpaceScence);
|
||||
}
|
||||
}
|
|
@ -87,6 +87,7 @@ void Engine::Shutdown() {
|
|||
}
|
||||
|
||||
void Engine::Update(float deltaTime) {
|
||||
deltaTime = std::min(deltaTime, 0.3f);
|
||||
if (scence_)
|
||||
scence_->OnUpdate(deltaTime);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
#include "tinyengine/event.hpp"
|
||||
#include "tinyengine/engine.hpp"
|
||||
|
||||
struct {
|
||||
bool left = false;
|
||||
bool right = false;
|
||||
} MouseState;
|
||||
|
||||
void OnWindowResize(GLFWwindow* window, int width, int height) {
|
||||
Renderer::SetViewport(0, 0, width, height);
|
||||
}
|
||||
|
|
|
@ -336,6 +336,33 @@ InnerBmpFont::InnerBmpFont() {
|
|||
0,0,1,1,0,0,0,0,
|
||||
0,0,1,1,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0});
|
||||
saveChar('[',
|
||||
{0,0,0,0,0,0,0,0,
|
||||
0,0,1,1,1,1,0,0,
|
||||
0,0,1,0,0,0,0,0,
|
||||
0,0,1,0,0,0,0,0,
|
||||
0,0,1,0,0,0,0,0,
|
||||
0,0,1,0,0,0,0,0,
|
||||
0,0,1,1,1,1,0,0,
|
||||
0,0,0,0,0,0,0,0});
|
||||
saveChar(']',
|
||||
{0,0,0,0,0,0,0,0,
|
||||
0,0,1,1,1,1,0,0,
|
||||
0,0,0,0,0,1,0,0,
|
||||
0,0,0,0,0,1,0,0,
|
||||
0,0,0,0,0,1,0,0,
|
||||
0,0,0,0,0,1,0,0,
|
||||
0,0,1,1,1,1,0,0,
|
||||
0,0,0,0,0,0,0,0});
|
||||
saveChar('-',
|
||||
{0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
1,1,1,1,1,1,1,1,
|
||||
1,1,1,1,1,1,1,1,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0});
|
||||
|
||||
errorChar_ = fontMat({1,1,1,1,1,1,1,1,
|
||||
1,0,0,0,0,0,0,1,
|
||||
|
|
Reference in New Issue