life is now better

pull/23/head
Ondřej Hruška 4 years ago
parent 54ff5fbce9
commit 2800b8cab2
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 75
      examples/life.csn

@ -1,14 +1,33 @@
( (
; simple GOL with screen and a buffer ; simple GOL with screen and a buffer + DRAWING!!!
; Middle-click to payse or resume
; (hold the button until paused - there is a sleep between generations and checking buttons)
;
; When paused, draw with left (white) and right (black) mouse buttons
;
; Resume by clicking middle again.
(def GENERATION_MS 200)
; Real pixel size
(sc-init 400 400) (sc-init 400 400)
; Upscaling factor (bug pixels)
(sc-opt SCREEN_UPSCALE 10) (sc-opt SCREEN_UPSCALE 10)
(sc-opt SCREEN_AUTO_BLIT 0)
; Number of big pixels
(def W 40) (def W 40)
(def H 40) (def H 40)
; !!! If you change size, also update the following constants.
; Compile-time math is not implemented yet.
(def XMAX 39) ; W-1 (def XMAX 39) ; W-1
(def YMAX 39) ; H-1 (def YMAX 39) ; H-1
(def NCELLS 1600) ; W*H (def NCELLS 1600) ; W*H
; --- end of config ---
(sc-opt SCREEN_AUTO_BLIT 0)
(sc-erase 0) ; all black (sc-erase 0) ; all black
(sym ng g15) (sym ng g15)
@ -27,13 +46,61 @@
(bfwr @ng 95 1) (bfwr @ng 95 1)
(bfwr @ng 96 1) (bfwr @ng 96 1)
(bfwr @ng 97 1) (bfwr @ng 97 1)
(def LBTN 0)
(def RBTN 1)
(def MBTN 2)
(:loop) (:loop)
(sc-poll) (sc-poll)
; TODO interactivity?
; Drawing
(sc-mbtn _ MBTN
(nz?
(:release)
(sc-poll)
(mslp 10)
(sc-mbtn _ MBTN (nz? (j :release)))
(:mousing)
(sc-poll)
(mslp 10)
(ld r3 -1)
(sc-mbtn _ LBTN)
(ld.nz r3 1)
(sc-mbtn _ RBTN)
(ld.nz r3 0)
(tst r3 (nneg?
(sc-mouse r0 r1)
(tst r3)
(sc-wr.nz r0 r1 #ffffff)
(sc-wr.z r0 r1 #000000)
(sc-blit)
(mul r1 W)
(add r0 r1)
(ld8 r3:8 r3)
(bfwr @ng r0 r3)
))
(sc-mbtn _ MBTN
(z? (j :mousing)))
(:release2)
(sc-poll)
(mslp 10)
(sc-mbtn _ MBTN (nz? (j :release2)))
)
)
(call Display) (call Display)
(sc-blit) (sc-blit)
(mslp 200) (mslp GENERATION_MS)
(j :loop) (j :loop)
(proc CountNeighbors x y (proc CountNeighbors x y

Loading…
Cancel
Save