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

2019/1/3

Bounce off a round player

1
2
3
4
5
6
danpost danpost

2019/1/10

#
Randomness wrote...
provide me a piece of code so maybe I can understand better what you mean ?
Something like this:
if (Greenfoot.isKeyDown("up")) {
    yourplayer2.move(-2);
    if (ball.isTouchingPlayer(yourplayer2)) {
        ball.move(-2, yourplayer2.getRotation());
    }
} // no else part required
Remove all "ball.bounce();" from steuerung class.
Randomness Randomness

2019/1/10

#
can I ask you where you got the move method from?
danpost danpost

2019/1/10

#
Randomness wrote...
can I ask you where you got the move method from?
It is a member of the SmoothMover class.
Randomness Randomness

2019/1/10

#
there's definitly not a move method with 2 arguments in the SmoothMover class. Atleast not in my one
danpost danpost

2019/1/10

#
Randomness wrote...
there's definitly not a move method with 2 arguments in the SmoothMover class. Atleast not in my one
Remove your SmoothMover class and re-import it (use menu bar -- "Edit >> Import class...".)
Randomness Randomness

2019/1/10

#
public void move(int distance)
    {
        move((double)distance);
    }
    
    /**
     * Move forward by the specified exact distance.
     */
    public void move(double distance)
    {
        double radians = Math.toRadians(getRotation());
        double dx = Math.cos(radians) * distance;
        double dy = Math.sin(radians) * distance;
        setLocation(exactX + dx, exactY + dy);
    }
this is the onle move code in it
danpost danpost

2019/1/10

#
Randomness wrote...
<< Code Omitted >> this is the onle move code in it
Sorry -- my bad. Must have got that confused with something else. Alright -- replace my line 4 above with this:
int rot = ball.getRotation();
ball.setRotation(yourplayer2.getRotation());
ball.move(-2);
ball.setRotation(rot);
Randomness Randomness

2019/1/10

#
nice solution! I mean, the ball doesn't bounce when you hit it instead it somehow sticks to your playerl, so yeah. Other game stragedy :D Sometimes when you stop touching the ball , the ball doesn't move in the same direction as when you left him, why?
danpost danpost

2019/1/10

#
Randomness wrote...
nice solution! I mean, the ball doesn't bounce when you hit it instead it somehow sticks to your playerl, so yeah. Other game stragedy :D Sometimes when you stop touching the ball , the ball doesn't move in the same direction as when you left him, why?
The ball will only bounce once (probably near the beginning of the pushing). It should leave in that bounce direction. Or, if the player moved up behind the ball, the ball will leave in the direction it was originally going.
Randomness Randomness

2019/1/10

#
wouldn't it makes more sense if the player is behind the ball, the ball will leave in the direction of the player? why doesn't it do this? uuuurg it's just so buggy :( why is this soooo difficult to fix
danpost danpost

2019/1/10

#
Randomness wrote...
wouldn't it makes more sense if the player is behind the ball, the ball will leave in the direction of the player? why doesn't it do this? uuuurg it's just so buggy :( why is this soooo difficult to fix
You could try removing lines 1 and 4 in my replacement code above.
Randomness Randomness

2019/1/10

#
it seems like it's impossible to make this game playable.. everything is just soooo buggy and not to fix Mo ball
danpost danpost

2019/1/10

#
Randomness wrote...
it seems like it's impossible to make this game playable.. everything is just soooo buggy and not to fix Mo ball
Did you see my version of it? here.
Randomness Randomness

2019/1/10

#
yeah but it's to compare them because my movements are harder than yours. so yeah maybe your updated project is better mayber not :(
danpost danpost

2019/1/10

#
Randomness wrote...
my movements are harder than yours
What do you mean by that?
There are more replies on the next page.
1
2
3
4
5
6