Browse Source

started player code. Added player static sprite

master
Arc0re 5 years ago
parent
commit
67171847d3
  1. 16
      game.cpp
  2. BIN
      game.exe
  3. BIN
      gfx/tiles.png

16
game.cpp

@ -70,6 +70,10 @@ struct Rect { @@ -70,6 +70,10 @@ struct Rect {
rect.h = r.rect.h;
}
SDL_Rect* operator ()(){
return ▭
}
void print() {
auto r = rect;
printf("x: %d, y: %d, w: %d, h: %d\n", r.x, r.y, r.w, r.h);
@ -92,6 +96,17 @@ SDL_Renderer* renderer; @@ -92,6 +96,17 @@ SDL_Renderer* renderer;
SDL_Texture* tiles;
bool quit;
struct Player {
Rect src_rect;
Rect body_hitbox; // player is a 16*16 tile + 8 pixels in height for the head, we ignore those
int x, y;
Player() : src_rect(0, 39, TILE_WIDTH, TILE_HEIGHT + 10/*head size*/), body_hitbox(0, 48, TILE_WIDTH, TILE_HEIGHT), x(0), y(0) {}
void draw() {
Rect dst(x, y, src_rect()->w, src_rect()->h);
SDL_RenderCopy(renderer, tiles, src_rect(), dst());
}
} player;
// A room is a screen in the sense of a static screen, aka the player doesnt move a camera,
// he just moves in the current room
/*
@ -174,6 +189,7 @@ extern "C" int main(int argc, char** argv) { @@ -174,6 +189,7 @@ extern "C" int main(int argc, char** argv) {
// Current room rendering
draw_room(&next_room);
player.draw();
SDL_RenderPresent(renderer);
}

BIN
game.exe

Binary file not shown.

BIN
gfx/tiles.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Loading…
Cancel
Save