> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.5q-gBOaUm2L/rev.40
 * 
 * authors: 
 *   Natalia Valencia

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



/* @pjs preload="/static/uploaded_resources/p.14209/SPACECRAFT.png"; */
/* @pjs preload="/static/uploaded_resources/p.14209/Alien.png"; */
/* @pjs preload="/static/uploaded_resources/p.14209/fondo-oscuro.jpg"; */
/* @pjs preload="/static/uploaded_resources/p.14209/SpaceInvaders_logo.png"; */




Rain rain;
Logo logo;
Ship ship;
Ship2 ship2;
Invaders invaders;



PImage fondo;

void setup()
{
  size(800, 400);

  fondo=loadImage("/static/uploaded_resources/p.14209/fondo-oscuro.jpg");
  
  rain = new Rain();
  logo = new Logo();
  ship = new Ship();
   ship2 = new Ship2();
   invaders = new Invaders();
 
}

   void draw ()

{
 image(fondo,0,0,800,400); 
   
rain.dibujar();
rain.mover();

logo.dibujar();
logo.mover();

ship.dibujar();
ship.mover();

ship2.dibujar();
ship2.mover();

invaders.dibujar();
invaders.mover();

}

class Invaders

{
int numInvaders= 2;
  
float []posx = new float[numInvaders];
float []posy = new float[numInvaders];

float []velx = new float[numInvaders]; 
float []vely = new float[numInvaders]; 
PImage i;

Invaders()

{
  //posx = 30;
  //posy = 110;
  //vely = 7;
  //velx = 9;
  
  i= loadImage("/static/uploaded_resources/p.14209/Alien.png");
}

void dibujar()
{
 int posInvaders = 0;
  image(i,posx[posInvaders],posy[posInvaders],90,90); 
 
while (posInvaders<numInvaders)
{
    posx[posInvaders] = random(0, width);
    posy[posInvaders] =random(0, height);
    velx[posInvaders] = random(1,1);
    vely[posInvaders] = random(1,1);
    posInvaders +=1;
}
}
void mover()
{ 
  int posInvaders = 0;
  posx[posInvaders] =posx[posInvaders] +velx[posInvaders];
posy[posInvaders] =posy[posInvaders] +vely[posInvaders];

if(posx[posInvaders]>width)
{
velx[posInvaders] =- 1;
}
if(posx[posInvaders]<0)
{
  velx[posInvaders]= 1;
}
if(posy[posInvaders]>height)
{
vely[posInvaders] =- 1;
}
if(posy[posInvaders]<0)
{
  vely[posInvaders]= 1;
}

}
}
  
class Logo
{

float posx;
float posy;
float velx;
float vely;
PImage l;

Logo()
{
    posx = 200;
    posy = 200;
    vely = 1;
    
    l= loadImage("/static/uploaded_resources/p.14209/SpaceInvaders_logo.png");
}
void dibujar()
{

  image(l,posx,posy); 
}

void mover()
{
posy = posy - vely;

    if (posy<0)
    {
    posy = 800;
    }
    
    if (posy> 800)
    {
    posy = 0;
    }
}
}

class Rain
{

int numRain= 300;
float[] posx = new float[numRain];
float[] posy = new float[numRain];
float[] vel = new float[numRain]; 


void dibujar () 
{
   
int posRain = 0;
while (posRain<numRain)
{
    posx[posRain] = random(0, width);
    posy[posRain] =random(0, height);
    vel[posRain] = random(5,5);
    posRain +=1;
}
}
void mover()
{
    int posRain = 0;
    while (posRain < numRain)
    {
    
    fill(random (255),random (255),random (255)*vel[posRain],200);
    ellipse(posx[posRain], posy[posRain],vel[posRain],vel[posRain]);
    posy[posRain] += vel[posRain]/2;
    noStroke();
    
    if (posy[posRain] > height) 
    {
      posy[posRain] = 0;
    }
    posRain +=1;
  } 
}
}

class Ship

{
  
int posx;
int posy;

int velx;
int vely;
PImage s;

Ship()

{
  posx = 30;
  posy = 110;
  vely = -1;
  velx = 1;
  
  s= loadImage("/static/uploaded_resources/p.14209/SPACECRAFT.png");
}

void dibujar()
{

  image(s,posx,posy,200,100); 
}

void mover()
{ 
  posx =posx +velx;
posy =posy +vely;

if(posx>width)
{
velx =- 1;
}
if(posx<0)
{
  velx= 1;
}
if(posy>height)
{
vely =- 1;
}
if(posy<0)
{
  vely= 1;
}


}

}
  
  
  class Ship2

{
  
int posx;
int posy;

int velx;
int vely;
PImage s;

Ship2()

{
  posx = 400;
  posy = 200;
  vely = 1;
  velx = 1;
  
  s= loadImage("/static/uploaded_resources/p.14209/SPACECRAFT.png");
}

void dibujar()
{

  image(s,posx,posy,200,100); 
}

void mover()
{ 
  posx =posx +velx;
posy =posy +vely;

if(posx>width)
{
velx =- 1;
}
if(posx<0)
{
  velx= 1;
}
if(posy>height)
{
vely =- 1;
}
if(posy<0)
{
  vely= 1;
}

}
}