working game (but bad)
This commit is contained in:
parent
dbb296ff5d
commit
5c65b99604
6 changed files with 89 additions and 12 deletions
|
@ -1,10 +1,10 @@
|
|||
#include "NoteTile.hpp"
|
||||
#include "GameData.hpp"
|
||||
#include "NoteSprite.hpp"
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <SFML/Window/Window.hpp>
|
||||
#include <memory>
|
||||
|
||||
const int NotePlaceXPos[3] = {200, 400, 600};
|
||||
std::vector<std::unique_ptr<NoteTile>> NoteTile::existing_tiles{};
|
||||
// private
|
||||
NoteTile::NoteTile(float play_time, float good_interval, NotePlaceEnum place,
|
||||
|
@ -13,9 +13,9 @@ NoteTile::NoteTile(float play_time, float good_interval, NotePlaceEnum place,
|
|||
note_sprite() {
|
||||
// TODO do real note_sprite init, make it fall at good speed far enough...
|
||||
note_sprite.fall_speed = 100;
|
||||
note_sprite.sprite.setPosition(
|
||||
sf::Vector2f(NotePlaceXPos[place],
|
||||
480 - note_sprite.fall_speed * (play_time - current_time)));
|
||||
note_sprite.sprite.setPosition(sf::Vector2f(
|
||||
NOTE_PLACE_X_POS[place],
|
||||
NOTE_PRESS_HEIGHT - note_sprite.fall_speed * (play_time - current_time)));
|
||||
}
|
||||
|
||||
// public
|
||||
|
@ -27,18 +27,33 @@ void NoteTile::create(float play_time, float good_interval, NotePlaceEnum place,
|
|||
}
|
||||
|
||||
bool NoteTile::checkPress(float press_time, NotePlaceEnum key_pressed) {
|
||||
for (const auto ¬e_tile : NoteTile::existing_tiles) {
|
||||
auto &tiles = NoteTile::existing_tiles;
|
||||
for (auto it = tiles.begin(); it != tiles.end(); ++it) {
|
||||
const auto ¬e_tile = *it;
|
||||
if (note_tile->play_time - note_tile->good_interval / 2 < press_time &&
|
||||
note_tile->play_time + note_tile->good_interval / 2 > press_time &&
|
||||
note_tile->place == key_pressed) {
|
||||
printf("good touch \n");
|
||||
tiles.erase(it);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
printf("badd touch \n");
|
||||
return false;
|
||||
}
|
||||
|
||||
void NoteTile::update(float dtime, sf::RenderWindow &window) {
|
||||
for (const auto ¬e_tile : NoteTile::existing_tiles) {
|
||||
note_tile->note_sprite.update(dtime, window);
|
||||
auto &tiles = NoteTile::existing_tiles;
|
||||
|
||||
for (auto it = tiles.begin(); it != tiles.end();) {
|
||||
auto ¬e_tile = *it;
|
||||
|
||||
if (note_tile->note_sprite.sprite.getPosition().y > SCREEN_HEIGHT) {
|
||||
printf("missed tile \n");
|
||||
it = tiles.erase(it);
|
||||
} else {
|
||||
note_tile->note_sprite.update(dtime, window);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue