how do i make my images spin? (without popmatrix and all that stuff i don't understand)

edited January 2018 in Library Questions

Asteroid2

this is the picture

Answers

  • post what you have

  • edited January 2018
         PFont font1;
    
          import ddf.minim.*;
          Minim minim;
    
    
          //Astronaut
          float X=390;
          float Y=285;
    
    
    
          int leven=0;
    
    
    
          float j = 30;
          float k = 50;
          float l = 40;
    
          float t = 50;
          float o = 30;
          float p = 40;
    
    
    
          //MUZIEK//
          AudioPlayer bm; //TOE III -Domyeah
          AudioPlayer bm2; // TOE III v2016 -Domyeah
          //SFX//
          AudioPlayer biep;
          AudioPlayer krak;
    
    
    
          float bwg=1000;
    
    
    
          float xx=200;
          float yy=200;
    
    
          //Grote steen
          float c=random (0,1000);
          float b=random(-200,-400);
    
    
    
          //Middel steen
          float D=random (0,1000);
          float A=random(-200,-400);
    
    
    
          //Kleine steen
          float I=random (0,1000);
          float U=random(-200,-400);
    
    
          //
          ///
          //////
          //////////
          ///////////////////
          int lifes=3;/////////////////////
          ///////////////////
          ///////////
          ///////
          ///
          //
    
    
    
          //Grote steen
          float C=random (0,1000);
          float B=random(800,950);
    
    
    
          //Middel steen
          float d=random (0,1000);
          float a=random(800,950);
    
    
    
          //Kleine steen
          float i=random (0,1000);
          float u=random(800,950);
    
    
    
    
    
    
    
          ////////////
          //plaatjes//
          ////////////
          PImage Meteor;
          PImage Asteroid;
          PImage Koekje;
          /////////////
          PImage Meteor2;
          PImage Asteroid2;
          PImage Koekje2;
    
          /////////////
          PImage Astronaut;
          PImage Astronaut2;
          PImage Astronaut3;
    
          PImage wallpaper;
          PImage dood;
    
          //planeentie ding
          PImage PLANET;
    
          //grootte scherm
          void setup(){
    
          size(1000,750);
    
    
    
          minim = new Minim(this);
          bm = minim.loadFile("bm.wav");
          bm.loop();
          bm.skip(38600);
          minim = new Minim(this);
          bm2 = minim.loadFile("bm2.wav");
          bm2.loop();
          bm2.skip(38550);
    
          font1=loadFont("font1.vlw");
          textFont(font1);
    
    
          }
          void draw(){
    
    
          if(leven>25){
          j+=0.3;
          k+=0.3;
          l+=0.3;
          }
    
          t+=0.4;
          o+=0.4;
          p+=0.4;
    
    
          textSize(49);
          fill(#3491EA);
          text("SCORE: "+leven,10,50);
    
    
          wallpaper=loadImage("achtergrond.jpg");
          wallpaper.resize(1000,750);
    
    
    
    
          if(leven>10){
          bwg-=1;
          }
    
    
          if (lifes==0){
          bm.pause();
          }
    
          /////////////////
          //CONTROLS DING//
          if(keyPressed==true){
          if(key=='a'){
          X-=40;
          }}
          if(keyPressed==true){
          if(key=='d'){
          X+=40;
          }}
          if(keyPressed==true){
          if(key=='w'){
          Y-=40;
          }}
          if(keyPressed==true){
          if(key=='s'){
          Y+=40;
          }}
    
    
    
             //////////////////////////////////////////////
          //////o m a e    w a    m o u    s h i n d e i r u//////
             //////////////////////////////////////////////
          if(X>890){
          X=-110;
          }
          if(X<-110){
          X=890;
          }
    
    
    
    
          if(lifes>0){  
          image(wallpaper,0,0);
    
          Astronaut=loadImage("Astronaut.png");
          Astronaut.resize(220,180);}
          image(Astronaut,X,Y);
    
    
    
          //boven
          if(leven>25){
          B-=j;
          a-=k;
          u-=l;
          }
    
    
          //onder
          b+=t;
          A+=o;
          U+=p;
    
    
    
    
    
          ////////////////////////////////
          ////////////////////////////////
          if(dist(X+110,Y+90,c+100,b+100)<175){
    
          minim = new Minim(this);
          krak = minim.loadFile("krak.wav");
          krak.play();
          krak.skip(1000);
          b=random(-200,-400);
          c=random(0,1000);
    
          if(lifes>0){
          lifes-=1;
    
          }}
          ////////////////////////////////
          ////////////////////////////////
    
    
          ////////////////////////////////
          ////////////////////////////////
          if(dist(X+110,Y+90,I+35,U+35)<110){
    
          minim = new Minim(this);
          krak = minim.loadFile("krak.wav");
          krak.play();
          krak.skip(1000);
          U=random(-200,-400);
          I=random(0,1000);
    
          if(lifes>0){
          lifes-=1;
    
          }}
          ////////////////////////////////
          ////////////////////////////////
    
    
          ////////////////////////////////
          ////////////////////////////////
          if(dist(X+110,Y+90,D+63,A+63)<130){
    
          minim = new Minim(this);
          krak = minim.loadFile("krak.wav");
          krak.play();
          krak.skip(1000);
          A=random(-200,-400);
          D=random(0,1000);
    
          if(lifes>0){
          lifes-=1;
    
          }}
          ////////////////////////////////
          ////////////////////////////////
    
    
    
    
    
    
    
    
    
          /////////////////////////////////
          Koekje2=loadImage("Koekje2.png");
          Koekje2.resize(110,110);
    
          image(Koekje2,d,a);
    
    
          Asteroid2=loadImage("Asteroid2.png");
          Asteroid2.resize(84,84);
    
          image(Asteroid2,i,u);
    
    
          Meteor2=loadImage("Meteor2.png");
          Meteor2.resize(185,185);
    
          image(Meteor2,C,B); 
          /////////////////////////////////
    
    
    
    
    
    
    
    
    
          /////////////////////////////////
          Koekje=loadImage("Koekje.png");
          Koekje.resize(125,125);
    
          image(Koekje,D,A);
    
    
          Asteroid=loadImage("Asteroid.png");
          Asteroid.resize(80,80);
    
          image(Asteroid,I,U);
    
    
          Meteor=loadImage("Meteor.png");
          Meteor.resize(200,200);
    
          image(Meteor,c,b); 
          /////////////////////////////////
    
    
    
    
    
    
    
    
    
          ///////////////////
          //bovenste stenen//
          ///////////////////
          if(A>750){
          A=-400;
          D=random(0,1000);
          leven+=1;
          }
    
    
          if(b>750){
          b=-400;
          c=random(0,1000);
          leven+=1;
          }
    
    
          if(U>750){
          U=-400;
          I=random(0,1000);
          leven+=1;
          }
    
    
    
    
          textSize(49);
          fill(#3491EA);
          text("SCORE: "+leven,10,50);
    
    
    
    
    
    
          //death screen
          if(lifes<1){
    
          dood=loadImage("dood.jpg");
          dood.resize(1000,750);
          image(dood,0,0);
          fill(#81A0F5);
          text("GAME OVER",325,325);
          text("PRESS _ TO RESTART",310,425);
    
    
          b=-400;
          U=-400;
          A=-400;
    
    
          B=1150;
          u=1150;
          a=1150;
    
    
          biep = minim.loadFile("biep.wav");
    
          biep.play();
          bm2.pause();
          bm.pause();
          //////////////////////////////////
          if(keyPressed==true){
          if(key==' '){
          lifes=3;
    
          biep.pause();
    
          leven=0;
          bwg=1000;
    
    
    
    
    
    
    
    
    
          ////////////////////////////
          //DING DAT ZE LAAT STIJGEN//
          ////////////////////////////////
          if(leven>25){               ////
          B-=j;           ////////////////
          a-=k;           ////////////////
          u-=j;
          ///////////////////////////
          //  sry hier is niks :(  //
          ///////////////////////////
          b+=t;
          A+=o;            //////////////
          U+=p;                        //
          ///////////////////////////////
          //DING DAT ZE LAAT VALLEN//////
          ///////////////////////////
    
    
    
    
    
    
    
    
    
          bm = minim.loadFile("bm.wav");
          bm.loop();
          bm.skip(38500);
    
    
          bm2= minim.loadFile("bm2.wav");
          bm2.loop();
          bm2.skip(38500);
          }}}}
          //////////////////////////////////////////
    
    
          if(lifes==1){
          Astronaut3=loadImage("Astronaut3.png");
          Astronaut3.resize(220,180);
          image(Astronaut3,X,Y);
          }
    
          if(lifes==2){
          Astronaut2=loadImage("Astronaut2.png");
          Astronaut2.resize(220,180);
          image(Astronaut2,X,Y);
          }
    
    
    
    
    
    
          ///////////////////
          //bovenste stenen//
          ///////////////////
          if(u<-150){
          u=random(800,950);;
          i=random(0,1000);
          }
    
    
          if(B<-150){
          B=random(800,950);;
          C=random(0,1000);
          }
    
    
          if(a<-150){
          a=random(800,950);;
          d=random(0,1000);
          }
    
    
    
    
    
    
          ////////////////////////////////
          ////////////////////////////////
          if(dist(X+110,Y+90,C+100,B+100)<175){
    
          minim = new Minim(this);
          krak = minim.loadFile("krak.wav");
          krak.play();
          krak.skip(1000);
          B=random(800,950);
          C=random(0,1000);
    
          if(lifes>0){
          lifes-=1;
    
          }}
          ////////////////////////////////
          ////////////////////////////////
    
    
          ////////////////////////////////
          ////////////////////////////////
          if(dist(X+110,Y+90,I+35,U+35)<110){
    
          minim = new Minim(this);
          krak = minim.loadFile("krak.wav");
          krak.play();
          krak.skip(1000);
          u=random(800,950);
          i=random(0,1000);
    
          if(lifes>0){
          lifes-=1;
          }}
          ////////////////////////////////
          ////////////////////////////////
    
    
          ////////////////////////////////
          ////////////////////////////////
          if(dist(X+110,Y+90,D+63,A+63)<130){
    
          minim = new Minim(this);
          krak = minim.loadFile("krak.wav");
          krak.play();
          krak.skip(1000);
          a=random(800,950);
          d=random(0,1000);
    
          if(lifes>0){
          lifes-=1;
    
          }}
          ////////////////////////////////
          ////////////////////////////////
    
    
    
    
          }
    
        //i don't know what im doing
    
  • good luck lmao

  • I've been programming for about 2 weeks so i don't know anything

  • edit the post, highlight the code and press ctrl-o to format it.

    you will need push/popMatrix for this stuff...

  • edited January 2018

    I don't know what the heck all that code is for. Just draw a rotated image:

    PImage img;
    
    void setup() {
      size(400, 400);
      img = loadImage("http://" + "www.tfguy44.com/MyIcon1.PNG");
      imageMode(CENTER);
    }
    
    void draw() {
      background(255);
      pushMatrix();
      translate(mouseX, mouseY);
      rotate(map(millis()%5000, 0, 5000, 0, TWO_PI));
      image(img, 0, 0);
      popMatrix();
    }
    

    If you don't understand something, take the time to learn about it!

  • edited January 2018

    what does translate (mouseX,mouseY); do?

  • https://processing.org/reference/translate_.html

    translate translates, just like in maths class.

    mouseX and mouseY are also described in the reference, but you can probably guess what they do from the name

  • Answer ✓

    ctrl-t in the editor will indent your file properly, make it easier to read.

  • and you really shouldn't call anything like loadImage() or minim.loadFile() during your draw - file operations are too slow and draw() runs 60 times a seconds.

    make them all global variables and load them in setup().

  •   float j = 30;
      float k = 50;
      float l = 40;
    
      float t = 50;
      float o = 30;
      float p = 40;
    

    give your variables meaningful names so you don't have to waste time trying to remember what l does.

  •   b=-400;
      U=-400;
      A=-400;
    
    
      B=1150;
      u=1150;
      a=1150;
    

    and don't mix variables of different case, that's just asking for trouble.

    variables and methods should be lowerIntermedialCase. classes should have InitialCapitals. constants should be ALL_UPPER_CASE.

  •   //
      ///
      //////
      //////////
      ///////////////////
      int lifes=3;/////////////////////
      ///////////////////
      ///////////
      ///////
      ///
      //
    

    this is just a waste of time

  • koogs then how do i play a sound when something happens, during a draw??

  • edited January 2018

    sorry i just like to make my code pretty so i instantly know what it does lol don't judge

  • please reply

  • Answer ✓

    koogs then how do i play a sound when something happens, during a draw??

    because the variables are global you can access them anywhere...

    import ddf.minim.*;
    
    // global variables
    Minim minim;
    AudioPlayer song;
    boolean play = false;
    
    void setup()
    {
      size(100, 100);
    
      // start minim and load song     
      minim = new Minim(this);
      song = minim.loadFile("song.wav");
    }
    
    void draw()
    {
      background(0);
    
      // do whatever you want here
    
      // should we play the song?
      if (play) {
        song.rewind();
        song.play();
        play = false;
      }
    }
    
    // play the song when mouse is clicked
    void mouseReleased() {
      play = true;
    }
    
  • please reply

    please be patient. i am at work.

  • thanks!!!111

  • and for the images i just put image(img,x,y); in the draw and the rest in the setup?

  • Yes

    Try it

    Do you like it?

  • oh yes the lag is gone

Sign In or Register to comment.