Shield Clicker Project Part 7

It’s that time again time to add more to our project! One thing before we start however it is currently finals week for me so I might not post as frequently as I’m pretty busy but so far its been okay. Those of you who read my last post got a small sneak peek into what we will be doing next lesson. You are still likely wondering what it is and what it does which we will be finding out today.

This new item in our prestige shop will essentially give us another multiplier which obviously will be quite good as it is a very expensive upgrade but I think its quite worth it.

This code is essential to make our exchange button work and convert our shields to ptokens. It first checks if the user has enough shields of course, next it subtracts them from the total and updates the text. Which is all standard from all of our other purchase options. It then adds to our new variable ptokens and then sets the text for the ptokens text output. Finally it hides the info box from last lesson as it is now irrelevant and takes up a lot of space.

Now we can add the code for buying our rage and then finally using it.

Of course to start as always we have an if statement to ensure no one tries to buy the rage ability without having enough ptokens. It then subtract them from the total and sets the text once again. I did this text differently than the shields text, but I don’t want to redo the shields text as I’ve now coded over 250 lines and don’t think it makes sense to change.
It’s also a good demonstration of how in coding there are a lot of ways to solve the same problem. Continuing on with our code we then delete the rage button and its image. And shows the image and button of our next ability. But that’s the only sneak peek this lesson. Finally it activates our enrage(d) function.

If anyone guesses what the ability does in the comments they get to decide what the next ability is. So make sure to leave a comment if you have any ideas.

Now this code is definitely the most complicated part of this project and took me close to 45 minutes to figure out as I haven’t learned this in AP computer science yet. This code makes it so that the rage can only activate every so often and then the multiplier resets back to 1. This required me to make another variable.

new variable

after the timeout it starts a timed loop that activates roughly every 4-5 seconds which shows the ragemeter text box which has the words “Hephaestus’s RAGE Activated”. After which it sets the new variable ragemultiplier to 10. It then waits and then sets the multiplier back to 1.

Thats going to be it for this post, thank you all for reading. Let me know in the comment your guess to the new ability and any ideas you might have.