Skip to content

Commit 1cfd9d9

Browse files
Save state while halving difficulty
1 parent 8662694 commit 1cfd9d9

File tree

6 files changed

+22
-28
lines changed

6 files changed

+22
-28
lines changed

.github/makecode/blocks.png

11.5 KB
Loading

.github/makecode/blocksdiff.png

192 KB
Loading

images.g.jres

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
"mimeType": "image/x-mkcd-f4",
5050
"displayName": "arrow"
5151
},
52-
"image12": "hwQQABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
5352
"image6": {
5453
"data": "hwQQABAAAAD//////////x8RERERERHxH/////8fEfEfHxERER8R8R8fERERHxHxHx8REREfEfEfHxERER8f8R8fERER/x/xHx8RERH/H/EfHxERER8f8R8fERERHxHxHx8REREfEfEfHxERER8R8R//////HxHxHxEREREREfH//////////w==",
5554
"mimeType": "image/x-mkcd-f4",

images.g.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -147,24 +147,6 @@ f f f f f f f f f f f f f f f f
147147
. . . 6 6 . . .
148148
. . . 6 6 . . .
149149
. . . 6 6 . . .
150-
`;
151-
case "image12":return img`
152-
. . . . . . . . . . . . . . . .
153-
. . . . . . . . . . . . . . . .
154-
. . . . . . . . . . . . . . . .
155-
. . . . . . . . . . . . . . . .
156-
. . . . . . . . . . . . . . . .
157-
. . . . . . . . . . . . . . . .
158-
. . . . . . . . . . . . . . . .
159-
. . . . . . . . . . . . . . . .
160-
. . . . . . . . . . . . . . . .
161-
. . . . . . . . . . . . . . . .
162-
. . . . . . . . . . . . . . . .
163-
. . . . . . . . . . . . . . . .
164-
. . . . . . . . . . . . . . . .
165-
. . . . . . . . . . . . . . . .
166-
. . . . . . . . . . . . . . . .
167-
. . . . . . . . . . . . . . . .
168150
`;
169151
case "image6":
170152
case "buy_computer_button":return img`

main.blocks

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

main.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ function load_progress () {
140140
asic_speed = blockSettings.readNumber("game_asic_speed")
141141
asic_price = blockSettings.readNumber("game_asic_price")
142142
upgrades_obtained = blockSettings.readNumberArray("game_upgrades_obtained")
143+
old_difficulty = blockSettings.readNumber("game_old_difficulty")
143144
difficulty_halve_time_left = blockSettings.readNumber("game_difficulty_halve_time_left")
144145
difficulty_halve_max_time = blockSettings.readNumber("game_difficulty_halve_max_time")
145146
difficulty_halve_chance = blockSettings.readNumber("game_difficulty_halve_chance")
@@ -332,7 +333,11 @@ function buy_autoclicker_menu () {
332333
spriteutils.createRenderable(0, function (screen2) {
333334
screen2.fillRect(0, 0, 160, 20, 15)
334335
images.print(screen2, "MakeCoins: " + score, 2, 2, 1)
335-
images.print(screen2, "Target: " + magic_number, 2, 10, 1)
336+
if (difficulty_halving) {
337+
images.print(screen2, "Target: " + magic_number + "/" + max_height + " (" + difficulty_halve_time_left + ")", 2, 10, 1)
338+
} else {
339+
images.print(screen2, "Target: " + magic_number + "/" + max_height, 2, 10, 1)
340+
}
336341
screen2.drawLine(0, 20, 160, 20, 1)
337342
})
338343
spriteutils.createRenderable(0, function (screen2) {
@@ -416,6 +421,7 @@ function set_default_save () {
416421
asic_speed = 200
417422
asic_price = 100
418423
upgrades_obtained = []
424+
old_difficulty = max_height
419425
difficulty_halve_time_left = 0
420426
difficulty_halve_max_time = 30
421427
difficulty_halve_chance = 1
@@ -474,6 +480,7 @@ function save_progress () {
474480
blockSettings.writeNumber("game_asic_speed", asic_speed)
475481
blockSettings.writeNumber("game_asic_price", asic_price)
476482
blockSettings.writeNumberArray("game_upgrades_obtained", upgrades_obtained)
483+
blockSettings.writeNumber("game_old_difficulty", old_difficulty)
477484
blockSettings.writeNumber("game_difficulty_halve_time_left", difficulty_halve_time_left)
478485
blockSettings.writeNumber("game_difficulty_halve_max_time", difficulty_halve_max_time)
479486
blockSettings.writeNumber("game_difficulty_halve_chance", difficulty_halve_chance)
@@ -490,9 +497,9 @@ function enable_cursor (en: boolean) {
490497
}
491498
function save_bool (name: string, value: boolean) {
492499
if (value) {
493-
blockSettings.writeNumber(name, 0)
494-
} else {
495500
blockSettings.writeNumber(name, 1)
501+
} else {
502+
blockSettings.writeNumber(name, 0)
496503
}
497504
}
498505
function make_menu_button () {
@@ -577,6 +584,7 @@ let difficulty_halving = false
577584
let difficulty_halve_chance = 0
578585
let difficulty_halve_max_time = 0
579586
let difficulty_halve_time_left = 0
587+
let old_difficulty = 0
580588
let upgrades_obtained: number[] = []
581589
let asic_price = 0
582590
let asic_speed = 0
@@ -674,7 +682,7 @@ forever(function () {
674682
})
675683
})
676684
forever(function () {
677-
if (Math.floor(average_hash_per_sec) >= max_height) {
685+
if (Math.floor(average_hash_per_sec) >= max_height && !(difficulty_halving)) {
678686
while (Math.floor(average_hash_per_sec) >= max_height) {
679687
max_height = Math.floor(max_height * 1.5)
680688
score_change = Math.ceil(score_change * 1.5)
@@ -685,7 +693,7 @@ forever(function () {
685693
pause(1000)
686694
})
687695
forever(function () {
688-
if ((Math.percentChance(difficulty_halve_chance) || true) && !(difficulty_halving)) {
696+
if ((Math.percentChance(difficulty_halve_chance) || false) && !(difficulty_halving)) {
689697
sprite_difficulty_halver = sprites.create(assets.image`difficulty_halver`, SpriteKind.Thing)
690698
sprite_difficulty_halver.z = 30
691699
sprite_difficulty_halver.setPosition(randint(0, scene.screenWidth()), randint(0, scene.screenHeight()))
@@ -695,14 +703,19 @@ forever(function () {
695703
pause(10000)
696704
}
697705
if (difficulty_halving && difficulty_halve_time_left == 0) {
698-
max_height = max_height * 0.5
706+
Notification.waitForNotificationFinish()
707+
old_difficulty = max_height
708+
max_height = Math.round(max_height * 0.5)
699709
difficulty_halve_time_left = difficulty_halve_max_time
710+
timer.background(function () {
711+
Notification.notify("Difficulty has been halved for " + difficulty_halve_max_time + " seconds! (" + old_difficulty + " --> " + max_height + ")", assets.image`down_arrow`)
712+
})
700713
}
701714
if (difficulty_halving) {
702715
difficulty_halve_time_left += -1
703716
}
704717
if (difficulty_halving && difficulty_halve_time_left <= 0) {
705-
max_height = max_height * 2
718+
max_height = old_difficulty
706719
difficulty_halving = false
707720
}
708721
pause(1000)

0 commit comments

Comments
 (0)