class PersonajeP{
int TotalFarm;
//PImage FarmA[];
PImage FotogramasP[][];
float xa,ya,xr,yr;
int k,indI,numI;
PVector Pocicion;
PVector Velocidad;
PVector Aceleracion;
PVector Pivote;
float Angulo;
PersonajeP(int _x,int _y,PImage _direc[][],PVector _Vel,PVector _Acel,PVector _Pivote,float _Angulo){
//FarmA = _direc;
FotogramaCaminar(_direc);
xa = 0.0;
ya = 0.0;
xr = 0.0;
yr = 0.0;
indI = 0;
numI = 0;
//TotalFarm = FarmA.length;
Pocicion = new PVector(_x,_y);
Velocidad = new PVector(0,0);
Velocidad = _Vel;
Aceleracion = new PVector(0,0);
Aceleracion = _Acel;
Angulo = _Angulo;
Pivote = new PVector(0,0);
Pivote = _Pivote;
//Velocidad = new PVector(random(-1,1),random(-1,0));//la velocidad se escoje alatoriamente
}
void FotogramaCaminar(PImage _direc[][]){
FotogramasP = _direc;
}
void Mover(){
Velocidad.add(Aceleracion);
Pocicion.add(Velocidad);
//dibujar();
}
void Rotacion(){
translate(Pocicion.x + Pivote.x,Pocicion.y + Pivote.y);
rotate(Angulo);
}
void dibujar(){
translate(-Pivote.x,-Pivote.y);
image(FotogramasP[indI][numI],0,0);
/*if (mousePressed == false){
//k = (k+1) % CaminarFram.length;
image(CaminarFram[0],Pocicion.x,Pocicion.y);
}else{
//k = (k+1) % CorrerFram.length;
image(CorrerFram[1],Pocicion.x,Pocicion.y);
}*/
}
}
class BotonesC{
PFont f;
PImage ImagenBtn;
String texto;
int x,y,x2,y2,ancho,alto,TamTex;
int xr,xa;
color c ;
BotonesC(int _x,int _y,int _ancho,int _alto,PFont _f,PImage _img,String _text,int _tam,color _c){
f = _f;
ImagenBtn = _img;
texto = _text;
x = _x;
y = _y;
ImagenBtn.resize(_ancho, _alto);
TamTex = _tam;
c = _c;
x2 = x + ImagenBtn.width;
y2 = y + ImagenBtn.height;
}
boolean Click(){
if( (mouseX > x && mouseX < x2) && (mouseY > y && mouseY < y2 ) && mousePressed == true )
return(true);
else
return(false);
}
void dibujar(){
image(ImagenBtn,x,y);
textFont(f,TamTex);
fill(c);
text(texto,x,y + ImagenBtn.height/2);
}
void ActPocicion(int _x,int _y){
x = _x;
y = _y;
x2 = x + ImagenBtn.width;
y2 = y + ImagenBtn.height;
}
}
class FondosC{
int indi;
PImage fondosDirec[];
String[] NomDir = new String[3];
String dirI;
int ii;
FondosC(int _ii,String _dir){
indi = _ii;
fondosDirec = new PImage[_ii];
NomDir[0] = _dir;
NomDir[2] = ".png";
for(ii = 0; ii < _ii; ii++){
NomDir[1] = str(ii);
dirI = join(NomDir,"");
fondosDirec[ii] = loadImage(dirI);
fondosDirec[ii].resize(width, height);
}
}
void FondoAleatorio(){
image(fondosDirec[round(random(0,indi-1))],0,0);
}
void FondoFijo(int _mi){
image(fondosDirec[_mi],0,0);
//background(fondosDirec[_mi]);
}
}
PersonajeP Flores;
PersonajeP Lanzador;
PersonajeP Brazo;
String dirImag;
int i,j,k,numFondos;
float Angulo = 0.0;
float Angulo2 = 0.0;
float teta = 0.0;
Boolean LanzarF = false;
Boolean AclararImg = false;
Boolean BtRtPres = false;
Boolean clicR = false;
float mX = 0.0;
float mY = 0.0;
int Xi,Yi,AnchoE,AltoE,AnchoP,AltoP;
float Vx,Vy;
float tiempo = 0;
float gravedad = 9.8;
PVector V0,A0,Pv1,Pv2,Pv3;
FondosC FondosPan;
int[][] imagenSelec;
BotonesC BontonReini;
int[][][] ArrBrillPan;
int ArrBri[][];
int radio;
PImage FondoT;
void setup() {
size(300,300);//Tamaño de la ventana
smooth();
frameRate(30);
AnchoE = 1600;
AltoE = height;
AnchoP = width;
AltoP = height;
numFondos = 11;
radio = 50;
FondoT = loadImage("img/fondo.png");
FondoT.resize(width, height);
imagenSelec = new int[numFondos][2];
ArrBrillPan = new int[numFondos][AnchoP][AltoP];
for(i = 0; i < numFondos ; i++){
imagenSelec[i][0] = -1;
imagenSelec[i][1] = 0;
for(j = 0; j < AnchoP; j++){
for(k = 0; k < AltoP ; k++){
ArrBrillPan[i][j][k] = 0;
}
}
}
ArrBri = new int[AnchoP][AltoP];
for(i = 0; i < AnchoP; i++){
for(j = 0; j < AltoP; j++){
ArrBri[i][j] = 0;
}
}
Xi = 10;
Yi = 400;
Vx = 25;
Vy = 25;
Angulo = 0;
FondosPan = new FondosC(numFondos,"img/Fondos2/F");
for(i = 0; i < numFondos ; i++){
imagenSelec[i][0] = floor(random(numFondos));
imagenSelec[i][1] = 1;
}
V0 = new PVector(0,0);
A0 = new PVector(0,0);
Pv1 = new PVector(0,0);
Flores = new PersonajeP(0,0,Imagenes(1,1,"img/flores"),V0,A0,Pv1,0);
Pv2 = new PVector(0,0);
Lanzador = new PersonajeP(0,0,Imagenes(1,1,"img/Lanzador/lanzador"),V0,A0,Pv2,0);
Lanzador.Pocicion.x = 30;
Lanzador.Pocicion.y = height - Lanzador.FotogramasP[0][0].height;
Pv3 = new PVector(54,13);
Brazo = new PersonajeP(0,0,Imagenes(1,1,"img/Brazo/brazo"),V0,A0,Pv3,0);
Brazo.Pocicion.x = Lanzador.Pocicion.x + 76 - 54;
Brazo.Pocicion.y = Lanzador.Pocicion.y + 78 - 13;
Flores.Pocicion.x = Brazo.Pocicion.x + 8 - 17;
Flores.Pocicion.y = Brazo.Pocicion.y + 18 - 50;
Flores.Pivote.x = 17 + 54 - 8;
Flores.Pivote.y = 50 + 13 - 18;
BontonReini = new BotonesC(0,0,50,15,loadFont("Bokkman_Ligjyal.vlw"),loadImage("img/Boton/B1.png"),"Reiniciar",10,color(0,0,0));
BontonReini.ActPocicion(5,height - BontonReini.ImagenBtn.height - 5);
}
//-------------------------------------------------------------------------------
void draw(){
//color de fondo y cuadro para borrar todo cada farme
fill(255);
//clicR = false;
rect(0,0,width,height);
background(FondoT);
if(0 < (AnchoP * floor(Flores.Pocicion.x/AnchoP)) && (numFondos-1) >= floor(Flores.Pocicion.x/AnchoP) ){
FondosPan.FondoFijo( imagenSelec[floor(Flores.Pocicion.x/AnchoP)][0]);
}
FClick();
LansDet();
FCalcLansP();
ElemPersDib(Lanzador,0,0);
ElemPersDib(Brazo,0,Angulo2);
ElemPersDib(Flores,1,Angulo2);
if(0 < (AnchoP * floor(Flores.xr/AnchoP)) && (numFondos-1) >= floor(Flores.xr/AnchoP) ){
int pXdl = constrain(floor(Flores.xa + (Flores.FotogramasP[0][0].width/2)),0,AnchoP -1);
int pYdl = constrain(floor(Flores.Pocicion.y + (Flores.FotogramasP[0][0].height/2)),0,AltoP -1);
loadPixels();
Brillo2(ArrBrillPan);
updatePixels();
}
ElemPersDib(Flores,0,Angulo2);
pushMatrix();
BontonReini.xr = BontonReini.x;
if(Flores.Pocicion.x > (AnchoP * floor(Flores.Pocicion.x/AnchoP)) ){
BontonReini.xa = BontonReini.x - (AnchoP * floor(Flores.Pocicion.x/AnchoP));
BontonReini.x = BontonReini.xa;
}
BontonReini.dibujar();
BontonReini.x = BontonReini.xr;
popMatrix();
if(BontonReini.Click()){
for(i = 0; i < numFondos ; i++){
imagenSelec[i][0] = floor(random(numFondos));
for(j = 0; j < AnchoP; j++){
for(k = 0; k < AltoP ; k++){
ArrBrillPan[i][j][k] = 0;
}
}
}
}
}
//-------------------------------------------------------------------------------
PImage[][] Imagenes(int _ii,int _jj,String _dir){
PImage Direc2[][] = new PImage[_ii][_jj];
String[] NomDir = new String[3];
String dirI;
int ii,jj;
NomDir[0] = _dir;
NomDir[2] = ".png";
for(ii = 0; ii < _ii; ii++){
for(jj = 0; jj < _jj; jj++){
NomDir[1] = str(jj);
dirI = join(NomDir,"");
Direc2[ii][jj] = loadImage(dirI);
}
}
return(Direc2);
}
//-------------------------------------------------------------------------------
void BrilloPan(float _x,float _y){
float r,g,b,adjustBrightness,distance;
int loc;
color c;
loadPixels();
for (int x = 0; x < width; x++ ) {
for (int y = 0; y < height; y++ ) {
loc = x + y*width;
r = red (pixels[loc]);
g = green (pixels[loc]);
b = blue (pixels[loc]);
distance = dist(x,y,_x,_y);
adjustBrightness = ceil((50 - distance)/50) ;
r *= adjustBrightness;
g *= adjustBrightness;
b *= adjustBrightness;
r += (255*floor((distance)/50));
g += (255*floor((distance)/50));
b += (255*floor((distance)/50));
// Constrain RGB to between 0-255
r = constrain(r,0,255);
g = constrain(g,0,255);
b = constrain(b,0,255);
c = color(r,g,b);
pixels[loc] = c;
}
}
updatePixels();
}
//-------------------------------------------------------------------------------
void ElemPersDib(PersonajeP _PerTemp,int _mov,float _angulo){
switch(_mov){
case 1:
_PerTemp.Mover();
break;
}
pushMatrix();
_PerTemp.xr = _PerTemp.Pocicion.x;
if(Flores.Pocicion.x > (AnchoP * floor(Flores.Pocicion.x/AnchoP)) ){
_PerTemp.xa = _PerTemp.Pocicion.x - (AnchoP * floor(Flores.Pocicion.x/AnchoP));
_PerTemp.Pocicion.x = _PerTemp.xa;
}
_PerTemp.Angulo = -_angulo;
_PerTemp.Rotacion();
_PerTemp.dibujar();
_PerTemp.Pocicion.x = _PerTemp.xr;
popMatrix();
}
//-------------------------------------------------------------------------------
void FClick(){
if (mousePressed == true && !BtRtPres){
BtRtPres = true;
}else if(BtRtPres && mousePressed == false) {
clicR = true;
}
}
//-------------------------------------------------------------------------------
void LansDet(){
if (LanzarF == false && clicR){
LanzarF = true;
clicR = false;
BtRtPres = false;
}else if ( LanzarF == true && !AclararImg && clicR){
AclararImg = true;
clicR = false;
BtRtPres = false;
}else if( (clicR || (Flores.Pocicion.y + Flores.FotogramasP[0][0].height) > height) && AclararImg ){
LanzarF = false;
AclararImg = false;
clicR = false;
BtRtPres = false;
Flores.Pivote.x = 17 + 54 - 8;
Flores.Pivote.y = 50 + 13 - 18;
}
}
//-------------------------------------------------------------------------------
void FCalcLansP(){
if (!LanzarF){
Flores.Pocicion.x = Brazo.Pocicion.x + 8 - 17;
Flores.Pocicion.y = Brazo.Pocicion.y + 18 - 50;
Angulo = -atan2(mouseY - (Brazo.Pocicion.y + Brazo.Pivote.y), mouseX - (Brazo.Pocicion.x + Brazo.Pivote.x));
Angulo2 = Angulo;
}else{
if( ((Flores.Pocicion.y + Flores.FotogramasP[0][0].height) <= height) && !AclararImg){
tiempo = tiempo + 0.1;
Flores.Velocidad.x = Vx*cos(Angulo)*tiempo;
Flores.Velocidad.y = 0 - (Vy*sin(Angulo)*tiempo-(0.5*gravedad*(tiempo*tiempo)));
Angulo2 = Angulo2 - 0.3;
Flores.Pivote.x = 17;
Flores.Pivote.y = 50;
}
else{
Flores.Velocidad.x = 0;
Flores.Velocidad.y = 0;
tiempo = 0;
if(0 < (AnchoP * floor(Flores.xr/AnchoP)) && (numFondos-1) >= floor(Flores.xr/AnchoP) ){
int pXdl2 = constrain(floor(Flores.Pocicion.x - (AnchoP * floor(Flores.Pocicion.x/AnchoP)) + (Flores.FotogramasP[0][0].width/2)),0,AnchoP -1);
int pYdl2 = constrain(floor(Flores.Pocicion.y + (Flores.FotogramasP[0][0].height/2)),0,AltoP -1);
LlenarArr2(floor(Flores.Pocicion.x/AnchoP) - 1,pXdl2,pYdl2);
Brillo2(ArrBrillPan);
}
}
}
}
/*/-----------------------------------------------------------------
void LlenarArr(int _x,int _y){
int x,y;
for (x = 0; x < AnchoP; x++ ) {
for (y = 0; y < AltoP; y++ ) {
if(ArrBri[x][y] == 0){
float distance = dist(x,y,_x,_y);
ArrBri[x][y] = (floor(radio/distance));
ArrBri[x][y] = constrain(ArrBri[x][y],0,1);
}
}
}
}
*///-----------------------------------------------------------------
void LlenarArr2(int _k,int _x,int _y){
int x,y;
for (x = 0; x < AnchoP; x++ ) {
for (y = 0; y < AltoP; y++ ) {
if(ArrBrillPan[_k][x][y] == 0){
float distance = dist(x,y,_x,_y);
ArrBrillPan[_k][x][y] = (floor(radio/distance));
ArrBrillPan[_k][x][y] = constrain(ArrBrillPan[_k][x][y],0,1);
}
}
}
}
/*/-----------------------------------------------------------------
void Brillo(int _ArrB[][]){
int loc;
float r,g,b;
color c;
int x,y;
for(x = 0; x < AnchoP; x++){
for(y = 0; y < AltoP; y++){
loc = x + y*AnchoP;
r = red (pixels[loc]);
g = green (pixels[loc]);
b = blue (pixels[loc]);
r *= _ArrB[x][y];
g *= _ArrB[x][y];
b *= _ArrB[x][y];
r += 255 - (255 * _ArrB[x][y]);
g += 255 - (255 * _ArrB[x][y]);
b += 255 - (255 * _ArrB[x][y]);
r = constrain(r,0,255);
g = constrain(g,0,255);
b = constrain(b,0,255);
c = color(r,g,b);
pixels[loc] = c;
_ArrB[x][y] = 0;
}
}
}
*///----------------------------------------
void Brillo2(int _ArrB[][][]){
int loc;
float r,g,b;
color c;
int x,y;
for(x = 0; x < AnchoP; x++){
for(y = 0; y < AltoP; y++){
loc = x + y*AnchoP;
r = red (pixels[loc]);
g = green (pixels[loc]);
b = blue (pixels[loc]);
r *= _ArrB[floor(Flores.Pocicion.x/AnchoP) - 1][x][y];
g *= _ArrB[floor(Flores.Pocicion.x/AnchoP) - 1][x][y];
b *= _ArrB[floor(Flores.Pocicion.x/AnchoP) - 1][x][y];
r += 255 - (255 * _ArrB[floor(Flores.Pocicion.x/AnchoP) - 1][x][y]);
g += 255 - (255 * _ArrB[floor(Flores.Pocicion.x/AnchoP) - 1][x][y]);
b += 255 - (255 * _ArrB[floor(Flores.Pocicion.x/AnchoP) - 1][x][y]);
r = constrain(r,0,255);
g = constrain(g,0,255);
b = constrain(b,0,255);
c = color(r,g,b);
pixels[loc] = c;
}
}
}
mini juego que se trata de descubrir imágenes.
Un click para lanzar.
Otro click para parar y revelar parte de la imagen.
Un click mas para regresar al lanzador.
Click en reiniciar para recomenzar con imagenes en diferente orden.