python - Black screen in pygame without any errors? -
so have shmup game i've been working on,but bizarre reason none of objects seem show without errors in python shell! i've searched hours solution no avail. i've gone on of code @ least 20 times. note: before issue there error: valueerror: empty range randrange() (-40,-100, -60)
, had fixed @ time. code down here:
import pygame,random,os pygame.locals import * # initialize pygame pygame.init() # set variables red = (255,0,0) green = (0,255,0) blue = (0,0,255) black = (0,0,0) white = (255,255,255) width = 1280 height = 720 # create window screen = pygame.display.set_mode((1280,720)) clock = pygame.time.clock() # sprite groups all_sprites = pygame.sprite.group() enemies = pygame.sprite.group() # classes class player(pygame.sprite.sprite): def __init__(self): self.x, self.y = pygame.mouse.get_pos() pygame.sprite.sprite.__init__(self) #self.image = pygame.surface((32,32))++--3 #$self.image.fill((green)) self.image = pygame.image.load("vehicle.png") self.image.set_colorkey(white) self.rect = self.image.get_rect() self.rect.center = (width/2,700) self.speed = 0 def move(self): self.keypress = pygame.key.get_pressed() if self.keypress[pygame.k_a]: self.speed = 3 self.rect.x -= self.speed if self.keypress[pygame.k_d]: self.speed = 3 self.rect.x += self.speed #self.rect.x += 1 if self.rect.left > width: self.rect.right = 0 if self.rect.right < 0: self.rect.left = 1280 class enemy(pygame.sprite.sprite): def __init__(self): pygame.sprite.sprite.__init__(self) self.image = pygame.image.load("missile.png") self.rect = self.image.get_rect() self.rect.x = random.randrange(50,1920) self.rect.y = random.randrange(-40,-100) self.speedy = random.randrange(1,5) def enmove(self): self.rect.y = self.rect.y + self.speedy if self.rect.top > height: self.rect.x = random.randrange(30,1920) self.rect.y = random.randrange(-200,-100) self.speedy = random.randrange(1,8) class bullet(pygame.sprite.sprite): def __init__(self): pygame.sprite.sprite.__init__(self) self.image = pygame.surface((32,32)) self.rect = self.image.get_rect() def bmove(self): pass enemy = enemy() enemies.add(enemy) all_sprites.add(enemy) player = player() while true: pygame.event.pump() # main loop player.move() enemy.enmove() all_sprites.add(player) screen.fill(black) all_sprites.draw(screen) enemies.draw(screen) hits = pygame.sprite.spritecollide(player,enemies,false) all_sprites.update() pygame.display.update()
Comments
Post a Comment