Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by Daniel on 22/07/2017.
- */
- class Habbo{
- constructor(user_data){
- Habbo.Preload(user_data);
- }
- static Preload(user_data){
- Habbo.prototype.api = new Habbo.prototype._API();
- Habbo.prototype._canv = Habbo.API.Client.Canvas;
- this._r = (Habbo.API.User.Preload(user_data, function(ud){
- Habbo.prototype._me = ud;
- }.bind(this)));
- delete this._r;
- Habbo.Canvas.background(0);
- }
- static get Canvas(){
- return Habbo.prototype._canv;
- }
- static get User(){
- return Habbo.prototype._me;
- }
- static get API(){
- return Habbo.prototype.api;
- }
- }
- Habbo.prototype._API = function(){
- };
- Habbo.prototype._API.prototype.Assets = class{
- constructor(){
- }
- };
- Habbo.prototype._API.prototype.Client = class{
- constructor(){
- }
- static get Canvas(){
- return new Canvas("habbo-client", window.innerWidth-100, window.innerHeight-100);
- }
- };
- Habbo.prototype._API.prototype.Furni = class{
- constructor(){
- }
- };
- Habbo.prototype._API.prototype.User = class{
- constructor(user_data){
- this.id = user_data.id;
- this.user = user_data.user;
- }
- static Preload(user_data, fn){
- if(typeof fn==="function"){
- let u = new Habbo.API.User(user_data);
- fn(u);
- }
- }
- };
- Habbo.prototype._API.prototype.RoomTile = class extends Shape{
- constructor() {
- super();
- this.width = 64;
- this.height = 32;
- this.color = new Color(152, 152, 101);
- this.stroke = new Color(142, 142, 94);
- this.topWall = 0;
- this.rightWall = 0;
- this.bottomWall = 0;
- this.leftWall = 0;
- }
- readPixels() {
- return {
- x: this.x,
- y: this.y,
- z: this.z,
- w: this.width,
- h: this.height
- };
- }
- render(ctx){
- const lines = [
- [32, 0],
- [64, 16],
- [32, 32],
- [0, 16]
- ];
- ctx.beginPath();
- ctx.moveTo(this.x + lines[0][0], this.y + lines[0][1]);
- for(let i = 0; i < lines.length; i++){
- let ps = lines[i];
- ctx.lineTo(this.x + ps[0], this.y + ps[1]);
- }
- ctx.closePath();
- if(this.stroke){
- ctx.strokeStyle = "rgba(" + this.stroke.r + ", " + this.stroke.g + ", " + this.stroke.b + ", " + (this.stroke.a / 255) + ")";
- ctx.stroke();
- }
- if(this.color){
- ctx.fillStyle = "rgba(" + this.color.r + ", " + this.color.g + ", " + this.color.b + ", " + (this.color.a / 255) + ")";
- ctx.fill();
- }
- }
- };
- Habbo.prototype._API.prototype.Room = class extends Shape{
- constructor() {
- super();
- this.width = 8;
- this.height = 13;
- this.twidth = 64;
- this.theight = 32;
- this.totalwidth = this.width * this.twidth;
- this.totalheight = this.height * this.theight;
- this.dimension = this.buildDimension();
- }
- buildDimension(){
- let string = "";
- for(let x = 0; x < this.width; x++){
- for(let y = 0; y < this.height; y++){
- let posx = (x * this.twidth/2) + (y * this.twidth/2);
- let posy = (x * this.theight/2) + (y * -this.theight/2);
- string += posx+","+posy+":";
- }
- string += ";";
- }
- return string;
- }
- dimensions(){
- let r = [];
- let a = this.dimension.split(";");
- a.pop();
- for(let y = 0; y < a.length; y++){
- r[y] = [];
- let b = a[y].split(":");
- b.pop();
- for(let x = 0; x < b.length; x++){
- let c = b[x].split(",");
- let posx = parseInt(c[0]);
- let posy = parseInt(c[1]);
- let p = new Vector(posx,posy);
- r[y].push(p);
- }
- }
- return r;
- }
- readPixels() {
- return {
- x: this.x,
- y: this.y,
- w: this.width,
- h: this.height
- };
- }
- render(ctx){
- const d = this.dimensions();
- for(let x = 0; x < d.length; x++){
- let a = d[x];
- for(let y = 0; y < a.length; y++){
- let b = a[y];
- let tile = new Habbo.API.RoomTile();
- if(x===0){
- tile.color = new Color(255, 0, 0);
- tile.stroke = new Color(255, 255, 255);
- tile.topWall = 5;
- }
- if(y===a.length-1){
- tile.color = new Color(255, 0, 0);
- tile.stroke = new Color(255, 255, 255);
- tile.rightWall = 5;
- }
- Habbo.Canvas.add(tile,this.x + b.x, this.y + b.y);
- }
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement