home *** CD-ROM | disk | FTP | other *** search
/ ring.yamanashi.ac.jp/pub/pc/freem/action/ / action.zip / baku100.zip / baku100 / Kernel / PlainChar.tonyu < prev    next >
Text File  |  2007-09-23  |  5KB  |  245 lines

  1. extends classes.scr.Sprite;
  2.  
  3. native _changeAttr;
  4. //native _inspect;
  5. //native _dynamicInspect;
  6.  
  7. constructor PlainChar(xx,yy){
  8.  x=xx;
  9.  y=yy;
  10.  zOrder=0; 
  11.  _visible=1;
  12.  died=0;
  13.  _generator=0;
  14.  onCreate();    
  15.  super();
  16. }
  17.  
  18. function onCreate() {
  19.  
  20. }
  21.  
  22. function setDefaultProperties(xx,yy) {
  23.   x=xx;y=yy;
  24.   changeAttr("x",x);
  25.   changeAttr("y",y);
  26. }
  27.  
  28. function getGenerator() {
  29.   return _generator;
  30. }
  31. function setGenerator(g) {
  32.   _generator=g;
  33.   return g;
  34. }
  35.  
  36. function inspect () {
  37.  if ($_design_mode==1 && _generator) {
  38.   //print("!!!"+_generator);
  39.   _inspect(_generator);
  40.   $_inspector_target=this;
  41.  } else _dynamicInspect();
  42. }
  43.  
  44. function changeAttr (an,v) {
  45.  if (_generator!=0) {
  46.   _changeAttr (_generator,an,v);
  47.   onChangeAttr(an,v);
  48.  }
  49. }
  50.  
  51. function onChangeAttr(an,v){
  52. }
  53.  
  54. function onMouseDown (xx,yy,lb,rb) {
  55. }
  56. function onMouseDownForDesign (xx,yy,lb,rb) {
  57. }
  58.  
  59. function mouseDown (xx,yy,lb,rb) {
  60.  if (!designMode()) onMouseDown (xx,yy,lb,rb);
  61.  else onMouseDownForDesign (xx,yy,lb,rb);
  62.  inspect();
  63. }
  64.  
  65. function onMouseDrag (sx,sy,dx,dy,lb,rb) {
  66. }
  67. function onMouseDragDesign (sx,sy,dx,dy,lb,rb) {
  68. }
  69.  
  70. function mouseDrag (sx,sy,dx,dy,lb,rb) {
  71.  if (!designMode()) onMouseDrag (sx,sy,dx,dy,lb,rb);
  72.  else onMouseDragDesign (sx,sy,dx,dy,lb,rb);
  73.  if ($_design_mode==1) {
  74.   if (lb) {
  75.    x=x+(dx-sx);
  76.    y=y+(dy-sy);
  77.    changeAttr("x",x);
  78.    changeAttr("y",y);
  79.   }
  80.  }
  81.  inspect();
  82. }
  83.  
  84. function getWidth() {
  85.   return 16;
  86. }
  87. function getHeight() {
  88.   return 16;
  89. }
  90.  
  91. function crashTo(pp,xx,yy){
  92. // æ╝é╠âIâuâWâFâNâgé╞Å╒ô╦é╡é─éóéΘé⌐é╟éñé⌐é≡ö╗ÆΦé╡é▄é╖üB<HID=23>
  93.   if (!pp)return 0;
  94.   if ( abs(pp.x-(x+xx))*2 < getWidth()+pp.getWidth() ) {
  95.    return  abs(pp.y-(y+yy))*2 < getHeight()+pp.getHeight() ;
  96.   }
  97.   return 0;
  98. }
  99. function crashAt(xx,yy){
  100.   if (abs(xx-x)*2<getWidth()) {
  101.     return (abs(yy-y)*2<getHeight());
  102.   }
  103.   return 0;
  104. }
  105.  
  106. function onDraw() {
  107. // âIâuâWâFâNâgé╔ò`ëµé≡é╖éΘé╞é½é╔üAô┴ò╩é╚Åêù¥é≡é╖éΘÅΩìçé╔âåü[âUé¬ÆΦï`é╖éΘâüâ\âbâhé┼é╖üB<HID=90>
  108. }
  109. function drawFocus() {
  110.       var w,h,xx,yy;
  111.       xx=x;yy=y;
  112.       w=getWidth()*0.5+4;h=getHeight()*0.5+4;
  113.       drawSprite(xx-w,yy-h,0);
  114.       drawSprite(xx+w,yy-h,0);
  115.       drawSprite(xx-w,yy+h,0);
  116.       drawSprite(xx+w,yy+h,0);
  117. }
  118.  
  119. function draw() {
  120. /*    if ($_design_mode==1 && $_inspector_target==this ) {
  121.        drawFocus();
  122.     }*/
  123.     onDraw();
  124. }
  125.  
  126. function onUpdate() {
  127. //updateâüâ\âbâhé¬î─é╤Åoé│éΩé╜é╞é½é╔ô┴ò╩é╚Åêù¥é≡é╡é╜éóé╞é½é╔âåü[âUé¬ÆΦï`é╖éΘâüâ\âbâhé┼é╖üB<HID=28>
  128. }
  129.  
  130. function update() {
  131. //âIâuâWâFâNâgé╠Åæé½è╖éªÅêù¥é≡ìséóé▄é╖üB<HID=24>
  132.    if (!_updating) {
  133.        _updating=1;
  134.        onUpdate();
  135.        _updating=0;
  136.    }   
  137.    suspend();
  138. }
  139.  
  140. function updateEx(time) {
  141.    while (time>0) {update(); time-=1; }
  142. }
  143.  
  144. function onDie() {
  145. //âIâuâWâFâNâgé¬ÄÇé±é╛é╞é½é╔ô┴ò╩é╚Åêù¥é≡é╡é╜éóé╞é½é╔âåü[âUé¬ÆΦï`é╖éΘâüâ\âbâhé┼é╖üB<HID=52>
  146. }
  147. function die() {
  148. //âIâuâWâFâNâgé≡ÄEé╡é▄é╖üB<HID=27>
  149.   if(!died) {
  150.     onDie();
  151.     died=1;
  152.   }
  153. }
  154. function isDied() {
  155. //âIâuâWâFâNâgé¬ÄÇé±é┼éóéΘé⌐é╟éñé⌐é≡ö╗ÆΦé╡é▄é╖üB<HID=97>
  156.   return died;
  157. }
  158. function isDead() {
  159. //âIâuâWâFâNâgé¬ÄÇé±é┼éóéΘé⌐é╟éñé⌐é≡ö╗ÆΦé╡é▄é╖üB<HID=97>
  160.   return died;
  161. }
  162.  
  163.  
  164.  
  165. function wait(w) {
  166. //âIâuâWâFâNâgé╠ô«ì∞é≡êΩÄ₧ôIé╔ÆΓÄ~é╡üAæ╥ï@Å≤æ╘é╔é╡é▄é╖üB<HID=91>
  167.   if (_pProc) _pProc.wait(w);
  168. }
  169.  
  170. function notify() {
  171. //waitâüâ\âbâhé┼æ╥ï@Å≤æ╘é╔éáéΘâIâuâWâFâNâgé╠ô«ì∞é≡ì─èJé╡é▄é╖<HID=92>
  172.   if (_pProc) _pProc.notify();
  173. }
  174.  
  175. function setVisible(v) {
  176. //âIâuâWâFâNâgé╠ò\ĪüEö±ò\Īé≡É▌ÆΦé╡é▄é╖üB<HID=96>
  177.   _visible=v;
  178. }
  179.  
  180. function getVisible(v) {
  181. //setVisibleâüâ\âbâhé┼ÄwÆΦé╡é╜âIâuâWâFâNâgé╠ò\ĪüEö±ò\ĪÅ≤æ╘é≡ĵô╛é╡é▄é╖üB<HID=101>
  182.   return _visible;
  183. }
  184.  
  185. function screenOut(a) {
  186. //âIâuâWâFâNâgé¬ëµû╩èOé╔Åoé╜é⌐é╟éñé⌐é≡ö╗ÆΦé╡é▄é╖üB<HID=116>
  187.    var r; r=0;
  188.    if (x<$viewX+a)               r+=$viewX+a-x;
  189.    if (y<$viewY+a)               r+=$viewY+a-y;
  190.    if (x>$screenWidth +$viewX-a) r+=x-($screenWidth +$viewX-a);
  191.    if (y>$screenHeight+$viewY-a) r+=y-($screenHeight+$viewY-a);
  192.    return r;
  193. }
  194.  
  195. function getScreenX(r) {
  196. //âIâuâWâFâNâgé╠âXâNâèü[âôì└òWé≡ô╛é▄é╖üB<HID=114>
  197.   if (r==null) return x-$viewX;
  198.   return r-$viewX;
  199. }
  200. function getScreenY(r) {
  201. //âIâuâWâFâNâgé╠âXâNâèü[âôì└òWé≡ô╛é▄é╖üB<HID=114>
  202.   if (r==null) return y-$viewY;
  203.   return r-$viewY;
  204. }
  205. function gotoScreen(xx,yy) {
  206. //âIâuâWâFâNâgé╠ê╩Æué≡âXâNâèü[âôì└òWé≡ùpéóé─ÄwÆΦé╡é▄é╖üB<HID=114>
  207.   x=$viewX+xx;
  208.   y=$viewY+yy;
  209. }
  210. function onAppear() {
  211. }
  212.  
  213. function waitSelect(prompt,title) {
  214.    if (!title) $selectBox.open(prompt);
  215.    else $selectBox.open(prompt,title);
  216.    while (!$selectBox.getStatus()) update();
  217.    return $selectBox.getStatus()==1;
  218. }
  219.  
  220. function waitInput(title,prompt,default) {
  221.    $inputBox.open(title,prompt,default);
  222.    while (!$inputBox.getStatus()) update();
  223.    return $inputBox.getText();
  224. }
  225. function crashToLine(sx,sy,dx,dy,width,xx,yy){
  226.   var p,q,cx,cy;
  227.   if (xx==null) {
  228.     cx=x-sx;cy=y-sy;
  229.   } else {
  230.     cx=xx-sx;cy=yy-sy;
  231.   }
  232.   sx=dx-sx;
  233.   sy=dy-sy;
  234.   dx=sx*sx+sy*sy;
  235.   p=(  sx*cx +sy*cy)/dx;
  236.   q=( -sy*cx +sx*cy)/dx*dist(sx,sy);
  237.   return (p>=0 && p<=1 && abs(q)*2<width ); 
  238. }
  239.  
  240. function run() {
  241.   while(1) update();
  242. }
  243.  
  244. wait();
  245.