Knife Movemement

Ok so basically i want a knife to o down like 600 px, and if its there go back. But i want it to look smooth and that other things dont freeze while the knife goes down. Thats. (btw the comments are german) My Code:

//minim implementieren
import ddf.minim.*;
Minim minim;
AudioPlayer UpgradeSound;
AudioPlayer backgroundMusic;

//int fürs Förderband
int a=30;
int b=30;

//int fürs Messer
int m=600;
//int für die Sushi
int s = 50;
int r =3;

//coins also Geld
int coins=0;

//PreisKosten
int PriceCook=10;
int PriceKnife=10;
int PriceSushiRoll=10;
int PriceIngredients=10;

//Variablen zum LVL/Kaufpreis Anzeigen
String BuyPrice="Buy Price:";

int    LvlCook=0;
String TextCook="Cook LVL";

int    LvlKnife=0;
String TextKnife="Knife LVL";

int    LvlSushiRoll=0;
String TextSushiRoll="Sushi LVL";

int    LvlIngredients=0;
String TextIngredients="Ingre LVL";

//int für AFK generierte Coins
int AutoCoins=0;

void setup() {
  //Größe festlegen
  size(1200, 900);
  //Sound Datei zu Variable deklarieren&Hintergrundmusik loopen
  minim = new Minim(this);
  backgroundMusic = minim.loadFile("Background_Beat.mp3");
  UpgradeSound = minim.loadFile("UpgradeSound.wav");

  backgroundMusic.play();
  backgroundMusic.loop ();
}


void messerMove(){
  if(m>500){
    m += 20;
  } else if (m<600){
    m-=20;
  }
}


void draw() {

  //Tresen Grafik
  background(0); 
  fill(70, 45, 0);
  triangle(0, 500, 100, 400, 0, 400);
  noStroke();
  rect(0, 600, 1100, 300);
  quad(100, 600, 0, 600, 0, 500, 100, 400);
  stroke(0);
  fill(0);
  quad(25, 675, 25, 625, 75, 575, 75, 625);
  line(0, 500, 100, 400);
  line(0, 700, 100, 600);
  line(0, 700, 1000, 700);
  line(1000, 700, 1000, 900);
  line(1000, 700, 1100, 600);
  triangle(1000, 900, 1100, 800, 1100, 900);
  fill(30, 30, 30);
  quad(30, 670, 70, 630, 1040, 630, 1000, 670);


  //Förderband Grafik & Animation
  fill(0);
  line(a, 670, a+40, 630);
  line(a+30, 670, a+70, 630);
  line(a+60, 670, a+100, 630);
  line(a+90, 670, a+130, 630);
  line(a+120, 670, a+160, 630);
  line(a+150, 670, a+190, 630);
  line(a+180, 670, a+220, 630);
  line(a+210, 670, a+250, 630);
  line(a+240, 670, a+280, 630);
  line(a+270, 670, a+310, 630);
  line(a+300, 670, a+340, 630);
  line(a+330, 670, a+370, 630);
  line(a+360, 670, a+400, 630);
  line(a+390, 670, a+430, 630);
  line(a+420, 670, a+460, 630);
  line(a+450, 670, a+490, 630);
  line(a+480, 670, a+520, 630);
  line(a+510, 670, a+550, 630);
  line(a+540, 670, a+580, 630);
  line(a+570, 670, a+610, 630);
  line(a+600, 670, a+640, 630);
  line(a+630, 670, a+670, 630);
  line(a+660, 670, a+700, 630);
  line(a+690, 670, a+730, 630);
  line(a+720, 670, a+760, 630);
  line(a+750, 670, a+790, 630);
  line(a+780, 670, a+820, 630);
  line(a+810, 670, a+850, 630);
  line(a+840, 670, a+880, 630);
  line(a+870, 670, a+910, 630);
  line(a+900, 670, a+940, 630);
  line(a+930, 670, a+970, 630);
  //if zur wiederholung der Förderband Animation
  if (a==60) {
    a = 30;
  }
  a= a +3;

  //Sushi Grafik
  fill(0, 26, 17);
  rect(40, 615, s-40, 40);
  ellipse(s, 635, 30, 40);
  noStroke();
  ellipse(40, 635, 30, 40);
  ellipse(s -r, 635, 30, 40);
  stroke(0);
  fill(255);
  ellipse(s+2, 635, 25, 35);
  fill(255, 170, 153);
  ellipse(s+2.5, 635, 15, 20);  
  s = s +3;


  //Coins Anzeige
  fill(255);
  if (coins<100) {
    text("Coins: "+coins, 1000, 100);
  }
  textSize(50);
  //If für Größere Coins Anzahlen
  if (coins>=100 && coins<1000) {
    text("Coins: "+coins, 925, 100);
  }
  if (coins>=1000 && coins<10000) {
    text("Coins: "+coins, 890, 100);
  }
  if (coins>=10000 && coins<100000) {
    text("Coins: "+coins, 855, 100);
  }
  if (coins>=100000 && coins<1000000) {
    text("Coins: "+coins, 820, 100);
  }
  if (coins>=1000000 && coins<10000000) {
    text("Coins: "+coins, 785, 100);
  }
  if (coins>=10000000 && coins<100000000) {
    text("Coins: "+coins, 750, 100);
  }
  if (coins>=100000000 && coins<1000000000) {
    text("Coins: "+coins, 715, 100);
  }

  //Coins Berechnung Aufgrund der Updates

  coins=coins + AutoCoins;

  //Upgrades Grafik
  fill(170, 100, 0);
  rect(25, 725, 200, 150);
  rect(275, 725, 200, 150);
  rect(525, 725, 200, 150);
  rect(775, 725, 200, 150);


  //LVL Anzeige Upgrades
  fill(255);
  textSize(40);

  if (mouseX > 25 && mouseX < 225 && mouseY > 725 && mouseY <875) {
    text(BuyPrice, 35, 775);
    text(PriceCook, 115, 825);
  } else {
    text(TextCook, 35, 775);
    text(LvlCook, 115, 825);
  }

  if (mouseX > 275 && mouseX < 475 && mouseY > 725 && mouseY <875) {
    text(BuyPrice, 285, 775);
    text(PriceKnife, 365, 825);
  } else {
    text(TextKnife, 285, 775);
    text(LvlKnife, 365, 825);
  }

  if (mouseX > 525 && mouseX < 725 && mouseY > 725 && mouseY <875) {
    text(BuyPrice, 535, 775);
    text(PriceSushiRoll, 615, 825);
  } else {
    text(TextSushiRoll, 535, 775);
    text(LvlSushiRoll, 615, 825);
  }

  if (mouseX > 775 && mouseX < 975 && mouseY > 725 && mouseY < 875) {
    text(TextCook, 785, 775);
    text(PriceIngredients, 865, 825);
    if (coins>=100 && coins<1000) {
      text("Coins: "+coins, 925, 100);
    }
    if (coins>=1000 && coins<10000) {
      text("Coins: "+coins, 890, 100);
    }
    if (coins>=10000 && coins<100000) {
      text("Coins: "+coins, 855, 100);
    }
    if (coins>=100000 && coins<1000000) {
      text("Coins: "+coins, 820, 100);
    }
    if (coins>=1000000 && coins<10000000) {
      text("Coins: "+coins, 785, 100);
    }
    if (coins>=10000000 && coins<100000000) {
      text("Coins: "+coins, 750, 100);
    }
    if (coins>=100000000 && coins<1000000000) {
      text("Coins: "+coins, 715, 100);
    }
  } else {
    text(TextIngredients, 785, 775);
    text(LvlIngredients, 865, 825);
  }
  //Messer Grafik
  bezier(1000, m+50, 1180, m-100, 1030, m, 1100, m-100);
  fill(130, 46, 40);
  quad(1070, m-60,1080,m-30,1160,m-140,1140,m-160);
  
  
}







//Upgrade Mechanik
void mouseReleased() {
  //Gratis Geld für Testing
  if (mouseButton == RIGHT) {
      messerMove();
  }
  if (mouseButton == CENTER) {
    coins =+ 100000;
  }
  //Upgrade Köche
  if (mouseX > 25 && mouseX < 225 ) {
    if (mouseY > 725 && mouseY <875) {
      if (mouseButton == LEFT) {
        if (coins >= PriceCook) {
          UpgradeSound.play();
          UpgradeSound.rewind();
          coins = coins - PriceCook;
          LvlCook++;
          AutoCoins=AutoCoins * 2;
          PriceCook=PriceCook * 10;
          if (AutoCoins==0) {
            AutoCoins++;
          }
        }
      }
    }
  }
  //Upgrade Messer
  if (mouseX > 275 && mouseX < 475 ) {
    if (mouseY > 725 && mouseY <875) {
      if (mouseButton == LEFT) {
        if (coins >= PriceKnife) {
          UpgradeSound.play();
          UpgradeSound.rewind();
          coins = coins - PriceKnife;
          LvlKnife++;
        }
      }
    }
  }
  //Upgrade Sushi Rollen
  if (mouseX > 525 && mouseX < 725 ) {
    if (mouseY > 725 && mouseY <875) {
      if (mouseButton == LEFT) {
        if (coins >= PriceSushiRoll) {
          UpgradeSound.play();
          UpgradeSound.rewind();
          coins = coins - PriceSushiRoll;
          LvlSushiRoll++;
        }
      }
    }
  }
  //Upgrade Zutaten
  if (mouseX > 775 && mouseX < 975 ) {
    if (mouseY > 725 && mouseY <875) {
      if (mouseButton == LEFT) {
        if (coins >= PriceIngredients) {
          UpgradeSound.play();
          UpgradeSound.rewind();
          coins = coins - PriceIngredients;
          LvlIngredients++;
        }
      }
    }
  }
}
1 Like

Normally you say m+=m_add;

then use the if to say m_add should be positive or negative (if (m>600) m_add= -1*abs(m_add); )

Your condition is not logical but nvm

1 Like

Well, taking a fast look, your if condition is not reaching the second statement :thinking: :

else if (m<600)

A fast solution, but maybe isn’t what you want :sweat_smile:, is:

void messerMove(){
  if(m>500 && m <= 600){
    m += 20;
  } else if (m<600){
    m-=20;
  }
}

But if you want a more fluid movement one way to do it can be using flags and adding uniformly increments while that condition :wink:, and in order to “restart” the position of the knife, maybe if the limit is reached then m = 600; (the start value) :hocho:.

Care about your " if else" statements :see_no_evil:

Hope this helps in something, if not, feel free to continue asking :grimacing:.

1 Like

here is knife animation with rotate

you could also use translate


//minim implementieren
import ddf.minim.*;
Minim minim;
AudioPlayer UpgradeSound;
AudioPlayer backgroundMusic;

//int fürs Förderband
int a=30;
int b=30;

//int fürs Messer
int mForMesser=600;
float angleForMesser=2; 
float angleForMesser_Add = -.01; 

//int für die Sushi
int s = 50;
int r =3;

//coins also Geld
int coins=0;

//PreisKosten
int PriceCook=10;
int PriceKnife=10;
int PriceSushiRoll=10;
int PriceIngredients=10;

//Variablen zum LVL/Kaufpreis Anzeigen
String BuyPrice="Buy Price:";

int    LvlCook=0;
String TextCook="Cook LVL";

int    LvlKnife=0;
String TextKnife="Knife LVL";

int    LvlSushiRoll=0;
String TextSushiRoll="Sushi LVL";

int    LvlIngredients=0;
String TextIngredients="Ingre LVL";

//int für AFK generierte Coins
int AutoCoins=0;

void setup() {
  //Größe festlegen
  size(1200, 900);
  //Sound Datei zu Variable deklarieren&Hintergrundmusik loopen
  minim = new Minim(this);
  backgroundMusic = minim.loadFile("Background_Beat.mp3");
  UpgradeSound = minim.loadFile("UpgradeSound.wav");

  //backgroundMusic.play(); // !!!! 
  // backgroundMusic.loop ();
}


void messerMove() {
  if (mForMesser>500) {
    mForMesser += 20;
  } else if (mForMesser<600) {
    mForMesser-=20;
  }
}


void draw() {

  //Tresen Grafik
  background(0); 
  fill(70, 45, 0);
  triangle(0, 500, 100, 400, 0, 400);
  noStroke();
  rect(0, 600, 1100, 300);
  quad(100, 600, 0, 600, 0, 500, 100, 400);
  stroke(0);
  fill(0);
  quad(25, 675, 25, 625, 75, 575, 75, 625);
  line(0, 500, 100, 400);
  line(0, 700, 100, 600);
  line(0, 700, 1000, 700);
  line(1000, 700, 1000, 900);
  line(1000, 700, 1100, 600);
  triangle(1000, 900, 1100, 800, 1100, 900);
  fill(30, 30, 30);
  quad(30, 670, 70, 630, 1040, 630, 1000, 670);


  //Förderband Grafik & Animation
  fill(0);
  line(a, 670, a+40, 630);
  line(a+30, 670, a+70, 630);
  line(a+60, 670, a+100, 630);
  line(a+90, 670, a+130, 630);
  line(a+120, 670, a+160, 630);
  line(a+150, 670, a+190, 630);
  line(a+180, 670, a+220, 630);
  line(a+210, 670, a+250, 630);
  line(a+240, 670, a+280, 630);
  line(a+270, 670, a+310, 630);
  line(a+300, 670, a+340, 630);
  line(a+330, 670, a+370, 630);
  line(a+360, 670, a+400, 630);
  line(a+390, 670, a+430, 630);
  line(a+420, 670, a+460, 630);
  line(a+450, 670, a+490, 630);
  line(a+480, 670, a+520, 630);
  line(a+510, 670, a+550, 630);
  line(a+540, 670, a+580, 630);
  line(a+570, 670, a+610, 630);
  line(a+600, 670, a+640, 630);
  line(a+630, 670, a+670, 630);
  line(a+660, 670, a+700, 630);
  line(a+690, 670, a+730, 630);
  line(a+720, 670, a+760, 630);
  line(a+750, 670, a+790, 630);
  line(a+780, 670, a+820, 630);
  line(a+810, 670, a+850, 630);
  line(a+840, 670, a+880, 630);
  line(a+870, 670, a+910, 630);
  line(a+900, 670, a+940, 630);
  line(a+930, 670, a+970, 630);
  //if zur wiederholung der Förderband Animation
  if (a==60) {
    a = 30;
  }
  a= a +3;

  //Sushi Grafik
  fill(0, 26, 17);
  rect(40, 615, s-40, 40);
  ellipse(s, 635, 30, 40);
  noStroke();
  ellipse(40, 635, 30, 40);
  ellipse(s -r, 635, 30, 40);
  stroke(0);
  fill(255);
  ellipse(s+2, 635, 25, 35);
  fill(255, 170, 153);
  ellipse(s+2.5, 635, 15, 20);  
  s = s +3;


  //Coins Anzeige
  fill(255);
  if (coins<100) {
    text("Coins: "+coins, 1000, 100);
  }
  textSize(50);
  //If für Größere Coins Anzahlen
  if (coins>=100 && coins<1000) {
    text("Coins: "+coins, 925, 100);
  }
  if (coins>=1000 && coins<10000) {
    text("Coins: "+coins, 890, 100);
  }
  if (coins>=10000 && coins<100000) {
    text("Coins: "+coins, 855, 100);
  }
  if (coins>=100000 && coins<1000000) {
    text("Coins: "+coins, 820, 100);
  }
  if (coins>=1000000 && coins<10000000) {
    text("Coins: "+coins, 785, 100);
  }
  if (coins>=10000000 && coins<100000000) {
    text("Coins: "+coins, 750, 100);
  }
  if (coins>=100000000 && coins<1000000000) {
    text("Coins: "+coins, 715, 100);
  }

  //Coins Berechnung Aufgrund der Updates

  coins=coins + AutoCoins;

  //Upgrades Grafik
  fill(170, 100, 0);
  rect(25, 725, 200, 150);
  rect(275, 725, 200, 150);
  rect(525, 725, 200, 150);
  rect(775, 725, 200, 150);


  //LVL Anzeige Upgrades
  fill(255);
  textSize(40);

  if (mouseX > 25 && mouseX < 225 && mouseY > 725 && mouseY <875) {
    text(BuyPrice, 35, 775);
    text(PriceCook, 115, 825);
  } else {
    text(TextCook, 35, 775);
    text(LvlCook, 115, 825);
  }

  if (mouseX > 275 && mouseX < 475 && mouseY > 725 && mouseY <875) {
    text(BuyPrice, 285, 775);
    text(PriceKnife, 365, 825);
  } else {
    text(TextKnife, 285, 775);
    text(LvlKnife, 365, 825);
  }

  if (mouseX > 525 && mouseX < 725 && mouseY > 725 && mouseY <875) {
    text(BuyPrice, 535, 775);
    text(PriceSushiRoll, 615, 825);
  } else {
    text(TextSushiRoll, 535, 775);
    text(LvlSushiRoll, 615, 825);
  }

  if (mouseX > 775 && mouseX < 975 && mouseY > 725 && mouseY < 875) {
    text(TextCook, 785, 775);
    text(PriceIngredients, 865, 825);
    if (coins>=100 && coins<1000) {
      text("Coins: "+coins, 925, 100);
    }
    if (coins>=1000 && coins<10000) {
      text("Coins: "+coins, 890, 100);
    }
    if (coins>=10000 && coins<100000) {
      text("Coins: "+coins, 855, 100);
    }
    if (coins>=100000 && coins<1000000) {
      text("Coins: "+coins, 820, 100);
    }
    if (coins>=1000000 && coins<10000000) {
      text("Coins: "+coins, 785, 100);
    }
    if (coins>=10000000 && coins<100000000) {
      text("Coins: "+coins, 750, 100);
    }
    if (coins>=100000000 && coins<1000000000) {
      text("Coins: "+coins, 715, 100);
    }
  } else {
    text(TextIngredients, 785, 775);
    text(LvlIngredients, 865, 825);
  }
  //Messer Grafik
  pushMatrix(); 
  translate(950, 10); 
  rotate(angleForMesser); 
  bezier(0, mForMesser+50, 180, mForMesser-100, 30, mForMesser, 100, mForMesser-100);
  fill(130, 46, 40);
  quad(70, mForMesser-60, 80, mForMesser-30, 60, mForMesser-140, 40, mForMesser-160);
  angleForMesser+=angleForMesser_Add;
  println (angleForMesser); 
  if (angleForMesser<0.0)
    angleForMesser_Add= abs(angleForMesser_Add);
  if (angleForMesser>0.6)
    angleForMesser_Add=abs(angleForMesser_Add)*-1;
  popMatrix();
}

// ---------------------------------------------------------------------------------------------------

//Upgrade Mechanik
void mouseReleased() {
  //Gratis Geld für Testing
  if (mouseButton == RIGHT) {
    messerMove();
  }
  if (mouseButton == CENTER) {
    coins =+ 100000;
  }
  //Upgrade Köche
  if (mouseX > 25 && mouseX < 225 ) {
    if (mouseY > 725 && mouseY <875) {
      if (mouseButton == LEFT) {
        if (coins >= PriceCook) {
          UpgradeSound.play();
          UpgradeSound.rewind();
          coins = coins - PriceCook;
          LvlCook++;
          AutoCoins=AutoCoins * 2;
          PriceCook=PriceCook * 10;
          if (AutoCoins==0) {
            AutoCoins++;
          }
        }
      }
    }
  }
  //Upgrade Messer
  if (mouseX > 275 && mouseX < 475 ) {
    if (mouseY > 725 && mouseY <875) {
      if (mouseButton == LEFT) {
        if (coins >= PriceKnife) {
          UpgradeSound.play();
          UpgradeSound.rewind();
          coins = coins - PriceKnife;
          LvlKnife++;
        }
      }
    }
  }
  //Upgrade Sushi Rollen
  if (mouseX > 525 && mouseX < 725 ) {
    if (mouseY > 725 && mouseY <875) {
      if (mouseButton == LEFT) {
        if (coins >= PriceSushiRoll) {
          UpgradeSound.play();
          UpgradeSound.rewind();
          coins = coins - PriceSushiRoll;
          LvlSushiRoll++;
        }
      }
    }
  }
  //Upgrade Zutaten
  if (mouseX > 775 && mouseX < 975 ) {
    if (mouseY > 725 && mouseY <875) {
      if (mouseButton == LEFT) {
        if (coins >= PriceIngredients) {
          UpgradeSound.play();
          UpgradeSound.rewind();
          coins = coins - PriceIngredients;
          LvlIngredients++;
        }
      }
    }
  }
}
2 Likes