Hi all,
I’m trying to write a sketch, a sort of game, so that:
At the beginning of the game the “*” character is at the center of the screen and a certain number (nz=8) of a different character, “0”, are at the border of the screen
If there is no click, each “0” approaches the “" moving a line down or a line up (or remaining in the same line), a column right or a column left (or remaining in the same column) according to the reciprocal position of "” and “0”.
Each “0” has to disappear from its former position and reappear in the new one.
At the beginning of the game, this approach march must be slow, it will increase while the game goes on (any suggestion on this task?)
Clicking the mouse, sets the “" in a new position and the nz “0” change their approach march towards the new "”.
Later, I would like to detect if any character collide with some other character I’ll put on the screen (any suggestion on this task?).
I wrote a Basic program for the Commodore 64; I’d like to ho have a Processing version of the game. My first attempt is the following:
int dx,dy,xp,yp;
int x,y;
int nz;
int[] xz;
int[] yz;
int s;
void setup(){
//frameRate(5);
size(displayWidth,displayHeight);
background(#8891F0);
fill(#0C1CC1);
nz=8;
xz=new int[nz];
yz=new int[nz];
dx=displayWidth;
dy=displayHeight;
textSize(64);
xz[0]=15; yz[0]=64;
xz[1]=100; yz[1]=64;
xz[2]=dx-64; yz[2]=dy/4;
xz[3]=dx-64; yz[3]=dy-128;
xz[4]=dx/2; yz[4]=dy;
xz[5]=dx/4; yz[5]=dy;
xz[6]=0; yz[6]=6*dy/7;
xz[7]=0; yz[7]=3*dy/4;
s=64; // according to textSize
xp=dx/2;yp=dy/2;
}
void draw(){
if(mousePressed){xp=mouseX; yp=mouseY;}
text("*",xp,yp);
for (int k=0; k<nz-1; k++) {
text(" ",xz[k],yz[k]);
if (xz[k]<xp) {xz[k]=xz[k]+s;}
if (xz[k]>xp) {xz[k]=xz[k]-s;}
if (yz[k]<yp) {yz[k]=yz[k]+s;}
if (yz[k]>yp) {yz[k]=yz[k]-s;}
text("0",xz[k],yz[k]);
}
}
I knew it wouldn’t work correctly (the “old 0” don’t disappear), but, and here is the question (finally!): do you think this a good approach?
Thanks PascalAuder; using ellipse doesn’t solve my problem: I still get many ellipses. I would like to see only eight “0” characters approaching the “*”. The “text(” “,xz[k],yz[k]);” is supposed to clear the “old 0” before producing the new one.
Thanks jb4x; actually I didn’t describe the game I have in mind (trying to avoid a huge post).
Anyway, imagine the “*” as the protagonist and the “0s” as sort of zombies that follow you blindly. Suppose you complete the background screen with some “holes”: if a zombie reaches a hole, it falls inside and disappear. You complete a level if you destroy the zombies before they catch you (next level, you can have more zombies moving faster and so on).
It’s just an idea I had.
Programming this game for the old Commodore 64 is easy because the screen is an array and you can poke a type in a specific position and you can peek (read) which type is in a given position.
First, try putting background(#8891F0); on the first line of draw. You need to clear the screen each animation for the 0’s to appear.
text(" ", x, y); would not clear it as " " would just overlap with it and draw nothing. (You could try drawing it in the background color, but that could make things messy later on)
You’re right Sarah: void draw() {text(“A”,100,100); text(“B”,100,100);} … and A and B overlaps. I didn’t know that. As far as drawing in the background color, it’s a good idea, I’ll try that. As you can see, it’s a very simple game. I have in mind to write the program in Java mode, then pass to Android mode so that you tap on the screen to make … zombies fall in the holes (with different characters; now I’m just trying the first steps…). If you have other suggestions … they are welcomed. A big big Thank You.