xxxxxxxxxx
let gun;
let shoot;
let reload;
let score = 0;
function preload() {
gun = createSprite(940,679,2000,2000);
gun.scale = 5;
let gunAnimation = gun.addAnimation('gun','gun0.png');
shoot = createSprite(940, 679, 200, 200);
let shootAnimation = shoot.addAnimation('shoot','shoot0.png','shoot1.png','shoot2.png','shoot3.png','shoot5.png');
shootAnimation.frameDelay = 5;
shoot.scale = 5;
reload = createSprite(940,679,200,200);
let reloadAnimation = reload.addAnimation('reload','reload00.png','reload01.png','reload02.png','reload03.png','reload04.png','reload05.png','reload06.png','reload07.png','reload08.png','reload09.png','reload10.png','reload11.png','reload12.png');
reloadAnimation.frameDelay = 8;
reload.scale = 5;
}
//function fire(){
//if (mouseIsPressed)
//{
// gun.scale = 5;
//}
//}
function setup() {
createCanvas(windowWidth, windowHeight);
}
function draw(){
movegun();
textSize(30);
textStyle(BOLD);
text("Score: " + score, 210, 35);
crosshair();
range();
drawSprites();
}
function movegun(){
background(11,255,255);
if(mouseX < gun.position.x - 10) {
gun.velocity.x = -20;
}
else if(mouseX > gun.position.x + 10) {
gun.velocity.x = 20;
}
else {
//if close to the mouse, don't move
gun.velocity.x = 0;
}
/////////////////////////////////////////
if(mouseX < reload.position.x - 10) {
reload.velocity.x = -20;
}
else if(mouseX > reload.position.x + 10) {
reload.velocity.x = 20;
}
else {
//if close to the mouse, don't move
reload.velocity.x = 0;
}
///////////////////////////////////////
if(mouseX < shoot.position.x - 10) {
shoot.velocity.x = -20;
}
else if(mouseX > shoot.position.x + 10) {
shoot.velocity.x = 20;
}
else {
//if close to the mouse, don't move
shoot.velocity.x = 0;
}
/////////////////////////////////////
}
function crosshair() {
cursor(CROSS);
}
function range(){
// noStroke();
fill(101,67,33);
rect(1,801,2000,120);
rect(101,-1,30,801.5);
rect(1781,-1,30,801.5);
}