1
1

AnimationLayer.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /// <reference path="../Elements.ts" />
  2. // parseInt(Elements.getStyle(".anims-orcNotStand").style.width.slice(0, -2))
  3. class AnimationLayer {
  4. private name = "unknown";
  5. private layer = 0;
  6. private cStep = 0;
  7. private totalSteps = 9;
  8. private frameSize = 200;
  9. private heightMult = 1; // used to create shadows
  10. private feetHeight = 0; // used to move shadows up and down
  11. private filters = ["hue-rotate(0deg)", "brightness(1)"];
  12. private el = document.createElement("a");
  13. constructor (filename : string, layer = 1) {
  14. this.name = filename;
  15. this.layer = layer;
  16. this.el.classList.add("sceneAnimation");
  17. this.el.style.zIndex = layer.toString();
  18. let style = Elements.getStyle(".anims-" + filename);
  19. if (style == undefined || style.width == undefined) {
  20. console.error("Animation " + filename + " not found.");
  21. } else {
  22. let height = (parseInt(style.height.slice(0,-2)));
  23. this.frameSize = height;
  24. this.totalSteps = (parseInt(style.width.slice(0,-2)) / height);
  25. }
  26. this.el.classList.add("anims-" + filename);
  27. this.updateSize();
  28. }
  29. public updateSize () {
  30. this.el.style.transform = "scale(" + (Elements.AnimationHandler.spriteSize / this.frameSize) + "," + this.heightMult * (Elements.AnimationHandler.spriteSize / this.frameSize) + ")";
  31. this.el.style.width = this.frameSize + "px";
  32. this.el.style.height = this.frameSize + "px";
  33. this.el.style.marginLeft = "-" + this.frameSize/2 + "px";
  34. this.el.style.marginTop = "-" + ((this.frameSize / 2)) + "px";
  35. if (this.heightMult != 1) {
  36. //let realHeight = this.heightMult * (Elements.AnimationHandler.spriteSize / this.frameSize) * this.frameSize;
  37. this.el.style.top = "100%";
  38. this.el.style.marginTop = (- (this.feetHeight - (this.feetHeight * this.heightMult))) + "px";
  39. //this.el.style.top = "100%";
  40. //this.el.style.marginTop = "-" + (realHeight + this.feetHeight);
  41. //console.log("finalHeight: ", realHeight, "feetHeight:", this.feetHeight, "target:" , 130, this.el.style.marginTop);
  42. // Originally top: 50%;
  43. }
  44. }
  45. public addShadow (feetHeight : number) {
  46. let shadow = Elements.AnimationHandler.addAnimation(this.name, this.layer - 1);
  47. shadow.heightMult = 0.15;
  48. shadow.feetHeight = feetHeight;
  49. shadow.updateSize();
  50. shadow.brightify(0);
  51. }
  52. public updateSprite (percentage : number) {
  53. this.cStep = Math.floor(percentage * this.totalSteps);
  54. this.el.style.backgroundPositionX = "-" + (this.cStep * this.frameSize) + "px";
  55. }
  56. /**
  57. * Turn refers to how much we turn the hue wheel, in degres.
  58. * Anything that's colorizable begins at red, so:
  59. * RED = 0
  60. * YELLOW = 60
  61. * GEREN = 120
  62. * BLUE = 240
  63. * RED = 360
  64. *
  65. * So pink is between RED and BLUE. 300 can be pink.
  66. * @param degrees
  67. */
  68. public colorize (degrees : number) {
  69. this.filters[0] = "hue-rotate(" + degrees + "deg)";
  70. this.updateFilter();
  71. }
  72. public brightify (percent : number) {
  73. this.filters[1] = "brightness(" + percent + ")";
  74. this.updateFilter();
  75. }
  76. public updateFilter () {
  77. this.el.style.filter = this.filters.join(" ");
  78. }
  79. public getElement () {
  80. return this.el;
  81. }
  82. }
  83. /**
  84. Planning...
  85. Precise positioning is all out, so let's forget about all that.
  86. Due to animation limitations, the situations for fucking must be different:
  87. - Speed according to if someone fucking is going to cum or not. Highest speed is used.
  88. - Player has two stances only: Standing and On All Fours. Standing is used for combat grabs, generally, and the player is better able to fight back. On All Fours the player is weaker. Either way, doesn't matter here.
  89. - The complete list of possible fucking positions for enemies:
  90. * Holding Standing From the Front
  91. * Holding Standing from the back
  92. * Fucking Crotch standing from the front
  93. * Fucking Crotch standing from the back
  94. * Fucking Mouth standing
  95. * Fucking Crotch On All Fours
  96. * Fucking Mouth on All Fours
  97. - Obviously, enemies only need to implement the things they do. Cockbats, for instance, will only fuck mouth if standing or Mouth/Crotch if on all fours.
  98. - The player character is moving according to percentages and has a few states.
  99. * At 25%, the character will slightly move forward as if compensating for fucking
  100. * At 75%, the character will slightly move backward as if compensating for fucking
  101. - These should be used as marks for thrusts.
  102. **/