From 611ff3765319a883e8e216f7869c65bca5326def Mon Sep 17 00:00:00 2001 From: Crizomb Date: Thu, 12 Jun 2025 19:17:52 +0200 Subject: [PATCH] =?UTF-8?q?D=C3=A9but=20NoteSprite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsepriteThings/flower_tile.aseprite | Bin 0 -> 419 bytes SimpleGame/media/sprites/flower_tile.png | Bin 0 -> 254 bytes SimpleGame/src/CMakeLists.txt | 2 ++ SimpleGame/src/Include/NoteSprite.hpp | 19 +++++++++++++++++++ SimpleGame/src/Include/NoteTile.hpp | 5 +++-- SimpleGame/src/Source/NoteSprite.cpp | 16 ++++++++++++++++ SimpleGame/src/Source/NoteTile.cpp | 8 +++++++- 7 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 AsepriteThings/flower_tile.aseprite create mode 100644 SimpleGame/media/sprites/flower_tile.png create mode 100644 SimpleGame/src/Include/NoteSprite.hpp create mode 100644 SimpleGame/src/Source/NoteSprite.cpp diff --git a/AsepriteThings/flower_tile.aseprite b/AsepriteThings/flower_tile.aseprite new file mode 100644 index 0000000000000000000000000000000000000000..f651bbb8a82273152ee599ff7e04cfa3de5674c4 GIT binary patch literal 419 zcmZ3?$iVPmDItzu+j zX>VU*kkAyJ_b_?(|M;^{PT&6X|NsBlYqz)5wP$8!MTP~HIdxr+j(!l4@^;>p{^?#_ z`3CYJn-rLVBn5-U@S6bws%999Jepi`I_{xiXp@G)>RRLn_EXlSqry!hXs z=ge`n;|)vFdnXFYH2*k0=g$F&*)p5tW>}?|o{)%?OEceOVYc^0(Tg&nX3n1<4;WS( jxP|qvYmeCdp_O~%KV@^9lfCv&3KUiMGBBifG2Q?G8=hn? literal 0 HcmV?d00001 diff --git a/SimpleGame/media/sprites/flower_tile.png b/SimpleGame/media/sprites/flower_tile.png new file mode 100644 index 0000000000000000000000000000000000000000..3c5994039b429c111db8785cc445f056cad593fa GIT binary patch literal 254 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|c6hothFJ6_ zCrD%*=s0sySoAM{vVYazS%Syh(+>YIFyr2oW*r%s^7)_pizugv>HWzk4)P?rT+>li zID7yIKD;?Byyl$iH2W_<3=c24zFu +#include +class NoteTile; + +// Should just be a component of NoteTile +class NoteSprite { +public: + static sf::Texture texture; + friend class NoteTile; + +private: + sf::Sprite sprite; + float fall_speed; + NoteSprite(); + NoteSprite(sf::Vector2f start_pos, float fall_speed); + void update(float dtime); +}; diff --git a/SimpleGame/src/Include/NoteTile.hpp b/SimpleGame/src/Include/NoteTile.hpp index 84bfe41..9920b8a 100644 --- a/SimpleGame/src/Include/NoteTile.hpp +++ b/SimpleGame/src/Include/NoteTile.hpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -12,10 +13,10 @@ private: float good_interval; NotePlaceEnum place; // used for Graphics - sf::Vector2f position; + NoteSprite note_sprite; // probably some tileSprite class here in the future <- - // Constructor private, use create to create + // Constructor is rivate, use create NoteTile(float play_time, float good_interval, NotePlaceEnum place); public: diff --git a/SimpleGame/src/Source/NoteSprite.cpp b/SimpleGame/src/Source/NoteSprite.cpp new file mode 100644 index 0000000..6a0d290 --- /dev/null +++ b/SimpleGame/src/Source/NoteSprite.cpp @@ -0,0 +1,16 @@ +#include "NoteSprite.hpp" +#include +#include +#include + +sf::Texture NoteSprite::texture; + +NoteSprite::NoteSprite() : sprite(sf::Sprite(texture)), fall_speed(0.f) {}; +NoteSprite::NoteSprite(sf::Vector2f start_pos, float fall_speed) + : fall_speed(fall_speed), sprite(sf::Sprite(NoteSprite::texture)) { + sprite.setPosition(start_pos); // sprite position c'est le left up corner +}; + +void NoteSprite::update(float dtime) { + sprite.move(sf::Vector2f(0, fall_speed * dtime)); +}; diff --git a/SimpleGame/src/Source/NoteTile.cpp b/SimpleGame/src/Source/NoteTile.cpp index ae19611..384cc23 100644 --- a/SimpleGame/src/Source/NoteTile.cpp +++ b/SimpleGame/src/Source/NoteTile.cpp @@ -1,10 +1,16 @@ #include "NoteTile.hpp" +#include "NoteSprite.hpp" +#include std::vector> NoteTile::existing_tiles; // private NoteTile::NoteTile(float play_time, float good_interval, NotePlaceEnum place) - : play_time(play_time), good_interval(good_interval), place(place) { + : play_time(play_time), good_interval(good_interval), place(place), + note_sprite() { + // TODO do real note_sprite init, make it fall at good speed far enough... + note_sprite.sprite.setPosition(sf::Vector2f(200, 0)); + note_sprite.fall_speed = 1; NoteTile::existing_tiles.push_back(std::unique_ptr(this)); }