Advertisement
Guest User

Untitled

a guest
Sep 27th, 2011
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. canvasId="gameCanvas";
  2.  
  3. //System Events
  4. function eventStart()
  5. {
  6.     backgroundColor = "black";
  7.     setGameSpeed(30);
  8.     spriteAdd("player", "assets/img/player.png");
  9.     objectAdd("player", "player", 17, 17, 0);
  10.     objectAdd("block1", "none", 0, 0, 0);
  11.     objectAdd("block2", "none", 0, 0, 0);
  12.     keyAdd("up", 38);
  13.     keyAdd("down", 40);
  14.     keyAdd("left", 37);
  15.     keyAdd("right", 39);
  16.    
  17.     instanceAdd(320, 240, "player");
  18.     instanceAdd(96, 96, "block1");
  19.     instanceAdd(128, 96, "block1");
  20.     instanceAdd(96, 128, "block1");
  21.     instanceAdd(512, 96, "block2");
  22.     instanceAdd(480, 96, "block2");
  23.     instanceAdd(512, 128, "block2");
  24. }
  25. function eventStep()
  26. {
  27.  
  28. }
  29. function eventDraw()
  30. {
  31.    
  32. }
  33.  
  34. //Object Events
  35. function objectEventCreate(instance)
  36. {
  37.     var objectType=instances[instance].name;
  38.     var i=instance;
  39.     var inst=instances[i];
  40.    
  41.    
  42.    
  43.     if (objectType == "player")
  44.     {
  45.         hitboxSet(i, 31, 31, 16, 16, "player");
  46.     }
  47.     if (objectType == "block1" || objectType == "block2")
  48.     {
  49.         hitboxSet(i, 32, 32, 16, 16, "block");
  50.     }
  51.  
  52. }
  53. function objectEventStep(instance)
  54. {
  55.     var objectType=instances[instance].name;
  56.     var i=instance;
  57.     var inst=instances[i];
  58.    
  59.     if (objectType == "player")
  60.     {
  61.         var xx = keyCheck("right")-keyCheck("left");
  62.         var yy = keyCheck("down")-keyCheck("up");
  63.         var speed = 12;
  64.         var dir = pointDirection(0, 0, xx, yy, -1);
  65.        
  66.         if (dir != -1)
  67.         {
  68.             xx = lengthDirX(speed, dir);
  69.             yy = lengthDirY(speed, dir);
  70.         }
  71.        
  72.         if (xx != 0)
  73.         {
  74.             inst.xprevious = inst.x;
  75.             inst.x += xx;
  76.             var col = hitboxCollide(i, "block");
  77.             if (col != -1)
  78.             {
  79.                 if (xx < 0)
  80.                 {
  81.                     inst.x = instances[col].x + 49;
  82.                 }
  83.                 else
  84.                 {
  85.                     inst.x = instances[col].x - 16;
  86.                 }
  87.             }
  88.         }
  89.        
  90.         if (yy != 0)
  91.         {
  92.             inst.yprevious = inst.y;
  93.             inst.y += yy;
  94.             var col = hitboxCollide(i, "block");
  95.             if (col != -1)
  96.             {
  97.                 if (yy < 0)
  98.                 {
  99.                     inst.y = instances[col].y + 49;
  100.                 }
  101.                 else
  102.                 {
  103.                     inst.y = instances[col].y - 16;
  104.                 }
  105.             }
  106.         }
  107.        
  108.         if (inst.x < inst.xoffset)
  109.         {
  110.             inst.x = inst.xoffset;
  111.         }
  112.         if (inst.x > c.width - inst.xoffset)
  113.         {
  114.             inst.x = c.width - inst.xoffset;
  115.         }
  116.         if (inst.y < inst.yoffset)
  117.         {
  118.             inst.y = inst.yoffset;
  119.         }
  120.         if (inst.y > c.height - inst.yoffset)
  121.         {
  122.             inst.y = c.height - inst.yoffset;
  123.         }
  124.     }
  125.  
  126. }
  127. function objectEventDraw(instance)
  128. {
  129.     var objectType=instances[instance].name;
  130.     var i=instance;
  131.     var inst=instances[i];
  132.  
  133.     if (objectType == "block1")
  134.     {
  135.         cxt.fillStyle = "white";
  136.         fillRect(inst.x, inst.y, inst.x + 32, inst.y + 32);
  137.     }
  138.    
  139.     if (objectType == "block2")
  140.     {
  141.         cxt.strokeStyle = "white";
  142.         strokeRect(inst.x, inst.y, inst.x + 32, inst.y + 32);
  143.     }
  144. }
  145.  
  146. //Particles Events
  147. function particleEventDraw(particle)
  148. {
  149.     var particleType=particles[particle].type;
  150.     var i=particle;
  151.     var part=particles[i];
  152.  
  153. }
  154.  
  155. //Custom Functions
  156.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement