Début NoteSprite
This commit is contained in:
parent
6e6cfc347d
commit
611ff37653
7 changed files with 47 additions and 3 deletions
BIN
AsepriteThings/flower_tile.aseprite
Normal file
BIN
AsepriteThings/flower_tile.aseprite
Normal file
Binary file not shown.
BIN
SimpleGame/media/sprites/flower_tile.png
Normal file
BIN
SimpleGame/media/sprites/flower_tile.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 254 B |
|
@ -21,6 +21,8 @@ add_executable(simpleGame
|
||||||
Source/Game.cpp Include/Game.hpp Source/Main.cpp
|
Source/Game.cpp Include/Game.hpp Source/Main.cpp
|
||||||
Source/RoundTarget.cpp Include/RoundTarget.hpp
|
Source/RoundTarget.cpp Include/RoundTarget.hpp
|
||||||
Source/AudioEmitter.cpp Include/AudioEmitter.hpp
|
Source/AudioEmitter.cpp Include/AudioEmitter.hpp
|
||||||
|
Source/NoteSprite.cpp Include/NoteSprite.hpp
|
||||||
|
Source/NoteTile.cpp Include/NoteTile.hpp Include/NotePlaceEnum.hpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(simpleGame PRIVATE
|
target_include_directories(simpleGame PRIVATE
|
||||||
|
|
19
SimpleGame/src/Include/NoteSprite.hpp
Normal file
19
SimpleGame/src/Include/NoteSprite.hpp
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SFML/Graphics/Sprite.hpp>
|
||||||
|
#include <SFML/System/Vector2.hpp>
|
||||||
|
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);
|
||||||
|
};
|
|
@ -1,4 +1,5 @@
|
||||||
#include <NotePlaceEnum.hpp>
|
#include <NotePlaceEnum.hpp>
|
||||||
|
#include <NoteSprite.hpp>
|
||||||
#include <SFML/Graphics/StencilMode.hpp>
|
#include <SFML/Graphics/StencilMode.hpp>
|
||||||
#include <SFML/System/Vector2.hpp>
|
#include <SFML/System/Vector2.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -12,10 +13,10 @@ private:
|
||||||
float good_interval;
|
float good_interval;
|
||||||
NotePlaceEnum place;
|
NotePlaceEnum place;
|
||||||
// used for Graphics
|
// used for Graphics
|
||||||
sf::Vector2f position;
|
NoteSprite note_sprite;
|
||||||
// probably some tileSprite class here in the future <-
|
// 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);
|
NoteTile(float play_time, float good_interval, NotePlaceEnum place);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
16
SimpleGame/src/Source/NoteSprite.cpp
Normal file
16
SimpleGame/src/Source/NoteSprite.cpp
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#include "NoteSprite.hpp"
|
||||||
|
#include <SFML/Graphics/Sprite.hpp>
|
||||||
|
#include <SFML/Graphics/Texture.hpp>
|
||||||
|
#include <SFML/System/Vector2.hpp>
|
||||||
|
|
||||||
|
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));
|
||||||
|
};
|
|
@ -1,10 +1,16 @@
|
||||||
#include "NoteTile.hpp"
|
#include "NoteTile.hpp"
|
||||||
|
#include "NoteSprite.hpp"
|
||||||
|
#include <SFML/System/Vector2.hpp>
|
||||||
|
|
||||||
std::vector<std::unique_ptr<NoteTile>> NoteTile::existing_tiles;
|
std::vector<std::unique_ptr<NoteTile>> NoteTile::existing_tiles;
|
||||||
|
|
||||||
// private
|
// private
|
||||||
NoteTile::NoteTile(float play_time, float good_interval, NotePlaceEnum place)
|
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<NoteTile>(this));
|
NoteTile::existing_tiles.push_back(std::unique_ptr<NoteTile>(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue