curve authoring tool and also full fool

This commit is contained in:
Shoofle 2025-03-05 17:19:52 -05:00
parent ddf12e8240
commit a03204688a
8 changed files with 516 additions and 54 deletions

View File

@ -26,26 +26,32 @@ def Card_Offset_functions equ @-TheFool
dw .fUpdate
dw .fDraw
; CARD_VARS_START: timer
; CARD_VARS_START+2: timer 2
; CARD_VARS_START+4: animation frame for dog
; CARD_VARS_START+5:
; CARD_VARS_START+6: frame of zero
; CARD_VARS_START+7:
; CVS: timer for dog
; CVS+2: frame for dog
; CVS+3: timer for zero
; CVS+5: frame for zero
; CVS+6: timer for cloud 1
; CVS+8: frame for cloud 1
; CVS+9: timer for cloud 2
; CVS+11: frame for cloud 2
.fInit:
ld a, [rLCDC]
and a, %1111_1011
ld [rLCDC], a
ld hl, CARD_VARS_START
ld hl, CVS
ld a, 0
ld [hl+], a ; timer for dog @ +0
ld [hl+], a ; CVS: timer for dog
ld [hl+], a
ld [hl+], a ; timer for big zero @ +2
ld [hl+], a
ld [hl+], a ; frame of dog animation
ld [hl+], a
ld [hl+], a ; frame of zero animation
ld [hl+], a ; CVS+2: frame for dog
ld [hl+], a ; CVS+3: timer for zero
ld [hl+], a
ld [hl+], a ; CVS+5: frame for zero
ld [hl+], a ; CVS+6: timer for cloud 1
ld [hl+], a
ld [hl+], a ; CVS+8: frame for cloud 1
ld [hl+], a ; CVS+9: timer for cloud 2
ld [hl+], a
ld [hl+], a ; CVS+11: frame for cloud 2
ld [hl+], a ; CVS+12: timer for cloud 3
ld [hl+], a
ld [hl+], a ; CVS+14: frame for cloud 3
ld hl, .doggie1
ld de, MY_OAM
@ -59,57 +65,137 @@ def Card_Offset_functions equ @-TheFool
; y and x in b and c
; height and width in a & %11110000 and a & %00001111 ??? that's deranged
call BuildMetaSprite
ld hl, .zero
ld de, MY_OAM + 6*4 ; we've already written six sprites for the doggie, 4 bytes each
ld bc, $100*26+41
ld a, $22 ; two by two
call BuildMetaSprite
; set up the palette for the clouds
ld hl, rOBP1
ld [hl], %00_10_01_11
ld hl, .cloud1
; six sprites for the doggie, four for the zero, 4 bytes each
ld de, MY_OAM + 10*4
ld bc, 73*$100 + 15
ld a, $13 ; one by three
call BuildMetaSprite
; set those three sprites to use OBP palette 1
ld hl, MY_OAM + 10*4 + 3
set 4, [hl]
ld hl, MY_OAM + 11*4 + 3
set 4, [hl]
ld hl, MY_OAM + 12*4 + 3
set 4, [hl]
ld hl, .cloud2
; six sprites for the doggie, four for the zero, 4 bytes each
ld de, MY_OAM + 13*4
ld bc, 84*$100 + 58
ld a, $13 ; one by three
call BuildMetaSprite
ld hl, MY_OAM + 13*4 + 3
set 4, [hl]
ld hl, MY_OAM + 14*4 + 3
set 4, [hl]
ld hl, MY_OAM + 15*4 + 3
set 4, [hl]
ld hl, .cloud3
ld de, MY_OAM + 16*4
ld bc, 90*$100 + 67
ld a, $11
call BuildMetaSprite
ld hl, MY_OAM + 16*4+3
set 4, [hl]
ret
.fUpdate:
ld hl, CARD_VARS_START
ld hl, CVS
call IncrementTimer
ld a, [CARD_VARS_START+1]
ld a, [CVS+1] ; checking the high byte of the timer
cp a, 06 ; $10 00 = 1 second
jp c, .doneWithTimer1 ; if the timer is less than $0800, skip to end
jp c, .doneWithTimer1 ; if the timer is less than $0600, skip
;otherwise reset the timer
; if the timer is greater or equal to $0600, reset it
ld a, 0
ld [CARD_VARS_START], a
ld [CARD_VARS_START+1], a
; and make the dog dance
call .dogDance
ld [CVS], a
ld [CVS+1], a
call .dogDance ; and make the dog dance
.doneWithTimer1
ld hl, CARD_VARS_START+2
ld hl, CVS+3
call IncrementTimer
ld a, [CARD_VARS_START+2+1]
cp a, $02 ; $10 00 = 1 second
jp c, .doneWithTimer2 ; if the timer is less than $0800, skip to end
ld a, [CVS+3+1] ; check the high byte of the zero sprite timer
cp a, $30 ; $10 00 = 1 second
jp c, .doneWithTimer2
;otherwise reset the timer
ld a, 0
ld [CARD_VARS_START+2], a
ld [CARD_VARS_START+2+1], a
ld [CVS+3], a
ld [CVS+3+1], a
call .zeroRotate
.doneWithTimer2
ld hl, CVS+6
call IncrementTimer
ld a, [CVS+6+1]
cp a, $20
jp c, .doneWithTimer3
ld a, 0
ld [CVS+6], a
ld [CVS+6+1], a
call .cloud1Move
.doneWithTimer3
ld hl, CVS+9
call IncrementTimer
ld a, [CVS+9+1]
cp a, $20
jp c, .doneWithTimer4
ld a, 0
ld [CVS+9], a
ld [CVS+9+1], a
call .cloud2Move
.doneWithTimer4
ld hl, CVS+12
call IncrementTimer
ld a, [CVS+12+1]
cp a, $60
jp c, .doneWithTimer5
ld a, 0
ld [CVS+12], a
ld [CVS+12+1], a
call .cloud3Move
.doneWithTimer5
ret
.dogDance:
ld a, [CARD_VARS_START+4] ; dog animation frame
ld a, [CVS+2] ; dog animation frame
inc a
cp a, 2
jp nz, :+
ld a, 0 ; zero the frame if it was 2
:
ld [CARD_VARS_START+4], a
ld [CVS+2], a
cp a, 0
jp z, .frame1
cp a, 1
jp z, .frame2
ret ; shouldn't ever hit this
.frame1
ld hl, .doggie1
ld de, MY_OAM
@ -132,13 +218,20 @@ def Card_Offset_functions equ @-TheFool
ld a, $23
call BuildMetaSprite
ret
.doggie1: ; tiles start at 0
db $01, $02, $03
db $04, $08, $06
.doggie2:
db $01, $02, $07
db $04, $05, $09
.zeroRotate:
ld hl, .zeroCoords
ld a, [CARD_VARS_START + 6]
ld a, [CVS+5]
inc a
call ArrayClampLooping
ld [CARD_VARS_START + 6], a
ld [CVS+5], a
ld b, 0
ld c, a
@ -160,10 +253,113 @@ def Card_Offset_functions equ @-TheFool
; height and width in a & %11110000 and a & %00001111 ??? that's deranged
call BuildMetaSprite
ret
.zero:
db $0a, $0b
db $0c, $0d
.zeroCoords: ; length-prefixed list of y, x
db 4, 26, 41, 27, 42, 26, 43, 25, 42
.cloud1Move:
ld hl, .cloud1Anim
ld a, [CVS+8]
inc a
call ArrayClampLooping
ld [CVS+8], a
ld b, 0
ld c, a
ld hl, .cloud1Anim+1
add hl, bc ; add bc twice (it's a list of pairs) to jump to the bc'th element
add hl, bc ; of the list
ld b, [hl] ; load y into b
inc hl
ld c, [hl] ; load x into c
ld hl, .cloud1
; six sprites for the doggie, four for the zero, 4 bytes each
ld de, MY_OAM + 10*4
ld a, $13 ; two by two
; location of source tile map: hl
; location in memory to write to: de
; y and x in b and c (set above)
; height and width in a & %11110000 and a & %00001111 ??? that's deranged
call BuildMetaSprite
ret
.cloud1:
db $0e, $0f, $10
.cloud1Anim:
db 9, 73, 15, 73, 15, 73, 16, 73, 17, 73, 18, 73, 19, 73, 18, 73, 17, 73, 16,
.cloud2Move:
ld hl, .cloud2Anim
ld a, [CVS+11]
inc a
call ArrayClampLooping
ld [CVS+11], a
ld b, 0
ld c, a
ld hl, .cloud2Anim+1
add hl, bc ; add bc twice (it's a list of pairs) to jump to the bc'th element
add hl, bc ; of the list
ld b, [hl] ; load y into b
inc hl
ld c, [hl] ; load x into c
ld hl, .cloud2
; six sprites for the doggie, four for the zero, 4 bytes each
ld de, MY_OAM + 13*4
ld a, $13 ; two by two
; location of source tile map: hl
; location in memory to write to: de
; y and x in b and c (set above)
; height and width in a & %11110000 and a & %00001111 ??? that's deranged
call BuildMetaSprite
ret
.cloud2:
db $11, $12, $13
.cloud2Anim:
db 4, 84, 58, 84, 59, 84, 60, 84, 59,
.cloud3Move:
ld hl, .cloud3Anim
ld a, [CVS+14]
inc a
call ArrayClampLooping
ld [CVS+14], a
ld b, 0
ld c, a
ld hl, .cloud3Anim+1
add hl, bc ; add bc twice (it's a list of pairs) to jump to the bc'th element
add hl, bc ; of the list
ld b, [hl] ; load y into b
inc hl
ld c, [hl] ; load x into c
ld hl, .cloud3
; six sprites for the doggie, four for the zero, 4 bytes each
ld de, MY_OAM + 16*4
ld a, $11
; location of source tile map: hl
; location in memory to write to: de
; y and x in b and c (set above)
; height and width in a & %11110000 and a & %00001111 ??? that's deranged
call BuildMetaSprite
ret
.cloud3:
db $14
.cloud3Anim:
db 2, 90, 66, 90, 67,
.fDraw:
ret
@ -185,18 +381,15 @@ def Card_Offset_functions equ @-TheFool
db $00,$00,$c0,$c0,$e0,$e0,$30,$30,$18,$18,$18,$18,$0c,$0c,$0c,$0c
db $30,$30,$30,$30,$18,$18,$18,$18,$0c,$0c,$07,$07,$03,$03,$00,$00
db $0c,$0c,$0c,$0c,$18,$18,$18,$18,$30,$30,$e0,$e0,$c0,$c0,$00,$00
db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$07,$00,$3f
db $00,$00,$00,$00,$00,$00,$00,$00,$00,$07,$00,$1f,$00,$ff,$00,$ff
db $00,$00,$00,$00,$00,$00,$00,$00,$00,$80,$00,$c0,$00,$f0,$00,$fc
db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$07
db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$78,$00,$ff,$00,$ff
db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$c0,$00,$f0
db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$ff
.SpriteTilesEnd:
.doggie1: ; tiles start at 0
db $01, $02, $03
db $04, $08, $06
.doggie2:
db $01, $02, $07
db $04, $05, $09
.zero:
db $0a, $0b
db $0c, $0d
.KeyArtTiles:
db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00

Binary file not shown.

Binary file not shown.

View File

@ -155,6 +155,9 @@ LoadCardDataAsync:
ret
CardInit:
ld a, [rLCDC]
and a, %1111_1011
ld [rLCDC], a
call CARD_INIT - 1
ret

View File

@ -17,6 +17,13 @@ SpriteTiles:
db $00,$00,$c0,$c0,$e0,$e0,$30,$30,$18,$18,$18,$18,$0c,$0c,$0c,$0c
db $30,$30,$30,$30,$18,$18,$18,$18,$0c,$0c,$07,$07,$03,$03,$00,$00
db $0c,$0c,$0c,$0c,$18,$18,$18,$18,$30,$30,$e0,$e0,$c0,$c0,$00,$00
db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$07,$00,$3f
db $00,$00,$00,$00,$00,$00,$00,$00,$00,$07,$00,$1f,$00,$ff,$00,$ff
db $00,$00,$00,$00,$00,$00,$00,$00,$00,$80,$00,$c0,$00,$f0,$00,$fc
db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$07
db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$78,$00,$ff,$00,$ff
db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$c0,$00,$f0
db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$ff
@ -29,12 +36,12 @@ Sprites:
db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
db $00, $0e, $0f, $10, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
db $00, $00, $00, $00, $00, $00, $11, $12, $13, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
db $00, $00, $00, $00, $00, $00, $00, $14, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
db $00, $00, $00, $01, $02, $03, $01, $02, $07, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
db $00, $00, $00, $04, $08, $06, $04, $05, $09, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00

258
curve_authoring.html Normal file
View File

@ -0,0 +1,258 @@
<!doctype html>
<html>
<head>
<title>curve editor for gameboy animation</title>
<style>
body {
display: flex;
flex-direction: row;
gap: 1em;
}
#controls {
display: flex;
flex-direction: column;
gap: 1em;
}
</style>
</head>
<body>
<svg
viewBox="0 0 176 176"
style="border: 1px solid black; display: block; max-height: 700px">
<defs>
<g id="point">
<circle cx="0.5" cy="0.5" r="0.5" fill="black" fill-opacity="100%"/>
<circle cx="0.5" cy="0.5" r="2" fill="black" fill-opacity="25%"/>
<rect id="sprite" x="-0.5" y="-0.5" width="8" height="8" stroke="none" fill="gray" fill-opacity="50%"/>
</g>
<pattern id="smallGrid" width="1" height="1" patternUnits="userSpaceOnUse">
<path d="M 1 0 L 0 0 0 1" fill="none" stroke="darkseagreen" stroke-width="0.25"/>
</pattern>
<pattern id="grid" width="8" height="8" patternUnits="userSpaceOnUse">
<rect width="8" height="8" fill="url(#smallGrid)"/>
<path d="M 8 0 L 0 0 0 8" fill="none" stroke="darkseagreen" stroke-width="0.5"/>
</pattern>
</defs>
<g id="sequence">
</g>
<g id="lines">
</g>
<rect width="100%" height="100%" fill="url(#grid)" />
<rect x="8" y="16" width="160" height="144" style="fill: none; stroke: darkseagreen; stroke-width: 0.5"/>
</svg>
<div id="controls">
<fieldset>
<legend>control mode</legend>
<div>
<input type="radio" name="mode" id="add" value="add" checked/>
<label for="add">add points</label>
</div>
<div>
<input type="radio" name="mode" id="delete" value="delete"/>
<label for="delete">delete points</label>
</div>
<div>
<input type="radio" name="mode" id="move" value="move"/>
<label for="move">drag points around</label>
</div>
</fieldset>
<div>
<label for="sprite_width">width in 8x8 sprites:</label>
<input type="number"
id="sprite_width"
name="sprite_width"
min="1" max="16" step="1" value="1"
onchange="sprite_dims_change()"/>
</div>
<div>
<label for="sprite_height">height in 8x8 sprites:</label>
<input type="number"
id="sprite_height"
name="sprite_height"
min="1" max="16" step="1" value="1"
onchange="sprite_dims_change()"/>
</div>
<p>output is a length-prefixed list of y,x pairs.</p>
<textarea id="output">db 0,</textarea>
</div>
</body>
<script>
var svg = null;
var svg_group = null;
var text_output = null;
var moving_point_index = -1;
var the_list = [];
function length(dx, dy) {
return Math.sqrt(dx*dx + dy*dy);
}
const clicksvg = (event) => {
const mode = document.querySelector('input[name=mode]:checked').value; // either 'add', 'delete', or 'move'
const {x, y} = dom_to_svg_coords(svg, event.clientX, event.clientY);
if (mode == "add") {
the_list.push({x: Number((x-0.5).toFixed()),y: Number((y-0.5).toFixed())});
console.log(Number(x.toFixed()))
regenerate_svg_list();
regenerate_text_list();
}
if (mode == "delete") {
let closest = -1;
let distance = 3;
the_list.forEach((point, index) => {
let new_distance = length(point.x-x, point.y-y);
if (new_distance < distance) {
distance = new_distance;
closest = index;
}
});
if (closest != -1) {
the_list.splice(closest, 1);
}
regenerate_svg_list();
regenerate_text_list();
}
if (mode == "move" && moving_point_index != -1) {
const elem = document.querySelector(`g#sequence use:nth-child(${moving_point_index+1})`);
let newX = Number(Number(elem.getAttributeNS(null, "x")).toFixed());
let newY = Number(Number(elem.getAttributeNS(null, "y")).toFixed());
the_list[moving_point_index] = {x: newX, y: newY};
moving_point_index = -1;
regenerate_svg_list();
regenerate_text_list();
}
}
const mousemovesvg = (event) => {
const mode = document.querySelector('input[name=mode]:checked').value; // either 'add', 'delete', or 'move'
const {x, y} = dom_to_svg_coords(svg, event.clientX, event.clientY);
if (mode == 'move' && moving_point_index != -1) {
const previous_mouse_location = {x: event.clientX - event.movementX, y: event.clientY - event.movementY};
const prev_location_in_gbspace = dom_to_svg_coords(svg, previous_mouse_location.x, previous_mouse_location.y);
const gb_movement = {x: x - prev_location_in_gbspace.x, y: y - prev_location_in_gbspace.y};
const point = the_list[moving_point_index];
const elem = document.querySelector(`g#sequence use:nth-child(${moving_point_index+1})`);
let newX = Number(elem.getAttributeNS(null, "x")) + gb_movement.x;
let newY = Number(elem.getAttributeNS(null, 'y')) + gb_movement.y;
elem.setAttributeNS(null, "x", newX);
elem.setAttributeNS(null, "y", newY);
const lineTo = document.querySelector(`g#lines line:nth-child(${moving_point_index})`);
if (lineTo) {
lineTo.setAttributeNS(null, "x2", newX+0.5);
lineTo.setAttributeNS(null, "y2", newY+0.5);
}
const lineFrom = document.querySelector(`g#lines line:nth-child(${moving_point_index+1})`);
if (lineFrom) {
lineFrom.setAttributeNS(null, "x1", newX+0.5);
lineFrom.setAttributeNS(null, "y1", newY+0.5);
}
}
}
const mousedownsvg = (event) => {
const mode = document.querySelector('input[name=mode]:checked').value; // either 'add', 'delete', or 'move'
const {x, y} = dom_to_svg_coords(svg, event.clientX, event.clientY);
let closest = -1;
let distance = 3;
the_list.forEach((point, index) => {
let new_distance = length(point.x-x, point.y-y);
if (new_distance < distance) {
distance = new_distance;
closest = index;
}
});
if (mode == 'move') {
moving_point_index = closest;
}
}
const changetextarea = (event) => {
let raw = event.target.value;
let stripped = raw.replace(/db [0-9]+,/, "");
let pairs = stripped.matchAll(/ ?[0-9]+, ?[0-9]+/g);
let splits = pairs.map((x) => x[0].split(/,/));
let numbers = splits.map(([a, b]) => { return {y: Number(a), x: Number(b)}; } );
the_list = [... numbers];
regenerate_svg_list();
regenerate_text_list();
}
const sprite_dims_change = (event) => {
const width = document.querySelector('input#sprite_width').value;
const height = document.querySelector('input#sprite_height').value;
const rect = document.querySelector('g#point rect#sprite')
rect.setAttributeNS(null, "width", width*8);
rect.setAttributeNS(null, "height", height*8);
}
function regenerate_svg_list() {
svg_group.textContent = '';
for (const {x, y} of the_list) {
const newcircle = document.createElementNS("http://www.w3.org/2000/svg", "use");
newcircle.setAttributeNS(null, "href", "#point");
newcircle.setAttributeNS(null, "x", x);
newcircle.setAttributeNS(null, "y", y);
svg_group.appendChild(newcircle);
}
document.querySelector('g#lines').textContent = '';
for (const [second, first] of the_list.slice(1, the_list.length).map((e,i) => [e, the_list[i]])) {
const newline = document.createElementNS("http://www.w3.org/2000/svg", "line");
newline.setAttributeNS(null, "x1", first.x+0.5);
newline.setAttributeNS(null, "y1", first.y+0.5);
newline.setAttributeNS(null, "x2", second.x+0.5);
newline.setAttributeNS(null, "y2", second.y+0.5);
newline.setAttributeNS(null, "stroke", "black");
newline.setAttributeNS(null, "stroke-width", "0.25");
newline.setAttributeNS(null, "stroke-opacity", "50%");
document.querySelector('g#lines').appendChild(newline);
}
}
function regenerate_text_list() {
s = `db ${the_list.length}, `;
for (const {x, y} of the_list) {
s += `${y}, ${x}, `;
}
text_output.value = s;
}
function dom_to_svg_coords(s, clientX, clientY) {
// thanks to https://www.sitepoint.com/how-to-translate-from-dom-to-svg-coordinates-and-back-again/
const pt = s.createSVGPoint();
pt.x = clientX;
pt.y = clientY;
const svgP = pt.matrixTransform( s.getScreenCTM().inverse() );
return svgP;
}
window.onload = () => {
svg = document.querySelector('svg');
svg.onclick = clicksvg;
svg.onmousemove = mousemovesvg;
svg.onmousedown = mousedownsvg;
svg_group = document.querySelector('g#sequence');
text_output = document.querySelector('textarea#output');
text_output.onchange = changetextarea;
sprite_dims_change();
}
</script>
</html>

View File

@ -33,6 +33,7 @@ def GLOBAL_VARS_START equ $c400 ; defined mostly in mainmenu, program-wide state
def SCREEN_VARS_START equ $c500 ; per-screen variables like animation stuff
def CARD_HELPER_VARS_START equ $c600
def CARD_VARS_START equ $c700 ; variables for animation of individual cards
def CVS equ CARD_VARS_START
def SHUFFLED_DECK equ $c800 ; location for the shuffled deck
def ZEROES equ $D000

Binary file not shown.