Skip to content

Commit

Permalink
Add a poorly drawn car sprite
Browse files Browse the repository at this point in the history
  • Loading branch information
nonk123 committed May 28, 2024
1 parent 7a2dd60 commit d0012ab
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
Binary file added assets/car.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 15 additions & 1 deletion src/entities/car.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "defs.hpp"
#include "lane.hpp"
#include "sounds.hpp"
#include "sprites.hpp"

#include "entities/pedo.hpp"

Expand Down Expand Up @@ -96,7 +97,20 @@ void Car::update() {
}

void Car::draw() {
DrawRectangle(pos.x, pos.y, width, height, BLUE);
DrawTextureRec(
Sprites::car,
{
0.0f,
0.0f,
width,
direction == Direction::FORWARD ? height : -height,
},
{
std::floor(pos.x),
std::floor(pos.y),
},
WHITE
);
}

std::optional<std::size_t> Car::get_lane_idx() const {
Expand Down
2 changes: 1 addition & 1 deletion src/runner/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static void spawn_cars() {
spawn_delay = BASE_SPAWN_DELAY_PER_LANE + SPAWN_DELAY_RANDOM_OFFSET * randomness;
spawn_delay /= lanes_count;

const float WIDTH = LANE_WIDTH * 0.9f, HEIGHT = LANE_WIDTH * 1.8f;
const float WIDTH = LANE_WIDTH - 4.0f, HEIGHT = WIDTH * 2.0f;

float left;
Car::Direction dir;
Expand Down
2 changes: 2 additions & 0 deletions src/sprites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ void load_sprites() {
Sprites::Pedo::standing = LoadTexture("assets/pedo-stand.png");
Sprites::Pedo::walking[0] = LoadTexture("assets/pedo-walk-1.png");
Sprites::Pedo::walking[1] = LoadTexture("assets/pedo-walk-2.png");

Sprites::car = LoadTexture("assets/car.png");
}
4 changes: 4 additions & 0 deletions src/sprites.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ namespace Sprites::Pedo {
inline Texture2D standing;
inline std::array<Texture2D, 2> walking;
} // namespace Sprites::Pedo

namespace Sprites {
inline Texture2D car;
}

0 comments on commit d0012ab

Please sign in to comment.