From b763005d86f49d5186ace40cec97a385dbbea549 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Sat, 26 Feb 2022 01:14:46 -0800 Subject: [PATCH] Coordinates fixed on hearts. --- ueforth/common/grf_test.fs | 5 +++ ueforth/common/grf_utils.fs | 9 ++++ ueforth/common/heart.fs | 4 ++ ueforth/examples/heart_game.fs | 81 +++++++++++++++++++--------------- 4 files changed, 63 insertions(+), 36 deletions(-) diff --git a/ueforth/common/grf_test.fs b/ueforth/common/grf_test.fs index 696ee1f..3c33498 100755 --- a/ueforth/common/grf_test.fs +++ b/ueforth/common/grf_test.fs @@ -16,6 +16,9 @@ grf -1 -1 window + +internals + : run begin wait @@ -30,8 +33,10 @@ grf ." CHAR: " last-char . cr then ) + 0 to color 0 0 width height box g{ + vertical-flip 640 480 viewport $ff0000 to color 0 0 640 480 box diff --git a/ueforth/common/grf_utils.fs b/ueforth/common/grf_utils.fs index a0c7748..c2fb9e8 100644 --- a/ueforth/common/grf_utils.fs +++ b/ueforth/common/grf_utils.fs @@ -23,6 +23,7 @@ \ translate ( x y -- ) \ scale ( nx dx ny dy -- ) \ viewport ( w h -- ) +\ vertical-flip ( -- ) Use math style viewport. \ Conversions: \ screen>g ( x y -- x' y' ) Transform screen to viewport @@ -49,6 +50,8 @@ gstack value gp : raw-box { left top w h } left w + top h + { right bottom } + left right 2dup min to left max to right + top bottom 2dup min to top max to bottom left 0 max to left top 0 max to top right width min to right @@ -88,4 +91,10 @@ grf definitions also internals w 2/ negate h 2/ negate translate ; +: vertical-flip + 0 height 2/ translate + 1 1 -1 1 scale + 0 height 2/ negate translate +; + only forth definitions diff --git a/ueforth/common/heart.fs b/ueforth/common/heart.fs index f82b07a..09fc3c5 100644 --- a/ueforth/common/heart.fs +++ b/ueforth/common/heart.fs @@ -61,6 +61,10 @@ heart-end heart-size 0 fill : raw-heart 0 { x y sx sy r } heart-start c@ 0= if heart-initialize then y sy 2/ - to y + sy 0< if + y sy + to y + sy abs to sy + then sy 0 do i heart-size sy */ to r x heart-start r + c@ sx heart-ratio */ + diff --git a/ueforth/examples/heart_game.fs b/ueforth/examples/heart_game.fs index ff82246..d919ab2 100755 --- a/ueforth/examples/heart_game.fs +++ b/ueforth/examples/heart_game.fs @@ -68,29 +68,29 @@ create arrow-table 1 c, 1 c, 1 c, 1 c, 1 c, 1 c, 1 c, 1 c, 1 c, 1 c, 1 c, 1 c, 1 c, 1 c, 1 c, 1 c, 1 c, 1 c, 1 c, 1 c, 2 c, 3 c, 3 c, 3 c, 4 c, 4 c, 5 c, 5 c, 5 c, 5 c, -: arrow-- ( n -- ) 39 swap - arrow-table + c@ ; +: arrow-- ( n -- ) 39 swap - arrow-table + c@ 100 * ; : draw-one { e } e ->kind @ { kind } HEART-GOAL kind = if $ff0000 128 random dup 8 lshift + + to color - e ->x @ 100 / e ->y @ 100 / e ->step @ heart + e ->x @ e ->y @ e ->step @ heart exit then FIRE kind = if $222222 to color - e ->x @ 100 / 4 - e ->y @ 100 / 4 - 8 8 box + e ->x @ 400 - e ->y @ 400 - 800 800 box exit then SPARK kind = if $ff7700 128 random 8 lshift + to color - e ->x @ 100 / 4 - e ->y @ 100 / 4 - 8 8 box + e ->x @ 400 - e ->y @ 400 - 800 800 box exit then ARROW kind = if $ffff00 256 random + to color 39 for - e ->x @ 100 / e ->vx @ i 200 */ + i arrow-- 2/ - - e ->y @ 100 / e ->vy @ i 200 */ + i arrow-- 2/ - + e ->x @ e ->vx @ i 10 */ + i arrow-- 2/ - + e ->y @ e ->vy @ i 10 */ + i arrow-- 2/ - i arrow-- dup box next exit @@ -98,19 +98,25 @@ create arrow-table ; : volcano - height 2/ for - $334400 i 100 height */ + to color - width 2/ i 2/ - i height 2/ + i height 8 / + 1 box + 240 for + $334400 i 100 240 */ + to color + 32000 i 50 * - 5000 - 24000 i 100 * - + i 100 * 10000 + 100 box next 0 to color - width 2/ height 2/ - height 8 / 20 box + 32000 4000 - 24000 3000 - 8000 3000 box ; : draw - $003300 to color 0 0 width height box - volcano - entity-count 0 ?do i entity draw-one loop + 0 to color 0 0 width height box + g{ + vertical-flip + 100000 48000 viewport + $003300 to color 0 0 100000 48000 box + $0044cc to color 0 30000 100000 48000 box + volcano + entity-count 0 ?do i entity draw-one loop + }g flip ; @@ -125,10 +131,10 @@ create arrow-table ; : tick-one { e } - e ->vy @ 4 + e ->vy ! + e ->vy @ 4 - e ->vy ! e ->vx @ e ->x @ + e ->x ! e ->vy @ e ->y @ + e ->y ! - e ->y @ height 100 * > if DEAD e ->kind ! then + e ->y @ 0< if DEAD e ->kind ! then e ->kind @ { kind } FIRE kind = if e random-spark @@ -143,39 +149,44 @@ create arrow-table : random-heart { e } HEART-GOAL e ->kind ! - width 100 * random e ->x ! - height 100 * random e ->y ! + 64000 random e ->x ! + 48000 random e ->y ! 2000 random 1000 - e ->vx ! - 2000 random 2000 - e ->vy ! - 20 random 20 + e ->step ! + 2000 random e ->vy ! + 40 random 40 + 100 * e ->step ! ; : random-fire { e } FIRE e ->kind ! - width 10 * random width 50 * + e ->x ! - height 1 * random height 50 * + 100 + e ->y ! + 32000 8000 random + 4000 - e ->x ! + 24000 1000 random + 2000 - e ->y ! 200 random 100 - e ->vx ! - 200 random 400 - e ->vy ! + 200 random 200 + e ->vy ! ; : random-arrow { e } ARROW e ->kind ! - width 100 * random e ->x ! - height 100 * random e ->y ! + 64000 random e ->x ! + 48000 random e ->y ! 200 random 100 - e ->vx ! - 200 random 200 - e ->vy ! + 200 random e ->vy ! ; -: mouse-direction ( -- x y ) - mouse-x 3 2 */ - height mouse-y - negate 3 2 */ ; +: mouse-direction ( -- x y ) mouse-x mouse-y screen>g ; -: targeted-arrow +: shoot-arrow new entity { e } ARROW e ->kind ! 0 e ->x ! - height 100 * e ->y ! - mouse-direction e ->vy ! e ->vx ! + 0 e ->y ! + g{ + vertical-flip + 64000 48000 viewport + g{ + 70 1 70 1 scale + mouse-direction e ->vy ! e ->vx ! + }g + }g ; : init @@ -185,12 +196,10 @@ create arrow-table ; : volcano-spew - 1 for new entity random-fire next + 2 for new entity random-fire next ; -: fire - targeted-arrow -; +: fire shoot-arrow ; 0 value last-tm 0 value next-tm