Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
breakout clone
#4
"What can I do better?" is a lazy question. Please ask specific questions.

The first thing you should do is put all the code in one module. I and others would be more inclined to help if we could copy your posted code directly into our editor and run it. This is not a long enough program to need multiple modules.

I think bounce is not quite right. You can put all the bounces in one function (I would add a wall bounce), but I think it clearer if you have wall_bounce(), paddle_bounce() and brick_bounce().

I think paddle bounce "self.dy = -self.dy" makes for a dull game. If the ball hits in the center of the panel then dy = -dy, but if the ball hits off center you should adjust the relative lateral and vertical velocities. This would give the player some ability to aim the ball instead of just blocking the ball.

The bricks bounce looks wrong. You are going to hit a brick on the top, on the bottom, on the left side, or on the right side. You need a test for each. I would start by trying these (pseudo code):
if brick.left <= ball.center_x <= brick.right:
    # Hit top or bottom
    ball.dy = -ball.dy
else:
    # Hit side
    ball.dx = -ball.dx
I also question if it makes sense to do all the bricks. I would run your code to find out if that was easy for me to do.

I don't understand this: "How to get every brick gets vanishing after 3 hits?' Should a brick vanish after it is hit 3 times? Should all the bricks vanish after you hit a particular brick three times? Should all the bricks vanish after you hit any brick three times? Should all the bricks vanish after 3 brick hits? I suspect the first (hit a brick 3 times and it vanishes), but I also expect your code to do that.

This code:
            if bricks:
                for brick in bricks:
                    score = brick.takehit(score)
In conjunction with this code:
    def takehit(self, score):
        # the ball has collided with *this* brick
        self.hits -= 1
        if self.hits == 0:
            self.kill()
            score += 1
        return score
Should result in a brick disappearing after it "takehit()" 3 times
Reply


Messages In This Thread
breakout clone - by flash77 - Feb-09-2022, 07:27 PM
RE: breakout clone - by deanhystad - Feb-09-2022, 08:44 PM
RE: breakout clone - by flash77 - Feb-10-2022, 06:51 PM
RE: breakout clone - by deanhystad - Feb-13-2022, 04:17 AM
RE: breakout clone - by flash77 - Feb-14-2022, 08:40 PM
RE: breakout clone - by deanhystad - Feb-15-2022, 04:38 AM
RE: breakout clone - by deanhystad - Feb-18-2022, 11:04 PM
RE: breakout clone - by flash77 - Feb-19-2022, 05:55 PM
RE: breakout clone - by deanhystad - Feb-20-2022, 03:10 PM
RE: breakout clone - by flash77 - Feb-21-2022, 05:59 PM
RE: breakout clone - by flash77 - Feb-26-2022, 04:09 PM
RE: breakout clone - by deanhystad - Feb-26-2022, 04:12 PM
RE: breakout clone - by flash77 - Feb-26-2022, 04:31 PM
RE: breakout clone - by deanhystad - Feb-26-2022, 04:35 PM
RE: breakout clone - by flash77 - Feb-26-2022, 05:05 PM
RE: breakout clone - by deanhystad - Feb-26-2022, 06:20 PM
RE: breakout clone - by flash77 - Feb-26-2022, 08:53 PM
RE: breakout clone - by deanhystad - Feb-27-2022, 05:05 AM
RE: breakout clone - by flash77 - Feb-27-2022, 10:19 AM
RE: breakout clone - by deanhystad - Feb-27-2022, 02:41 PM
RE: breakout clone - by flash77 - Feb-27-2022, 06:41 PM
RE: breakout clone - by deanhystad - Feb-28-2022, 04:21 AM
RE: breakout clone - by flash77 - Mar-02-2022, 05:26 PM
RE: breakout clone - by deanhystad - Mar-02-2022, 08:44 PM
RE: breakout clone - by deanhystad - Mar-04-2022, 09:07 PM
RE: breakout clone - by flash77 - Mar-05-2022, 10:41 AM
RE: breakout clone - by deanhystad - Mar-05-2022, 02:50 PM
RE: breakout clone - by flash77 - Mar-05-2022, 07:11 PM
RE: breakout clone - by deanhystad - Mar-05-2022, 07:37 PM
RE: breakout clone - by flash77 - Mar-06-2022, 09:03 AM
RE: breakout clone - by deanhystad - Mar-06-2022, 04:53 PM
RE: breakout clone - by flash77 - Mar-07-2022, 06:13 PM
RE: breakout clone - by deanhystad - Mar-07-2022, 08:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  breakout clone pygame flash77 2 1,796 Feb-06-2022, 06:36 PM
Last Post: flash77
  [PyGame] arkanoid / breakout clone flash77 2 4,108 Feb-04-2022, 05:42 PM
Last Post: flash77

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020