Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Cannon c = new Cannon(400.0);
- ArrayList<CannonLaser> lasers = new ArrayList(5);
- int laserCount=5;
- void setup() {
- size(600, 800);
- smooth();
- }
- void draw() {
- background(255);
- c.show();
- for (int i = lasers.size()-1; i >= 0; i--) {
- CannonLaser dLaser = lasers.get(i);
- dLaser.show();
- }
- }
- void keyPressed() {
- if (keyCode==LEFT)
- c.move(0);
- else if (keyCode==RIGHT) c.move(1);
- else if (keyCode==32) {
- lasers.add(new CannonLaser(c.px, c.py, 20));
- }
- }
- class Cannon {
- float turret=85;
- float position;
- float px;
- float py;
- int moveSpeed = 5;
- CannonLaser l;
- public Cannon(float p) {
- position = p;
- }
- void show() {
- ellipseMode(CENTER);
- fill(0);
- stroke(128);
- ellipse(position, height, 100, 100);
- strokeWeight(20);
- stroke(0);
- py = height-turret;
- px = position;
- line(position, height, px, py);
- }
- void move(int direction) {
- if (direction == 0)
- position = position-moveSpeed;
- else if (direction==1)
- position = position+moveSpeed;
- }
- }
- class CannonLaser {
- boolean fired = false;
- float px;
- float py;
- float velocity;
- CannonLaser(float x, float y, float v) {
- px = x;
- py = y;
- velocity = v;
- fired=true;
- }
- // Move the Ball vertically up the screen
- void move() {
- py = py-velocity;
- }
- // Make the Ball visable
- void show() {
- move();
- ellipse(px, py, 5, 5);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment