Skip to content
This repository has been archived by the owner on Aug 21, 2022. It is now read-only.

Commit

Permalink
Add 7K support
Browse files Browse the repository at this point in the history
  • Loading branch information
kuroni committed Dec 28, 2018
1 parent 2d7a026 commit 5f0a2bf
Show file tree
Hide file tree
Showing 25 changed files with 146 additions and 22 deletions.
Binary file added img/mania/4K/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/mania/4K/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/mania/4K/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/mania/4K/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added img/mania/7K/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/mania/7K/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/mania/7K/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/mania/7K/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/mania/7K/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/mania/7K/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/mania/7K/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/mania/7K/bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/mania/left0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/mania/left1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/mania/left2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed img/mania/left3.png
Binary file not shown.
Binary file added img/mania/leftup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/mania/right0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/mania/right1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/mania/right2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed img/mania/right3.png
Binary file not shown.
Binary file added img/mania/rightup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion src/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ void create_config()
"dash": [16]
},
"mania": {
"key": [68, 70, 74, 75]
"4K": true,
"key4K": [68, 70, 74, 75],
"key7K": [83, 68, 70, 32, 74, 75, 76]
}
})V0G0N";
std::string error;
Expand Down
164 changes: 143 additions & 21 deletions src/mania.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,165 @@

namespace mania
{
sf::Sprite bg, left[4], right[4];
int left_key_value[2], right_key_value[2];
sf::Sprite bg, left_handup, right_handup, left_hand[3], right_hand[3];
sf::Sprite left_4K[2], right_4K[2], left_7K[4], right_7K[4];
int left_key_value_4K[2], right_key_value_4K[2];
int left_key_value_7K[4], right_key_value_7K[4];
bool is_4K;

bool init()
{
// getting configs
left_key_value[0] = data::cfg["mania"]["key"][0].asInt();
left_key_value[1] = data::cfg["mania"]["key"][1].asInt();
right_key_value[0] = data::cfg["mania"]["key"][2].asInt();
right_key_value[1] = data::cfg["mania"]["key"][3].asInt();
is_4K = data::cfg["mania"]["4K"].asBool();

// importing sprites
bg.setTexture(data::load_texture("img/mania/bg.png"));
for (int i = 0; i < 2; i++)
left_key_value_4K[i] = data::cfg["mania"]["key4K"][i].asInt();
for (int i = 0; i < 2; i++)
right_key_value_4K[i] = data::cfg["mania"]["key4K"][i + 2].asInt();

for (int i = 0; i < 4; i++)
left_key_value_7K[i] = data::cfg["mania"]["key7K"][i].asInt();
for (int i = 0; i < 4; i++)
right_key_value_7K[i] = data::cfg["mania"]["key7K"][i + 3].asInt();

// importing sprites
left_handup.setTexture(data::load_texture("img/mania/leftup.png"));
right_handup.setTexture(data::load_texture("img/mania/rightup.png"));
for (int i = 0; i < 3; i++)
{
left_hand[i].setTexture(data::load_texture("img/mania/left" + std::to_string(i) + ".png"));
right_hand[i].setTexture(data::load_texture("img/mania/right" + std::to_string(i) + ".png"));
}

if (is_4K)
{
left[i].setTexture(data::load_texture("img/mania/left" + std::to_string(i) + ".png"));
right[i].setTexture(data::load_texture("img/mania/right" + std::to_string(i) + ".png"));
bg.setTexture(data::load_texture("img/mania/4K/bg.png"));
for (int i = 0; i < 2; i++)
left_4K[i].setTexture(data::load_texture("img/mania/4K/" + std::to_string(i) + ".png"));
for (int i = 0; i < 2; i++)
right_4K[i].setTexture(data::load_texture("img/mania/4K/" + std::to_string(i + 2) + ".png"));
}
else
{
bg.setTexture(data::load_texture("img/mania/7K/bg.png"));
for (int i = 0; i < 4; i++)
left_7K[i].setTexture(data::load_texture("img/mania/7K/" + std::to_string(i) + ".png"));
for (int i = 0; i < 4; i++)
right_7K[i].setTexture(data::load_texture("img/mania/7K/" + std::to_string(i + 3) + ".png"));
}

return true;
}

void draw()
void draw_4K()
{
window.draw(bg);

// 0: not pressed, 1: left, 2: right, 3: both
int left_state = 0;
for (int i = 0; i < 2; i++)
if (GetKeyState(left_key_value[i]) & 0x8000)
left_state |= (1 << i);
window.draw(left[left_state]);
int left_cnt = 0, right_cnt = 0;
int left_sum = 0, right_sum = 0;

int right_state = 0;
for (int i = 0; i < 2; i++)
if (GetKeyState(right_key_value[i]) & 0x8000)
right_state |= (1 << i);
window.draw(right[right_state]);
{
if (GetKeyState(left_key_value_4K[i]) & 0x8000)
{
window.draw(left_4K[i]);
left_cnt++;
left_sum += i;
}
if (GetKeyState(right_key_value_4K[i]) & 0x8000)
{
window.draw(right_4K[i]);
right_cnt++;
right_sum += i;
}
}

// draw left hand
if (left_cnt == 0)
window.draw(left_handup);
else
{
double avg = 1.0 * left_sum / left_cnt;
if (avg == 0)
window.draw(left_hand[0]);
else if (avg == 0.5)
window.draw(left_hand[1]);
else
window.draw(left_hand[2]);
}

// draw right hand
if (right_cnt == 0)
window.draw(right_handup);
else
{
double avg = 1.0 * right_sum / right_cnt;
if (avg == 0)
window.draw(right_hand[0]);
else if (avg == 0.5)
window.draw(right_hand[1]);
else
window.draw(right_hand[2]);
}
}

void draw_7K()
{
window.draw(bg);

int left_cnt = 0, right_cnt = 0;
int left_sum = 0, right_sum = 0;

for (int i = 0; i < 4; i++)
{
if (GetKeyState(left_key_value_7K[i]) & 0x8000)
{
window.draw(left_7K[i]);
left_cnt++;
left_sum += i;
}
if (GetKeyState(right_key_value_7K[i]) & 0x8000)
{
window.draw(right_7K[i]);
right_cnt++;
right_sum += i;
}
}

// draw left hand
if (left_cnt == 0)
window.draw(left_handup);
else
{
double avg = 1.0 * left_sum / left_cnt;
if (avg < 1.0)
window.draw(left_hand[0]);
else if (avg <= 2.0)
window.draw(left_hand[1]);
else
window.draw(left_hand[2]);
}

// draw right hand
if (right_cnt == 0)
window.draw(right_handup);
else
{
double avg = 1.0 * right_sum / right_cnt;
if (avg < 1.0)
window.draw(right_hand[0]);
else if (avg <= 2.0)
window.draw(right_hand[1]);
else
window.draw(right_hand[2]);
}
}

void draw()
{
if (is_4K)
draw_4K();
else
draw_7K();
}
}; // namespace mania

0 comments on commit 5f0a2bf

Please sign in to comment.