From 322546a0b16397a3d00e995396bb8030acd60807 Mon Sep 17 00:00:00 2001 From: David Schmenk Date: Sat, 28 Dec 2019 08:19:31 -0800 Subject: [PATCH] Add sprite center --- src/inc/sprite.plh | 2 +- src/libsrc/apple/sprite.pla | 17 ++++++++++++----- src/samplesrc/hgrtest.pla | 6 +++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/inc/sprite.plh b/src/inc/sprite.plh index 4c26f97..da90150 100644 --- a/src/inc/sprite.plh +++ b/src/inc/sprite.plh @@ -1,5 +1,5 @@ import sprite - predef spriteCompile(w, h, srcptr)#1 + predef spriteCompile(w, h, xcenter, ycenter, srcptr)#1 predef spriteDup(sprtsrc)#1 predef spriteRead(filestr)#1 predef spriteSave(filestr, sprtptr)#1 diff --git a/src/libsrc/apple/sprite.pla b/src/libsrc/apple/sprite.pla index 358a94a..5f60ee1 100644 --- a/src/libsrc/apple/sprite.pla +++ b/src/libsrc/apple/sprite.pla @@ -8,6 +8,8 @@ struc t_sprite var s_undery[2] var s_underofst[2] byte s_undermap[2] + byte s_xcenter + byte s_ycenter byte s_pitch byte s_height var s_size @@ -121,7 +123,7 @@ def spriteBLTMask(x, y, w, h, srcptr)#0 srcptr = srcptr + (w + 1) / 2 next end -export def spriteCompile(w, h, srcptr)#1 +export def spriteCompile(w, h, xcenter, ycenter, srcptr)#1 var sprtptr, bytewidth, spritesize, i sprtptr = heapalloc(t_sprite) @@ -130,6 +132,8 @@ export def spriteCompile(w, h, srcptr)#1 spritesize = bytewidth * h sprtptr=>s_size = spritesize sprtptr->s_height = h + sprtptr->s_xcenter = xcenter + sprtptr->s_ycenter = ycenter sprtptr=>s_under[0] = heapalloc(spritesize) sprtptr=>s_under[1] = heapalloc(spritesize) for i = 0 to 13 @@ -155,6 +159,9 @@ export def spriteDup(sprtsrc)#1 sprtdup=>s_size = spritesize sprtdup->s_pitch = sprtsrc->s_pitch sprtdup->s_height = sprtsrc->s_height + sprtdup->s_height = sprtsrc->s_height + sprtdup->s_xcenter = sprtsrc->s_xcenter + sprtdup->s_ycenter = sprtsrc->s_ycenter sprtdup=>s_under[0] = heapalloc(spritesize) sprtdup=>s_under[1] = heapalloc(spritesize) for i = 0 to 13 @@ -250,14 +257,14 @@ export def spriteUnDrawXor(sprtptr)#0 hgrXorSrc(sprtptr=>s_underofst[drawpage], sprtptr=>s_undery[drawpage], sprtptr->s_pitch, sprtptr->s_height, sprtptr=>s_map[sprtptr->s_undermap[drawpage]]) end export def spritePos(x, y, sprtptr)#0 - sprtptr=>s_ypos = y - sprtptr=>s_xpos = x + sprtptr=>s_ypos = y - sprtptr->s_ycenter + sprtptr=>s_xpos = x - sprtptr->s_xcenter end export def spritePosIndex(x, y, i)#0 i = i & 15 if drawList[i] - drawList[i]=>s_ypos = y - drawList[i]=>s_xpos = x + drawList[i]=>s_ypos = y - drawList[i]->s_ycenter + drawList[i]=>s_xpos = x - drawList[i]->s_xcenter fin end export def spriteDrawList#0 diff --git a/src/samplesrc/hgrtest.pla b/src/samplesrc/hgrtest.pla index 1083c25..9646a73 100644 --- a/src/samplesrc/hgrtest.pla +++ b/src/samplesrc/hgrtest.pla @@ -51,11 +51,11 @@ def testblt(sprtnum)#0 while ^$C000 < 128 for k = 0 to sprtnum i[k] = i[k] + ii[k] - if i[k] < -10 or i[k] > 280 + if i[k] < 0 or i[k] > 279 ii[k] = -ii[k] fin j[k] = j[k] + jj[k] - if j[k] < -10 or j[k] > 192 + if j[k] < 0 or j[k] > 191 jj[k] = -jj[k] fin spritePosIndex(i[k], j[k], k) @@ -67,7 +67,7 @@ end hgrMode spriteDrawBuf(hgrDrawBuf(0)) // So we can see the compile process -sprtBall = spriteCompile(10, 10, @ball) +sprtBall = spriteCompile(10, 10, 5, 5, @ball) hgrColor(0) hgrClear() testline