Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.98 KB | None | 0 0
  1. var selfID = "";
  2.  
  3. class Entity{
  4.  
  5. constructor(id, x, y, action, facingDirection, path){
  6. this.x = x;
  7. this.y = y;
  8. this.remoteX = this.x;
  9. this.remoteY = this.y;
  10. this.id = id;
  11. this.facingDirection = facingDirection;
  12. this.action = action;
  13. this.stabLeftFrames = [];
  14. this.stabRightFrames = [];
  15. this.walkLeftFrames = [];
  16. this.walkRightFrames = [];
  17. this.idleLeftFrames = [];
  18. this.idleRightFrames = [];
  19. this.dieLeftFrames = [];
  20. this.dieRightFrames = [];
  21. this.bloodFrames = [];
  22. this.currentSprite = undefined;
  23. this.corpseTimer = 20000;
  24. this.init(path);
  25. }
  26.  
  27. init(path){
  28.  
  29. var textureID = resources[path].textures;
  30. var bloodID = resources[BLOODPATH].textures;
  31.  
  32. for (let i = 0; i < 5; i++){
  33. this.stabLeftFrames.push(textureID["stab_left_" + i]);
  34. this.stabRightFrames.push(textureID["stab_right_" + i]);
  35. }
  36.  
  37. for (let i = 0; i < 8; i++){
  38. this.walkLeftFrames.push(textureID["walk_left_" + i]);
  39. this.walkRightFrames.push(textureID["walk_right_" + i]);
  40. }
  41.  
  42. for (let i = 0; i < 8; i++){
  43. this.dieLeftFrames.push(textureID["die_left_" + i]);
  44. this.dieRightFrames.push(textureID["die_right_" + i]);
  45. }
  46.  
  47. for (let i = 0; i < 8; i++){
  48. this.bloodFrames.push(bloodID["blood_" + i]);
  49. }
  50.  
  51. this.idleLeftFrames.push(textureID["walk_left_0"]);
  52. this.idleLeftFrames.push(textureID["walk_left_0"]);
  53. this.idleRightFrames.push(textureID["walk_right_0"]);
  54. this.idleRightFrames.push(textureID["walk_right_0"]);
  55.  
  56. this.aliveHitArea = new PIXI.Rectangle(15, 2, 10, 37);
  57. this.deadHitArea = new PIXI.Rectangle(15, 20, 10, 20);
  58. this.currentSprite = new AnimatedSprite(this.idleLeftFrames);
  59. this.currentSprite.zIndex = 2;
  60. this.currentSprite.x = this.x;
  61. this.currentSprite.y = this.y;
  62. this.currentSprite.interactive = true;
  63. this.currentSprite.id = this.id;
  64. this.currentSprite.hitArea = this.aliveHitArea;
  65. this.currentSprite.on("pointerdown", onPointerDownEntity)
  66. .on("pointerover", onPointerOver)
  67. .on("pointerout", onPointerOut);
  68.  
  69. this.bloodSprite = new AnimatedSprite(this.bloodFrames);
  70.  
  71. world.worldContainer.addChild(this.currentSprite);
  72. }
  73.  
  74. getFullBodyBox(){
  75. return{
  76. x:this.x,
  77. y:this.y,
  78. width:40,
  79. height:40
  80. };
  81. }
  82.  
  83. getBodyBox(){
  84. return{
  85. x:this.x + 13,
  86. y:this.y + 2,
  87. width:13,
  88. height:37
  89. };
  90. }
  91.  
  92. update(){
  93. this.handleMovement();
  94. this.handleSprite();
  95. }
  96.  
  97. updateInfo(x, y, action, facingDirection){
  98. this.remoteX = x;
  99. this.remoteY = y;
  100. this.action = action;
  101. this.facingDirection = facingDirection;
  102.  
  103. }
  104.  
  105. handleSprite(){
  106.  
  107. if (this.id == selfID){
  108. if (this.action == "idle"){
  109. world.wayPoint.visible = false;
  110. }
  111. else{
  112. world.wayPoint.visible = true;
  113. }
  114. }
  115.  
  116. if (world.time == "day"){
  117. this.currentSprite.tint = "0xFFFFFF";
  118.  
  119. if (this.id == selfID){
  120. this.currentSprite.tint = "0xAAE1A3";
  121. }
  122. }
  123. if (world.time == "night"){
  124.  
  125. this.currentSprite.tint = "0x222222";
  126.  
  127. if (this.id == selfID){
  128. this.currentSprite.tint = "0x666666";
  129. }
  130. }
  131.  
  132. if (this.currentSprite.hovering && this.id != selfID){
  133. if (world.time == "day"){
  134. this.currentSprite.tint = "0xF00000";
  135. }
  136. if (world.time == "night"){
  137. this.currentSprite.tint = "0xFFFFFF";
  138. }
  139. }
  140.  
  141. if (this.action == "idle"){
  142. if (this.facingDirection == "left"){
  143. if (this.currentSprite.textures != this.idleLeftFrames){
  144. this.currentSprite.textures = this.idleLeftFrames;
  145. this.currentSprite.loop = true;
  146. this.currentSprite.animationSpeed = 0.1;
  147. this.currentSprite.play();
  148. }
  149. }
  150. if (this.facingDirection == "right"){
  151. if (this.currentSprite.textures != this.idleRightFrames){
  152. this.currentSprite.textures = this.idleRightFrames;
  153. this.currentSprite.loop = true;
  154. this.currentSprite.animationSpeed = 0.1;
  155. this.currentSprite.play();
  156. }
  157.  
  158. }
  159. }
  160.  
  161. if (this.action == "walking"){
  162. if (this.facingDirection == "left"){
  163. if (this.currentSprite.textures != this.walkLeftFrames){
  164. this.currentSprite.textures = this.walkLeftFrames;
  165. this.currentSprite.loop = true;
  166. this.currentSprite.animationSpeed = 0.55;
  167. this.currentSprite.play();
  168. }
  169.  
  170. }
  171. if (this.facingDirection == "right"){
  172. if (this.currentSprite.textures != this.walkRightFrames){
  173. this.currentSprite.textures = this.walkRightFrames;
  174. this.currentSprite.loop = true;
  175. this.currentSprite.animationSpeed = 0.15;
  176. this.currentSprite.play();
  177. }
  178. }
  179. }
  180.  
  181. if (this.action == "attacking"){
  182. if (this.facingDirection == "left"){
  183. if (this.currentSprite.textures != this.stabLeftFrames){
  184. this.currentSprite.textures = this.stabLeftFrames;
  185. this.currentSprite.loop = false;
  186. this.currentSprite.animationSpeed = 0.2;
  187. this.currentSprite.gotoAndPlay(0);
  188. }
  189. }
  190. if (this.facingDirection == "right"){
  191. if (this.currentSprite.textures != this.stabRightFrames){
  192. this.currentSprite.textures = this.stabRightFrames;
  193. this.currentSprite.loop = false;
  194. this.currentSprite.animationSpeed = 0.2;
  195. this.currentSprite.gotoAndPlay(0);
  196. }
  197. }
  198. }
  199.  
  200. if (this.action == "dead"){
  201.  
  202. if (this.action == "dead"){
  203. if (isEntityVisible(this)){
  204. this.currentSprite.visible = true;
  205. this.bloodSprite.visible = true;
  206. }
  207. else{
  208. this.currentSprite.visible = false;
  209. this.bloodSprite.visible = false;
  210. }
  211. }
  212.  
  213. this.bloodSprite.x = this.currentSprite.x;
  214. this.bloodSprite.y = this.currentSprite.y;
  215.  
  216. if (this.facingDirection == "left"){
  217. if (this.currentSprite.textures != this.dieLeftFrames){
  218. this.currentSprite.textures = this.dieLeftFrames;
  219. this.currentSprite.loop = false;
  220. this.currentSprite.animationSpeed = 0.1;
  221. this.currentSprite.gotoAndPlay(0);
  222. }
  223. }
  224. if (this.facingDirection == "right"){
  225. if (this.currentSprite.textures != this.dieRightFrames){
  226. this.currentSprite.textures = this.dieRightFrames;
  227. this.currentSprite.loop = false;
  228. this.currentSprite.animationSpeed = 0.1;
  229. this.currentSprite.gotoAndPlay(0);
  230. }
  231. }
  232.  
  233. if (this.corpseTimer > 0){
  234. this.corpseTimer -= DELTA_TIME;
  235. }
  236. if (this.corpseTimer <= 0){
  237. gui.miniMap.removeCorpseFromMiniMap(this);
  238. removeEntity(this.id);
  239. }
  240. }
  241. }
  242.  
  243. handleMovement(){
  244. if (this.action == "dead"){
  245. if (this.x >= world.width-20 || this.y >= world.height-20){
  246. gui.miniMap.removeCorpseFromMiniMap(this);
  247. removeEntity(this.id);
  248. }
  249. return;
  250. }
  251. var threshold = 32;
  252. var interpAmount = 0.10;
  253. var differenceX = this.remoteX - this.x;
  254. var differenceY = this.remoteY - this.y;
  255.  
  256. if (differenceX > threshold || differenceX < -threshold){
  257. this.x = this.remoteX;
  258. }else{
  259. this.x += differenceX * interpAmount;
  260. }
  261.  
  262. if (differenceY > threshold || differenceY < -threshold){
  263. this.y = this.remoteY;
  264. }else{
  265. this.y += differenceY * interpAmount;
  266. }
  267.  
  268. this.currentSprite.x = this.x;
  269. this.currentSprite.y = this.y;
  270. }
  271.  
  272. kill(x, y){
  273. let randomNumber = Math.random() * 1000000;
  274. this.id = randomNumber;
  275. this.currentSprite.id = randomNumber;
  276.  
  277. this.x = x;
  278. this.y = y;
  279. this.currentSprite.x = x;
  280. this.currentSprite.y = y;
  281.  
  282. this.action = "dead";
  283. this.currentSprite.hitArea = this.deadHitArea;
  284. this.bloodSprite.x = this.currentSprite.x;
  285. this.bloodSprite.y = this.currentSprite.y;
  286. this.bloodSprite.zIndex = 1;
  287. this.bloodSprite.loop = false;
  288. this.bloodSprite.animationSpeed = 0.1;
  289. this.bloodSprite.gotoAndPlay(0);
  290. world.worldContainer.addChild(this.bloodSprite);
  291. gui.miniMap.addCorpseToMiniMap(this);
  292.  
  293. }
  294.  
  295. checkStab(){
  296. if (world.time == "day"){
  297. if (this.stamina < 50){
  298. createMessageBox("You need at least 50 stamina to stab during the day.", "0xFFA500", false);
  299. return false;
  300. }
  301. }
  302. if (world.time == "night"){
  303. if (this.stamina < 25){
  304. createMessageBox("You need at least 25 stamina to stab during the night.", "0xFFA500", false);
  305. return false;
  306. }
  307. }
  308. return true;
  309. }
  310.  
  311. attackThis(){
  312. var player = getEntityByID(selfID);
  313. if (player){
  314. if(player.checkStab() && this.action != "dead" && this.id != -1 && this.id != selfID){
  315. wayPointTarget = this;
  316. }
  317. }
  318. ws.send(encode({type: "input", data:{type:"attack", target:this.id}}));
  319. }
  320. }
  321.  
  322. function onPointerDownEntity(event){
  323. var button = event.data.originalEvent.which;
  324.  
  325. if (button === 3 || button === 2){
  326. var e = getEntityByID(this.id);
  327. if (e){
  328. e.attackThis();
  329. }
  330. }
  331. }
  332.  
  333. function onPointerOver(event){
  334. this.hovering = true;
  335. }
  336.  
  337. function onPointerOut(event){
  338. this.hovering = false;
  339. }
  340.  
  341. function killLocalPlayer(useFilters = true, killerName){
  342. if (useFilters){
  343. app.stage.filters = [shockwaveFilter, deathFilter];
  344. shockwaveFilter.time = 0;
  345. }
  346.  
  347. localStorage.setItem("deathcount", "1");
  348. AD_DEATHS++;
  349. startDeathTimer();
  350. document.getElementById("killedby").innerHTML = "<h2>" + "You were killed by: " + killerName + "</h2>";
  351. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement