Skip to content

Add Game Demo: nu-niversal paperclips #1108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 1, 2025
Merged

Conversation

0x4D5352
Copy link
Contributor

@0x4D5352 0x4D5352 commented May 1, 2025

Inspired by @kiil, this PR adds another game for exploration & inspiration - this time, based on the seminal incremental idle game Universal Paperclips.

This game implements a screen drawing loop with a roughly 60FPS framerate, asynchronous user interaction via the new job send and job recv commands, rudimentary deltatime calculations, and the ability to save and load state memory.

The game does not feature any of the special mechanics that emerge from the original, though a future project may emerge to make a more 1:1 replica of the original.

I have also updated the .gitignore to make sure no one accidentally pushes their game save to the repo after trying it out. 😃

@cablehead
Copy link

cablehead commented May 1, 2025

here's a patch to fix the "Clips per Second" calculation:

diff --git a/game.nu b/game.nu
index f9b58e8..ceab4e4 100644
--- a/game.nu
+++ b/game.nu
@@ -10,6 +10,7 @@ def make-paperclip [state, amount: int] {
   $new_state.paperclips.total += $amount
   $new_state.paperclips.stock += $amount
   $new_state.wire.length -= $amount
+  $new_state.paperclips.current_second_clips += $amount
   $new_state
 }
 
@@ -97,8 +98,10 @@ def main [] {
       total: 0
       stock: 0
       price: 25
-      rate: -1
+      rate: 0  # Changed from -1 to 0: This will show last second's rate
+      current_second_clips: 0  # Accumulator for current second
     }
+    last_second_timestamp: (date now)  # Track when current second started
     market: {
       demand: 0
       level: 1
@@ -157,6 +160,14 @@ def main [] {
     }
     let prev = date now
 
+    # Check if a second has passed and roll over counters
+    let now = date now
+    if ($now - $state.last_second_timestamp) >= 1sec {
+      $state.paperclips.rate = $state.paperclips.current_second_clips
+      $state.paperclips.current_second_clips = 0
+      $state.last_second_timestamp = $now
+    }
+
     if (($state.paperclips.total > 9) and ($state.autoclippers.count < 1)) and not $state.autoclippers.unlocked {
       $state.autoclippers.unlocked = true
       $state.control_line += "; [b]uy autoclipper"

@0x4D5352
Copy link
Contributor Author

0x4D5352 commented May 1, 2025

@cablehead hey!!! thanks so much for the fixes; pulled them in 😄

@fdncred fdncred merged commit 16e22d0 into nushell:main May 1, 2025
1 check passed
@fdncred
Copy link
Contributor

fdncred commented May 1, 2025

Thanks! Looks cool!

@0x4D5352 0x4D5352 deleted the paperclips branch May 1, 2025 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants