Loading...
Logo
Processing Forum
I am making a game which contains killing a monster. I want to get some private color for monster and when i get this color ( i want to get color when my hero is near to the monster) my hero's y will be 1321321. How can i get this color ? I couldn't find any way to make my hero disappear If you know please inform me.( I used 2 vectors for those monster and hero)

Here is a video of my game


I'm sory for the video :P If you watch you will know what I mean. But the yellow one is enemy and the other one is hero.

Thank you so much ! 

Replies(12)



maybe read about collisions
http://www.processing.org/learning/topics/collision.html

you can compare x positions of monster with x position of hero:

when x positions of monster + width of monster/2 > x position of hero - width hero / 2 -> collision

or show some code....
collision couldn't work we have 2 vectors the monster's is (10,440) and he is going between x(10,400) and the other vector is hero's (300,40) when the game starts hero is falling down to the 450. 

Copy code
  1. kare=new PVector(x,y);
  2. yaratik=new PVector(10,442);
  3. x=300;
  4. y=40;
yaratik=enemy 
kare=our hero

here is another video 
this is my main codes.. 

String grafik_ana_klasor="Data";
PImage arkaplan, ananas, apple, banana, cilek, burger, kapi, kapikilit, anahtar;
PImage duvarres, superduvar, yardimci; 
PVector kare, yaratik;
PFont font;
String s="Siyah bir anahtar olmali bir yerlerde ! O anahtar sana geri getirecek kaybolan taslari!";
int aa=3600;
int bb=50;
int time1, time2=20;
int count=0;
boolean r=false;
boolean u;
boolean d=false;
boolean l=false;
boolean zipla=false;
boolean dursag=false;
boolean dursol=false; 
boolean ustundedurdum=false;
boolean a=false;
boolean oyunoyna=false;
boolean kilit=true;
color c= color(0, 128, 144);
float burgerx=400;
float burgery=440;
float ananasx=1300;
float ananasy=440;
float cilekx=700;
float cileky=268;
float engelx=1042;
float engely=380;
float anahtarx=6256;
float anahtary=440;
float kapix=1894;
float kapiy=100;
float superduvarx=4472;
float superduvary=350;
float yardimcix=3644;
float yardimciy=344;
float x=300;
float y=40;
float canavarx=10;
float canavary=440;
float speedY=20; 
float gravity=0.2;
float px, py=10;
float ivme=2;
float canavarson=400;
float canavarbaslangic=10;
float canavarhiz=2;
int number=0;
Canavar canavar;
Duvaryatay duvar1, duvar2, duvar3, duvar1alt, duvar4, duvar5, duvar6, duvar7, duvar8, duvar9, duvar10, duvar11, duvar12, duvar13, duvar14, duvar15;
Duvarengel duvarengel1, duvarengel2, duvarengel3, duvarengel4, duvarengel5, duvarengel6, duvarengel7, duvarengel8;
Duvardikey duvardikey1, duvardikey2;
/*------------------------------------------------------------------------SETUP------------------------------------------------*/
void setup()
{

  size(800, 600);
  kare=new PVector(x, y);
  yaratik=new PVector(10, 442);
  arkaplan=new PImage();
  arkaplan=loadImage("arkaplanbulut.jpg");
  burger=new PImage();
  burger=loadImage("burger.png");
  ananas=new PImage();
  ananas=loadImage("ananas.png");
  duvarres=new PImage();
  duvarres=loadImage("duvar.png");
  cilek=new PImage();
  cilek=loadImage("cilek.png");
  anahtar=new PImage();
  anahtar=loadImage("anahtar.png");
  kapi=new PImage();
  kapi=loadImage("kapi.png");
  kapikilit=new PImage();
  kapikilit=loadImage("kapikilit.png");
  superduvar=new PImage();
  superduvar=loadImage("anahtar2.png");
  yardimci=new PImage();
  yardimci=loadImage("yardimci.png");
  karakter_sag=new Animasyon("karakter_sag", 7, 6);
  karakter_sol=new Animasyon("karakter_sol", 7, 6);
  karakter_stop=new Animasyon("karakter_stop", 1, 4);
  karakter_jumpright=new Animasyon("karakter_jumpright", 1, 4);
  karakter_jumpleft=new Animasyon("karakter_jumpleft", 1, 4);
  karakter_jump=new Animasyon("karakter_jump", 1, 4);
  canavar_sag=new Animasyon("canavar_sag", 3, 6);
  canavar_sol=new Animasyon("canavar_sol", 3, 6);
  font = loadFont("Garamond-Bold-48.vlw");
  canavar=new Canavar(400, 10, 2);
}
/*------------------------------------------------------------------------DRAW------------------------------------------------*/
void draw()
{
  duvar1=new Duvaryatay(0, 462, 20);
  duvar2=new Duvaryatay(660, 300, 5);
  duvar3=new Duvaryatay(850, 462, 30);
  duvar4=new Duvaryatay(2010, 462, 110);
  duvar5=new Duvaryatay(2310, 350, 15);
  duvar6=new Duvaryatay(2470, 254, 15);
  duvar7=new Duvaryatay(3800, 350, 20);
  duvar8=new Duvaryatay(4504, 350, 10);
  duvar9=new Duvaryatay(3388, 302, 4);
  duvar10=new Duvaryatay(1232, 270, 3);
  duvar11=new Duvaryatay(6000, 462, 10);
  duvar12=new Duvaryatay(6032, 302, 4);
  duvardikey1=new Duvardikey(5498, 366, 3);
  duvardikey2=new Duvardikey(6320, -20, 16);
  duvarengel1=new Duvarengel(1042, 334, 1042, 334, 1042, 3, 4);
  duvarengel2=new Duvarengel(1426, 302, 1426, 302, 1426, 2, 5);
  duvarengel3=new Duvarengel(3194, 398, 3194, 398, 3194, 1, 2);
  duvarengel4=new Duvarengel(3260, 366, 3260, 366, 3260, 1, 3);
  duvarengel5=new Duvarengel(3324, 334, 3324, 334, 3324, 1, 4);
  duvarengel6=new Duvarengel(3580, 366, 3580, 366, 3580, 5, 3);
  duvarengel7=new Duvarengel(4856, 398, 4856, 398, 4856, 4, 2);
  background(255);
  pushMatrix();
  translate(px, py);
  image(arkaplan, 0, -10);
  yardimci();
  image(arkaplan, 3350, -10);
  image(burger, burgerx, burgery);
  image(ananas, ananasx, ananasy);
  image(cilek, cilekx, cileky);
  image(anahtar, anahtarx, anahtary);
  image(kapi, kapix, kapiy);
  if (kilit) {
    image(kapikilit, kapix, kapiy);
  }
  image(superduvar, superduvarx, superduvary);
  image(yardimci, yardimcix, yardimciy);  
  canavar.ciz(yaratik);
  duvar1.ciz();
  duvar2.ciz();
  duvar3.ciz();
  duvar4.ciz();
  duvar5.ciz();
  duvar6.ciz();
  duvar7.ciz();
  duvar8.ciz();
  duvar9.ciz();
  duvar10.ciz();
  duvar11.ciz();
  duvar12.ciz();
  duvardikey1.ciz();
  duvardikey2.ciz();
  duvarengel1.ciz();
  duvarengel2.ciz();
  duvarengel3.ciz();
  duvarengel4.ciz();
  duvarengel5.ciz();
  duvarengel6.ciz();
  duvarengel7.ciz();
  popMatrix();
  fill(0);
  stroke(50);

  /*-----------------------------------TUŞLAR------------------------------------------------*/
  if (d)
  {
    kare.y+=1;
    karakter_stop.ciz(kare, 1);
  }
  if (r)
  {
    if (dursag==false)
    {
      px=px-2;
      karakter_sag.ciz(kare, 1);
      burgerx=burgerx-2;
      ananasx=ananasx-2;
      cilekx=cilekx-2;
      kare.x=kare.x+0.02;
      engelx=engelx-2;
      anahtarx-=2;
      kapix-=2;
      superduvarx-=2;
      yardimcix-=2;
      aa-=2;
      canavar.donus2-=2;
      canavar.donus1-=2;
      yaratik.x-=2;
    }
    else
    {
      karakter_sag.ciz(kare, 1);
    }
  }

  if (u)
  {
    if (time1<-2 || kare.y<=0)
    {
      if (ustundedurdum==false)
      {
        u=false;
        ustundedurdum=true;
      }

      else
      {
        kare.y=kare.y;
      }
    }
    zipla=false;
    if (time1<=0 && time1>=-2)
    {
      kare.y=kare.y-6.5;
      ivme=ivme+gravity;
    }

    ustundedurdum=false;
  }

  if (l)
  {
    if (dursol==false)
    {
      px=px+2;
      karakter_sol.ciz(kare, 1);
      burgerx=burgerx+2;
      ananasx=ananasx+2;
      cilekx=cilekx+2;
      kare.x=kare.x-0.02;
      engelx=engelx+2;
      anahtarx+=2;
      kapix+=2;
      superduvarx+=2;
      yardimcix+=2;  
      canavar.donus1+=2;
      canavar.donus2+=2;
      yaratik.x+=2;
      aa+=2;
    }
    else
    {
      karakter_sol.ciz(kare, 1);
    }
  }
  if (u && !r && !l && !d )
  {
    karakter_jump.ciz(kare, 1);
  }
  if (!u)
  {
    ivme=ivme*-0.2;
    carpisma ();
  }


  if ( !u && !r && !l && !d )
  {
    karakter_stop.ciz(kare, 1);
  }
  dusme();
  meyvetoplama();
  engellerecarpma();
  anahtaral();
  alttancarpma();
  //olme();
  float m = mag(yaratik.x,kare.x);
  println(m);
//  println(kare);
//  println(yaratik);
}

/*------------------------------------------------------------------------KEYCODELAR------------------------------------------------*/
void keyPressed()
{
  if (keyCode==RIGHT || key =='d')
  {
    r=true;
  }
  if (key == ' ' || key == 'w' || keyCode == UP)
  {

    if (kare.y>=450-32 || zipla)
    {
      if (time1<=0)
      {
        u=true;
        ustundedurdum=true;
      }
    }
    ustundedurdum=false;
    time1--;
  }
  if (keyCode==DOWN || key == 's')
  {
    d=true;
  }   
  if (keyCode==LEFT || key == 'a')
  {
    l=true;
  }
}
void keyReleased()
{
  if (keyCode==RIGHT || key == 'd')
  {
    r=false;
  }
  if (keyCode==UP || key == 'w'|| key == ' ')
  {
    u=false;
    time1=0;
  }
  if (keyCode==LEFT || key == 'a')
  {
    l=false;
  }
  if (keyCode==DOWN || key == 's')
  {
    d=false;
  }
}




this is animation class for hero and monster 


Copy code
  1. Animasyon karakter_sag;
  2. Animasyon karakter_sol;
  3. Animasyon karakter_stop;
  4. Animasyon karakter_jumpright;
  5. Animasyon karakter_jumpleft;
  6. Animasyon karakter_jump;
  7. Animasyon canavar_sag;
  8. Animasyon canavar_sol;
  9. class Animasyon {
  10.   PImage[] resimler;
  11.   int sayi;
  12.   int frame=0;
  13.   int hiz, hiz2;

  14.   Animasyon(String Resim, int tsayi, int hizx)
  15.   {
  16.     hiz=hiz2=hizx;
  17.     sayi=tsayi;
  18.     resimler=new PImage[sayi];
  19.     for (int i=0;i<sayi;i++)
  20.     {
  21.       String dosya=grafik_ana_klasor+"/animasyon/"+Resim+"/ByBarT_"+nf(i, 2)+".png";
  22.       resimler[i]=loadImage(dosya);
  23.     }
  24.   }

  25.   void ciz(PVector v, int n)
  26.   {
  27.     if (hiz<=0)
  28.     {
  29.       frame=(frame+1)%sayi;
  30.       hiz=hiz2;
  31.     }
  32.     hiz--;
  33.     for (int i=0;i<n;i++)
  34.     {
  35.       image(resimler[frame], v.x+i*en(), v.y);
  36.     }
  37.   }

  38.   int en()
  39.   {
  40.     return resimler[0].width;
  41.   }
  42.   int boy()
  43.   {
  44.     return resimler[0].height;
  45.   }
  46. }
and class enemy 

Copy code
  1. class Canavar
  2. {

  3.   int donus1;
  4.   int donus2;
  5.   float hiz;

  6.   
  7.   Canavar(int donus1x, int donus2x,int hizx)
  8.   {
  9.     donus1=donus1x;
  10.     donus2=donus2x;
  11.     hiz=hizx;

  12.   }
  13.   void ciz(PVector n)
  14.   {
  15.     
  16.     n.x+=hiz;
  17.     
  18.    if(n.x>donus1-2 || n.x<donus2)
  19.   {
  20.     hiz=-hiz;
  21.     number+=1;
  22.   }
  23.     if(number%2==0)
  24.     {
  25.     canavar_sag.ciz(n,1);
  26.     }
  27.     else if(number%2==1)
  28.     {
  29.       canavar_sol.ciz(n,1);
  30.     }
  31.  
  32.   }
}




Hello,

we can't run your code - too many images...

you could zip it and load it to rapidshare


Remarks:

I stick to my idea with collision - just check if dist () is smaller a value

look up dist()

http://www.processing.org/reference/dist_.html

when the dist (distance) between the two (hero and enemy) is small, they collide?
Then hero changes color or does he die?
 
When he dies, make a variable heroDead=true;
When you paint the hero : only paint the hero when heroDead = false


if you want to get enemy's color use get ()
that works not only for images but for the general screen as well:

http://www.processing.org/reference/get_.html


Remark:
for duvardikey1, duvardikey2 etc. you can use a array. I think.


Greetings, Chrisir  


Here is my game :) thank you so much for your attention. There is somethings you have to know;
canavar=enemy,
kare=hero's vector
carpisma=collision,
dusme=fall,
duvar=wall,
duvarengel=blocks the green one
meyvetoplama=picking fruits ( it has not finished)
yardimci=the old guy in the game,
animasyon=animation,
I dont know how can i use array for walls :S :(:(:(




It is a very nice Game!



is this the enemy canavar and the hero ?

Has canavar the position canavarx?





When yaratik is the enemy, olme() works.

What do you want olme to do?

With
    yaratik.y=1321321321;
you place yaratik very far below the screen.
You could also have a var named yaratikIsAlive
and say yaratikIsAlive = false;
and don't paint yaratik anymore when yaratikIsAlive == false.


Greetings, Chrisir 





Thank you :)

this is canavar(enemy the yellow mushroom)
canavar=new Canavar(400,10,2);

and the hero is the other guy

enemy's x and y
 yaratik=new PVector(10,442);
when i write canavar.ciz(yaratik) it drows enemy using PVector yaratik (ciz means draw)

I want to kill or die when our hero touchs the enemy. This is what i want to do with olme() olme means die,

 I used this 

if((yaratik.x > kare.x) && (yaratik.x< kare.x+32) && (yaratik.y<kare.y+32)) // you remember kare=hero :) 
  {
   yaratik.y=13212; // we can use var. or bool. here 
  }


but I couldn't write correctly this codes. When I thouch Right kare.x+=0.02 ( I used this function to do falling and collision if I don't write it our hero's x will always be 300 so we couldn't work with kare.x) thats why while yaratik.x is growing by 2 our hero's x is growing by 0.02. Here is the problem :) If you can help me I will be very thankful to you:):) 

Greetings Barkın :)



you want the hero to die when he touches the enemy.

So in olme() have a var named kareIsAlive
and say kareIsAlive = false;
he died.
and don't paint kare anymore when kareIsAlive == false

You could also have a splash screen then or restart kare at the beginning of game or the last save position

Remarks:
  • with Ctrl-t in every tab you can beautify your code (the indents).
  • for the forum it is better when your program is in english.
  • Why do you say one time canavar but another time yaratik ?
  • You have classes for your guys. But then, put all the properties into the class and not only half of them

Then read about arrays: http://processing.org/reference/Array.html
There's a whole section on Array Functions in the reference
http://processing.org/reference/

Greetings, Chrisir  


I've known them already my problem is not with hero's death my problem is I couldn't hit mushroom and hero :/ 

When I press right hero's X increasing 0.02 when I press left hero's X decreasing 0.02 

But at the moment yaratik's ( or canavar same thing) X increasing and decreasing 2

When I wrote 
 if((yaratik.x > kare.x) && (yaratik.x< kare.x+32) && (yaratik.y<kare.y+32))
this it works but if I move hero out of the yaratik's moving distance hero's X is 304.1321321 like this.So this function kill me AGAİN however I was not hit yaratik. I couldn't do this case. 


ok, so hero dies.

why not start again,
mushroom to it's first position

hero at (300,40) like when the game starts hero is falling down to the 450.

you can also have a screen saying you died and show the sign for 1.2 seconds

there must be a pause anyway when hero dies.





Dear Chrisir 

I couldn't make the "if" which cause hero dies I need this "if". I need to find if(?) this question mark. After that I can do restart it is not hard


So in olme()
there's your if