Adding/Removing a difficulty [1.6-1.7] #2113
Replies: 5 comments 14 replies
-
you are le gaming |
Beta Was this translation helpful? Give feedback.
-
all this has done for me was effectively brick my whole kade engine, thanks. Nevermind I accidently deleted the wrong line of code. |
Beta Was this translation helpful? Give feedback.
-
Edit: I tried Searching for the code, but couldn't find it. |
Beta Was this translation helpful? Give feedback.
-
You should pr this into a guide |
Beta Was this translation helpful? Give feedback.
-
Update to 1.8 |
Beta Was this translation helpful? Give feedback.
-
Edit 9/26/21- Hiya! Just polishing up everything here so it's easier to follow. If you have any suggestions on how to make it easier to read, drop em down in the comments. otherwise, happy coding!
ALSO!!! Make sure to back up all the files you edit just in case something goes wrong! This is a tried and true method but in case you miss something, you can go back and proofread!
----KE 1.6 USERS!----
Some lines are different, but luckily everything's simpler!
Here I'll be addressing some of the differences in the code, but still follow the tutorial below nonetheless.
If you can't find the code that I'm talking about in the tutorial below, check back up here and see if it's in a different spot. If I don't mention it, then it's not there at all and you don't have to worry about it.
FreeplayState.hx:
Around line 88 are where the diffs are located.
Around lines 382 and 383 are where the curDifficulty values are located.
ChartingState.hx:
Feel free to skip this section, as there isn't any code we need to change here.
----FreeplayState.hx----
So, lets first start in FreeplayState.hx. here, you wanna seek to--
#if sys if (FileSystem.exists('assets/data/${format}/{format}.json')) diffsThatExist.push("Normal"); (FileSystem.exists('assets/data/${format}/{format}-easy.json')) diffsThatExist.push("Easy"); (FileSystem.exists('assets/data/${format}/{format}-hard.json')) diffsThatExist.push("Hard");
We're going to add what .json file we want to load when we load our custom difficulty. for this example, we're gonna be making an "Erect" difficulty.
after you add in your line for your difficulty, it should look something like this--
#if sys if (FileSystem.exists('assets/data/${format}/{format}.json')) diffsThatExist.push("Normal"); (FileSystem.exists('assets/data/${format}/{format}-easy.json')) diffsThatExist.push("Easy"); (FileSystem.exists('assets/data/${format}/{format}-hard.json')) diffsThatExist.push("Hard"); (FileSystem.exists('assets/data/${format}/{format}-erect.json')) diffsThatExist.push("Erect");
Luckily for us, the next line of code we have to edit is just underneath this. you should find the code that looks like this--
#else diffsThatExist = ["Easy", "Normal", "Hard"]; #end
Here, we can slot in our difficulty. now, depending on where you want your difficulty to be on the list, you wanna put it where you'd scroll to (so say you want your difficulty to be in between easy and normal, you'd put it there).
now, since our difficulty is harder than hard, it should look like this--
#else diffsThatExist = ["Easy", "Normal", "Hard", "Erect"]; #end
just under this should be the list of difficulties yet again, looking like this--
if (diffsThatExist.contains("Easy")) FreeplayState.loadDiff(0,format,meta.songName,diffs); if (diffsThatExist.contains("Normal")) FreeplayState.loadDiff(1,format,meta.songName,diffs); if (diffsThatExist.contains("Hard")) FreeplayState.loadDiff(2,format,meta.songName,diffs);
Now, depending on where you want your difficulty to be on the scale, you might have to change a bit of the other difficulties. if you noticed, on the second line of each part there is a number that represents each difficulty (0-easy, 1-normal, 2-hard) here we want to change them accordingly so that our difficulty fits in (so 3-erect)
if (diffsThatExist.contains("Easy")) FreeplayState.loadDiff(0,format,meta.songName,diffs); if (diffsThatExist.contains("Normal")) FreeplayState.loadDiff(1,format,meta.songName,diffs); if (diffsThatExist.contains("Hard")) FreeplayState.loadDiff(2,format,meta.songName,diffs); if (diffsThatExist.contains("Erect")) FreeplayState.loadDiff(3,format,meta.songName,diffs);
Under this piece of code should be the code that represents the number of difficulties that exist--
if (diffsThatExist.length != 3) trace("I ONLY FOUND " + diffsThatExist);
here, we want to change the 3 to the amount of difficulties we want. in this case, 4 is the number we want.
after this, search a few hundred lines down (around line 475) where we find a curDifficulty function--
if (curDifficulty < 0) curDifficulty = 2; if (curDifficulty > 2) curDifficulty = 0;
here, we want to change the 2s to the number that we want. remember, the difficulties start with 0, so we want a number that is 1 less than the amount of difficulties in total--
if (curDifficulty < 0) curDifficulty = 3; if (curDifficulty > 3) curDifficulty = 0;
go down to around line 515, and its more of the same previous stuff. here's an example of before and after.
if (songs[curSelected].diffs.length != 3) { switch(songs[curSelected].diffs[0]) { case "Easy": curDifficulty = 0; case "Normal": curDifficulty = 1; case "Hard": curDifficulty = 2; } }
if (songs[curSelected].diffs.length != 4) { switch(songs[curSelected].diffs[0]) { case "Easy": curDifficulty = 0; case "Normal": curDifficulty = 1; case "Hard": curDifficulty = 2; case "Erect": curDifficulty = 3; } }
----Other .hx Files----
Now we have done everything we need to do in the FreeplayState.hx file (yall just did the hardest part!).
There are 4 more files we need to edit. open up-
CoolUtil.hx
ChartingState.hx
Highscore.hx
StoryMenuState.hx
----CoolUtil.hx----
At line 9, add in your difficulty. ['Easy', 'Normal', 'Hard', 'Erect']
then you can save and close that file.
----ChartingState.hx----
Search down to line 3312. here, you want to add in the file tag to the list. (you know how the chart files have -hard or -easy after them? that's what we're adding)
["-easy", "", "-hard", "-erect"]
go down to line 3338, here you do the exact same thing.
that's it for that file, go ahead and save and close.
----Highscore.hx----
Starting at line 99, you will find a list that you will add in your difficulty.
so now there is an extra line that looks like this--
if (diff == 0) daSong += '-easy'; else if (diff == 1) daSong += ''; else if (diff == 2) daSong += '-hard'; else if (diff == 3) daSong += '-erect';
if you are wondering, this is the chart file tag from before. save and close this file.
----StoryMenuState.hx----
Now, if you DONT want the story menu to have your extra difficulty, you are able to skip this step and still have everything working.
If you DO want the difficulty to be in the Story Menu, note that you WILL have to make an extra sprite for the designated difficulty beforehand. (if you do not know how to do so, feel free to ask).
Now, go to line 182. here you will find a list of difficulties and their designated animations from the .xml file (yes, you can animate the difficulties!)
Here we want to add in our difficulty. now, the first part should have our difficulty in lowercase, and the second part should be the animation name in the .xml file.
sprDifficulty.animation.addByPrefix('erect', 'ERECT');
next, navigate down to line 383. go ahead and change the 2 to the number of difficulties - 1 (so 3 in our case). right under that at line 390 is the area where our difficulty animations are played. here, add in our difficulty (make sure its in lowercase like last time) and add in the offset. if you dont know what to set it to, set it to 20 or 70.
case 3: sprDifficulty.animation.play('erect'); sprDifficulty.offset.x = 20;
Save that and you're done! go ahead and compile the game and whatnot and check out your new difficulty!
Now, if you wanna REMOVE a difficulty, do everything that was just said but instead of adding one, you're removing one (so in the parts where there's a difficulty count, you would put 1 in place of 2).
That's about it, if ya have any questions, feel free to ask!
Beta Was this translation helpful? Give feedback.
All reactions