0

Hi I am making a game where the sprite I control has to get past another sprite moving back and forth. I am trying to make an if statement that says if the sprite I control is past a certain point, i win the game

writing something like

if mysprite.get_position() > (-100, 10):
    mysprite.say("I win!")

does not seem to work. I'm trying to figure out how to compare where its position is on the grid. thanks!

scrbbL
  • 436
  • 2
  • 5
Noah M
  • 33
  • 1
  • 4
  • What type is mysprite? – scrbbL Jan 03 '18 at 21:01
  • ^I am using codesters tbh so I am not too sure. pretty sure it's just a basic sprite – Noah M Jan 03 '18 at 21:05
  • Please post a [minimal, complete and verifiable example](https://stackoverflow.com/help/mcve) and try to elaborate the question. Your goals are a bit unclear. – skrx Jan 03 '18 at 21:08
  • To indent your code correctly here, you can just select it and press Ctrl+K or the `{}` button (that will add four extra spaces before each line). – skrx Jan 03 '18 at 21:12
  • If you just want to check if the x or y position of your sprite is past the point, do something like: `if mysprite.get_position()[0] > -100:`. You can't just [compare some tuples](https://stackoverflow.com/q/5292303/6220679). – skrx Jan 03 '18 at 22:24

1 Answers1

0

The Sprite class on codesters appears to have get_x and get_y methods. You should be able implement your position check using something like this:

if my_sprite.get_y() > -100:
    my_sprite.say("I win!")

I was able to get an output console by clicking on the console button:

the console button

I added the following code to get a list of Sprite attributes and methods:

for entry in dir(sprite):
    print entry

I did not see get_position in the output.