basic 2d entity. entitylist

master
BuildTools 5 years ago
parent 41185cb000
commit f85006c2ff
  1. 8
      main.cpp
  2. 3
      stuff/globals/globals.cpp
  3. 2
      stuff/globals/globals.h
  4. 17
      stuff/objects/entityList.h
  5. 25
      stuff/objects/square.h
  6. 2
      threedee.vcxproj
  7. 6
      threedee.vcxproj.filters

@ -7,6 +7,7 @@
#include "stuff/globals/globals.h"
#include "stuff/callbacks/callbacks.h"
#include "stuff/objects/square.h"
int main(int argc, char** argv)
{
@ -16,14 +17,15 @@ int main(int argc, char** argv)
SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow("threedee", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1280, 720, SDL_WINDOW_SHOWN);
surface = SDL_GetWindowSurface(window);
SDL_Event eventHandler;
global::entList.push_back(square(200, 200, 50, 50));
while (global::running)
{
callbacks::handleCallbacks(&eventHandler);
SDL_Rect cursor{ global::mousePos.x, global::mousePos.y, 5, 5 };
SDL_FillRect(surface, &cursor, SDL_MapRGB(surface->format, 0xFF, 0xFF, 0xFF));
global::entList.run(surface);
SDL_UpdateWindowSurface(window);
SDL_Delay(1);

@ -1,4 +1,5 @@
#include "globals.h"
bool global::running = true;
vector2 global::mousePos;
vector2 global::mousePos;
entityList global::entList;

@ -1,7 +1,9 @@
#pragma once
#include "../objects/vector.h"
#include "../objects/entityList.h"
namespace global
{
extern bool running;
extern vector2 mousePos;
extern entityList entList;
}

@ -0,0 +1,17 @@
#pragma once
#include <vector>
#include "SDL.h"
#include "square.h"
class entityList : public std::vector<square>
{
public:
void run(SDL_Surface* surface)
{
for (square entity : *this)
{
entity.run(surface);
}
}
};

@ -0,0 +1,25 @@
#pragma once
#include "SDL.h"
struct square
{
SDL_Rect rect;
square()
{
rect.x = 0;
rect.y = 0;
rect.w = 0;
rect.h = 0;
}
square(int x_, int y_, int w_, int h_)
{
rect.x = x_;
rect.y = y_;
rect.w = w_;
rect.h = h_;
}
void run(SDL_Surface* surface)
{
SDL_FillRect(surface, &this->rect, SDL_MapRGB(surface->format, 0xFF, 0xFF, 0xFF));
}
};

@ -242,6 +242,8 @@
<ClInclude Include="sdl\include\SDL_vulkan.h" />
<ClInclude Include="stuff\callbacks\callbacks.h" />
<ClInclude Include="stuff\globals\globals.h" />
<ClInclude Include="stuff\objects\entityList.h" />
<ClInclude Include="stuff\objects\square.h" />
<ClInclude Include="stuff\objects\vector2.h" />
<ClInclude Include="stuff\objects\vector.h" />
</ItemGroup>

@ -285,6 +285,12 @@
<ClInclude Include="stuff\callbacks\callbacks.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="stuff\objects\square.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="stuff\objects\entityList.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">

Loading…
Cancel
Save