Skip to content

Commit

Permalink
upd for gcc compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
atic_an committed Mar 6, 2021
1 parent 1f00b44 commit 9a415c4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 23 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
cmake_minimum_required(VERSION 3.5)
project(main)

if(WIN32)
set(CMAKE_CXX_STANDARD 20)

if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -openmp")
else()
set(CMAKE_CXX_STANDARD 14)
endif()

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
Expand Down
2 changes: 1 addition & 1 deletion Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void Image::Draw(Image &canvas, std::function<Pixel(Point, Pixel)> PixFunc) cons

void Image::FastDraw(Image &canvas, int lines, int from_line) const
{
std::memcpy(canvas.data + (from_line * canvas.width), data, canvas.width * lines * sizeof(Pixel));
memcpy(canvas.data + (from_line * canvas.width), data, canvas.width * lines * sizeof(Pixel));
}

void Image::PixelsChange(std::function<Pixel(Pixel)> PixFunc, bool with_hash_pixel)
Expand Down
2 changes: 1 addition & 1 deletion Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private: static Player *player_getter;
for (int i = 0; i < 3; i++)boots_imgs.emplace_back("../resources/boots_" + std::to_string(i + 1) + ".png");
//boots ---

key_black = Image::Image(key);
key_black = Image(key);
key_black.PixelsChange(shadow_func, false);
}

Expand Down
53 changes: 35 additions & 18 deletions Sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@

void Sprite::SpriteFromImg(Image &img0, int p_frames, int ms_on_frame, int scale)
{
frames = p_frames;
frames = p_frames;
s_per_frame = ms_on_frame / 1000.0;

if (p_frames <= 0) {
if (p_frames <= 0)
{
std::cerr << "too few amount of frames : " << p_frames << std::endl;
std::abort();
}

if (frames == 1) {
if (frames == 1)
{
imgs.emplace_back(img0);
return;
}
Expand All @@ -26,64 +28,79 @@ void Sprite::SpriteFromImg(Image &img0, int p_frames, int ms_on_frame, int scale

int temp_x_now = 0;

for (int frame = 0; frame < frames; frame++, temp_x_now -= sz_w) {
for (int frame = 0; frame < frames; frame++, temp_x_now -= sz_w)
{
imgs.emplace_back(sz_w, sz_h, chans);
img0.Draw(imgs[frame], {.x = temp_x_now, .y = 0}, false, false, true);
}
}

Sprite::Sprite(const std::string &path, int p_frames, int ms_on_frame, int scale, bool _loop) : imgs(), loop(_loop)
{
SpriteFromImg(Image {path, scale}, p_frames, ms_on_frame, scale);
auto im_gg = Image{path, scale};
auto &img_ptr = im_gg;
SpriteFromImg(img_ptr, p_frames, ms_on_frame, scale);
}

Sprite::Sprite(const std::string &path, SpritePixSz frame_sz, int ms_on_frame, int scale, bool _loop) : imgs(), loop(_loop)
{
auto img0 = Image {path, scale};
if (frame_sz.width == 0)std::abort();
auto img0 = Image{path, scale};
if (frame_sz.width == 0)
std::abort();
int p_frames = img0.Width() / (frame_sz.width * scale);
SpriteFromImg(img0, p_frames, ms_on_frame, scale);
}

Sprite::Sprite(Image &img, SpritePixSz frame_sz, int ms_on_frame, int scale, bool _loop) : imgs(), loop(_loop)
{
if (frame_sz.width == 0)error("sz need to be more than 0");
if (frame_sz.width == 0)
error("sz need to be more than 0");
int p_frames = img.Width() / (frame_sz.width * scale);
SpriteFromImg(img, p_frames, ms_on_frame, scale);
}

void Sprite::Draw(Image &canvas, const Point p, double time_start, bool flip_OX, bool flip_OY)
{
if (frames == 0)return;
if (frames == 0)
return;
double dt = GameTime::Now().GetSecAfter(time_start);
if (dt < 0)dt = 0;
if (dt < 0)
dt = 0;
int _frame = (int)(dt / s_per_frame);
imgs[_frame % frames].Draw(canvas, p, flip_OX, flip_OY);
}

void Sprite::Draw(Image &canvas, const Point p, bool flip_OX, bool flip_OY)
{
if (frames == 0)return;
if (frames == 0)
return;
double dt = GameTime::Now().GetSecAfter(time_start_prev_frame);
if (dt < 0)dt = 0;

if (dt < 0)
dt = 0;

int add_frame = 0;

if (time_start_prev_frame < 0) {
if (time_start_prev_frame < 0)
{
time_start_prev_frame = GameTime::Now().GetTime();
add_frame = 0;
frame_now = 0;
}
else if (dt > s_per_frame) {
else if (dt > s_per_frame)
{
add_frame = (int)(dt / s_per_frame);
time_start_prev_frame += add_frame * s_per_frame;
}

if (loop) {
if (loop)
{
frame_now = (frame_now + add_frame) % frames;
} else {
}
else
{
frame_now = frame_now + add_frame;
if (frame_now >= frames) frame_now = frames - 1;
if (frame_now >= frames)
frame_now = frames - 1;
}

imgs[frame_now].Draw(canvas, p, flip_OX, flip_OY);
Expand Down
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ int main(int argc, char **argv)
int frames = 0;

bool is_alive = true;
Image for_die = Image::Image(0, 0, 0);
Image for_die = Image(0, 0, 0);

double die_time = 0;
double die_duration = 3;
Expand Down

0 comments on commit 9a415c4

Please sign in to comment.