Advertisement
Guest User

habbo js

a guest
Jul 26th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Created by Daniel on 22/07/2017.
  3.  */
  4. class Habbo{
  5.     constructor(user_data){
  6.         Habbo.Preload(user_data);
  7.     }
  8.  
  9.  
  10.     static Preload(user_data){
  11.         Habbo.prototype.api = new Habbo.prototype._API();
  12.         Habbo.prototype._canv = Habbo.API.Client.Canvas;
  13.         this._r = (Habbo.API.User.Preload(user_data, function(ud){
  14.             Habbo.prototype._me = ud;
  15.         }.bind(this)));
  16.         delete this._r;
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.         Habbo.Canvas.background(0);
  24.     }
  25.  
  26.     static get Canvas(){
  27.         return Habbo.prototype._canv;
  28.     }
  29.  
  30.     static get User(){
  31.         return Habbo.prototype._me;
  32.     }
  33.  
  34.  
  35.     static get API(){
  36.         return Habbo.prototype.api;
  37.     }
  38. }
  39.  
  40.  
  41.  
  42. Habbo.prototype._API = function(){
  43.  
  44. };
  45.  
  46.  
  47. Habbo.prototype._API.prototype.Assets = class{
  48.     constructor(){
  49.  
  50.     }
  51. };
  52.  
  53.  
  54. Habbo.prototype._API.prototype.Client = class{
  55.     constructor(){
  56.  
  57.     }
  58.  
  59.  
  60.     static get Canvas(){
  61.         return new Canvas("habbo-client", window.innerWidth-100, window.innerHeight-100);
  62.     }
  63. };
  64.  
  65.  
  66. Habbo.prototype._API.prototype.Furni = class{
  67.     constructor(){
  68.  
  69.     }
  70. };
  71.  
  72.  
  73. Habbo.prototype._API.prototype.User = class{
  74.     constructor(user_data){
  75.         this.id = user_data.id;
  76.         this.user = user_data.user;
  77.     }
  78.  
  79.  
  80.     static Preload(user_data, fn){
  81.         if(typeof fn==="function"){
  82.             let u = new Habbo.API.User(user_data);
  83.             fn(u);
  84.         }
  85.     }
  86. };
  87.  
  88.  
  89. Habbo.prototype._API.prototype.RoomTile = class extends Shape{
  90.     constructor() {
  91.         super();
  92.         this.width = 64;
  93.         this.height = 32;
  94.         this.color = new Color(152, 152, 101);
  95.         this.stroke = new Color(142, 142, 94);
  96.  
  97.         this.topWall = 0;
  98.         this.rightWall = 0;
  99.         this.bottomWall = 0;
  100.         this.leftWall = 0;
  101.     }
  102.  
  103.     readPixels() {
  104.         return {
  105.             x: this.x,
  106.             y: this.y,
  107.             z: this.z,
  108.             w: this.width,
  109.             h: this.height
  110.         };
  111.     }
  112.  
  113.     render(ctx){
  114.         const lines = [
  115.             [32, 0],
  116.             [64, 16],
  117.             [32, 32],
  118.             [0, 16]
  119.         ];
  120.  
  121.         ctx.beginPath();
  122.         ctx.moveTo(this.x + lines[0][0], this.y + lines[0][1]);
  123.  
  124.         for(let i = 0; i < lines.length; i++){
  125.             let ps = lines[i];
  126.  
  127.             ctx.lineTo(this.x + ps[0], this.y + ps[1]);
  128.  
  129.  
  130.         }
  131.  
  132.  
  133.  
  134.         ctx.closePath();
  135.         if(this.stroke){
  136.             ctx.strokeStyle = "rgba(" + this.stroke.r + ", " + this.stroke.g + ", " + this.stroke.b + ", " + (this.stroke.a / 255) + ")";
  137.             ctx.stroke();
  138.         }
  139.         if(this.color){
  140.             ctx.fillStyle = "rgba(" + this.color.r + ", " + this.color.g + ", " + this.color.b + ", " + (this.color.a / 255) + ")";
  141.             ctx.fill();
  142.  
  143.         }
  144.  
  145.     }
  146.  
  147.  
  148.  
  149. };
  150.  
  151.  
  152. Habbo.prototype._API.prototype.Room = class extends Shape{
  153.     constructor() {
  154.         super();
  155.         this.width = 8;
  156.         this.height = 13;
  157.         this.twidth = 64;
  158.         this.theight = 32;
  159.  
  160.         this.totalwidth = this.width * this.twidth;
  161.         this.totalheight = this.height * this.theight;
  162.  
  163.         this.dimension = this.buildDimension();
  164.     }
  165.  
  166.  
  167.     buildDimension(){
  168.         let string = "";
  169.         for(let x = 0; x < this.width; x++){
  170.             for(let y = 0; y < this.height; y++){
  171.                 let posx = (x * this.twidth/2) + (y * this.twidth/2);
  172.                 let posy = (x * this.theight/2) + (y * -this.theight/2);
  173.                 string += posx+","+posy+":";
  174.             }
  175.             string += ";";
  176.         }
  177.         return string;
  178.     }
  179.  
  180.  
  181.     dimensions(){
  182.         let r = [];
  183.         let a = this.dimension.split(";");
  184.         a.pop();
  185.         for(let y = 0; y < a.length; y++){
  186.             r[y] = [];
  187.             let b = a[y].split(":");
  188.             b.pop();
  189.             for(let x = 0; x < b.length; x++){
  190.                 let c = b[x].split(",");
  191.                 let posx = parseInt(c[0]);
  192.                 let posy = parseInt(c[1]);
  193.                 let p = new Vector(posx,posy);
  194.                 r[y].push(p);
  195.             }
  196.         }
  197.         return r;
  198.     }
  199.  
  200.     readPixels() {
  201.         return {
  202.             x: this.x,
  203.             y: this.y,
  204.             w: this.width,
  205.             h: this.height
  206.         };
  207.     }
  208.  
  209.     render(ctx){
  210.         const d = this.dimensions();
  211.         for(let x = 0; x < d.length; x++){
  212.             let a = d[x];
  213.             for(let y = 0; y < a.length; y++){
  214.                 let b = a[y];
  215.                 let tile = new Habbo.API.RoomTile();
  216.  
  217.                 if(x===0){
  218.                     tile.color = new Color(255, 0, 0);
  219.                     tile.stroke = new Color(255, 255, 255);
  220.                     tile.topWall = 5;
  221.                 }
  222.  
  223.                 if(y===a.length-1){
  224.                     tile.color = new Color(255, 0, 0);
  225.                     tile.stroke = new Color(255, 255, 255);
  226.                     tile.rightWall = 5;
  227.                 }
  228.  
  229.                 Habbo.Canvas.add(tile,this.x + b.x, this.y + b.y);
  230.             }
  231.         }
  232.     }
  233. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement