Skip to content

Commit

Permalink
DK_ -> dk::
Browse files Browse the repository at this point in the history
namespace changes
  • Loading branch information
durkisneer1 committed Nov 11, 2023
1 parent 6bd4ad0 commit ecd07b9
Show file tree
Hide file tree
Showing 52 changed files with 502 additions and 461 deletions.
Binary file modified .vs/DurkGame/v17/Browse.VC.db
Binary file not shown.
Binary file modified .vs/DurkGame/v17/Solution.VC.db
Binary file not shown.
Binary file modified .vs/DurkGame/v17/ipch/9fbacb1493641a2f.ipch
Binary file not shown.
Binary file modified .vs/DurkGame/v17/ipch/AutoPCH/a5ab5374925417d3/MAIN.ipch
Binary file not shown.
33 changes: 18 additions & 15 deletions DurkGame/DK_Character.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@
#include "DK_Globals.h"


class DK_Character {
public:
DK_Character(SDL_Renderer* renderer, DK_Texture* texture);
~DK_Character() = default;
namespace dk {
class Character {
public:
Character(SDL_Renderer* renderer, dk::Texture* texture);
~Character() = default;

[[nodiscard]] DK_Math::Vector2 getPosition() const;
[[nodiscard]] DK_Rect getRect() const;
[[nodiscard]] dk::math::Vector2 getPosition() const;
[[nodiscard]] dk::Rect getRect() const;
void process();

protected:
SDL_Renderer* renderer;
DK_Texture* texture;
DK_Rect rect = {};
protected:
SDL_Renderer* renderer;
dk::Texture* texture;
dk::Rect rect = {};

DK_Math::Vector2 velocity;
DK_Math::Vector2 position;
dk::math::Vector2 velocity;
dk::math::Vector2 position;

void move();
void draw();
};
void move();
void draw();
};
}
22 changes: 12 additions & 10 deletions DurkGame/DK_Clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
#include <SDL.h>


namespace DK_Time {
class Clock {
public:
Clock() = default;
~Clock() = default;
namespace dk {
namespace time {
class Clock {
public:
Clock() = default;
~Clock() = default;

float tick(int frameRate = 0);
float tick(int frameRate = 0);

private:
Uint32 startTicks = 0;
Uint32 endTicks = 0;
};
private:
Uint32 startTicks = 0;
Uint32 endTicks = 0;
};
}
}
14 changes: 8 additions & 6 deletions DurkGame/DK_Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
#include "DK_Math.h"


namespace DK_Display {
SDL_Window* setMode(const char* title, DK_Math::Vector2 size);
SDL_Renderer* setRenderer(SDL_Window* window);
namespace dk {
namespace display {
SDL_Window* setMode(const char* title, dk::math::Vector2 size);
SDL_Renderer* setRenderer(SDL_Window* window);

void cls(SDL_Renderer* renderer);
void fill(SDL_Renderer* renderer, SDL_Color color);
void flip(SDL_Renderer* renderer);
void cls(SDL_Renderer* renderer);
void fill(SDL_Renderer* renderer, SDL_Color color);
void flip(SDL_Renderer* renderer);
}
}
20 changes: 11 additions & 9 deletions DurkGame/DK_Font.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
#include "DK_Surface.h"


class DK_Font {
public:
DK_Font(SDL_Renderer* renderer, const char* fileDir, int ptSize);
DK_Texture* render(const char* text, SDL_Color color, int wrapLength = 0);
~DK_Font() { if (font) TTF_CloseFont(font); }
namespace dk {
class Font {
public:
Font(SDL_Renderer* renderer, const char* fileDir, int ptSize);
dk::Texture* render(const char* text, SDL_Color color, int wrapLength = 0);
~Font() { if (font) TTF_CloseFont(font); }

private:
SDL_Renderer* renderer;
TTF_Font* font;
};
private:
SDL_Renderer* renderer;
TTF_Font* font;
};
}
2 changes: 1 addition & 1 deletion DurkGame/DK_Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
#include "DK_Math.h"


extern const DK_Math::Vector2 WIN_SIZE;
extern const dk::math::Vector2 WIN_SIZE;
extern const float GRAVITY;
20 changes: 11 additions & 9 deletions DurkGame/DK_Input.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
#include "DK_Math.h"


namespace DK_Input {
DK_Math::Vector2 getMousePos();
namespace dk {
namespace input {
dk::math::Vector2 getMousePos();

const Uint8* getKeysPressed();
const Uint8* getKeysPressed();

DK_Math::Vector2 getVector(
const std::vector<SDL_Scancode>& up,
const std::vector<SDL_Scancode>& left,
const std::vector<SDL_Scancode>& down,
const std::vector<SDL_Scancode>& right
);
dk::math::Vector2 getVector(
const std::vector<SDL_Scancode>& up,
const std::vector<SDL_Scancode>& left,
const std::vector<SDL_Scancode>& down,
const std::vector<SDL_Scancode>& right
);
}
}
32 changes: 17 additions & 15 deletions DurkGame/DK_Math.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@
#include <cmath>


namespace DK_Math {
struct Vector2 {
float x = 0.0f;
float y = 0.0f;
namespace dk {
namespace math {
struct Vector2 {
float x = 0.0f;
float y = 0.0f;

Vector2() = default;
Vector2(float x, float y);
Vector2(int x, int y);
Vector2() = default;
Vector2(float x, float y);
Vector2(int x, int y);

void ZERO();
[[nodiscard]] float getLength() const;
void normalize();
void ZERO();
[[nodiscard]] float getLength() const;
void normalize();

Vector2 operator*(float scalar) const;
Vector2 operator/(float scalar) const;
Vector2 operator+(const Vector2& other) const;
Vector2 operator+=(const Vector2& other);
};
Vector2 operator*(float scalar) const;
Vector2 operator/(float scalar) const;
Vector2 operator+(const Vector2& other) const;
Vector2 operator+=(const Vector2& other);
};
}
}
54 changes: 28 additions & 26 deletions DurkGame/DK_Rect.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,35 @@
#include "DK_Math.h"


struct DK_Rect : public SDL_FRect {
DK_Rect() = default;
namespace dk {
struct Rect : public SDL_FRect {
Rect() = default;

DK_Rect(float x, float y, float w, float h) : SDL_FRect{ x, y, w, h } {}
DK_Rect(int x, int y, int w, int h) : SDL_FRect{ (float)x, (float)y, (float)w, (float)h } {}
Rect(float x, float y, float w, float h) : SDL_FRect{ x, y, w, h } {}
Rect(int x, int y, int w, int h) : SDL_FRect{ (float)x, (float)y, (float)w, (float)h } {}

DK_Math::Vector2 getPos();
DK_Math::Vector2 getSize();
bool collidePoint(DK_Math::Vector2 pos);
dk::math::Vector2 getPos();
dk::math::Vector2 getSize();
bool collidePoint(dk::math::Vector2 pos);

void setCenter(DK_Math::Vector2 pos);
void setTopLeft(DK_Math::Vector2 pos);
void setTopMid(DK_Math::Vector2 pos);
void setTopRight(DK_Math::Vector2 pos);
void setBottomLeft(DK_Math::Vector2 pos);
void setBottomMid(DK_Math::Vector2 pos);
void setBottomRight(DK_Math::Vector2 pos);
void setLeftMid(DK_Math::Vector2 pos);
void setRightMid(DK_Math::Vector2 pos);
void setCenter(dk::math::Vector2 pos);
void setTopLeft(dk::math::Vector2 pos);
void setTopMid(dk::math::Vector2 pos);
void setTopRight(dk::math::Vector2 pos);
void setBottomLeft(dk::math::Vector2 pos);
void setBottomMid(dk::math::Vector2 pos);
void setBottomRight(dk::math::Vector2 pos);
void setLeftMid(dk::math::Vector2 pos);
void setRightMid(dk::math::Vector2 pos);

DK_Math::Vector2 getCenter();
DK_Math::Vector2 getTopLeft();
DK_Math::Vector2 getTopMid();
DK_Math::Vector2 getTopRight();
DK_Math::Vector2 getBottomLeft();
DK_Math::Vector2 getBottomMid();
DK_Math::Vector2 getBottomRight();
DK_Math::Vector2 getLeftMid();
DK_Math::Vector2 getRightMid();
};
dk::math::Vector2 getCenter();
dk::math::Vector2 getTopLeft();
dk::math::Vector2 getTopMid();
dk::math::Vector2 getTopRight();
dk::math::Vector2 getBottomLeft();
dk::math::Vector2 getBottomMid();
dk::math::Vector2 getBottomRight();
dk::math::Vector2 getLeftMid();
dk::math::Vector2 getRightMid();
};
}
36 changes: 19 additions & 17 deletions DurkGame/DK_Surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@
#include "DK_Rect.h"


class DK_Surface {
public:
DK_Surface() = default;
DK_Surface(DK_Math::Vector2 size);
~DK_Surface() {
if (surface) SDL_FreeSurface(surface);
}
namespace dk {
class Surface {
public:
Surface() = default;
Surface(dk::math::Vector2 size);
~Surface() {
if (surface) SDL_FreeSurface(surface);
}

void fill(SDL_Color color);
DK_Math::Vector2 getSize();
DK_Rect getRect();
void free() { SDL_FreeSurface(surface); }
void fill(SDL_Color color);
dk::math::Vector2 getSize();
dk::Rect getRect();
void free() { SDL_FreeSurface(surface); }

SDL_Surface* get() { return surface; }
void set(SDL_Surface* setSurface);
SDL_Surface* get() { return surface; }
void set(SDL_Surface* setSurface);

private:
SDL_Surface* surface = nullptr;
DK_Rect rect = {};
};
private:
SDL_Surface* surface = nullptr;
dk::Rect rect = {};
};
}
36 changes: 19 additions & 17 deletions DurkGame/DK_Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@
#include "DK_Surface.h"


class DK_Texture {
public:
DK_Texture() = default;
DK_Texture(SDL_Renderer* renderer, const char* fileDir);
DK_Texture(SDL_Renderer* renderer, DK_Surface* surface);
~DK_Texture() { if (texture) SDL_DestroyTexture(texture); }
namespace dk {
class Texture {
public:
Texture() = default;
Texture(SDL_Renderer* renderer, const char* fileDir);
Texture(SDL_Renderer* renderer, dk::Surface* surface);
~Texture() { if (texture) SDL_DestroyTexture(texture); }

[[nodiscard]] DK_Math::Vector2 getSize() const;
[[nodiscard]] DK_Rect getRect() const;
[[nodiscard]] dk::math::Vector2 getSize() const;
[[nodiscard]] dk::Rect getRect() const;

void loadTextureFile(SDL_Renderer* renderer, const char* fileDir);
void setSize(int w, int h);
void scaleBy(float scale);
void blit(SDL_Renderer* renderer, DK_Rect rect);
void blitAngle(SDL_Renderer* renderer, DK_Rect rect, float angle);
private:
SDL_Texture* texture = nullptr;
DK_Rect rect = {};
};
void loadTextureFile(SDL_Renderer* renderer, const char* fileDir);
void setSize(int w, int h);
void scaleBy(float scale);
void blit(SDL_Renderer* renderer, dk::Rect rect);
void blitAngle(SDL_Renderer* renderer, dk::Rect rect, float angle);
private:
SDL_Texture* texture = nullptr;
dk::Rect rect = {};
};
}
Binary file removed DurkGame/Debug/DurkGame.obj
Binary file not shown.
Binary file modified DurkGame/Debug/DurkGame.pch
Binary file not shown.
Empty file.
Binary file removed DurkGame/Debug/character.obj
Binary file not shown.
Binary file removed DurkGame/Debug/clock.obj
Binary file not shown.
Binary file removed DurkGame/Debug/display.obj
Binary file not shown.
Binary file modified DurkGame/Debug/dk_character.obj
Binary file not shown.
Binary file modified DurkGame/Debug/dk_clock.obj
Binary file not shown.
Binary file modified DurkGame/Debug/dk_display.obj
Binary file not shown.
Binary file modified DurkGame/Debug/dk_font.obj
Binary file not shown.
Binary file modified DurkGame/Debug/dk_input.obj
Binary file not shown.
Binary file modified DurkGame/Debug/dk_math.obj
Binary file not shown.
Binary file modified DurkGame/Debug/dk_rect.obj
Binary file not shown.
Binary file modified DurkGame/Debug/dk_surface.obj
Binary file not shown.
Binary file modified DurkGame/Debug/dk_texture.obj
Binary file not shown.
Binary file modified DurkGame/Debug/durk_game.obj
Binary file not shown.
Binary file removed DurkGame/Debug/font.obj
Binary file not shown.
Binary file removed DurkGame/Debug/input.obj
Binary file not shown.
Binary file removed DurkGame/Debug/math.obj
Binary file not shown.
Binary file modified DurkGame/Debug/pch.obj
Binary file not shown.
Binary file removed DurkGame/Debug/rect.obj
Binary file not shown.
Binary file removed DurkGame/Debug/texture.obj
Binary file not shown.
7 changes: 5 additions & 2 deletions DurkGame/DurkGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#include "DK_Surface.h"


void DK_Init();
namespace dk {
void init();

void quit(SDL_Window* window, SDL_Renderer* renderer);
}

void DK_Quit(SDL_Window* window, SDL_Renderer* renderer);
40 changes: 21 additions & 19 deletions DurkGame/dk_character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@
#include "DK_Character.h"


DK_Character::DK_Character(SDL_Renderer* renderer, DK_Texture* texture) {
this->renderer = renderer;
this->texture = texture;
rect = texture->getRect();
}
namespace dk {
Character::Character(SDL_Renderer* renderer, dk::Texture* texture) {
this->renderer = renderer;
this->texture = texture;
rect = texture->getRect();
}

DK_Math::Vector2 DK_Character::getPosition() const {
return position;
}
dk::math::Vector2 Character::getPosition() const {
return position;
}

DK_Rect DK_Character::getRect() const {
return rect;
}
dk::Rect Character::getRect() const {
return rect;
}

void DK_Character::move() {
// velocity.y += GRAVITY; // FIXME: Implement gravity
position += velocity;
rect.setCenter(position);
}
void Character::move() {
// velocity.y += GRAVITY; // FIXME: Implement gravity
position += velocity;
rect.setCenter(position);
}

void DK_Character::draw() {
if (!texture) return;
texture->blit(renderer, rect);
void Character::draw() {
if (!texture) return;
texture->blit(renderer, rect);
}
}
Loading

0 comments on commit ecd07b9

Please sign in to comment.