Repeat image
in
Programming Questions
•
5 months ago
Hey community!
I am making a project for university, and I am currently stuck on something. I need help on how to make a bit of code repeat. I have two ufo's that go left to right (ufo) and right to left across the screen (ufo2) but I need them to do it over and over again.
- PImage space;
- PImage trader;
- PImage trader2;
- PImage ship;
- PImage ufo;
- PImage ufo2;
- PImage earth;
- PImage uranaus;
- PImage mars;
- PImage venus;
- float x;
- float y;
- int posx;
- int posy;
- boolean left, right, up, down;
- boolean runOnce = true;
- void setup() {
- size (1249, 768);
- smooth();
- space = loadImage("space.png");
- trader = loadImage("trader.png");
- trader2 = loadImage("trader2.png");
- ufo = loadImage("ufo.png");
- ufo2 = loadImage("ufo2.png");
- earth = loadImage("earth.png");
- uranaus = loadImage("uranaus.png");
- venus = loadImage("venus.png");
- x = 50;
- y = 1200;
- }
- void draw() {
- background(space);
- imageMode(CENTER);
- fill(256, 165, 0);
- image(trader2, 600 + posx, 700 + posy);
- image(ufo, x, 600);
- image(ufo2, y, 500);
- image(earth, 1030, 25);
- image(uranaus, 630, 25);
- image(venus, 230, 25);
- x +=4;
- y -=4;
- }
- void keyPressed()
- {
- if (keyCode== RIGHT)
- posx+=10;
- if (keyCode== LEFT)
- posx-=10;
- if (posx<0) posx=0;
- if (posx>width) posx=width;
- if (keyCode== DOWN)
- posy+=10;
- if (keyCode== UP)
- posy-=10;
- if (posy<0) posy=0;
- if (posy>height) posy=height;
- }
1