2024-11-01 01:59:29 +00:00
|
|
|
%import math
|
2023-08-31 14:56:52 +00:00
|
|
|
%import diskio
|
2023-08-31 21:24:46 +00:00
|
|
|
%import textio
|
2023-09-01 14:56:46 +00:00
|
|
|
%import sprites
|
2023-08-31 14:56:52 +00:00
|
|
|
%zeropage basicsafe
|
|
|
|
%option no_sysinit
|
|
|
|
|
2023-09-01 14:56:46 +00:00
|
|
|
; an example that displays and moves a single dragon (actually 2 sprites).
|
|
|
|
|
2023-08-31 14:56:52 +00:00
|
|
|
main {
|
2024-11-15 01:05:12 +00:00
|
|
|
const long SPRITE_DATA = $12000
|
2024-04-07 19:49:03 +00:00
|
|
|
const ubyte SPRITE_PALETTE_OFFSET = 1 ; sprite palette at color index 16
|
2023-09-01 14:56:46 +00:00
|
|
|
|
2023-08-31 21:24:46 +00:00
|
|
|
sub start() {
|
|
|
|
txt.plot(32,30)
|
|
|
|
txt.print("there be dragons!")
|
2023-08-31 14:56:52 +00:00
|
|
|
|
2023-08-31 21:24:46 +00:00
|
|
|
; load the sprite data and color palette directly into Vera ram
|
2024-11-15 01:37:49 +00:00
|
|
|
void diskio.vload_raw("dragonsprite.bin", bnk(SPRITE_DATA), SPRITE_DATA & $ffff)
|
2024-04-07 19:49:03 +00:00
|
|
|
void diskio.vload_raw("dragonsprite.pal", 1, $fa00 + SPRITE_PALETTE_OFFSET*16*2)
|
2023-08-31 14:56:52 +00:00
|
|
|
|
2023-08-31 21:24:46 +00:00
|
|
|
; initialize the dragon sprites
|
2024-11-15 01:37:49 +00:00
|
|
|
sprites.init(1, bnk(SPRITE_DATA), SPRITE_DATA & $ffff, sprites.SIZE_64, sprites.SIZE_64, sprites.COLORS_16, SPRITE_PALETTE_OFFSET)
|
|
|
|
sprites.init(2, bnk(SPRITE_DATA), (SPRITE_DATA & $ffff) + 64*64/2, sprites.SIZE_64, sprites.SIZE_64, sprites.COLORS_16,SPRITE_PALETTE_OFFSET)
|
2023-08-31 14:56:52 +00:00
|
|
|
|
|
|
|
ubyte tt = 0
|
2023-08-31 21:24:46 +00:00
|
|
|
word xpos = -64
|
|
|
|
word ypos
|
|
|
|
bool flippedx = false
|
2023-08-31 14:56:52 +00:00
|
|
|
|
2023-11-30 19:49:47 +00:00
|
|
|
sprites.pos(1, 0, 100)
|
|
|
|
sprites.pos(2, 100, 300)
|
|
|
|
|
2023-08-31 14:56:52 +00:00
|
|
|
repeat {
|
2023-08-31 20:31:04 +00:00
|
|
|
if flippedx
|
2023-08-31 14:56:52 +00:00
|
|
|
xpos -= 2
|
|
|
|
else
|
|
|
|
xpos += 2
|
|
|
|
|
|
|
|
if xpos >= 640 or xpos <= -64
|
2023-08-31 20:31:04 +00:00
|
|
|
flippedx = not flippedx
|
2023-08-31 14:56:52 +00:00
|
|
|
|
|
|
|
ypos = (240-64 as word) + math.sin8(tt)
|
|
|
|
tt++
|
2023-08-31 20:31:04 +00:00
|
|
|
|
2023-08-31 21:24:46 +00:00
|
|
|
txt.plot(32, 32)
|
|
|
|
txt.print("at: ")
|
|
|
|
txt.print_w(sprites.getx(1))
|
|
|
|
txt.chrout(',')
|
|
|
|
txt.print_w(sprites.gety(1))
|
|
|
|
txt.print(" ")
|
|
|
|
|
2023-08-31 14:56:52 +00:00
|
|
|
sys.waitvsync()
|
2023-11-30 19:49:47 +00:00
|
|
|
; we set absolute sprite position, rather than the relative move() routines
|
2023-08-31 14:56:52 +00:00
|
|
|
sprites.pos(1, xpos, ypos)
|
|
|
|
sprites.pos(2, xpos, ypos+64)
|
2023-08-31 20:31:04 +00:00
|
|
|
sprites.flipx(1, flippedx)
|
|
|
|
sprites.flipx(2, flippedx)
|
2023-08-31 14:56:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|