Python Forum
Snake Game - obstacle problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Snake Game - obstacle problem
#4
Thanks for trying to help me out :) eventually I figured it out. So for anyone with the same problem, this is what I did:

while True:
    game.update()

    if food.distance(bomb1) < 40 or food.distance(bomb2) < 40 or food.distance(bomb3) < 40 \
            or food.distance(bomb4) < 40 or food.distance(bomb5) < 40:
        food.goto(random.randint(-250, 250), random.randint(-250, 250))
        game.update() 
I tested it and it works - if the apple spawns too close to the bomb, it will immediately spawn again somewhere else.
Reply


Messages In This Thread
Snake Game - obstacle problem - by Samira - Oct-17-2019, 07:59 PM
RE: Snake Game - obstacle problem - by Samira - Oct-31-2019, 02:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to add segments to the snake body blacklight 1 2,969 Sep-13-2023, 07:33 AM
Last Post: angelabarrios
  [PyGame] Snake game: how to get an instance for my snake's body multiple times? hajebazil 2 2,217 Jan-30-2022, 04:58 AM
Last Post: hajebazil
  help with snake game blacklight 3 2,663 Jul-30-2020, 01:13 AM
Last Post: nilamo
  [PyGame] Problem With Entering Game Loop ElevenDecember 3 2,784 Jan-19-2020, 08:25 AM
Last Post: michael1789
  [PyGame] Problem when moving game window michael1789 15 9,063 Jan-17-2020, 01:40 PM
Last Post: metulburr
  [PyGame] Made my first Python program: Snake. Please help me improve it andrerocha1998 7 6,316 Feb-19-2019, 07:08 PM
Last Post: Windspar
  Creating Snake game in Turtle Shadower 1 8,701 Feb-11-2019, 07:00 PM
Last Post: woooee
  [PyGame] Game Logic problem with a "The Game of Life" Replication Coda 2 3,196 Dec-24-2018, 09:26 AM
Last Post: Coda
  [PyGame] Pong game key.event problem erickDarko 2 4,266 Dec-12-2018, 03:17 PM
Last Post: erickDarko
  [PyGame] Basic Snake game (using OOP) PyAlex 1 12,641 Sep-10-2018, 09:02 PM
Last Post: Mekire

Forum Jump:

User Panel Messages

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