Skip to content

Commit

Permalink
achievements stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Joalor64GH authored Oct 22, 2024
1 parent 9eb1835 commit 772e1de
Show file tree
Hide file tree
Showing 29 changed files with 225 additions and 22 deletions.
14 changes: 12 additions & 2 deletions assets/achievements/achList.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
example
full_combo
full_combo
single_digit_miss
multi_miss
perfect
super
amazing
be_better
can_improve
dont_give_up
failed
freaky_friday
konami
5 changes: 5 additions & 0 deletions assets/achievements/amazing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Amazing!",
"desc": "Looking good!",
"hint": "Get an A on any song."
}
5 changes: 5 additions & 0 deletions assets/achievements/be_better.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Be better!",
"desc": "Try a little harder!",
"hint": "Get a B on any song."
}
5 changes: 5 additions & 0 deletions assets/achievements/can_improve.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Can Improve",
"desc": "Try more!",
"hint": "Get a C on any song."
}
5 changes: 5 additions & 0 deletions assets/achievements/dont_give_up.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Don't Give Up",
"desc": "Believe in yourself!",
"hint": "Get a D on any song."
}
5 changes: 0 additions & 5 deletions assets/achievements/example.json

This file was deleted.

5 changes: 5 additions & 0 deletions assets/achievements/failed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Failed...",
"desc": "Yeah, maybe try botplay for a bit.",
"hint": "Get an F on any song."
}
5 changes: 5 additions & 0 deletions assets/achievements/freaky_friday.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Freaky Friday",
"desc": "Wait, wrong game.",
"hint": "Play on a Friday Night."
}
2 changes: 1 addition & 1 deletion assets/achievements/full_combo.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "FC",
"name": "Full Combo",
"desc": "Great job!",
"hint": "Complete a song without missing."
}
5 changes: 5 additions & 0 deletions assets/achievements/konami.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Konami",
"desc": "What could this be??",
"hint": "Up, Up, Down, Down, Left, Right, Left, Right"
}
5 changes: 5 additions & 0 deletions assets/achievements/multi_miss.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Multi-Miss",
"desc": "...But maybe more will.",
"hint": "Miss more than 10 times."
}
5 changes: 5 additions & 0 deletions assets/achievements/perfect.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Perfect!",
"desc": "Wow, you did it!",
"hint": "Get a P on any song."
}
5 changes: 5 additions & 0 deletions assets/achievements/single_digit_miss.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Single Digit Miss",
"desc": "A few misses never hurts anyone.",
"hint": "Miss less than 10 times."
}
5 changes: 5 additions & 0 deletions assets/achievements/super.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Super!",
"desc": "Keep going!",
"hint": "Get an S on any song."
}
File renamed without changes
Binary file added assets/images/achievements/be_better.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 assets/images/achievements/can_improve.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 assets/images/achievements/dont_give_up.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 assets/images/achievements/failed.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 assets/images/achievements/freaky_friday.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 assets/images/achievements/konami.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 assets/images/achievements/multi_miss.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 assets/images/achievements/perfect.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 assets/images/achievements/single_digit_miss.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 assets/images/achievements/super.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions docs/01 - scripting.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import('package.Class');

This is a list of the current Libraries/Classes that you can use:

**NOTE: These classes are already imported anyways.**
### Standard Haxe Classes
* Array
* Bool
Expand All @@ -40,8 +41,6 @@ This is a list of the current Libraries/Classes that you can use:
* Xml

### Game-Specific Classes
(Note: Most of these classes are already imported anyways.)

* Achievements
* Application
* Assets
Expand Down Expand Up @@ -151,7 +150,7 @@ import('flixel.FlxG');
var state = FlxG.state;
function update() {
function update(elapsed:Float) {
if (Input.justPressed('accept'))
ExtendableState.switchState(new ScriptedState('name')); // load custom state
Expand Down
18 changes: 16 additions & 2 deletions docs/06 - adding-a-custom-achievement.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,21 @@ Example:
import('states.PlayState');
import('backend.Achievements');
function update() {
// i'll add something here when i change the logic and stuff
var condition:Bool = false;
function update(elapsed:Float) {
if (PlayState.instance.score < 9000)
condition = true;
}
function endSong() {
if (condition) {
Achievements.unlock('over_nine_thousand', {
date: Date.now(),
song: PlayState.song.song
}, {
trace('achievement unlocked successfully!');
});
}
}
```
22 changes: 22 additions & 0 deletions source/states/AchievementsState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,28 @@ class AchievementsState extends ExtendableState {
FlxG.sound.play(Paths.sound('cancel'));
ExtendableState.switchState(new MenuState());
}

if (Input.justPressed('reset')) {
if (Input.pressed('alt')) {
openSubState(new PromptSubState('This action will reset ALL of the achievements.\nProceed anyways?', () -> {
FlxG.sound.play(Paths.sound('select'));
for (i in 0...achievementArray.length) {
achievementArray[i].forget();
achievementGrp.members[i].text = '???';
}
}, function() {
FlxG.sound.play(Paths.sound('cancel'));
}));
} else {
openSubState(new PromptSubState('This action will reset the selected achievement.\nProceed anyways?', () -> {
FlxG.sound.play(Paths.sound('select'));
achievementArray[curSelected].forget();
achievementGrp.members[curSelected].text = '???';
}, function() {
FlxG.sound.play(Paths.sound('cancel'));
}));
}
}
}

function changeSelection(change:Int = 0, ?playSound:Bool = true) {
Expand Down
126 changes: 117 additions & 9 deletions source/states/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class PlayState extends ExtendableState {
public static var chartingMode:Bool = false;
public static var gotAchievement:Bool = false;

public static var konami:Int = 0;
public static var didKonami:Bool = false;

public var speed:Float = 1;

public var ratingDisplay:Rating;
Expand Down Expand Up @@ -43,6 +46,7 @@ class PlayState extends ExtendableState {
public var camZooming:Bool = true;
public var paused:Bool = false;
public var startingSong:Bool = false;
public var endingSong:Bool = false;

public var countdown3:FlxSprite;
public var countdown2:FlxSprite;
Expand Down Expand Up @@ -427,6 +431,46 @@ class PlayState extends ExtendableState {
Input.justReleased('right')
];

if (Input.justPressed('left')) {
if (konami == 4 || konami == 6) {
konami += 1;
} else {
konami = 0;
}
}
if (Input.justPressed('down')) {
if (konami == 2 || konami == 3) {
konami += 1;
} else {
konami = 0;
}
}
if (Input.justPressed('up')) {
if (konami == 0 || konami == 1) {
konami += 1;
} else {
konami = 0;
}
}
if (Input.justPressed('right')) {
if (konami == 5 || konami == 7) {
konami += 1;
} else {
konami = 0;
}
}
if (konami == 8) {
didKonami = true;
FlxG.sound.play(Paths.sound('start'));
}

// prevent player input when botplay is on
if (SaveData.settings.botPlay) {
justPressed = [false, false, false, false];
pressed = [false, false, false, false];
released = [false, false, false, false];
}

for (i in 0...justPressed.length) {
if (justPressed[i]) {
strumline.members[i].press();
Expand Down Expand Up @@ -635,29 +679,93 @@ class PlayState extends ExtendableState {
return rank;
}

function checkForAchievement() {
if (!gotAchievement)
endSong(); // placeholder for now
else {
// nothing yet
}
}

function endSong() {
var ret:Dynamic = callOnScripts('endSong', []);
if (ret != Hscript.Function_Stop) {
timeTxt.visible = timeBar.visible = false;
endingSong = true;
canPause = false;

if (chartingMode) {
openChartEditor();
return;
}

if (!gotAchievement) {
checkForAchievement([
'full_combo', 'single_digit_miss', 'multi_miss', 'perfect', 'super', 'amazing', 'be_better', 'can_improve', 'dont_give_up', 'failed', 'konami'
]);
return;
}

if (!SaveData.settings.botPlay)
HighScore.saveScore(song.song, score);
new FlxTimer().start(0.5, (tmr:FlxTimer) -> {
persistentUpdate = true;
openSubState(new ResultsSubState(rank, score, accuracy));
});
canPause = false;
}
}

function checkForAchievement(ach:Array<String> = null):String {
if (chartingMode || SaveData.settings.botPlay)
return null;

for (i in 0...achs.length) {
var achievementName:String = achs[i];
if (!Achievements.isUnlocked(achievementName) && !SaveData.settings.botPlay) {
var unlock:Bool = false;

switch (achievementName) {
case 'full_combo':
if (misses == 0)
unlock = true;
case 'single_digit_miss':
if (misses > 0 && misses < 10)
unlock = true;
case 'multi_miss':
if (misses > 10)
unlock = true;
case 'perfect':
if (rank == "P")
unlock = true;
case 'super':
if (rank == "S")
unlock = true;
case 'amazing':
if (rank == "A")
unlock = true;
case 'be_better':
if (rank == "B")
unlock = true;
case 'can_improve':
if (rank == "C")
unlock = true;
case 'dont_give_up':
if (rank == "D")
unlock = true;
case 'failed':
if (rank == "F")
unlock = true;
case 'konami':
if (didKonami)
unlock = true;
}

if (unlock) {
gotAchievement = true;
Achievements.unlock(achievementName, {
date: Date.now(),
song: song.song
}, () -> {
trace('finished showing achievement');
gotAchievement = false;
endSong();
});
return achievementName;
}
}
return null;
}
}

Expand Down

0 comments on commit 772e1de

Please sign in to comment.