Implement time-based lerp, footer animation
This commit is contained in:
parent
e9e8fa804a
commit
835a5159cf
3
defs.jor
3
defs.jor
|
@ -8,8 +8,9 @@ s" jorth.log" open const LOGFILE
|
|||
: 2dup over over ;
|
||||
: noop ;
|
||||
|
||||
|
||||
: defer word new-word docolon , ' noop , ' ret , ;
|
||||
: is ( cp -- ) word lookup drop cell + ! ;
|
||||
: redefine ( cp cpdeferred ) cell + ! ;
|
||||
|
||||
: decompile
|
||||
word lookup if 1 begin ( cp i )
|
||||
|
|
57
game.jor
57
game.jor
|
@ -1,6 +1,8 @@
|
|||
: blah
|
||||
' seremit task-emit !
|
||||
' log-emit task-echo ! ;
|
||||
blah
|
||||
' seremit task-emit !
|
||||
|
||||
: start-repl activate blah
|
||||
s" .:: J O R T H ( jean forth) ::." type cr
|
||||
|
@ -51,6 +53,30 @@ defentity player
|
|||
100 player entity.x !
|
||||
100 player entity.y !
|
||||
|
||||
( timer + lerping )
|
||||
: clamp0 ( range val -- i )
|
||||
2dup <= if drop else
|
||||
dup 0 <= if drop drop 0 else
|
||||
swap drop then then ;
|
||||
: >ratio ( range value -- f )
|
||||
over swap clamp0 >fix swap >fix fix/ ;
|
||||
: <ratio ( range ratio -- v )
|
||||
swap >fix fix* <fix ;
|
||||
: >range ( start end -- start range ) over - ;
|
||||
: <range ( start range -- start end ) over + ;
|
||||
: lerpr ( start end ratio ) r> >range r< <ratio + ;
|
||||
: lerpn ( start1 end1 start2 end2 val )
|
||||
r> >range r< rot - >ratio lerpr ;
|
||||
: lerp ( start end duration timer -- i )
|
||||
@ ticks udelta ( start end duration delta )
|
||||
>ratio lerpr ;
|
||||
|
||||
: triggered ( duration timer -- b )
|
||||
dup r> @ ticks udelta ( duration delta )
|
||||
2dup <= if drop r< +! 1 else drop drop 0 then ;
|
||||
|
||||
: now! ( timer -- ) ticks swap ! ;
|
||||
|
||||
: tick-player
|
||||
0 ^LEFT key-down if 3 - W player entity.dir ! then
|
||||
^RIGHT key-down if 3 + E player entity.dir ! then
|
||||
|
@ -59,6 +85,33 @@ defentity player
|
|||
^DOWN key-down if 3 + S player entity.dir ! then
|
||||
player entity.y +! ;
|
||||
|
||||
var MODE-TRAVEL
|
||||
var MODE-TEXT
|
||||
var split-timer
|
||||
|
||||
: enter-mode-text
|
||||
split-timer now!
|
||||
MODE-TEXT @ ' tick redefine ;
|
||||
|
||||
: mode-travel
|
||||
tick-player
|
||||
^SPACE key-pressed if
|
||||
enter-mode-text
|
||||
then ;
|
||||
' mode-travel MODE-TRAVEL !
|
||||
|
||||
: mode-text-hide
|
||||
24 0 10 split-timer lerp dup split-screen
|
||||
0 = if ' mode-travel ' tick redefine then ;
|
||||
|
||||
: mode-text-show
|
||||
0 24 10 split-timer lerp split-screen
|
||||
^SPACE key-pressed if
|
||||
split-timer now!
|
||||
' mode-text-hide ' tick redefine
|
||||
then ;
|
||||
' mode-text-show MODE-TEXT !
|
||||
|
||||
: draw-player
|
||||
player entity.x @
|
||||
player entity.y @
|
||||
|
@ -75,5 +128,5 @@ defentity player
|
|||
600 600 2 draw-sprite
|
||||
draw-screen ;
|
||||
|
||||
' tick-player is tick
|
||||
' full-draw is draw
|
||||
MODE-TRAVEL @ ' tick redefine
|
||||
' full-draw ' draw redefine
|
||||
|
|
27
jorth.c
27
jorth.c
|
@ -93,6 +93,23 @@ BINOP(f_or, u, ||)
|
|||
BINOP(f_bitand, u, &)
|
||||
BINOP(f_bitor, u, |)
|
||||
BINOP(f_bitxor, u, ^)
|
||||
BINOP(f_shr, u, >>)
|
||||
BINOP(f_shl, u, <<)
|
||||
|
||||
void f_itofix() {
|
||||
TOP().i = TOP().i << FIX_FRACTIONAL_BITS;
|
||||
}
|
||||
void f_fixtoi() {
|
||||
TOP().i = TOP().i >> FIX_FRACTIONAL_BITS;
|
||||
}
|
||||
void f_fixmul() {
|
||||
ST1().i = ((long)ST1().i * (long)TOP().i) / (1 << FIX_FRACTIONAL_BITS);
|
||||
DROP(1);
|
||||
}
|
||||
void f_fixdiv() {
|
||||
ST1().i = ((long)ST1().i * (1 << FIX_FRACTIONAL_BITS)) / TOP().i;
|
||||
DROP(1);
|
||||
}
|
||||
|
||||
void f_eq0() {
|
||||
TOP().i = (TOP().i == 0);
|
||||
|
@ -217,13 +234,13 @@ void f_word() {
|
|||
int key = ' ';
|
||||
int ibuf = 0;
|
||||
|
||||
while (key == ' ' || key == '\n' || key == '\r') {
|
||||
while (key == ' ' || key == '\t' || key == '\n' || key == '\r') {
|
||||
f_key();
|
||||
key = TOP().i;
|
||||
DROP(1);
|
||||
}
|
||||
|
||||
while (key != ' ' && key != '\n' && key != '\r' && key != 0) {
|
||||
while (key != ' ' && key != '\t' && key != '\n' && key != '\r' && key != 0) {
|
||||
buf[ibuf++] = key;
|
||||
f_key();
|
||||
key = TOP().i;
|
||||
|
@ -794,6 +811,12 @@ void f_init() {
|
|||
CDEF("&", f_bitand);
|
||||
CDEF("|", f_bitor);
|
||||
CDEF("^", f_bitxor);
|
||||
CDEF("<<", f_shl);
|
||||
CDEF(">>", f_shr);
|
||||
CDEF(">fix", f_itofix);
|
||||
CDEF("<fix", f_fixtoi);
|
||||
CDEF("fix*", f_fixmul);
|
||||
CDEF("fix/", f_fixdiv);
|
||||
CDEF("@", f_get);
|
||||
CDEF("!", f_set);
|
||||
CDEF("+!", f_addset);
|
||||
|
|
1
jorth.h
1
jorth.h
|
@ -3,6 +3,7 @@
|
|||
#define MEM_SIZE 16384
|
||||
#define STACK_SIZE 64
|
||||
#define RSTACK_SIZE 32
|
||||
#define FIX_FRACTIONAL_BITS 5
|
||||
|
||||
void f_init();
|
||||
|
||||
|
|
|
@ -175,7 +175,10 @@ void f_scroll() { // ( x y -- )
|
|||
void f_ticks() {
|
||||
PUSHU(timer_counter);
|
||||
}
|
||||
|
||||
void f_splitscreen() {
|
||||
setSplitScreen(399 - (TOP().i << 1));
|
||||
DROP(1);
|
||||
}
|
||||
void game_f_init() {
|
||||
f_init();
|
||||
CDEF("seremit", f_seremit);
|
||||
|
@ -184,6 +187,7 @@ void game_f_init() {
|
|||
CDEF("draw-sprite", f_drawSprite);
|
||||
CDEF("scroll", f_scroll);
|
||||
CDEF("draw-screen", drawScreen);
|
||||
CDEF("split-screen", f_splitscreen);
|
||||
CDEF("ticks", f_ticks);
|
||||
|
||||
f_loadfile("game.jor");
|
||||
|
|
Loading…
Reference in a new issue