Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var selfID = "";
- class Entity{
- constructor(id, x, y, action, facingDirection, path){
- this.x = x;
- this.y = y;
- this.remoteX = this.x;
- this.remoteY = this.y;
- this.id = id;
- this.facingDirection = facingDirection;
- this.action = action;
- this.stabLeftFrames = [];
- this.stabRightFrames = [];
- this.walkLeftFrames = [];
- this.walkRightFrames = [];
- this.idleLeftFrames = [];
- this.idleRightFrames = [];
- this.dieLeftFrames = [];
- this.dieRightFrames = [];
- this.bloodFrames = [];
- this.currentSprite = undefined;
- this.corpseTimer = 20000;
- this.init(path);
- }
- init(path){
- var textureID = resources[path].textures;
- var bloodID = resources[BLOODPATH].textures;
- for (let i = 0; i < 5; i++){
- this.stabLeftFrames.push(textureID["stab_left_" + i]);
- this.stabRightFrames.push(textureID["stab_right_" + i]);
- }
- for (let i = 0; i < 8; i++){
- this.walkLeftFrames.push(textureID["walk_left_" + i]);
- this.walkRightFrames.push(textureID["walk_right_" + i]);
- }
- for (let i = 0; i < 8; i++){
- this.dieLeftFrames.push(textureID["die_left_" + i]);
- this.dieRightFrames.push(textureID["die_right_" + i]);
- }
- for (let i = 0; i < 8; i++){
- this.bloodFrames.push(bloodID["blood_" + i]);
- }
- this.idleLeftFrames.push(textureID["walk_left_0"]);
- this.idleLeftFrames.push(textureID["walk_left_0"]);
- this.idleRightFrames.push(textureID["walk_right_0"]);
- this.idleRightFrames.push(textureID["walk_right_0"]);
- this.aliveHitArea = new PIXI.Rectangle(15, 2, 10, 37);
- this.deadHitArea = new PIXI.Rectangle(15, 20, 10, 20);
- this.currentSprite = new AnimatedSprite(this.idleLeftFrames);
- this.currentSprite.zIndex = 2;
- this.currentSprite.x = this.x;
- this.currentSprite.y = this.y;
- this.currentSprite.interactive = true;
- this.currentSprite.id = this.id;
- this.currentSprite.hitArea = this.aliveHitArea;
- this.currentSprite.on("pointerdown", onPointerDownEntity)
- .on("pointerover", onPointerOver)
- .on("pointerout", onPointerOut);
- this.bloodSprite = new AnimatedSprite(this.bloodFrames);
- world.worldContainer.addChild(this.currentSprite);
- }
- getFullBodyBox(){
- return{
- x:this.x,
- y:this.y,
- width:40,
- height:40
- };
- }
- getBodyBox(){
- return{
- x:this.x + 13,
- y:this.y + 2,
- width:13,
- height:37
- };
- }
- update(){
- this.handleMovement();
- this.handleSprite();
- }
- updateInfo(x, y, action, facingDirection){
- this.remoteX = x;
- this.remoteY = y;
- this.action = action;
- this.facingDirection = facingDirection;
- }
- handleSprite(){
- if (this.id == selfID){
- if (this.action == "idle"){
- world.wayPoint.visible = false;
- }
- else{
- world.wayPoint.visible = true;
- }
- }
- if (world.time == "day"){
- this.currentSprite.tint = "0xFFFFFF";
- if (this.id == selfID){
- this.currentSprite.tint = "0xAAE1A3";
- }
- }
- if (world.time == "night"){
- this.currentSprite.tint = "0x222222";
- if (this.id == selfID){
- this.currentSprite.tint = "0x666666";
- }
- }
- if (this.currentSprite.hovering && this.id != selfID){
- if (world.time == "day"){
- this.currentSprite.tint = "0xF00000";
- }
- if (world.time == "night"){
- this.currentSprite.tint = "0xFFFFFF";
- }
- }
- if (this.action == "idle"){
- if (this.facingDirection == "left"){
- if (this.currentSprite.textures != this.idleLeftFrames){
- this.currentSprite.textures = this.idleLeftFrames;
- this.currentSprite.loop = true;
- this.currentSprite.animationSpeed = 0.1;
- this.currentSprite.play();
- }
- }
- if (this.facingDirection == "right"){
- if (this.currentSprite.textures != this.idleRightFrames){
- this.currentSprite.textures = this.idleRightFrames;
- this.currentSprite.loop = true;
- this.currentSprite.animationSpeed = 0.1;
- this.currentSprite.play();
- }
- }
- }
- if (this.action == "walking"){
- if (this.facingDirection == "left"){
- if (this.currentSprite.textures != this.walkLeftFrames){
- this.currentSprite.textures = this.walkLeftFrames;
- this.currentSprite.loop = true;
- this.currentSprite.animationSpeed = 0.55;
- this.currentSprite.play();
- }
- }
- if (this.facingDirection == "right"){
- if (this.currentSprite.textures != this.walkRightFrames){
- this.currentSprite.textures = this.walkRightFrames;
- this.currentSprite.loop = true;
- this.currentSprite.animationSpeed = 0.15;
- this.currentSprite.play();
- }
- }
- }
- if (this.action == "attacking"){
- if (this.facingDirection == "left"){
- if (this.currentSprite.textures != this.stabLeftFrames){
- this.currentSprite.textures = this.stabLeftFrames;
- this.currentSprite.loop = false;
- this.currentSprite.animationSpeed = 0.2;
- this.currentSprite.gotoAndPlay(0);
- }
- }
- if (this.facingDirection == "right"){
- if (this.currentSprite.textures != this.stabRightFrames){
- this.currentSprite.textures = this.stabRightFrames;
- this.currentSprite.loop = false;
- this.currentSprite.animationSpeed = 0.2;
- this.currentSprite.gotoAndPlay(0);
- }
- }
- }
- if (this.action == "dead"){
- if (this.action == "dead"){
- if (isEntityVisible(this)){
- this.currentSprite.visible = true;
- this.bloodSprite.visible = true;
- }
- else{
- this.currentSprite.visible = false;
- this.bloodSprite.visible = false;
- }
- }
- this.bloodSprite.x = this.currentSprite.x;
- this.bloodSprite.y = this.currentSprite.y;
- if (this.facingDirection == "left"){
- if (this.currentSprite.textures != this.dieLeftFrames){
- this.currentSprite.textures = this.dieLeftFrames;
- this.currentSprite.loop = false;
- this.currentSprite.animationSpeed = 0.1;
- this.currentSprite.gotoAndPlay(0);
- }
- }
- if (this.facingDirection == "right"){
- if (this.currentSprite.textures != this.dieRightFrames){
- this.currentSprite.textures = this.dieRightFrames;
- this.currentSprite.loop = false;
- this.currentSprite.animationSpeed = 0.1;
- this.currentSprite.gotoAndPlay(0);
- }
- }
- if (this.corpseTimer > 0){
- this.corpseTimer -= DELTA_TIME;
- }
- if (this.corpseTimer <= 0){
- gui.miniMap.removeCorpseFromMiniMap(this);
- removeEntity(this.id);
- }
- }
- }
- handleMovement(){
- if (this.action == "dead"){
- if (this.x >= world.width-20 || this.y >= world.height-20){
- gui.miniMap.removeCorpseFromMiniMap(this);
- removeEntity(this.id);
- }
- return;
- }
- var threshold = 32;
- var interpAmount = 0.10;
- var differenceX = this.remoteX - this.x;
- var differenceY = this.remoteY - this.y;
- if (differenceX > threshold || differenceX < -threshold){
- this.x = this.remoteX;
- }else{
- this.x += differenceX * interpAmount;
- }
- if (differenceY > threshold || differenceY < -threshold){
- this.y = this.remoteY;
- }else{
- this.y += differenceY * interpAmount;
- }
- this.currentSprite.x = this.x;
- this.currentSprite.y = this.y;
- }
- kill(x, y){
- let randomNumber = Math.random() * 1000000;
- this.id = randomNumber;
- this.currentSprite.id = randomNumber;
- this.x = x;
- this.y = y;
- this.currentSprite.x = x;
- this.currentSprite.y = y;
- this.action = "dead";
- this.currentSprite.hitArea = this.deadHitArea;
- this.bloodSprite.x = this.currentSprite.x;
- this.bloodSprite.y = this.currentSprite.y;
- this.bloodSprite.zIndex = 1;
- this.bloodSprite.loop = false;
- this.bloodSprite.animationSpeed = 0.1;
- this.bloodSprite.gotoAndPlay(0);
- world.worldContainer.addChild(this.bloodSprite);
- gui.miniMap.addCorpseToMiniMap(this);
- }
- checkStab(){
- if (world.time == "day"){
- if (this.stamina < 50){
- createMessageBox("You need at least 50 stamina to stab during the day.", "0xFFA500", false);
- return false;
- }
- }
- if (world.time == "night"){
- if (this.stamina < 25){
- createMessageBox("You need at least 25 stamina to stab during the night.", "0xFFA500", false);
- return false;
- }
- }
- return true;
- }
- attackThis(){
- var player = getEntityByID(selfID);
- if (player){
- if(player.checkStab() && this.action != "dead" && this.id != -1 && this.id != selfID){
- wayPointTarget = this;
- }
- }
- ws.send(encode({type: "input", data:{type:"attack", target:this.id}}));
- }
- }
- function onPointerDownEntity(event){
- var button = event.data.originalEvent.which;
- if (button === 3 || button === 2){
- var e = getEntityByID(this.id);
- if (e){
- e.attackThis();
- }
- }
- }
- function onPointerOver(event){
- this.hovering = true;
- }
- function onPointerOut(event){
- this.hovering = false;
- }
- function killLocalPlayer(useFilters = true, killerName){
- if (useFilters){
- app.stage.filters = [shockwaveFilter, deathFilter];
- shockwaveFilter.time = 0;
- }
- localStorage.setItem("deathcount", "1");
- AD_DEATHS++;
- startDeathTimer();
- document.getElementById("killedby").innerHTML = "<h2>" + "You were killed by: " + killerName + "</h2>";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement