Jan-28-2019, 03:52 PM
Hi
Im making a rock, paper, scissors game...
I need some help, what im trying to do is the following:
-Im trying to make some random scissors appear from top to bottom of screen(if you hit the scissors you loose life)
-Another thing im trying to do, is that some rocks appear from top to bottom of screen(if you catch a rock you get one point)
Thanks a lot for the support
Im making a rock, paper, scissors game...
I need some help, what im trying to do is the following:
-Im trying to make some random scissors appear from top to bottom of screen(if you hit the scissors you loose life)
-Another thing im trying to do, is that some rocks appear from top to bottom of screen(if you catch a rock you get one point)
Thanks a lot for the support
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
import pygame pygame.init() # Did code to python pep 8 style guide. class Player: @classmethod def load_images( cls ): # convert image to pygame format will help with speed # convert_alpha() will not show invisable parts with pngs and jpg cls .images = [ pygame.image.load( 'napkin.png' ).convert_alpha(), pygame.image.load( 'napkin2.png' ).convert_alpha(), pygame.image.load( 'napkin3.png' ).convert_alpha()] def __init__( self , x, y, w, h): self .rect = pygame.Rect(x, y, w, h) self .velocity = 5 self .is_jumping = False self .jump_count = 5 self .walk_left = 0 , 2 # self.walk_left == (0, 2) self .walk_right = 0 , 1 self .walk_count = 0 self .walk_pos = 0 self .tick = 100 self .next_tick = 100 def can_move( self , ticks): if ticks > self .tick: self .tick + = self .next_tick return True return False def draw( self , surface): surface.blit(Player.images[ self .walk_pos], self .rect) def move_left( self ): if self .rect.x > self .velocity: self .walk_count = ( self .walk_count + 1 ) % len ( self .walk_left) self .walk_pos = self .walk_left[ self .walk_count] self .rect.x - = self .velocity def move_right( self , width): if self .rect.x < width - self .rect.width - self .velocity: self .walk_count = ( self .walk_count + 1 ) % len ( self .walk_right) self .walk_pos = self .walk_right[ self .walk_count] self .rect.x + = self .velocity class Scene: def __init__( self ): # basic pygame setup pygame.display.set_caption( 'Napkin Move' ) self .rect = pygame.Rect( 0 , 0 , 1364 , 500 ) self .surface = pygame.display.set_mode( self .rect.size) self .clock = pygame.time.Clock() # Scene setup Player.load_images() self .background = pygame.image.load( 'bg1.png' ).convert_alpha() self .background = pygame.transform.scale( self .background, self .rect.size) self .player = Player( 300 , 410 , 64 , 64 ) def mainloop( self ): self .running = True while self .running: for event in pygame.event.get(): if event. type = = pygame.QUIT: self .running = False elif event. type = = pygame.KEYDOWN: if event.key = = pygame.K_a: self .player.move_left() elif event.key = = pygame.K_d: self .player.move_right( self .rect.width) ticks = pygame.time.get_ticks() keys = pygame.key.get_pressed() if self .player.can_move(ticks): if keys[pygame.K_LEFT]: self .player.move_left() elif keys[pygame.K_RIGHT]: self .player.move_right( self .rect.width) # drawing self .surface.blit( self .background, ( 0 , 0 )) self .player.draw( self .surface) # draw code here pygame.display.flip() self .clock.tick( 30 ) if __name__ = = '__main__' : scene = Scene() scene.mainloop() pygame.quit() |