We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey all- So I'm attempting to create a simple game where the user controls a black hole with the left/right arrow keys and tries to catch falling objects inside. I'm still on the falling objects piece. I'd like to drop a new "space" image every two seconds, but I'm hitting a wall in trying to sustain the image and keep the timer function on a continuous loop.
All help is greatly appreciated- thanks.
int currenttime = 0;//initializing the time variables
int interval = 1000;
int savedTime;
int totalTime = 2000;
PImage r;
int maxImages = 5;//# of space images
int imageIndex = 0;//#initial image to be displayed first
int x = 400; //x for black hole
int y1 = -10;
int x1 = int(random(10, 780));
PImage back;//loading the star image
PImage cir;//loading blur around black hole
///*
import ddf.minim.*;//audio player
Minim minim;//audio player
AudioPlayer player;
//*/
PImage[] spaceArray = new PImage[4]; //loading space images
void setup() {
size(800, 575,P3D);
savedTime= millis();//setting millis as savedTime
frameRate(200);
for (int i = 0; i< 4;i++){//for loop for space array
//i = int(random(spaceArray.length));//array of space images
spaceArray[i] = loadImage("space"+ i + ".png");
}
///*
minim = new Minim(this);//audio player
player = minim.loadFile("01 Io.mp3");//loading song
player.loop(); //playing and looping song
//*/
back = loadImage("stars.jpeg");//background
PGraphics pg = createGraphics(200,200,P2D);//setting specs. for black hole blur ring
pg.beginDraw();
pg.fill(255);
pg.background(0,0,0,0);
pg.noStroke();
pg.ellipse(100,100,100,100);
pg.filter(BLUR,5);
pg.endDraw();
cir = pg.get();
imageMode(CENTER);//tfguy44
smooth();
}
void draw() {
int passedTime = millis() - savedTime;
background(back);//star picture
if (y1 < 1000){
y1++;
}
image(spaceArray[imageIndex],x1, y1, 50, 60);//space image
if (passedTime > totalTime){//timer to (with framerate =1000) drop an object every second
//int y1 = -10;
//float x1 = random(10, 780);//randomized x for falling objects
for(int i =0; i<200; i++){
imageUpdate();
}
//image(spaceArray[0],x1,y1, 50,60);//space image
//(image(spaceArray[(int)random(0,4)],x1,y1, 50,60));//space image
savedTime = millis();
println("got this far");
}
if (keyPressed && (key == CODED)) { // If it’s a coded key
if (keyCode == LEFT) { //if it's left arrow
if (x - 53 >= 0 ) { //keeps the black hole from leaving the screen left
x-=7;
} }else if (keyCode == RIGHT) { //if it's the right arrow
if (x + 53 <=800) { //stops it at edge of screen right
x+=7;
} }
}
image(cir, x, 490);//white blur around black hole
fill(0);//color hole
ellipse(x, 490, 90, 90);//black hole
}
void imageUpdate(){
//x1+=1;
y1+=1;
image(spaceArray[(int)random(0,4)],x1,y1, 50,60);
}
Answers
the idea is that in draw() a image is displayed with the index imageIndex (no matter where the timer is, one image is the current image)
so when the timer is due, just change the index imageIndex in imageUpdate()
I'm sorry- I should have been more detailed in my description. I would like a new image to drop down every two seconds, then maintain on its path downward so it can be a continuous game with variability in the dropping images.
Just load all images into an array in setup() and display them in draw()
Are there more than one item at a time falling?
this is the simple version. It restarts when a image leaves the screen.
here...