classlib.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. function backgroundimage(id,src,w,h,x,y,speed,screens)
  2. {
  3. this.id = id;
  4. this.src = src;
  5. this.w = w;
  6. this.h = h;
  7. this.x = x;
  8. this.screens = screens;
  9. this.y = 0 - (g.canvasheight * (screens - 1));
  10. this.speed = speed;
  11. var i = new Image();
  12. i.src = src;
  13. this.img = i;
  14. };
  15. function spritesheet(s)
  16. {
  17. this.sheet = s;
  18. this.sheetname = s.sheetname;
  19. this.type = s.type;
  20. this.height = s.height;
  21. this.width = s.width;
  22. this.framewidth = s.framewidth;
  23. this.frameheight = s.frameheight;
  24. this.framedelay = s.framedelay;
  25. this.framesperdirection = s.framesperdirection;
  26. this.deathframe = s.deathframe;
  27. this.deathframecount = s.deathframecount;
  28. this.attackframe = s.attackframe;
  29. this.attackframecount = s.attackframecount;
  30. this.painframe = s.painframe;
  31. this.painframecount = s.painframecount;
  32. this.image = new Image();
  33. this.image.setAttribute("id", this.sheetname);
  34. this.image.src = s.src;
  35. this.canvas = document.createElement("canvas");
  36. this.canvas.width = s.width;
  37. this.canvas.height = s.height;
  38. this.canvas.getContext("2d").drawImage(this.image, 0, 0);
  39. };
  40. function laser(id,w,h,col,sp)
  41. {
  42. this.id = id;
  43. this.w = w;
  44. this.h = h;
  45. this.color = col;
  46. this.speed = sp;
  47. };
  48. function textsprite(id, x, y, txt, s)
  49. {
  50. this.id = id;
  51. this.x = x;
  52. this.y = y;
  53. this.text = txt;
  54. this.speed = s;
  55. this.ticks = 10; // ticks before removal
  56. this.visible = false;
  57. };
  58. function sprite(id, nameid, spritesheet, x, y, speed, direction, visible)
  59. {
  60. this.id = id;
  61. this.nid = nameid;
  62. this.spritesheet = spritesheet;
  63. this.frame = 0; this.startframe = 0;
  64. this.framedelay = spritesheet.framedelay;
  65. this.framedelaymax = spritesheet.framedelay;
  66. this.x = x;
  67. this.y = y;
  68. this.oldx = x;
  69. this.oldy = y;
  70. this.basex = x;
  71. this.basey = y;
  72. this.targetx = -1;
  73. this.targety = -1;
  74. this.w = spritesheet.framewidth;
  75. this.h = spritesheet.frameheight;
  76. this.speed = speed;
  77. this.basespeed = speed;
  78. this.direction = direction;
  79. this.lastdirection = direction;
  80. this.offset = 0;
  81. this.frame = 0;
  82. this.row = 0; // row index
  83. this.visible = visible > 0 ? true : false;
  84. this.moveup = false;
  85. this.movedown = false;
  86. this.moveleft = false;
  87. this.moveright = false;
  88. this.angle = 0;
  89. this.opacity = 1;
  90. this.decay = 0;
  91. this.dying = false;
  92. this.spinning = 0;
  93. this.dead = false;
  94. this.inpain = false;
  95. this.boosting = 0;
  96. this.jumping = false;
  97. this.nextthink = 1;
  98. this.basenextthink = this.nextthink;
  99. };