python - Pygame failing. Badly -


i've been trying learn pygame this site, , keeps failing.

i'm it's supposed python 3. here's code that's failing (straight site):

import pygame # colors black = (0, 0, 0) white = (255, 255, 255) blue = (0, 0, 255) # screen dimensions screen_width = 800 screen_height = 600 # player. without player, game? class player(pygame.sprite.sprite):     def __init__(self, x, y):         super.__init__()         # set height, width         self.image = pygame.surface([15, 15])         self.image.fill(white)          # make our top-left corner passed-in location.         self.rect = self.image.get_rect()         self.rect.y = y         self.rect.x = x          # set speed vector         self.change_x = 0         self.change_y = 0         self.walls = none          def changespeed(self, x, y):             # think twat?             # keff keff. changes player's speed.             self.change_x += x             self.change_y += y          def update(self):             # update player position.             # move left/right             self.rect.x += self.change_x              # did run wall?             block_hit_list = pygame.sprite.spritecollide(self, self.walls,   false)             block in block_hit_list:                 # keep player out!                 if self.change_y > 0:                     self.rect.bottom = block.rect.top                 else:                     self.rect.top = block.rect.bottom             # same thing , down, have 1 variable mess             self.rect.y += self.change_y              # did run wall?             block_hit_list = pygame.sprite.spritecollide(self, self.walls, false)             block in block_hit_list:                 # please leave premises.                 if self.change_y > 0:                     self.rect.bottom = block.rect.top                 else:                     self.rect.top = block.rect.bottom   class wall(pygame.sprite.sprite):     # defines wall. mean else can do?     def __init__(self, x, y, width, height):         # construction.         super().__init__()         # make blue, , not invisible         self.image = pygame.surface([width, height])         self.image.fill(blue)         # make top left corner "center" thing         self.rect = self.image.get_rect()         self.rect.y = y         self.rect.x = x     # easy. of work done player , not walls.   # initialize pygame pygame.init() # create pygame window screen = pygame.display.set_mode([screen_width, screen_height]) # line self explanatory... pygame.display.set_caption('1-2 walls') # make list of sprites, census. all_sprite_list = pygame.sprite.group() # build our walls. wall_list = pygame.sprite.group() # each wall follows format created # can copy-paste on , on till you're happy # define wall @ x, y, x2, y2 wall = wall(0, 0, 10, 600) # put in appropriate lists wall_list.add(wall) all_sprite_list.add(wall) #blank line here wall = wall(10, 0, 790, 10) wall_list.add(wall) all_sprite_list.add(wall)  wall = wall(10, 200, 100, 10) wall_list.add(wall) all_sprite_list.add(wall)  # spawn player @ x 50 y 50. player = player(50, 50) player.walls = wall_list  all_sprite_list.add(player) # start clock clock = pygame.time.clock()  done = false  while not done:     # ask pygame what's happening can deal     event in pygame.event.get():     # did quit game?         if event.type == pygame.quit():             done = true         elif event.type == pygame.keydown:             if event.key == pygame.k_left:                 player.changespeed(-3, 0)             elif event.key == pygame.k_right:                 player.changespeed(3, 0)             elif event.key == pygame.k_up:                 player.changespeed(0, 3)             elif event.key == pygame.k_down:                 player.changespeed(0, -3)         elif event.type == pygame.keyup:             if event.key == pygame.k_left:                 player.changespeed(3, 0)             elif event.key == pygame.k_right:                 player.changespeed(-3, 0)             elif event.key == pygame.k_up:                 player.changespeed(0, 3)             elif event.key == pygame.k_down:                 player.changespeed(0, -3)      # update our census     all_sprite_list.update()      screen.fill(black)      all_sprite_list.draw(screen)      pygame.display.flip()      clock.tick(60) pygame.quit() 

when run it, error saying

traceback (most recent call last): line 16, in __init__      super.__init__()  typeerror: descriptor '__init__' of 'super' object needs argument 

you should notice calling super differently in wall , player. way doing in wall correct:

super().__init__() 

whereas in player missing parentheses after super.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -