Skip to content
Snippets Groups Projects
Unverified Commit d0a0fe56 authored by Leon Niklas Lux's avatar Leon Niklas Lux Committed by Leon Lux
Browse files

Spielklassen in Namespace packen

parent d2d748e3
No related branches found
No related tags found
1 merge request!55Abgabe des Projektes
Showing
with 96 additions and 1 deletion
......@@ -3,6 +3,9 @@
#include <algorithm>
#include <box2d/b2_math.h>
namespace game
{
BulletManager::BulletManager(b2World *world, TilesheetManager &tilesheetManager, lvl::Level &level)
: m_world(world), m_tilesheetManager(tilesheetManager), m_level(level)
{
......@@ -110,4 +113,6 @@ void BulletManager::cleanup()
}
m_player_projectiles.clear();
m_enemy_projectiles.clear();
}
}
\ No newline at end of file
......@@ -7,6 +7,9 @@
#include <box2d/box2d.h>
#include <vector>
namespace game
{
/**
* @class BulletManager
* @brief A class responsible for managing projectiles in the game.
......@@ -93,3 +96,5 @@ class BulletManager
*/
void cleanup();
};
}
\ No newline at end of file
#include "BulletObject.hpp"
namespace game
{
BulletObject::BulletObject(b2World *world, const b2Vec2 &position, const b2Vec2 &size, float density, float scale,
float friction, const std::vector<int> &tileIDs)
: DynamicObject(world, position, size, density, scale, friction, tileIDs, true)
......@@ -15,4 +18,6 @@ void BulletObject::ApplyLinearImpulse(const b2Vec2 &impulse)
b2Body *BulletObject::getBody()
{
return m_body;
}
}
\ No newline at end of file
......@@ -2,6 +2,9 @@
#include "DynamicObject.hpp"
#include <box2d/box2d.h>
namespace game
{
/**
* @class BulletObject
* @brief A class representing a bullet in a physics-based game world.
......@@ -51,3 +54,5 @@ class BulletObject : public DynamicObject
*/
b2Body *getBody();
};
}
\ No newline at end of file
#include "Camera.hpp"
namespace game
{
Camera::Camera(int viewportWidth, int viewportHeight, int levelWidth, int levelHeight)
: m_X(0), m_Y(0), m_viewportWidth(viewportWidth), m_viewportHeight(viewportHeight), m_LevelWidth(levelWidth),
m_LevelHeight(levelHeight)
......@@ -53,4 +56,6 @@ void Camera::updateContext(int x, int y, int viewportWidth, int viewportHeight,
m_viewportHeight = viewportHeight;
m_LevelWidth = levelWidth;
m_LevelHeight = levelHeight;
}
}
\ No newline at end of file
#pragma once
#include <algorithm>
namespace game
{
/**
* @brief Smoothing factor for camera movement.
*/
......@@ -89,3 +92,5 @@ class Camera
int m_LevelWidth; ///< The width of the level.
int m_LevelHeight; ///< The height of the level.
};
}
\ No newline at end of file
#include "ContactListener.hpp"
#include <iostream>
namespace game
{
ContactListener::ContactListener()
{
}
......@@ -123,4 +126,6 @@ bool ContactListener::door_entered()
bool state= m_door_entered;
m_door_entered = false;
return state;
}
}
\ No newline at end of file
......@@ -3,6 +3,9 @@
#include <box2d/box2d.h>
#include <vector>
namespace game
{
/**
* @class ContactListener
* @brief A class that handles collision events in the Box2D physics world.
......@@ -84,3 +87,5 @@ class ContactListener : public b2ContactListener
bool m_door_entered;
};
}
\ No newline at end of file
#include "DynamicObject.hpp"
namespace game
{
DynamicObject::DynamicObject(b2World *world, const b2Vec2 &position, const b2Vec2 &size, float density, float scale,
float friction, const std::vector<int> &tileIDs, bool isBullet)
: GameObject(world, position, size, density, scale, friction, tileIDs, isBullet, true)
{
m_body->SetLinearDamping(3.0f);
}
}
\ No newline at end of file
#pragma once
#include "GameObject.hpp"
namespace game
{
/**
* @class DynamicObject
* @brief A class representing a dynamic object in the Box2D physics world.
......@@ -30,3 +33,5 @@ class DynamicObject : public GameObject
DynamicObject(b2World *world, const b2Vec2 &position, const b2Vec2 &size, float density, float scale,
float friction, const std::vector<int> &tileIDs, bool isBullet);
};
}
\ No newline at end of file
#include "Enemy.hpp"
#include <box2d/b2_math.h>
namespace game
{
Enemy::Enemy(b2World *world, const b2Vec2 &position, const b2Vec2 &size, float density, float scale, float friction,
BulletManager &bulletmanager, const std::vector<int> &tileIDs, int health, int damage)
: DynamicObject(world, position, size, density, scale, friction, tileIDs, false), m_lastFire(1000), m_fireRate(2),
......@@ -47,4 +50,6 @@ void Enemy::take_damage(int damage)
b2Body *Enemy::getBody()
{
return m_body;
}
}
\ No newline at end of file
......@@ -2,6 +2,9 @@
#include "BulletManager.hpp"
#include "DynamicObject.hpp"
namespace game
{
/**
* @class Enemy
* @brief A class representing an enemy object in the game, with physics and rendering capabilities.
......@@ -68,3 +71,5 @@ class Enemy : public DynamicObject
Uint32 m_fireDelay; /**< The delay between shots in milliseconds. */
Uint32 m_lastFire; /**< The timestamp of the last shot fired. */
};
}
\ No newline at end of file
#include "EnemyManager.hpp"
namespace game
{
EnemyManager::EnemyManager(b2World *world, BulletManager &bulletManager, TilesheetManager &tilesheetManager,
lvl::Level &level)
: m_world(world), m_bulletManager(bulletManager), m_tilesheetManager(tilesheetManager)
......@@ -65,4 +68,6 @@ void EnemyManager::cleanup()
delete enemy;
}
m_enemies.clear();
}
}
\ No newline at end of file
......@@ -7,6 +7,9 @@
#include <box2d/box2d.h>
#include <vector>
namespace game
{
/**
* @class EnemyManager
* @brief A class responsible for managing and handling multiple enemies in the game.
......@@ -84,3 +87,5 @@ class EnemyManager
*/
void cleanup();
};
}
\ No newline at end of file
......@@ -4,6 +4,9 @@
#include <box2d/b2_math.h>
#include <unordered_set>
namespace game
{
GameContext::GameContext(lvl::Level &level, EnemyManager &enemy_manager, BulletManager &bullet_manager,
TilesheetManager &tilesheet_manager, ObjectManager &object_manager, Player &player, SDL_Renderer* renderer, Camera &camera)
: m_level(level), m_bulletManager(bullet_manager), m_enemyManager(enemy_manager), m_objectManager(object_manager),
......@@ -134,4 +137,6 @@ void GameContext::loadRoom(const lvl::Room &next_room)
lvl::Room &GameContext::getCurrentRoom()
{
return m_current_room;
}
}
\ No newline at end of file
......@@ -10,6 +10,9 @@
#include "level.hpp"
#include "room.hpp"
namespace game
{
/**
* @class GameContext
* @brief Manages the game's core context, handling levels, rooms, and game objects.
......@@ -82,3 +85,5 @@ class GameContext
SDL_Renderer* m_renderer; ///< Pointer to the SDL renderer.
int m_tileSize; ///< Tile size used in the game (respects scale factor).
};
}
\ No newline at end of file
......@@ -6,7 +6,7 @@ int main()
{
try
{
GameWindow game(640, 640, 2.0f);
game::GameWindow game(640, 640, 2.0f);
game.run();
}
catch (const std::runtime_error &ex)
......
......@@ -2,6 +2,9 @@
#include "TilesheetManager.hpp"
#include <box2d/b2_body.h>
namespace game
{
GameObject::GameObject(b2World *world, const b2Vec2 &position, const b2Vec2 &size, float density, float scale,
float friction, const std::vector<int> &tileIDs, bool isBullet, bool isDynamic)
: m_world(world), m_size(scale * size), m_frameDuration(0.0f), m_lastFrameSwitch(0.0f), m_currentFrame(tileIDs[0]),
......@@ -104,4 +107,6 @@ void GameObject::nextFrame()
float GameObject::getPixelsPerMeterScaled() const
{
return m_pixelsPerMeterScaled;
}
}
\ No newline at end of file
......@@ -5,6 +5,9 @@
#include <box2d/box2d.h>
#include <vector>
namespace game
{
constexpr float pixelsPerMeter = 20.0; /**< Conversion factor from meters to pixels. */
/**
......@@ -124,3 +127,5 @@ class GameObject
const std::vector<int> m_tileIDs; /**< List of tile IDs representing the animation frames */
float m_pixelsPerMeterScaled; /**< Conversion factor from meters to pixels. */
};
}
\ No newline at end of file
#include "GameWindow.hpp"
#include "TilesheetManager.hpp"
namespace game
{
GameWindow::GameWindow(const int32_t width, const int32_t height, const float_t scale) noexcept(false)
: SDLApplication("ISAAC is Back", width, height), m_Score(0), m_Scale(scale), m_level("level.h5"),
m_world(b2Vec2({0.0f, 0.0f})), m_tilesheetManager(m_Renderer, m_level.getSpritesheet(), m_Scale),
......@@ -95,3 +98,5 @@ b2Vec2 GameWindow::getPlayerPosition() const
{
return m_player.getPosition();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment