We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › please help me!!!
Page Index Toggle Pages: 1
please help me!!! (Read 248 times)
please help me!!!
Sep 9th, 2008, 5:41am
 
hey i cant get these two pieces of code to work, any help would be great

int ii;
int NUMSHOTS = 100;
Shoot[] history = new Shoot[NUMSHOTS];
boolean hit;



void setup()
{
 frameRate(60);
 size(400, 400);
 smooth();
}

void draw()
{



 for (int ii = 0; ii < NUMSHOTS; ii = ii + 1)
 {
   draw_shot(history[ii], ii);

 } for(int i = 0; i < NUMSHOTS; i = i + 1)
 if( hit(history[i],300,350,300,350))
 {rect(300,300,50,50);
 }
   
}

class Shoot
{

 int x;
 int y;
 int creationFrame;

}


// Draw this shot object to the screen.
// If the shot object is 'old' (was made at least 50 frames ago)
//  then remove it from the shot array.
void draw_shot(Shoot shot, int index)
{
 if (shot == null) return;
 strokeWeight(2);
 stroke(220,200,0);
 line(shot.x, shot.y, shot.x, shot.y+10);
 shot.y+=3;


 if (shot.creationFrame + 350 < frameCount || shot.y > height - 10 )
 {

   history[index] = null;
 }    
}

// Find a slot on our shot array that is unused,
// then create a shot object at x.
void create_shot(int x, int y)
{
 for (ii = 0; ii < NUMSHOTS; ii = ii + 1)
 {
   if (history[ii] == null)
   {
     history[ii] = new Shoot();
     history[ii].x = x;
     history[ii].y = y;
     history[ii].creationFrame = frameCount;
     break; // I'm done
   }
 }
}

void mousePressed()
{
 create_shot(mouseX, mouseY);
}
boolean hit(Shoot shot, int x1, int x2, int y1, int y2){
 if(x1<shot.x && shot.x>x2 && y1<shot.y && shot.y>y2){
   return true;
 } else{
   return false;
 }
}



the second is meant to draw a bulding made up of windows but only draws one window
city [] history = new city[10];
window [] structure = new window[100];

int speed;
void setup(){
 size(400,400);
 smooth();
}
void draw(){
 for(int i = 0; i<10; i++){
   draw_building(history[i],i);
 }
}


class city {
 int y;
 int x;

}

void draw_building(city building, int index)
{      

 if(building == null) return;
 int XstartPoint = building.x;
 int YstartPoint = building.y;
 for(int i = 0; i<6; i++){
   for(int k = 0; k<3; k++){
     fill(255);
     stroke(0);
     strokeWeight(1);
     create_window(XstartPoint, YstartPoint);
     for(int b = 0; b<100;b++){
       draw_window(structure[b],b);
       XstartPoint +=10;
     }
YstartPoint +=10;

   }
 }
}

void create_building(int x,int y)
{
 for (int i = 0; i < 10; i = i + 1)
 {
   if (history[i] == null)
   {
     history[i] = new city();
     history[i].x = x;
     history[i].y = y;
     break; // I'm doneint ii;
int NUMSHOTS = 100;
Shoot[] history = new Shoot[NUMSHOTS];
boolean hit;



void setup()
{
 frameRate(60);
 size(400, 400);
 smooth();
}

void draw()
{



 for (int ii = 0; ii < NUMSHOTS; ii = ii + 1)
 {
   draw_shot(history[ii], ii);

 } for(int i = 0; i < NUMSHOTS; i = i + 1)
 if( hit(history[i],300,350,300,350))
 {rect(300,300,50,50);
 }
   
}

class Shoot
{

 int x;
 int y;
 int creationFrame;

}


// Draw this shot object to the screen.
// If the shot object is 'old' (was made at least 50 frames ago)
//  then remove it from the shot array.
void draw_shot(Shoot shot, int index)
{
 if (shot == null) return;
 strokeWeight(2);
 stroke(220,200,0);
 line(shot.x, shot.y, shot.x, shot.y+10);
 shot.y+=3;


 if (shot.creationFrame + 350 < frameCount || shot.y > height - 10 )
 {

   history[index] = null;
 }    
}

// Find a slot on our shot array that is unused,
// then create a shot object at x.
void create_shot(int x, int y)
{
 for (ii = 0; ii < NUMSHOTS; ii = ii + 1)
 {
   if (history[ii] == null)
   {
     history[ii] = new Shoot();
     history[ii].x = x;
     history[ii].y = y;
     history[ii].creationFrame = frameCount;
     break; // I'm done
   }
 }
}

void mousePressed()
{
 create_shot(mouseX, mouseY);
}
boolean hit(Shoot shot, int x1, int x2, int y1, int y2){
 if(x1<shot.x && shot.x>x2 && y1<shot.y && shot.y>y2){
   return true;
 } else{
   return false;
 }
}

   }
 }
}

void mousePressed()
{
 create_building(mouseX,mouseY);
}


class window{
 int x;
 int y;
}

void draw_window(window glass, int index){

 if (glass == null) return;
 rect(glass.x,glass.y,10,10);
}

void create_window(int x, int y){
 for (int w = 0; w < 100; w = w + 1)
 {
   if (structure[w] == null)
   {
     structure[w] = new window();
     structure[w].x = x;
     structure[w].y = y;
     break; // I'm done
   }
 }
}



cheers
Page Index Toggle Pages: 1