pygame

How to convert a group of images into a single data_test.npz file?

谁说我不能喝 提交于 2020-01-06 02:39:14
问题 I am building a self driving RC car. I have 100s of images taken from pi camera and each one of them are named as direction.jpg . How do I convert these images into single .npz file so that I can train a Neural net. The code below is a simple python script that enables my car to move on key press and snaps photos every second. #!/usr/bin/env python """Interactive control for the car""" import time import io import pygame import pygame.font import picamera import configuration import helpers

pygame KEYDOWN event and key events

妖精的绣舞 提交于 2020-01-06 02:21:06
问题 Hi there is an issue that doesn't really matter when developing a game with pygame but that kept on bothering me for a while. while not gameExit: for event in pygame.event.get():e if event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT: pass so above is a working code and I believe while not gameExit: for event in pygame.event.get():e if event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT: pass works as well. However, when I just try something like "event.key == pygame.K

What is the correct sequence for bliting surfaces to the screen in pygame?

不打扰是莪最后的温柔 提交于 2020-01-05 15:43:30
问题 I am creating a simple mp3 player and my first task was to create a simple button that a user could press. I created a class called Button which handled this behavior and detects if a user has clicked it and then changes color. I am now trying to have a default text that the button displays and another string (pres_string) which will be displayed if the button is being pressed. The only problem is my background surface seems to be in the wrong place and is drawing over any changes I have made

Trying to make a “solid” block in pygame

♀尐吖头ヾ 提交于 2020-01-05 14:03:32
问题 So i want my player to not be able to pass through the block, but it teleports to the other side, any idea why? here's my code: def update(self, collidable): self.rect.x += self.hspeed collision_list = pygame.sprite.spritecollide(self, collidable, False) for collided_object in collision_list: if (self.hspeed > 0): # right direction self.rect.right = collided_object.rect.left elif (self.hspeed < 0): # left direction self.rect.left = collided_object.rect.right self.rect.y += self.vspeed

Receiving multiple messages via socketserver but one is sent

爷,独闯天下 提交于 2020-01-05 12:57:29
问题 A have a application with two threads. Its a network controlled game, 1. thread (Server) Accept socket connections and receive messages When message is sent, create an event and add it to the queue Code: class SingleTCPHandler(SocketServer.StreamRequestHandler): def handle(self): try: while True: sleep(0.06) message = self.rfile.readline().strip() my_event = pygame.event.Event(USEREVENT, {'control':message}) print message pygame.event.post(my_event) 2. thread (pygame) In charge of game

Is it possible to show an image for a while and then change it back?

六月ゝ 毕业季﹏ 提交于 2020-01-05 09:34:55
问题 def monkey_bomb(self): self.image = pygame.image.load("./images/monkey_bomb.png") delay(1000) self.image = pygame.image.load("./images/monkey.png") This is one of the method in my player sprite class so what I wanted to do is that when the player sprite hits a bomb, it will show a explosion effect, then go back to the normal image for the player sprite but seems like pygame doesn't support the whole 'delay' thing, how do I do this in another way? 回答1: You don't want to delay in the middle of

Python Game Timer (Threads?)

穿精又带淫゛_ 提交于 2020-01-05 07:36:55
问题 I am designing a game in Python and would like to know how to make an efficient timer that can run along side my game. Note: I am using Pygame. I currently have a timer like so: import time seconds = 60 def start_timer(): global seconds while seconds > 0: print seconds seconds -= 1 time.sleep(1) However, when run in my main game function my game hangs because of the timer.sleep . def main(self): Timer.start_timer() I'm pretty sure my issue has something to do with not using threading,

Counting time in pygame

梦想与她 提交于 2020-01-05 05:26:29
问题 I want to count time in pygame, when an event occurs. Ive read something in the documentation but I dont really understand on how to do it. In the documentation you can get time in miliseconds but it starts counting when the pygame.init() is called. I want to count from 0 when the boolean is true. import pygame pygame.init() loop = True boolean = False while loop: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() if event.type == pygame.KEYDOWN: if event.key

How to make your character move without tapping repeatedly on buttons?

我怕爱的太早我们不能终老 提交于 2020-01-05 04:26:09
问题 I'm working on a racing game. I have been using this code but my player keeps moving once only. How do I solve this problem? change = 7 dist = 7 change_r = 0 change_l = 0 dist_u = 0 dist_d = 0 pygame.display.update() for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT: change_r = True elif event.key == pygame.K_LEFT: change_l = True elif event.key == pygame.K_UP: dist_u = True elif event.key == pygame.K_DOWN: dist_d = True if event.type == pygame

Pygame - Smoother Movement

让人想犯罪 __ 提交于 2020-01-05 04:22:11
问题 I have added an Object/Image on the main_screen , the object is called cancer_cell . What I'm trying to do here is that I want the object move smoothly. I have to repeatedle press on the arrow keys to keep it moving. How do I make it move while arrow keys are pressed ? here's the code: exitgame = False cellpos_x = 0 cellpos_y = cancer_cell.get_rect().height*2 while not exitgame: for event in pygame.event.get(): if event.type == pygame.QUIT: exitgame = True quitgame() if event.type == pygame