xxxxxxxxxx
82
// monster maker
let canvasWidth = 400;
let canvasHeight = 400;
let background_sprite;
let bodies = [];
function preload(){
background_sprite = loadImage('data/background.jpg');
}
function setup() {
canvasWidth = background_sprite.width;
canvasHeight = background_sprite.height;
createCanvas(canvasWidth, canvasHeight);
}
function draw() {
background(220);
image(background_sprite, 0, 0);
}
class mon_body{
constructor(sprite, legs, arms, heads, tail){
this.sprite = sprite; // the type of monster
this.legAnchors = legs; //locations of all the places legs can be drawn on this sprite/monster
this.armAnchors = arms;
this.headAnchors = heads;
this.tailAnchor = tail;
}
}
class anchor{
constructor(x, y){
this.x = x;
this.y = y;
}
}
class mon_leg{
constructor(sprite, pivotX, pivotY){
this.sprite = sprite;
this.pivotX = pivotX; //where the leg attaches to the anchor, relative to the dimensions of the leg.
this.pivotY = pivotY;
}
display(anchorX, anchorY)
{
let x = anchorX - pivotX; //location to draw it at. anchor modified by pivot
let y = anchorY - pivotY;
image(sprite, x, y);
}
}
class mon_arm{
constructor(sprite, x, y){
this.sprite = sprite;
this.x = x;
this.y = y;
}
}
class mon_head{
constructor(sprite, x, y){
this.sprite = sprite;
this.x = x;
this.y = y;
}
}
class mon_tail{
constructor(sprite, x, y){
this.sprite = sprite;
this.x = x;
this.y = y;
}
}