Coordinates fixed on hearts.

This commit is contained in:
Brad Nelson
2022-02-26 01:14:46 -08:00
parent f8f0c1a4b7
commit b763005d86
4 changed files with 63 additions and 36 deletions

View File

@ -16,6 +16,9 @@
grf grf
-1 -1 window -1 -1 window
internals
: run : run
begin begin
wait wait
@ -30,8 +33,10 @@ grf
." CHAR: " last-char . cr ." CHAR: " last-char . cr
then then
) )
0 to color 0 0 width height box 0 to color 0 0 width height box
g{ g{
vertical-flip
640 480 viewport 640 480 viewport
$ff0000 to color $ff0000 to color
0 0 640 480 box 0 0 640 480 box

View File

@ -23,6 +23,7 @@
\ translate ( x y -- ) \ translate ( x y -- )
\ scale ( nx dx ny dy -- ) \ scale ( nx dx ny dy -- )
\ viewport ( w h -- ) \ viewport ( w h -- )
\ vertical-flip ( -- ) Use math style viewport.
\ Conversions: \ Conversions:
\ screen>g ( x y -- x' y' ) Transform screen to viewport \ screen>g ( x y -- x' y' ) Transform screen to viewport
@ -49,6 +50,8 @@ gstack value gp
: raw-box { left top w h } : raw-box { left top w h }
left w + top h + { right bottom } 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 left 0 max to left
top 0 max to top top 0 max to top
right width min to right right width min to right
@ -88,4 +91,10 @@ grf definitions also internals
w 2/ negate h 2/ negate translate 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 only forth definitions

View File

@ -61,6 +61,10 @@ heart-end heart-size 0 fill
: raw-heart 0 { x y sx sy r } : raw-heart 0 { x y sx sy r }
heart-start c@ 0= if heart-initialize then heart-start c@ 0= if heart-initialize then
y sy 2/ - to y y sy 2/ - to y
sy 0< if
y sy + to y
sy abs to sy
then
sy 0 do sy 0 do
i heart-size sy */ to r i heart-size sy */ to r
x heart-start r + c@ sx heart-ratio */ + x heart-start r + c@ sx heart-ratio */ +

View File

@ -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,
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, 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 } : draw-one { e } e ->kind @ { kind }
HEART-GOAL kind = if HEART-GOAL kind = if
$ff0000 128 random dup 8 lshift + + to color $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 exit
then then
FIRE kind = if FIRE kind = if
$222222 to color $222222 to color
e ->x @ 100 / 4 - e ->y @ 100 / 4 - 8 8 box e ->x @ 400 - e ->y @ 400 - 800 800 box
exit exit
then then
SPARK kind = if SPARK kind = if
$ff7700 128 random 8 lshift + to color $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 exit
then then
ARROW kind = if ARROW kind = if
$ffff00 256 random + to color $ffff00 256 random + to color
39 for 39 for
e ->x @ 100 / e ->vx @ i 200 */ + i arrow-- 2/ - e ->x @ e ->vx @ i 10 */ + i arrow-- 2/ -
e ->y @ 100 / e ->vy @ i 200 */ + i arrow-- 2/ - e ->y @ e ->vy @ i 10 */ + i arrow-- 2/ -
i arrow-- dup box i arrow-- dup box
next next
exit exit
@ -98,19 +98,25 @@ create arrow-table
; ;
: volcano : volcano
height 2/ for 240 for
$334400 i 100 height */ + to color $334400 i 100 240 */ + to color
width 2/ i 2/ - i height 2/ + i height 8 / + 1 box 32000 i 50 * - 5000 - 24000 i 100 * -
i 100 * 10000 + 100 box
next next
0 to color 0 to color
width 2/ height 2/ 32000 4000 - 24000 3000 - 8000 3000 box
height 8 / 20 box
; ;
: draw : draw
$003300 to color 0 0 width height box 0 to color 0 0 width height box
volcano g{
entity-count 0 ?do i entity draw-one loop 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 flip
; ;
@ -125,10 +131,10 @@ create arrow-table
; ;
: tick-one { e } : tick-one { e }
e ->vy @ 4 + e ->vy ! e ->vy @ 4 - e ->vy !
e ->vx @ e ->x @ + e ->x ! e ->vx @ e ->x @ + e ->x !
e ->vy @ e ->y @ + e ->y ! 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 } e ->kind @ { kind }
FIRE kind = if FIRE kind = if
e random-spark e random-spark
@ -143,39 +149,44 @@ create arrow-table
: random-heart { e } : random-heart { e }
HEART-GOAL e ->kind ! HEART-GOAL e ->kind !
width 100 * random e ->x ! 64000 random e ->x !
height 100 * random e ->y ! 48000 random e ->y !
2000 random 1000 - e ->vx ! 2000 random 1000 - e ->vx !
2000 random 2000 - e ->vy ! 2000 random e ->vy !
20 random 20 + e ->step ! 40 random 40 + 100 * e ->step !
; ;
: random-fire { e } : random-fire { e }
FIRE e ->kind ! FIRE e ->kind !
width 10 * random width 50 * + e ->x ! 32000 8000 random + 4000 - e ->x !
height 1 * random height 50 * + 100 + e ->y ! 24000 1000 random + 2000 - e ->y !
200 random 100 - e ->vx ! 200 random 100 - e ->vx !
200 random 400 - e ->vy ! 200 random 200 + e ->vy !
; ;
: random-arrow { e } : random-arrow { e }
ARROW e ->kind ! ARROW e ->kind !
width 100 * random e ->x ! 64000 random e ->x !
height 100 * random e ->y ! 48000 random e ->y !
200 random 100 - e ->vx ! 200 random 100 - e ->vx !
200 random 200 - e ->vy ! 200 random e ->vy !
; ;
: mouse-direction ( -- x y ) : mouse-direction ( -- x y ) mouse-x mouse-y screen>g ;
mouse-x 3 2 */
height mouse-y - negate 3 2 */ ;
: targeted-arrow : shoot-arrow
new entity { e } new entity { e }
ARROW e ->kind ! ARROW e ->kind !
0 e ->x ! 0 e ->x !
height 100 * e ->y ! 0 e ->y !
mouse-direction e ->vy ! e ->vx ! g{
vertical-flip
64000 48000 viewport
g{
70 1 70 1 scale
mouse-direction e ->vy ! e ->vx !
}g
}g
; ;
: init : init
@ -185,12 +196,10 @@ create arrow-table
; ;
: volcano-spew : volcano-spew
1 for new entity random-fire next 2 for new entity random-fire next
; ;
: fire : fire shoot-arrow ;
targeted-arrow
;
0 value last-tm 0 value last-tm
0 value next-tm 0 value next-tm