Skip to content

Commit

Permalink
Add stoooopid functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sahroush committed Apr 30, 2023
1 parent 0d28c91 commit 0eb4558
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,24 @@ void Level::handle_key_up(Keyboard::Key key){
}
}

bool Level::is_terrain(int x, int y){
if(lines.size() <= x)
return 0;
if(lines[x].size() <= y)
return 0;
return lines[x][y] == '.';
}

IntRect Level::get_block_frame(int x, int y){
int id = 8 * is_terrain(x-1, y);
id += 4 * is_terrain(x, y+1);
id += 2 * is_terrain(x+1, y);
id += 1*is_terrain(x, y-1);
IntRect ans;
ans.width = BLOCK_WIDTH;
ans.height = BLOCK_HEIGHT;
}

void Level::init_heart(){
heart_sprite = new Sprite;
heart_sprite->setTexture(heart_texture);
Expand Down
2 changes: 2 additions & 0 deletions src/level.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "cherry.hpp"

const Vector2f BLOCK_SCALE = {7.f, 7.f};
const int BLOCK_WIDTH = 11, BLOCK_HEIGHT = 11;
const float SMALL_MOVEMENT = 0.1;

namespace level{
Expand Down Expand Up @@ -85,4 +86,5 @@ class Level{
bool is_terrain(int x, int y);
vector <string> lines;
vector <IntRect> terrain_frames = {};
IntRect get_block_frame(int x, int y);
};

0 comments on commit 0eb4558

Please sign in to comment.