Kirjautuminen

Haku

Tehtävät

Keskustelu: Koodit: 8th: Siniaalto skrolleri

jalski [11.05.2022 23:54:48]

#

Alla yksinkertainen siniaalto skrolleri 8th-ohjelmointikielellä.

needs nk/gui
needs nk/win

with: nk

64 font:system font:new "font1" font:atlas! drop

"8th 22.03" constant MESSAGE

: new-win
  {
    name: "main",
    wide: 800,
    high: 220,
    bg: "black",
    title: "Sinus Scroller"
  }
  win ;

0.1 var, dt
var frame-time
var current-time
var game-time

800 var, x
var theta
30 var, amplitude

: draw
  x @ MESSAGE measure nip n:neg n:< if
    win-wide x !
  then
  x @ >r
  -8 x n:+!
  theta @
  ( MESSAGE swap 1 s:slice dup
    measure swap r> dup 3 pick n:+ >r
    4 pick n:sin amplitude @ n:* win-content-bounds x>rect -1 a:@ nip 2 n:/  amplitude @ n:- n:+ 2swap 4 a:close
    swap "font1" "black" "white" draw-text 0.8 n:+
  ) 0 MESSAGE s:len nip n:1- loop theta ! rdrop ;

: secs
  d:ticks d:ticks/sec n:/ ;

: event-loop
  0 event-msec
  secs game-time !

  repeat
    {
      bg: "black",
      flags: [ @WINDOW_NO_SCROLLBAR ]
    }
    begin
      secs current-time !
      current-time @ game-time @ n:- frame-time !
      current-time @ game-time !
      dt @ frame-time @ n:- game-time n:+!
      repeat
        secs game-time @  n:< not if
          secs game-time !
          break
        then
        0.01 sleep
      again
      event
      draw
    end
    render
  again ;

: app:main
  new-win
  event-loop ;

Vastaus

Aihe on jo aika vanha, joten et voi enää vastata siihen.

Tietoa sivustosta