0

i am making a game and i need to be able to sense if a character is touching a tree or not and i can't because the tree is part of the background.

i've already tried using x and y co-ordinates but the trees aren't in a specific clump so this doesn't work. i also tried using a piece of code - look below - that detects if something is touching something else, however, the thing has to be defined and i can't define the tree.

def tree():
    tree = #brown

if sprite_x < 0 + sprite_width and sprite_x + tree_width > 0 and sprite_y < 0 + sprite_height and sprite_height + sprite_y > tree_height :
     #do stuff

i expect the code to sense if the character is touching a brown colour (the tree) and to allow me to use that output.

barry
  • 3
  • 1
  • 5
  • Can you provide some more detail about how the trees are indicated? – blackbrandt Jul 10 '19 at 16:09
  • the trees aren't indicated that's why i'm trying to get a code running purely on sensing the colour – barry Jul 10 '19 at 16:18
  • Please provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – blackbrandt Jul 10 '19 at 16:19
  • If you can access the screen pixels the solution would be pretty straight forward, something like `if pixel_array[sprite_x, sprite_y] == BROWN` where `pixel_array` is the screen pixels and `BROWN` some variable pointing to the same color used for the trees – Rotem Tal Jul 12 '19 at 08:22
  • that would work @rotemtal but how would i access the screen pixels? – barry Jul 12 '19 at 17:20
  • Well, you can look [here](https://stackoverflow.com/questions/3800458/quickly-getting-the-color-of-some-pixels-on-the-screen-in-python-on-windows-7) – Rotem Tal Jul 13 '19 at 18:30
  • Thanks @rotemtal that has really helped answer my question! – barry Jul 14 '19 at 08:27

0 Answers0