User Tools

Site Tools


epgy:siyp13:game

SIYP - Video Game Design and Computer Programming

EXAMPLES:


Student Pages

Sample Code

Draw Circle

void setup() {  //setup function called initially, only once
  size(500, 400);
  }
 
 
void draw() {  //draw function loops 
 
    ellipse(20,20,20,20);
 
}

Draw 2 Colored Circles

 
void setup() {  //setup function called initially, only once
  size(500, 400);
  }
 
 
void draw() {  //draw function loops 
 
    fill(255,0,0);
 
    ellipse(20,20,20,20);
 
    fill(0,255,0);
 
    ellipse(40,40,20,20);
 
 
}

mouseX and mouseY

int counter;
 
 
void setup() {  //setup function called initially, only once
  size(500, 400);
  }
 
 
void draw() {  //draw function loops 
 
    fill(255,0,0);
 
    ellipse(mouseX,mouseY,20,20);
 
    fill(0,255,0);
 
    ellipse(40,40,20,20);
 
 
}

Fix my code

//Traffic Light: exercise 2 (Processing mod 1)
 
rectMode(CENTER);
ellipseMode(CENTER);
noStroke();
 
// rectangle (traffic light backing)
fill(195, 195, 55);
rect(50,50, 50, 100);
 
// green light
fill(6, 255, 6);
ellipse(10, 20, 25, 25); // x pos should be 50
 
// yellow light
fill(255, 255, 6);
ellipse(50, 70, 25, 25); // y pos should be 50
 
// red light
fill(255, 6, 6);
ellipse(80, 100, 25, 25); //x pos should be 50, y pos should be 80
noFill();

Black Background

// SECTION 1
int x = 20;
int y = 20;
 
//SECTION 2
void setup() {  //setup function called initially, only once
  size(500, 400);
  }
 
 
//SECTION 3
void draw() {  //draw function loops 
 
    background(0);    // makes it black
 
    fill(255,0,0);
 
    ellipse(mouseX,mouseY,20,20);
 
    fill(0,255,0);
 
    ellipse(40,40,20,20);
 
 
}

Falling Green Ball

// SECTION 1
 
int counter;
int x = 20;
int y = 20;
 
 
 
 
//SECTION 2
void setup() {  //setup function called initially, only once
  size(500, 400);
  }
 
 
//SECTION 3
void draw() {  //draw function loops 
 
    background(0);    // makes it black
 
    fill(255,0,0);
 
    ellipse(mouseX,mouseY,20,20);
 
    fill(0,255,0);
 
    ellipse(x,y,20,20);
 
    y=y+1;
 
 
}

keypress

// SECTION 1
 
int counter;
int x = 20;
int y = 20;
 
 
 
 
//SECTION 2
void setup() {  //setup function called initially, only once
  size(500, 400);
  }
 
 
//SECTION 3
void draw() {  //draw function loops 
 
    background(255);    // makes it black
 
    fill(255,0,0);
 
    ellipse(mouseX,mouseY,20,20);
 
    fill(0,255,0);
 
    ellipse(x,y,20,20);
 
 
 
    if (key == 'd'){
        x = x+1;
    }
 
 
}
// SECTION 1
 
int counter;
int x = 20;
int y = 20;
 
 
 
 
//SECTION 2
void setup() {  //setup function called initially, only once
  size(500, 400);
  }
 
 
//SECTION 3
void draw() {  //draw function loops 
 
    background(255);    // makes it black
 
    fill(255,0,0);
 
    ellipse(mouseX,mouseY,20,20);
 
    fill(0,255,0);
 
    ellipse(x,y,20,20);
 
 
 
    if (key == 'd'){
        x = x+1;
    }
 
    if (key == 's'){
        y = y+1;
    }
 
    if (key == 'a'){
        x = x-1;
    }
 
    if (key == 'w'){
        y = y-1;
    }
 
 
}

'if' color box

void setup(){
  size(600,500);  
  background(255);
}
 
 
 
void draw(){
 
    rect(50,50,50,50);
 
    if (mousePressed){
        fill(255,0,0);
    }
    else {
        fill(0,255,255);
    }
 
 
}

Bouncing Ball

// Credit: Ren Ervin Bettendorf 
 
/* SCREENSAVERS FER DAYS BROSKIES */
 
int dx = 2;
int dy = 3;
 
int x = 50;
int y = 50;
 
void setup(){
  size(600,500);  
  background(0);
  frameRate(60);
}
 
 
 
void draw(){
    fill(255);
    rect(x,y,25,25,5);
 
    x = x + dx;
    y = y + dy;
 
    if ( x< 0 || x > 475){
       dx = -1 * dx;
    }
 
    if ( y < 0 || y > 475){
       dy = -1 * dy;  
    }
 
}

Make a Face

int counter;
 
void setup() {  //setup function called initially, only once
  size(500, 500);
  background(255);  //set background white
}
 
void draw() {  //draw function loops 
 
    background(255);
 
    fill(255,255,0);
 
    ellipse(mouseX+50,mouseY+50,200,200);
 
    // eyes
    fill(0,0,255);
    ellipse(mouseX+75,mouseY+200,20,20);
    ellipse(mouseX+25,mouseY+20,20,20);
 
 
}
/soe/sherol/.html/teaching/data/pages/epgy/siyp13/game.txt · Last modified: 2013/08/16 19:42 by ffpaladin