diff --git a/CMakeLists.txt b/CMakeLists.txt index e4cc378..81602d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/Image.cpp b/Image.cpp index 69a9b60..8b4e7e5 100644 --- a/Image.cpp +++ b/Image.cpp @@ -184,7 +184,7 @@ void Image::Draw(Image &canvas, std::function 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 PixFunc, bool with_hash_pixel) diff --git a/Player.h b/Player.h index 93931c4..ec2a683 100644 --- a/Player.h +++ b/Player.h @@ -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); } diff --git a/Sprite.cpp b/Sprite.cpp index c13279a..a0e1afd 100644 --- a/Sprite.cpp +++ b/Sprite.cpp @@ -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; } @@ -26,7 +28,8 @@ 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); } @@ -34,56 +37,70 @@ void Sprite::SpriteFromImg(Image &img0, int p_frames, int ms_on_frame, int scale 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); diff --git a/main.cpp b/main.cpp index 0d52e74..d6f945f 100644 --- a/main.cpp +++ b/main.cpp @@ -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;