I am trying to run the turtle that can move left and right by arrow key, and at the same time two object call harm and benefit fall down from top of the screen. However, I can not do both of them at the same time
I running by repl.it.
def run():
screen.onkey(left,"Left")
screen.onkey(right,"Right")
while True:
benefit()
harm()
run()
Can someone help me with this?
Not sure what framework you're using to drive your app, but most likely you want to split what's going on to single-frame actions. Find how to execute something each time a new frame is displayed and in that code execute something that moves your objects just a bit. For falling objects you can do that by either updating the y coordinate by some constant, or by (this_frame_time - last_frame_time) * speed to keep the movement smooth.
Related
I'm currently making a BTD6 Auto Farmer what this means is that it will farm the game for me and click on the screen and play the game for me and complete the maps and stuff so I can get rewards that do not give me a competitive advantage because the game is single-player.
And to complete this bot I'd have to wait a certain amount of time and then see whenever a button shows up on the screen and to accomplish this I need to make a function that will wait for an image to show up on the screen and if the image shows up the function should press that image and that's all.
I tried many things and couldn't get it to work, here is my code that doesn't work:
def click_image(img):
x = pag.locateCenterOnScreen(img, confidence=config.OPENCV_CONFIDENCE)
pag.click(x)
This didn't work and I'm not surprised because the code creates the variable then tries pressing the variable there is no check or wait and I don't know how to implement that and that's what I'm asking for, that's the answer I'm looking for :)
It seems like you want to perform an asynchronous task, you should look into the python package asyncio.
Im new to using asciimatics, and im playing around with it to make a game. However, when i add a cross_hairs to a scene, it wont move to the next scene. How can i move to the next scene when i have cross_hairs?
Assuming you are using something very similar to this sample, asciimatics is playing a Scene with 2 or more Sprites.
If so, this sample already allows you to move to the next Scene by pressing space. Job done! :-)
In a little more detail... It relies on the default global key handler to do this. As covered here, it just raises the NextScene exception to tell asciimatics to move on.
If you want to move to a new Scene based off a different event (e.g. the cross hairs hitting another Sprite), you should just raise that Exception at the time you detect the condition.
Firstly, there are a couple of similar questions posted on this. But they are not complete questions, and no one has really answered them all. I am using Python to send input to a game active in widow modes using "ctypes" package. The original idea is mentioned here
In particular, my codes are:
x=500
y=400
for i in range(10):
time.sleep(4)
if i > 0:
x=x+17
pos=(x,y)
#ctypes.windll.user32.SetCursorPos(x,y) # this does not work in game but
#outside the game window
ctypes.windll.user32.mouse_event(0,x,y,0,0)
print i
In order for the "mouse_event" to work, I tried inputting hexadecimal values but can't get it to move consistently. I tried setting up separate class & functions to import, then calling the function. The function works outside the game window but not inside the game window.
The separate class & functions are based on this question
Thank you for your help in advance.
I am developing a small game with four members for a board. When a player moves something, that move has to updated in remaining players screen(their webpage). I ended up tornado, but I can't find any examples for my case.
I need to display the move to all players when a move was saved in DB. Polling DB continuously after x seconds may miss some moves. How can I achieve this.
Use websockets instead. Here's the documentation with a simple example.
I am making a kind of puzzle game and it's been suggested that I use Pygame. I have looked at some tutorials but I am unable to get certain things to show.
Number of moves - I'm basically looking for something that will count how many times the numbers 1 - 6 are pressed.
Timer - I'd like this to start when someone presses a key and stop after a condition has been fulfilled.
Win / fail screen - I'm looking to have something pop up saying the user has won or failed depending on if certain criteria have been met.
Any help on getting these displayed would be greatly appreciated.
Firstly get familiar with pygame font module : http://www.pygame.org/docs/ref/font.html
You will need a way to display string and numbers to the user. Simply make a font object, and render surfaces with the strings, to later blit them like any other bitmap you had.
Also i suggest to look into the time module: the pygame docs are really helpful : http://www.pygame.org/docs/ref/time.html. Here you will use this module to create a small class Timer, with a Clock object to stop and reset, and update functions. In the update functions, you can add the delta(the difference between the last and recent call of tick()) to the overall time or simply depend on the functions given in the time module. You can call stop when a condition is satisfied.
Last, for the screen, you may want to divide your game/app into states, where the game state is only rendered and looped when a play flag == true. When the game is over, you can switch the state to win/lose state to display the information and probably a prompt if the player may want to play again.