classlib.js 2.6 KB

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