Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float rot = 0;
- boolean upp, ner;
- int antal = 30;
- int[] posX = new int[antal];
- int[] posY = new int[antal];
- void hinder(){
- background( 0 );
- fill(255, 0, 0);
- for(int i = 0; i < antal; i++){
- ellipse(posX[i], posY[i], 40, 40);
- }
- }
- void theWhale(int direction){
- if(go){
- int d = direction;
- setVelocity(d);
- //Ska ej rotera när den står still
- if( velocity.x > 0.05) rot = velocity.heading2D();
- fill( 200, 200, 0 );
- noStroke();
- pushMatrix();
- translate( whale.x, whale.y );
- rotate(rot);
- ellipse( 0, 0, 40, 20 );
- popMatrix();
- }
- }
- //Sätt hastigheten
- void setVelocity(int direction){
- int d = direction;
- switch(d){
- case -1:
- acceleration.set(0.13, 0.05, 0);
- break;
- case 1:
- acceleration.set(0.13, -0.05, 0);
- break;
- case 0:
- acceleration.x = 0.13;
- break;
- case 3:
- acceleration.x = -0.015;
- //Jag msåte veta när den går upp och när den går ner när den ska stanna
- //så att den inte går åt motsatt håll
- if(acceleration.y > 0){
- acceleration.y = -(acceleration.y+0.02);
- upp = true;
- ner = false;
- }
- else if(acceleration.y < 0){
- acceleration.y = -(acceleration.y-0.02);
- upp = false;
- ner = true;
- }
- else{
- upp = false;
- ner = false;
- }
- break;
- }
- //Ska ej röra på sig när den står still
- if(velocity.x<0){
- acceleration.set(0, 0, 0);
- velocity.set(0, 0, 0);
- }
- else if(velocity.x > 2) velocity.x = 2;
- if(upp && velocity.y<0){
- velocity.y = 0;
- acceleration.y = 0;
- }
- else if(ner && velocity.y>0){
- velocity.y = 0;
- acceleration.y = 0;
- }
- //if(velocity.y > 2) velocity.y = 2;
- velocity.add(acceleration);
- //println(velocity.y);
- //println("Upp: " + upp + " Ner: " + ner);
- whale.add(velocity);
- if(whale.x > width) whale.x = 0;
- if(whale.y > height) whale.y = 0;
- else if(whale.y <0) whale.y = height;
- //println(velocity.x);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement