This site requires JavaScript, please enable it in your browser!
Greenfoot back
xandreas_1
xandreas_1 wrote ...

2019/3/1

Decreasing Sroller World of Danpost

xandreas_1 xandreas_1

2019/3/1

#
Hi guys, in my game the Scroller world moves forward when the key w is pressed. also I got an increasing variable rate so the car got an increasing speed til a specific rate. How can I decrease the variable rate and move the Scroller World forwards continously, when I stopped pressing the key w?
danpost danpost

2019/3/1

#
xandreas_1 wrote...
in my game the Scroller world moves forward when the key w is pressed. also I got an increasing variable rate so the car got an increasing speed til a specific rate. How can I decrease the variable rate and move the Scroller World forwards continously, when I stopped pressing the key w?
Please show your world class codes.
xandreas_1 xandreas_1

2019/3/1

#
danpost wrote...
xandreas_1 wrote...
in my game the Scroller world moves forward when the key w is pressed. also I got an increasing variable rate so the car got an increasing speed til a specific rate. How can I decrease the variable rate and move the Scroller World forwards continously, when I stopped pressing the key w?
Please show your world class codes.
private void scroll() 
    {
        
     
        
     if(Timer1 == 40)
     {
         
             if(Greenfoot.isKeyDown("w") && rate < 7)   
             { 
                rate++;
                
              }
              
              
              if(Greenfoot.isKeyDown("s") && rate < 6) 
             {
                rate++;
                
              }
              
              Timer1 = 0;
         
     }
      
     else
    {
     Timer1++; 
    }
    
    
    
         
    if(Greenfoot.isKeyDown("w") == false && rate > 0)   
             { 
                rate--;
                
                
              }

     
      
     else
    {
     if(Greenfoot.isKeyDown("w") == false && rate > 0 == false)rate = 0;
    }
    
    
   
   
  
     int dsx = 0;
     if((Greenfoot.isKeyDown("W") && Greenfoot.isKeyDown("S") == false ) | rate > 0) 
     {
         dsx ++;
         
        }
     if(Greenfoot.isKeyDown("S") && Greenfoot.isKeyDown("W") == false ) dsx --;
     
     scroller.scroll(dsx*rate, 0);
     
    }
danpost danpost

2019/3/1

#
xandreas_1 wrote...
I got an increasing variable rate so the car got an increasing speed til a specific rate. How can I decrease the variable rate and move the Scroller World forwards continously, when I stopped pressing the key w?
Is the car supposed to stay center screen? and, what does your car's act method look like?
xandreas_1 xandreas_1

2019/3/1

#
danpost wrote...
xandreas_1 wrote...
I got an increasing variable rate so the car got an increasing speed til a specific rate. How can I decrease the variable rate and move the Scroller World forwards continously, when I stopped pressing the key w?
Is the car supposed to stay center screen? and, what does your car's act method look like?
No the car is moving up and down in y direction when it touches the specific color on the Image aof the world, it doesnt move in x direction.
public void act() 
    {
       
      MovementY();

      
     
      ausrichten(); 
      
      
    } 
    
    public void ausrichten(){                       
        setLocation(wheel2.getX(), wheel2.getY()); 
        
                                                    
        turnTowards(wheel1.getX(), wheel1.getY());  
        
        
                                                    
        move(33);                                   
    }                                               
   
    public void MovementY(){

        for(int i = 0; i < 50; i++){
            if(getWorld().getBackground().getColorAt(getX(), getY()+36).equals(color1)) 
            { 
                setLocation(getX(), getY() - 5); 
                
            }
        }

        
        if(!getWorld().getBackground().getColorAt(getX(), getY()+45).equals(color1) && Timer8 > 1) 
        {
            if(Timer7 >= 1)
            {
                d = d+1;
                Timer7 = 0;  
            }
            else
            {
               Timer7++; 
               
            }
            
            setLocation(getX(), getY() + 1*d);
            Timer8 = 0;
            
        }
        else
        {
            Timer8++;
            
        }
    
        
        if(getWorld().getBackground().getColorAt(getX(), getY()+60).equals(color1))
        {
           d= 1; 
        }

        
    }
    
    
    
   
    
      
    
    }
danpost danpost

2019/3/1

#
xandreas_1 wrote...
No the car is moving up and down in y direction when it touches the specific color on the Image aof the world, it doesnt move in x direction. << Code Omitted >>
So, what you are trying to achieve is that the car appears to move forward (to the right) by use of the scrolling. The user controls the apparent speed of the car using key input. Correct?
xandreas_1 xandreas_1

2019/3/1

#
danpost wrote...
xandreas_1 wrote...
No the car is moving up and down in y direction when it touches the specific color on the Image aof the world, it doesnt move in x direction. << Code Omitted >>
So, what you are trying to achieve is that the car appears to move forward (to the right) by use of the scrolling. The user controls the apparent speed of the car using key input. Correct?
yes absolutly right
danpost danpost

2019/3/1

#
xandreas_1 wrote...
yes absolutly right
What you are doing is misplacing the behavior of the car and putting it on the scrolling. It would be better to control the car with the keys, allowing it to be moved along the x-axis, then have the scrolling be determined by the amount the car moved along the x-axis, moving the car back to its original horizontal location. That would be actor follow scrolling code with some ranged actor movement (along the y-axis). See my tutorial on this.
You need to login to post a reply.