Skip to content

Commit

Permalink
ep6 using delta
Browse files Browse the repository at this point in the history
  • Loading branch information
danielblagy committed Apr 13, 2022
1 parent 0eb1bb5 commit 512b96a
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions dewcin_yt/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,44 @@ dewcin_app_entry_point
{
// game init code

int x = 250, y = 250;
float x = 250.0f, y = 250.0f;

dewcin::Game::setGameUpdate([&](float delta)
{
wchar_t charBuffer[256];
swprintf(charBuffer, 256, L"delta: %f\n", delta);
OutputDebugString(charBuffer);
//swprintf(charBuffer, 256, L"delta: %f\n", delta);
//OutputDebugString(charBuffer);

dewcin::Renderer::SetPixel(10, 10, { 0, 0, 255 });

dewcin::Renderer::FillRectangle({ x, y, 320, 180 }, { 0, 255, 0 });
static int frames = 0;
static float timePassed = 0.0f;

if (dewcin::Input::isKeyPressed(DC_UP))
y -= 10;
else if (dewcin::Input::isKeyPressed(DC_DOWN))
y += 10;
frames++;
timePassed += delta;

if (dewcin::Input::isKeyPressed(DC_LEFT))
x -= 10;
else if (dewcin::Input::isKeyPressed(DC_RIGHT))
x += 10;
if (timePassed >= 1.0f)
{
swprintf(charBuffer, 256, L"FPS: %d\n", frames);
OutputDebugString(charBuffer);

if (dewcin::Input::isMouseButtonPressed(DC_MOUSE_MIDDLE))
OutputDebugString(L"mouse middle button pressed!\n");
timePassed -= 1.0f;
frames = 0;
}

dewcin::Input::Position mousePosition = dewcin::Input::getMousePosition();
swprintf(charBuffer, 256, L"%d, %d\n", mousePosition.x, mousePosition.y);
OutputDebugString(charBuffer);
dewcin::Renderer::SetPixel(10, 10, { 0, 0, 255 });

// x = 3.4 = 3 x = 3.4 + 0.5 = 3.9 -> 3
// x = 3.8 = 3 x = 3.8 ) 0.5 = 4.3 -> 4
dewcin::Renderer::FillRectangle({ int(x + 0.5f), int(y + 0.5f), 320, 180 }, { 0, 255, 0 });

if (dewcin::Input::isKeyPressed(DC_W))
y -= 100.0f * delta;
else if (dewcin::Input::isKeyPressed(DC_S))
y += 100.0f * delta;

if (dewcin::Input::isKeyPressed(DC_A))
x -= 100.0f * delta;
else if (dewcin::Input::isKeyPressed(DC_D))
x += 100.0f * delta;
}
);

Expand Down

0 comments on commit 512b96a

Please sign in to comment.