Processing: Making an array of an image fall
in
Programming Questions
•
5 months ago
Hi, I'm a beginner to Processing.
I'm trying to make a game where an array of pictures (pokeballs) fall randomly from the top of the screen and the user has to shoot at them and every time the user hits one the speed gets increased by 1. However, I'm having difficulty getting the pokeballs to fall so I was wondering is anyone could help me? To be honest, I've looked at loads of examples and I just don't get it as there's different ways and it's confusing me.
- Main class:
- PFont font;
- int life = 3;
- boolean playerAlive = true;
- PImage back;
- void setup(){
- size(500,500);
- font = loadFont("CourierNewPS-BoldMT-48.vlw");
- image = loadImage("Pokeball2.png");
- frameRate(60);
- smooth();
- back= loadImage("bg.jpg");
- }
- void draw(){
- background (back);
- image.update();
- //text
- text("Lives remaining:"+life, width-250,height-30);
- fill(0);
- if(life<=0){
- textFont(font, 20);
- fill(0);
- text("Gave Over!", width/2-100, height/2);
- }
- }
- class Pokeball{
- float x, y, s;
- float radius = 20;
- Pokeball (float x, float y, float s){
- xpos = x;
- ypos = y;
- speed = s;
- }
- void update(){
- ypos+=speed;
- if (ypos>20+20){
- ypos = 0-20;
- speed = 2.0;
- xpos = random(500);
- if (xpos - 20<=0){
- xpos = 30.0;
- }
- }
- }
- }
- Pokeball class:
- PImage[] image = new PImage[500];
- float x = random (500); //x axies location
- float y = 505;//y axies location
- float speed = 2.0;
- class Pokeball{
- PImage [] image = {getRandomX(), getRandomX, getRandomX, getRandomX, getRandomX};
- PImage [] image = {0,0,0,0,0};
- }
1