2013/05/16

Sprite function test program #1

This is test program #1 for sprite functions.
// Sprite test1
// for V2.00 later only

// Set graphics mode
width(0)
int wgx,wgy
getWidth(wgx,wgy):// Get screen width by graphics mode
locate(0,2):print "Graphic Width:";wgx;"*";wgy

// sprite pattern (X68 type)
dim char ptnA(255) = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                   ,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0
                   ,0,0,2,0,2,0,2,0,0,2,0,2,0,2,0,0
                   ,0,0,0,3,0,3,0,3,3,0,3,0,3,0,0,0
                   ,0,1,2,0,4,0,0,4,4,0,0,4,0,2,1,0
                   ,0,0,0,3,0,5,0,5,5,0,5,0,3,0,0,0
                   ,0,0,2,0,0,0,6,0,0,6,0,0,0,2,0,0
                   ,0,1,0,3,4,5,0,7,7,0,5,4,3,0,1,0
                   ,0,1,0,3,4,5,0,7,7,0,5,4,3,0,1,0
                   ,0,0,2,0,0,0,6,0,0,6,0,0,0,2,0,0
                   ,0,0,0,3,0,5,0,5,5,0,5,0,3,0,0,0
                   ,0,1,2,0,4,0,0,4,4,0,0,4,0,2,1,0
                   ,0,0,0,3,0,3,0,3,3,0,3,0,3,0,0,0
                   ,0,0,2,0,2,0,2,0,0,2,0,2,0,2,0,0
                   ,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0
                   ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
}
int spA=16:// pattern No.
int pbA=1://3 :// palette block No.
int planeA=0:// plane No.
//
dim char ptnB(255)={ // あ(multi color)
   0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0
  ,0,0,0,0,0,0,1,0 ,0,0,0,0,0,0,0,0
  ,0,0,0,0,0,0,1,0 ,0,0,0,0,0,0,0,0
  ,0,0,0,1,2,3,4,5 ,6,7,8,9,1,0,0,0
  ,0,0,0,0,0,0,1,0 ,0,0,0,0,0,0,0,0
  ,0,0,0,0,0,0,1,0 ,0,0,0,0,0,0,0,0
  ,0,0,0,0,0,0,1,2 ,3,4,5,0,0,0,0,0
  ,0,0,0,0,1,2,3,0 ,0,0,4,5,6,0,0,0
  ,0,0,0,1,0,0,2,0 ,0,3,0,0,0,4,0,0
  ,0,0,1,0,0,0,2,0 ,0,3,0,0,0,4,0,0
  ,0,0,1,0,0,0,2,0 ,3,0,0,0,0,4,0,0
  ,0,0,1,0,0,0,2,1 ,0,0,0,0,0,3,0,0
  ,0,0,0,1,0,0,2,0 ,0,0,0,3,4,0,0,0
  ,0,0,0,0,1,2,0,0 ,0,3,4,0,0,0,0,0
  ,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0
  ,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0
}
int spB=spA+1:// pattern No.
int pbB=pbA+1:// palette block No.
int planeB=planeA+1:// plane No.
//
int i,x,y
sp_init():// Hide sprite screen
sp_clr()
sp_def(spA,ptnA)
sp_def(spB,ptnB)
for i = 0 to 7
    sp_color(i,rgb(0,i*256/8,0),pbA)
next
//
 sp_color(0,0,pbB)
 sp_color(1,&hff00ffff,pbB)
 sp_color(2,&hffff00ff,pbB)
 sp_color(3,&h800000ff,pbB)
 sp_color(4,&h8080ffff,pbB)
 sp_color(5,&hff8080ff,pbB)
 sp_color(6,&hff0000ff,pbB)
 sp_color(7,&h00ff00ff,pbB)
 sp_color(8,&h0080ffff,pbB)
 sp_color(9,&hffffffff,pbB)
//
int pbA2=pbB+1 :// palette block No.
for i = 0 to 7
    sp_color(i,rgb(i*256/8,0,0),pbA2)
next
//
width(32)
vpage(B_SPAGE+B_TPAGE,YES):// display sprite screen
//vpriority(TPAGE,SPAGE,GPAGE0,GPAGE1,GPAGE2,GPAGE3)
vpriority(SPAGE,TPAGE,GPAGE0,GPAGE1,GPAGE2,GPAGE3)
cls()
tborder(1,CTHRED)
//
// Display sprite at touched position
//
str exit$,mes$
if isLocalizeJapan() then {
 exit$="中断"
 mes$="画面にタッチ&ドラッグしてください"
} else {
 exit$="exit"
 mes$="Please touch & drag"
}
setFunctionKey(0,exit$,'!')
setFunctionKeyBackgroundImage("funcBack.png")
displayFunctionKeyAll(YES,YES):// v2.0
//
setTouchArea(0,0,0,0,0,YES):// Need for getting any touch coordinate
//
dim float tpoint(2)
int touchCnt
str cs
int dt=0,t
int ts=time():/* start time
locate(0,1):print mes$
//
sp_disp(YES)
//
if NO then {
 sp_halt(YES):// Halt screen update until finish to change the values.
 sp_setting(planeA+0,0,0,spA,pbA2,SPRITE_FLIP_NONE,SPRITE_PRW_SPBG0BG1)
 sp_setting(planeA+1,16,16,spA,pbA2,SPRITE_FLIP_NONE,SPRITE_PRW_SPBG0BG1)
 sp_setting(planeA+2,32,32,spA,pbA2,SPRITE_FLIP_NONE,SPRITE_PRW_SPBG0BG1)
 sp_halt(NO):// Resume display
 end
}
//
int x0=-1,y0=-1
repeat
 // timer count until key input
 while (not kbhit())
  t=time()
  if t-ts>dt then { :/* change second
   dt=dt+1
  // locate(20,0):print dt;
  // beep2(0)
  // locate(20,1)
  }
  touchCnt=getTouchPoint(tpoint)
  if (touchCnt>0) then {
   x=tpoint(0):// float → int
   y=tpoint(1)
   if x<>x0 or y<>y0 then {
    locate(0,0):print x;",";y
    sp_halt(YES):// Halt screen update until finish to change the values.
    // normal
    if pbA<>1 then {
     sp_setting(planeA  ,    x,    y,spA,pbA ,SPRITE_FLIP_NONE,SPRITE_PRW_SPBG0BG1)
    } else {
     // sp_move() is palette block 1 only
     sp_move(   planeA  ,    x,    y,spA)
    }
    // Flip
    sp_setting(planeB  , x+16, y+16,spB,pbB ,SPRITE_FLIP_NONE  ,SPRITE_PRW_SPBG0BG1)
    sp_setting(planeB+1, x-16, y+16,spB,pbB ,SPRITE_FLIP_HORIZONTAL ,SPRITE_PRW_SPBG0BG1)
    sp_setting(planeB+2, x+16, y-16,spB,pbB ,SPRITE_FLIP_VERTICAL ,SPRITE_PRW_SPBG0BG1)
    sp_setting(planeB+3, x-16, y-16,spB,pbB ,SPRITE_FLIP_HORIZONTAL_VERTICAL,SPRITE_PRW_SPBG0BG1)
    // Same pattern by another palette
    sp_setting(planeB+4,wgx-x,wgy-y,spA,pbA2,SPRITE_FLIP_NONE,SPRITE_PRW_SPBG0BG1)
    sp_halt(NO):// Resume display
    //
    x0=x
    y0=y
   }
   // Do not re-displayed when the coordinate is same. Sprite would flicker Failure to do so. 
  }
 endwhile
 // key operation
 cs=inkey$()
until cs="!"

float ver=osVersion()
print "iOS=";ver
//
end



Zip archive file: XBsprite.zip

No comments:

Post a Comment