Skip to content

Commit fbb542d

Browse files
Make status bar for difficulty halver
1 parent 1cfd9d9 commit fbb542d

File tree

5 files changed

+32
-15
lines changed

5 files changed

+32
-15
lines changed

.github/makecode/blocks.png

10.3 KB
Loading

.github/makecode/blocksdiff.png

-99.9 KB
Loading

main.blocks

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

main.ts

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ function menu_menu () {
180180
Notification.notify("Saved progress!", assets.image`floppy_disc`)
181181
})
182182
} else if (blockMenu.selectedMenuOption().includes("Wipe")) {
183-
if (game.ask("Are you sure you", "want to wipe save?")) {
183+
if (game.ask("Are you sure you want to", "wipe your save?")) {
184184
wipe_save()
185185
timer.background(function () {
186186
Notification.waitForNotificationFinish()
@@ -334,9 +334,9 @@ spriteutils.createRenderable(0, function (screen2) {
334334
screen2.fillRect(0, 0, 160, 20, 15)
335335
images.print(screen2, "MakeCoins: " + score, 2, 2, 1)
336336
if (difficulty_halving) {
337-
images.print(screen2, "Target: " + magic_number + "/" + max_height + " (" + difficulty_halve_time_left + ")", 2, 10, 1)
337+
images.print(screen2, "Target: " + magic_number + " (" + difficulty_halve_time_left + ")", 2, 10, 1)
338338
} else {
339-
images.print(screen2, "Target: " + magic_number + "/" + max_height, 2, 10, 1)
339+
images.print(screen2, "Target: " + magic_number, 2, 10, 1)
340340
}
341341
screen2.drawLine(0, 20, 160, 20, 1)
342342
})
@@ -424,7 +424,7 @@ function set_default_save () {
424424
old_difficulty = max_height
425425
difficulty_halve_time_left = 0
426426
difficulty_halve_max_time = 30
427-
difficulty_halve_chance = 1
427+
difficulty_halve_chance = 2
428428
difficulty_halving = false
429429
}
430430
function wipe_save () {
@@ -553,6 +553,15 @@ function get_upgrades_menu () {
553553
}
554554
move_till_not_touching(sprite_cursor_pointer, sprite_upgrades_button, 0, -1)
555555
}
556+
function make_difficulty_halving_status () {
557+
sprite_difficulty_halving_status_bar = statusbars.create(52, 2, StatusBarKind.Energy)
558+
sprite_difficulty_halving_status_bar.top = 22
559+
sprite_difficulty_halving_status_bar.left = 2
560+
sprite_difficulty_halving_status_bar.z = 0
561+
sprite_difficulty_halving_status_bar.setColor(7, 2, 5)
562+
sprite_difficulty_halving_status_bar.max = difficulty_halve_max_time
563+
sprite_difficulty_halving_status_bar.value = 0
564+
}
556565
function make_main_computer () {
557566
sprite_computer = sprites.create(assets.image`computer_monitor`, SpriteKind.Thing)
558567
sprite_computer.left = 16
@@ -566,6 +575,7 @@ function pretty_hashes_per_sec (hashes_per_sec: number) {
566575
return "" + number_to_si_prefix(hashes_per_sec) + "H/S: " + spriteutils.roundWithPrecision(hashes_per_sec / number_to_si_divider(hashes_per_sec), 2)
567576
}
568577
let sprite_difficulty_halver: Sprite = null
578+
let sprite_difficulty_halving_status_bar: StatusBarSprite = null
569579
let local_upgrade_got: blockObject.BlockObject = null
570580
let local_upgrades_shown = 0
571581
let local_available_upgrades: blockObject.BlockObject[] = []
@@ -609,7 +619,7 @@ let average_hash_per_sec = 0
609619
let ticks_per_second = 0
610620
let max_ticks_per_second = 0
611621
let debug = false
612-
debug = true
622+
debug = false
613623
max_ticks_per_second = 20
614624
let raw_tick_count = 0
615625
ticks_per_second = 0
@@ -624,6 +634,7 @@ define_upgrades()
624634
scene.setBackgroundColor(11)
625635
blockMenu.setColors(1, 15)
626636
load_progress()
637+
make_difficulty_halving_status()
627638
game.onUpdate(function () {
628639
sprite_cursor.top = sprite_cursor_pointer.top
629640
sprite_cursor.left = sprite_cursor_pointer.left
@@ -694,13 +705,14 @@ forever(function () {
694705
})
695706
forever(function () {
696707
if ((Math.percentChance(difficulty_halve_chance) || false) && !(difficulty_halving)) {
697-
sprite_difficulty_halver = sprites.create(assets.image`difficulty_halver`, SpriteKind.Thing)
698-
sprite_difficulty_halver.z = 30
699-
sprite_difficulty_halver.setPosition(randint(0, scene.screenWidth()), randint(0, scene.screenHeight()))
700-
sprite_difficulty_halver.setStayInScreen(true)
701-
sprite_difficulty_halver.startEffect(effects.halo, 1750)
702-
sprite_difficulty_halver.lifespan = 10000
703-
pause(10000)
708+
timer.throttle("summon_difficulty_halver", 10000, function () {
709+
sprite_difficulty_halver = sprites.create(assets.image`difficulty_halver`, SpriteKind.Thing)
710+
sprite_difficulty_halver.z = 30
711+
sprite_difficulty_halver.setPosition(randint(0, scene.screenWidth()), randint(0, scene.screenHeight()))
712+
sprite_difficulty_halver.setStayInScreen(true)
713+
sprite_difficulty_halver.startEffect(effects.halo, 1750)
714+
sprite_difficulty_halver.lifespan = 10000
715+
})
704716
}
705717
if (difficulty_halving && difficulty_halve_time_left == 0) {
706718
Notification.waitForNotificationFinish()
@@ -720,3 +732,7 @@ forever(function () {
720732
}
721733
pause(1000)
722734
})
735+
forever(function () {
736+
sprite_difficulty_halving_status_bar.setFlag(SpriteFlag.Invisible, !(difficulty_halving))
737+
sprite_difficulty_halving_status_bar.value = difficulty_halve_time_left
738+
})

pxt.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"block-menu": "github:riknoll/arcade-custom-menu#v0.0.1",
1111
"settings-blocks": "github:microsoft/pxt-settings-blocks#v1.0.0",
1212
"Notifications": "github:unsignedarduino/notifications#2a1dfa1a8c4ecf02cfb8b53521f82371a222e3e5",
13-
"arcade-block-objects": "github:microsoft/arcade-block-objects#f486ac1d4dcc096b9297174f97f8cdef1576c7ff"
13+
"arcade-block-objects": "github:microsoft/arcade-block-objects#f486ac1d4dcc096b9297174f97f8cdef1576c7ff",
14+
"pxt-status-bar": "github:jwunderl/pxt-status-bar#v0.4.1"
1415
},
1516
"files": [
1617
"main.blocks",

0 commit comments

Comments
 (0)