Python Forum
SOLVED - Collision detection - TURTLE
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SOLVED - Collision detection - TURTLE
#1
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[i].penup()
blocks_row2[i].penup()
blocks_row3[i].penup()

blocks_row1[i].color(random.choice(colors)) # ROW Nr1
blocks_row1[i].goto((-400 + (82 * i)), 460)
blocks_row2[i].color(random.choice(colors)) # ROW Nr2
blocks_row2[i].goto((-400 + (82 * i)), 418)
blocks_row3[i].color(random.choice(colors)) # ROW Nr2
blocks_row3[i].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
Reply


Messages In This Thread
SOLVED - Collision detection - TURTLE - by OuateDePhoque - Nov-16-2020, 01:35 PM
RE: HELP - Collision detection - TURTLE - by DPaul - Nov-16-2020, 06:19 PM
RE: HELP - Collision detection - TURTLE - by DPaul - Nov-17-2020, 07:35 AM
RE: HELP - Collision detection - TURTLE - by DPaul - Nov-17-2020, 04:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Turtle Detection ChinaPlaneFlyer 1 659 Apr-17-2023, 02:49 PM
Last Post: deanhystad
Star I was making code for collision for my character izmamonke 2 2,095 Aug-06-2021, 04:30 PM
Last Post: izmamonke
  bouncing ball with variable collision points (in time) Zhaleh 1 2,382 Jul-24-2020, 02:54 PM
Last Post: Marbelous
  Player object wont recognize collision with other objects. Jan_97 3 2,725 Dec-22-2019, 04:08 PM
Last Post: joe_momma
  wn = turtle.screen() AttributeError: module 'turtle' has no attribute 'screen' Shadower 1 6,191 Feb-06-2019, 01:25 AM
Last Post: woooee
  Help! Turtle not working, even when we click the turtle demo in IDLE nothing happens. BertyBee 3 5,650 Jan-04-2019, 02:44 AM
Last Post: SheeppOSU
  Collision function problem jtstewart95 2 2,767 May-02-2018, 11:44 PM
Last Post: scidam
  Union of dictionaries (taking max value on collision) meee 5 3,764 Jan-17-2018, 09:14 PM
Last Post: Mekire
  Need help figuring out Sprite.Group Collision code PySam 3 3,377 Sep-15-2017, 03:00 AM
Last Post: PySam

Forum Jump:

User Panel Messages

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