Skip to content
This repository has been archived by the owner on Mar 31, 2019. It is now read-only.

Commit

Permalink
fix some bug and add feature
Browse files Browse the repository at this point in the history
fix bug for scoring db
add canBeHit
set Origin
add textAccuracy in select song
  • Loading branch information
ouoam committed Nov 26, 2018
1 parent b827f77 commit ccbfb25
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Oshu/DB/ScoringDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ScoringDB : public virtual DB {

score->Rank = (Scoring::ScoreRank::Enum)std::stoi(GetWithDef(*ranking, "Rank", "0"));
score->TotalScore = std::stod(GetWithDef(*ranking, "TotalScore", "0"));
score->Accuracy = std::stod(GetWithDef(*ranking, "TotalScore", "0"));
score->Accuracy = std::stod(GetWithDef(*ranking, "Accuracy", "0"));
score->MaxCombo = std::stoi(GetWithDef(*ranking, "MaxCombo", "0"));

score->Statistics[Scoring::HitResult::Miss] = std::stoi(GetWithDef(*ranking, "StatMiss", "0"));
Expand Down
23 changes: 14 additions & 9 deletions Oshu/Object/Circle.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,31 @@ class Circle : public ContainerHitObject {
}

void StartPreemptState() {
circle.fadeTo(255, hitObject->TimeFadeIn);
circleOverlay.fadeTo(255, hitObject->TimeFadeIn);
circle.fadeTo(255, hitObject->TimeFadeIn).moveTo(sf::Vector2f(0, 0));
circleOverlay.fadeTo(255, hitObject->TimeFadeIn).moveTo(sf::Vector2f(0, 0));
approach.fadeTo(255, std::min(hitObject->TimeFadeIn * 2, hitObject->TimePreempt));
approach.scaleTo(1.1, hitObject->TimePreempt);

}

void onMouseClick(uint8_t key) {
approach.fadeTo(255).fadeTo(0, 50).then().expire();
approach.fadeTo(255).fadeTo(0, 50)
.moveTo(sf::Vector2f(0, 0)).then().expire();
circle.fadeTo(0, 500).scaleTo(1)
.scaleTo(1.5f, 250, Object::Animate::Easing::OutQuad).then().expire();
.scaleTo(1.5f, 250, Object::Animate::Easing::OutQuad)
.moveTo(sf::Vector2f(0, 0)).then().expire();
circleOverlay.fadeTo(0, 500).scaleTo(1)
.scaleTo(1.5f, 250, Object::Animate::Easing::OutQuad).then().expire();
.scaleTo(1.5f, 250, Object::Animate::Easing::OutQuad)
.then().expire();
canClick = false;
}

void onMiss() {
circle.fadeTo(200).fadeTo(0, 500).then().expire();
circleOverlay.fadeTo(200).fadeTo(0, 500).then().expire();
approach.fadeTo(200).fadeTo(0, 500).then().expire();
circle.fadeTo(200).fadeTo(0, 500)
.moveTo(sf::Vector2f(0, 0)).then().expire();
circleOverlay.fadeTo(200).fadeTo(0, 500)
.moveTo(sf::Vector2f(0, 0)).then().expire();
approach.fadeTo(200).fadeTo(0, 500)
.then().expire();
}

void shake() {
Expand Down
11 changes: 11 additions & 0 deletions Oshu/Object/Container.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include "../Beatmap/Beatmap.h"

namespace Object {
Expand All @@ -18,6 +19,10 @@ class Container : public sf::Drawable, public sf::Transformable {
bool canClick = true;

static int renderLayer;

virtual bool canBeHit(sf::Vector2f pos) {
return false;
};
};

class ContainerHitObject : public Container {
Expand All @@ -39,6 +44,12 @@ class ContainerHitObject : public Container {
virtual void onMiss() { };

ContainerHitObject(Beatmap::bmHitObjects *HitObject) : hitObject(HitObject) {}

virtual bool canBeHit(sf::Vector2f pos) {
sf::Vector2f offset = pos - getPosition();
float dist = sqrt(offset.x * offset.x + offset.y * offset.y);
return (dist <= (hitObject->CR) / 2);
}
};

}
13 changes: 10 additions & 3 deletions Oshu/Object/Slider.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class Slider : public ContainerHitObject {

public:
Slider(Beatmap::bmHitObjects *HitObject) : ContainerHitObject(HitObject) {
setPosition((sf::Vector2f)HitObject->position);
setOrigin((sf::Vector2f)HitObject->position);

lineThinkness = GenerateTrianglesStrip(hitObject->sliders.curvePoints, hitObject->CR - 5);
sliderBody.setVertex(lineThinkness);

Expand All @@ -41,26 +44,30 @@ class Slider : public ContainerHitObject {
void StartPreemptState() {
circle->StartPreemptState();

sliderBody.fadeTo(255, hitObject->TimeFadeIn);
sliderBody.fadeTo(255, hitObject->TimeFadeIn).moveOriginTo(sf::Vector2f(0, 0));
}

void onMouseClick(uint8_t key) {
circle->onMouseClick(key);
canClick = circle->canClick;

sliderBody.fadeTo(0, 500).then().expire(); /////////
sliderBody.fadeTo(0, 500).moveOriginTo(sf::Vector2f(0, 0)).then().expire(); /////////
}

void onMiss() {
circle->miss();

sliderBody.fadeTo(200).fadeTo(0, 500).then().expire();
sliderBody.fadeTo(200).fadeTo(0, 500).moveOriginTo(sf::Vector2f(0, 0)).then().expire();
}

void shake() {
circle->shake();
}

virtual bool canBeHit(sf::Vector2f pos) {
return circle->canBeHit(pos);
}

private:
void draw(sf::RenderTarget& target, sf::RenderStates states) const {
// Use only slider
Expand Down
34 changes: 17 additions & 17 deletions Oshu/UI/Playfield.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,7 @@ class Playfield : public UI {

sf::Vector2f clickPos = transform.getInverse().transformPoint(click);

sf::Vector2f offset = clickPos - (sf::Vector2f)obj->hitObject->position;

float dist = sqrt(offset.x * offset.x + offset.y * offset.y);

if (dist <= (obj->hitObject->CR) / 2) {
if (obj->canBeHit(clickPos)) {
int64_t offsetTime = time - obj->hitObject->time;
Scoring::HitResult::Enum result = hitwindows.ResultFor(offsetTime);
if (result == Scoring::HitResult::None) {
Expand Down Expand Up @@ -170,18 +166,19 @@ class Playfield : public UI {
virtual void onDelete() {
UI::onDelete();

playVideo.stop();
updateVideoThreadRunning = false;

updateVideoMutex.lock();
playVideoTextureMutex.lock();

MutexText.lock();
Mutex.lock();

playVideo.stop();
updateVideoThreadRunning = false;

for (auto obj : objs)
delete obj;
objs.clear();

if (scoreProcessor != nullptr)
delete scoreProcessor;

Expand Down Expand Up @@ -251,7 +248,7 @@ class Playfield : public UI {



char buff[100];
char buff[20];

snprintf(buff, sizeof(buff), "%07.0lf", scoreProcessor->TotalScore);
textScore.setString(buff);
Expand Down Expand Up @@ -386,8 +383,8 @@ class Playfield : public UI {
case sf::Event::KeyPressed:
if (event.key.code == sf::Keyboard::Escape)
gobackUI();
if (event.key.alt && event.key.control)
m_window.setMouseCursorGrabbed(false);
//if (event.key.alt && event.key.control)
// m_window.setMouseCursorGrabbed(false);
if (event.key.code == sf::Keyboard::Tilde)
retry();

Expand All @@ -401,7 +398,7 @@ class Playfield : public UI {
break;

case sf::Event::GainedFocus:
m_window.setMouseCursorGrabbed(true);
//m_window.setMouseCursorGrabbed(true);
break;

case sf::Event::Resized:
Expand Down Expand Up @@ -504,7 +501,7 @@ class Playfield : public UI {
hitwindows.SetDifficulty(bmPlay.Difficulty.OverallDifficulty);

m_window.setKeyRepeatEnabled(false);
m_window.setMouseCursorGrabbed(true);
//m_window.setMouseCursorGrabbed(true);

scoreProcessor = new Scoring::ScoreProcessor(&bmPlay);

Expand Down Expand Up @@ -534,11 +531,11 @@ class Playfield : public UI {
}

void retry() {
eventMutext.lock();
drawMutex.lock();
updateMutex.lock();
//eventMutext.lock();
//drawMutex.lock();
//updateMutex.lock();

playSong.stop();
//playSong.stop();

onDelete();

Expand All @@ -555,6 +552,9 @@ class Playfield : public UI {

updateVideoMutex.unlock();
playVideoTextureMutex.unlock();

MutexText.unlock();
Mutex.unlock();
}

//virtual ~Playfield() {
Expand Down
11 changes: 11 additions & 0 deletions Oshu/UI/Select.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ class SelectUI : public UI {
sf::Text textUser;
sf::Text textScore;
sf::Text textText;
sf::Text textAccuracy;

textText.setFont(font);
textText.setCharacterSize(20 * globalScale.y);
Expand All @@ -291,6 +292,10 @@ class SelectUI : public UI {
textScore.setCharacterSize(14 * globalScale.y);
textScore.setFillColor(sf::Color::White);

textAccuracy.setFont(font);
textAccuracy.setCharacterSize(14 * globalScale.y);
textAccuracy.setFillColor(sf::Color::White);

textText.setString("LeaderBoard");
textText.setPosition(sf::Vector2f(30 * globalScale.x, 30 * globalScale.y));
renderScore.draw(textText);
Expand All @@ -315,8 +320,14 @@ class SelectUI : public UI {
textScore.setString(temp);
textScore.setPosition(position + sf::Vector2f(0, 30 * globalScale.y));

char buff[20];
snprintf(buff, sizeof(buff), "%.2lf", ((*beatmapScore)[i])->Accuracy * 100.0);
textAccuracy.setString(std::string(buff) + " %");
textAccuracy.setPosition(position + sf::Vector2f(150 * globalScale.x, 6 * globalScale.y));

renderScore.draw(textUser);
renderScore.draw(textScore);
renderScore.draw(textAccuracy);
}

updateScore = false;
Expand Down
Binary file modified Oshu/game.db
Binary file not shown.

0 comments on commit ccbfb25

Please sign in to comment.