cheatsheets devlog projects search

uxn-day-3.md

Uxn - Day 3

2023-01-06 2

A much better day!

https://compudanzas.net/uxn_tutorial_day_3.html

I had a much better time with this day as I could actually understand what was happening. I think starting with this day might have been much better and then going to the first 2 days. I think the first 2 days I was lost in the trees and day 3 shows you the forest.

I also have some stuff I want to do to make it easier to grok uxn. The stack machine idea is definitely intuitive and I like it but visually seeing things would be nice.

The final code for day 3:

( day 3 )

( devices )
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ]
|80 @Controller [ &vector $2 &button $1 &key $1 ]

( macros )
%DRAW-SQUARE {
    .Screen/x DEO2
    .Screen/y DEO2

    ;square .Screen/addr DEO2

    #01 .Screen/sprite DEO
}

( main )
|0100
    #2ce9 .System/r DEO2
    #01c0 .System/g DEO2
    #2ce5 .System/b DEO2

    ;on-controller .Controller/vector DEO2

    #0000 #0000
    DRAW-SQUARE
BRK

@on-controller
    .Controller/key DEI

    DUP LIT "w  EQU
    ,&up JCN

    DUP LIT "a EQU
    ,&left JCN

    DUP LIT "s EQU
    ,&down JCN

    DUP LIT "d EQU
    ,&right JCN

    POP
    BRK

    &up
        .Screen/y DEI2
        #0008 SUB2
        .Screen/x DEI2
        ,&draw JMP

    &left
        .Screen/y DEI2
        .Screen/x DEI2
        #0008 SUB2
        ,&draw JMP

    &down
        .Screen/y DEI2
        #0008 ADD2
        .Screen/x DEI2
        ,&draw JMP

    &right
        .Screen/y DEI2
        .Screen/x DEI2
        #0008 ADD2
        ,&draw JMP

    &draw
        DRAW-SQUARE
        POP
BRK

@square ff81 8181 8181 81ff

This program lets you control a square over the screen. Very fun.

8d4dde0f94d396fbd2d6a3221232de8e