Advertisement
cr88192

Early BS2 script test.

May 24th, 2016
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --- EntityBase2D.bs ---
  2.  
  3. public class EntityBase2D {
  4.     public vec2f origin;
  5.     public float angle;
  6.     public float radius;
  7.     public string sprite;
  8.     public vec2f sprite_sz;
  9.    
  10.     /** called after entity creation */
  11.     public abstract void spawn();
  12.     public abstract void tick();
  13.     public abstract void touch(EntityBase2D other);
  14.     public abstract void use(EntityBase2D other);
  15. }
  16.  
  17. --- NpcDialogBox.bs ---
  18.  
  19. public native void IsoTest_SetDialog(NpcDialogBox dbox);
  20.  
  21. public class NpcDialogBox {
  22.     /** first frame of face sprite */
  23.     public string face1;
  24.     /** second frame of face sprite */
  25.     public string face2;
  26.  
  27.     /** text for dialog box */
  28.     public string text;
  29.     public string[] options;
  30.     public NpcDialogBox[] optchain;
  31.    
  32.     public void impulse(int imp)
  33.     {
  34.         frgl_printf("Diag Impulse %d\n", imp);
  35.        
  36.         if((imp>0) && optchain)
  37.         {
  38.             IsoTest_SetDialog(optchain[imp-1]);
  39.         }
  40.     }
  41. }
  42.  
  43. --- IsoMain.bs ---
  44.  
  45. native int frgl_printf(cstring str, ...);
  46. native int clock();
  47. native int rand();
  48.  
  49. public EntityBase2D[] world_entity;
  50. public int world_max_entity;
  51.  
  52. public class misc_chest extends EntityBase2D {
  53.     int isOpen;
  54.  
  55.     public void spawn()
  56.     {
  57.         sprite_sz=#[32, 32];
  58.         radius=8;
  59.         if(rand()&1)
  60.         {
  61.             isOpen=0;
  62.             sprite="sprites/isotest/chest_closed";
  63.         }else
  64.         {
  65.             isOpen=1;
  66.             sprite="sprites/isotest/chest_open";
  67.         }
  68.     }
  69.  
  70.     public void tick()
  71.     {
  72.     }
  73.    
  74.     public void touch(EntityBase2D other)
  75.     {
  76.     }
  77.  
  78.     public void use(EntityBase2D other)
  79.     {
  80. //      isOpen=!isOpen;
  81.         if(isOpen)
  82.         {
  83.             sprite="sprites/isotest/chest_closed";
  84.             isOpen=0;
  85.             return;
  86.         }
  87.  
  88.         sprite="sprites/isotest/chest_open";
  89.         isOpen=1;
  90.     }
  91. }
  92.  
  93. public class player extends EntityBase2D {
  94.     public void spawn()
  95.     {
  96.         sprite_sz=#[32, 48];
  97.         radius=8;
  98.     }
  99.  
  100.     public void tick()
  101.     {
  102.     }
  103.    
  104.     public void touch(EntityBase2D other)
  105.     {
  106.     }
  107.  
  108.     public void use(EntityBase2D other)
  109.     {
  110.     }
  111. }
  112.  
  113. public class npc_elf extends EntityBase2D {
  114.     static NpcDialogBox diag0, diag1, diag2;
  115.     static bool isInit=false;
  116.    
  117.     public static void init()
  118.     {
  119.         if(isInit)
  120.             return;
  121.         isInit=true;
  122.        
  123.         frgl_printf("Elf Init\n");
  124.  
  125.         diag0=new NpcDialogBox;
  126.         diag1=new NpcDialogBox;
  127.         diag2=new NpcDialogBox;
  128.  
  129.         diag0.face1="sprites/elf/elfface0_happy0";
  130.         diag0.face2="sprites/elf/elfface0_cheer0";
  131.         diag0.text=
  132. """
  133. Greetings! I am an Elf.
  134. Elves are a common resident here.
  135. """;
  136.         diag0.options=[
  137.             "Ask about elves.",
  138.             "Ask about goats.",
  139.             "Goodbye."];
  140.         diag0.optchain=[null, diag1, diag2, null, null, null];
  141.  
  142.         diag1.face1="sprites/elf/elfface0_happy0";
  143.         diag1.face2="sprites/elf/elfface0_cheer0";
  144.         diag1.text=
  145. """
  146. Elves are a common resident here.
  147. Here, being, of course, the polar region.
  148. The polar region is a space 'inside' of what you think of as
  149. the North and South poles.
  150. In effect, an alternate Earth which occupies the same physical space.
  151. """;
  152.         diag1.options=["Return."];
  153.         diag1.optchain=[diag0, diag0, null, null, null];
  154.  
  155.         diag2.face1="sprites/elf/elfface0_unhappy0";
  156.         diag2.face2="sprites/elf/elfface0_shock0";
  157.         diag2.text=
  158. """
  159. Why do you ask about goats?
  160. We must never speak of goats!
  161. """;
  162.         diag2.options=["Return."];
  163.         diag2.optchain=[diag0, diag0, null, null, null];
  164.     }
  165.  
  166.     public void spawn()
  167.     {
  168.         init();
  169.    
  170.         sprite_sz=#[32, 64];
  171.         radius=8;
  172.         sprite="sprites/elf/elf0_1";
  173.     }
  174.  
  175.     public void tick()
  176.     {
  177.     }
  178.    
  179.     public void touch(EntityBase2D other)
  180.     {
  181.     }
  182.  
  183.     public void use(EntityBase2D other)
  184.     {
  185.         IsoTest_SetDialog(diag0);
  186. //      sprite="sprites/isotest/chest_open";
  187. //      isOpen=1;
  188.     }
  189. }
  190.  
  191. double accDt;
  192.  
  193. public void update(double dt)
  194. {
  195.     int i;
  196.    
  197.     accDt=accDt+dt;
  198.     if(accDt<0.04)
  199.         return;
  200.     accDt-=0.04;
  201.    
  202.     for(i=0; i<world_max_entity; i++)
  203.     {
  204.         world_entity[i].tick();
  205.     }
  206. }
  207.  
  208. public int main(string[] args)
  209. {
  210.     frgl_printf("IsoMain\n");
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement