let bug;
let fullwidth = ABWorld.fullwidth();
let fullheight = ABWorld.fullheight();
let angle = 0;
var attack = false;
let attacker = 0;
let x = fullwidth/2;
let y = fullheight/2;
let speed = 15;
function preload() {
}
function setup() {
createCanvas(fullwidth, fullheight);
// Create object
//frameRate(30);
bug = new Hero();
}
function draw() {
background(50, 89, 100);
bug.display();
if (attacker < 0) {
attack = false;
}
attacker--;
}
// Jitter class
class Hero {
constructor() {
this.x = x;
this.y = y;
this.size = fullheight/15;
}
display() {
this.x=x;
this.y = y;
// Head
noStroke();
fill('black');
rect(this.x-this.size/3, this.y-this.size/3, this.size+this.size/3, this.size+this.size/3);
fill(254, 239, 147);
rect(this.x, this.y, this.size, this.size);
rect(this.x, this.y+this.size, 2*this.size/3, this.size/7);
fill('white');
arc(this.x+4*this.size/5, this.y+2*this.size/6, this.size/4, this.size/4, 0, PI + QUARTER_PI, CHORD);
arc(this.x+this.size, this.y+2*this.size/3, this.size/2, this.size/5, PI/2, 3*PI/2, CHORD);
fill('black');
arc(this.x+5*this.size/6, this.y+2*this.size/6, this.size/8, this.size/8, 0, PI + QUARTER_PI, CHORD);
noFill();
stroke(238, 218, 116);
strokeWeight(3);
beginShape();
vertex(this.x+this.size/2, this.y+2*this.size/5);
vertex(this.x+this.size/3, this.y+2*this.size/5);
vertex(this.x+this.size/3, this.y+3*this.size/5);
vertex(this.x+this.size/2, this.y+3*this.size/5);
vertex(this.x+this.size/2, this.y+2.5*this.size/5);
vertex(this.x+5*this.size/12, this.y+2.5*this.size/5);
endShape();
// Leg
fill(183);
stroke(140);
rect(this.x, this.y+2.5*this.size, 2*this.size/3, this.size+this.size/3);
fill(84);
rect(this.x, this.y+3.5*this.size, this.size, this.size/2);
if(attack === false) {
// Torso
fill(183);
stroke(140);
rect(this.x-this.size/3, this.y+7*this.size/6, this.size+this.size/3, this.size+this.size/3);
rect(this.x-this.size/5, this.y+7*this.size/6, this.size, this.size/2);
// Arm
fill(254, 239, 147);
noStroke();
rect(this.x+this.size/10, this.y+13*this.size/8, this.size/2, this.size);
// Sword
fill(183);
stroke(140);
rect(this.x+3*this.size/5, this.y+2.25*this.size, this.size/6, this.size/2);
triangle(this.x+23*this.size/30, this.y+2.25*this.size+this.size/8, this.x+23*this.size/30, this.y+2.25*this.size+3*this.size/8, this.x+2*this.size, this.y+2.25*this.size+2*this.size/8);
}
else {
// Torso
fill(183);
stroke(140);
rect(this.x-this.size/3, this.y+7*this.size/6, this.size+this.size/3, this.size+this.size/3);
rect(this.x-this.size/5, this.y+7*this.size/6, this.size/2, this.size);
// Arm
fill(254, 239, 147);
noStroke();
rect(this.x+2*this.size/10, this.y+12*this.size/8, this.size, this.size/2);
// Sword
fill(183);
stroke(140);
rect(this.x+6*this.size/5, this.y+1.5*this.size, this.size/6, this.size/2);
triangle(this.x+42*this.size/30, this.y+1.5*this.size+this.size/8, this.x+42*this.size/30, this.y+1.5*this.size+3*this.size/8, this.x+8*this.size/3, this.y+1.5*this.size+2*this.size/8);
}
}
}
function keyPressed() {
if (keyIsDown(LEFT_ARROW)||keyIsDown(65)){
x-=speed;
}
if (keyIsDown(RIGHT_ARROW)||keyIsDown(68)){
x+=speed;
}
if (keyIsDown(UP_ARROW)||keyIsDown(87)){
y-=speed;
}
if (keyIsDown(DOWN_ARROW)||keyIsDown(83)){
y+=speed;
}
if (keyCode === 32) {
attack=true;
attacker = 10;
}
}