Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

OuateDePhoque

New Coder
Hello y'all!

I'm new here, so I hope my question will be clear enough!

I'm trying to create a Breakout game using Python n Turtle.
I created my lists of blocks and my main block to .clone() but
wenn the ball reaches the top of the game, where the blocks are, it only erases the first block...

I tried to solve this issue with different kind of loops, but the proble is still present...

I hope someone can help me!
THX in advence!

CODE:

# CREATING BLOCKS

block1 = turtle.Turtle()
block1.shape("square")
block1.speed(0)
block1.shapesize(2, 4) # Size of block 40x80

# BLOCKS ROW Nr.1 (10 Blocks)
blocks_row1 = [block1.clone(), block1.clone(), block1.clone(), block1.clone(), block1.clone(), block1.clone(),
block1.clone(), block1.clone(), block1.clone(), block1.clone()]
# BLOCKS ROW Nr.2 (10 Blocks)
blocks_row2 = [block1.clone(), block1.clone(), block1.clone(), block1.clone(), block1.clone(), block1.clone(),
block1.clone(), block1.clone(), block1.clone(), block1.clone()]
# BLOCKS ROW Nr.3 (10 Blocks)
blocks_row3 = [block1.clone(), block1.clone(), block1.clone(), block1.clone(), block1.clone(), block1.clone(),
block1.clone(), block1.clone(), block1.clone(), block1.clone()]

all_blocks = [blocks_row1, blocks_row2, blocks_row3]

def starting_block_positions():
for i in range(len(blocks_row1)):
blocks_row1.penup()
blocks_row2.penup()
blocks_row3.penup()

blocks_row1.color(random.choice(colors)) # ROW Nr1
blocks_row1.goto((-400 + (82 * i)), 460)
blocks_row2.color(random.choice(colors)) # ROW Nr2
blocks_row2.goto((-400 + (82 * i)), 418)
blocks_row3.color(random.choice(colors)) # ROW Nr2
blocks_row3.goto((-400 + (82 * i)), 376)

# COLLISION WITH BLOCKS
elif ball.ycor() > 356: # COLLISION WITH BLOCKS
while counter_collision < len(blocks_row1):
if (abs(ball.xcor()) - abs(blocks_row3[counter_collision].xcor()) < 20) and (abs(ball.ycor()) - abs(blocks_row3[counter_collision].ycor()) < 40):
blocks_row3[counter_collision].hideturtle()
ball.setheading(270)
ball.forward(BALL_SPEED_STANDARD)
break
elif (abs(ball.xcor()) - abs(blocks_row2[counter_collision].xcor()) < 80) and (abs(ball.ycor()) - abs(blocks_row2[counter_collision].ycor()) < 40):
blocks_row2[counter_collision].hideturtle()
ball.setheading(270)
ball.forward(BALL_SPEED_STANDARD)
break
elif (abs(ball.xcor()) - abs(blocks_row1[counter_collision].xcor()) < 80) and (abs(ball.ycor()) -abs(blocks_row1[counter_collision].ycor()) < 40):
blocks_row1[counter_collision].hideturtle()
ball.setheading(270)
ball.forward(BALL_SPEED_STANDARD)
break
counter_collision += 1
 
Back
Top Bottom