> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.f438fBoTIQP/rev.7
 * 
 * authors: 
 *   GoToLoop

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



/**
 * Bullet Fire Example (v1.02)
 * by GoToLoop (2014/Mar)
 *
 * forum.processing.org/two/discussion/3470/triggerbullet
 *
 * studio.processingtogether.com/sp/pad/export/ro.9FioSBFuQzD8V/latest
 */

static final int BW = 030, BH = 010, BS = 010;
int bx, by;
boolean isShooting;

void setup() {
  size(600, 150, JAVA2D);
  frameRate(60);
  smooth(4);
  rectMode(CORNER);

  fill(#FF0000);
  stroke(0);
  strokeWeight(2);

  by = height-BH >> 1;
}

void draw() {
  background(0300);
  if (isShooting)  animateBullet();
}

void keyPressed() {
  final int k = keyCode;
  if (!isShooting && k == ENTER | k == RETURN | k == ' ')  startBullet();
}

void mousePressed() {
  if (!isShooting & mouseButton == LEFT)  startBullet();
}

void startBullet() {
  isShooting = true;
  bx = -BW;
}

void animateBullet() {
  rect(bx += BS, by, BW, BH);
  if (bx > width)  isShooting = false;
}