I want to create a game in which I have enemies coming from two sides of the screen. Right now I have it so that enemies scroll around the screen one at a time. I would like you to have more than once, gradually increasing how often they collide. This is my code.
import pygame, sys, time, random from pygame.locals import * pygame.init() winW = 1000 winH = 600 surface = pygame.display.set_mode ((winW, winH),0,32) pygame.display.set_caption ('Moving Orc') class Enemy: def __init__(self, char, startY, startX): self.char=char self.startY=startY self.startX=startX self.drawChar() def drawChar (self): self.space = pygame.image.load (self.char) self.spaceRect = self.space.get_rect () self.spaceRect.topleft = (self.startX,self.startY) self.moveChar() def moveChar (self): if self.startX == 0: self.xMoveAmt = 5 elif self.startX == 800: self.xMoveAmt = -5 while True: surface.fill ((255,255,255)) self.spaceRect.left += self.xMoveAmt surface.blit (self.space, self.spaceRect) pygame.display.update() time.sleep (0.02) if self.spaceRect.right >= winW: surface.fill ((255,255,255)) break elif self.spaceRect.left <= 0: surface.fill ((255,255,255)) break
I have it so that every time you enter the loop, it resets the list, which it executes through the class that I made. And one guy will cross the screen to the left or right.
Where would I even start?
source share