Page 1 of 1

Halloween demo

PostPosted: Tue Nov 04, 2014 5:43 pm
by BenChang
Gimp file for halloween demo layout

Re: Halloween demo

PostPosted: Tue Nov 04, 2014 5:49 pm
by BenChang
Code: Select all
PImage background;

void setup ()
{
  size(800,600);
  background = loadImage ("background.png");
}

void draw ()
{
  image (background,0,0);
}

Re: Halloween demo

PostPosted: Tue Nov 04, 2014 6:03 pm
by BenChang
Code: Select all
PImage background;
PImage house;
FadingBox houseGlow;

void setup ()
{
  size(800,600);
  background = loadImage ("background.png");
  house = loadImage ("house.png");
 
  houseGlow = new FadingBox (546,251,62,78,1);

}

void draw ()
{
  image (background,0,0);
 
  houseGlow.draw();
 
  image (house,0,0);
 
 
}

Code: Select all
class FadingBox
{
   // properties
   int x;
   int y;
   int w;
   int h;
 
   int c;  // color
   int colorChange;
   
   // constructor method
   FadingBox (int x,int y,int w,int h, int speed)
   {
     // "this" means "this object instance"
     
     this.x = x;
     this.y = y;
     this.w = w;
     this.h = h;
     this.colorChange = speed;
     
     this.c =0;
 
   }
   
   // draw method
   // NOT called automatically
   void draw ()
   {
      stroke(255,c,0);
      fill(255,c,0);
     
      rect (x,y,w,h);
     
      c = c + colorChange;
      if (c>255 || c<0)
      {
         colorChange *= -1;
      }
     
   }
 
}

Re: Halloween demo

PostPosted: Tue Nov 04, 2014 6:16 pm
by BenChang
Code: Select all
PImage background;
PImage house;
PImage tombstones;

FadingBox houseGlow;
Cloud cloud;


void setup ()
{
  size(800,600);
  background = loadImage ("background.png");
  house = loadImage ("house.png");
  tombstones = loadImage ("tombstones.png");
 
  houseGlow = new FadingBox (546,251,62,78,1);

  cloud = new Cloud();
}

void draw ()
{
  image (background,0,0);
 
  houseGlow.draw();
 
  cloud.draw();

 
  image (house,0,0);
  image (tombstones,0,0);
 
 
}

Re: Halloween demo

PostPosted: Tue Nov 04, 2014 6:26 pm
by BenChang
Code: Select all
PImage background;
PImage house;
PImage tombstones;

FadingBox houseGlow;
Cloud[] clouds;

int lastTime;
float deltaTime;

void setup ()
{
  size(800,600);
  background = loadImage ("background.png");
  house = loadImage ("house.png");
  tombstones = loadImage ("tombstones.png");
 
  houseGlow = new FadingBox (546,251,62,78,1);

  clouds = new Cloud[10];
  for (int i=0;i<10;i++)
    clouds[i] = new Cloud();


  lastTime = millis();
}
 
void draw ()
{
  int currentTime = millis();
  deltaTime = (currentTime - lastTime) / 1000.0;
  println(deltaTime);
  lastTime = currentTime;
 
  image (background,0,0);
 
  for (int i=0;i<10;i++)
    clouds[i].draw();
 
  houseGlow.draw();
  image (house,0,0);
  image (tombstones,0,0);
 
 
}

Code: Select all
class Cloud
{
   PImage img;
   float x;
   float y;
   float speed;
   
   Cloud ()
   {
     img = loadImage ("cloud.png");
     
     x=random(0,800);
     y=random(0,200);
     speed = random (100);
   } 
   
   void draw ()
   {
      x=x + speed * deltaTime;
      if (x>800)
        x=-200; 
      image (img,x,y);
   }
}

Re: Halloween demo

PostPosted: Tue Nov 04, 2014 6:50 pm
by BenChang
Code: Select all
class Zombie
{
   PImage[] frames;
   int currentFrame=0;
   int numFrames = 2;
   int x,y;
   
   float delay = .2;  // 200 milliseconds = 12 frames per second
 
   float spriteFrameTime=0;
 
   Zombie()
  {
    frames=new PImage[2];
    frames[0]=loadImage("zombie1.png");
    frames[1]=loadImage("zombie2.png");
   
    x=300;
    y=200;
   
   
  }
 
 
  void draw()
  {
     spriteFrameTime += deltaTime;
     
     if (spriteFrameTime > delay)
     {
       currentFrame ++;
       if (currentFrame>= numFrames)
       {
          currentFrame=0;
       }
       spriteFrameTime = 0;    // reset the timer
       
     }
     image (frames[currentFrame],x,y); 
  }
}

Code: Select all
class Ghost
{
   PImage img;
   float x;
   float y;
   float speed;
   
   Ghost ()
   {
     img = loadImage("ghost.png");
     
     x=random(0,800);
     y=random(350,400);
     speed = random (30,50);
     
   }
   
   void draw ()
   {
      // jitter
      x=x+ random(-100,100) * deltaTime;
     
      y=y - speed * deltaTime;
      if (y<-125)
        y=random(350,400);
       
      image (img,x,y); 
   }
   
   
}

Code: Select all
PImage background;
PImage house;
PImage tombstones;
PImage ground;

FadingBox houseGlow;
Cloud[] clouds;
Ghost ghost;
Zombie fred;

int lastTime;
float deltaTime;

void setup ()
{
  size(800,600);
  background = loadImage ("background.png");
  house = loadImage ("house.png");
  tombstones = loadImage ("tombstones.png");
  ground = loadImage ("ground.png");
 
  houseGlow = new FadingBox (546,251,62,78,1);

  clouds = new Cloud[10];
  for (int i=0;i<10;i++)
    clouds[i] = new Cloud();

  ghost  = new Ghost();
  fred = new Zombie();
 
  lastTime = millis();
}
 
void draw ()
{
  int currentTime = millis();
  deltaTime = (currentTime - lastTime) / 1000.0;

  lastTime = currentTime;
 
  image (background,0,0);
 
  ghost.draw();
 
  image (ground,0,0);
 
  for (int i=0;i<10;i++)
    clouds[i].draw();
 
  houseGlow.draw();
  image (house,0,0);
  image (tombstones,0,0);
 
  fred.draw();
 
}