[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Help Starting/doing The Main Code
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] Help Starting/doing The Main Code
- From: "Jake b" <ninmonkeys@xxxxxxxxx>
- Date: Fri, 26 Sep 2008 23:19:38 -0500
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Sat, 27 Sep 2008 00:19:46 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=IwqKNwV3Xr8rfLnv5xOZ7attcVmIWZlCrTthfUvj/lc=; b=ehNpS336fcunSPmeAnspiuC5msi9IXJF5SuMiaA12F9p/UMvpsExVXQB4KQJuD0xKb LD6NSs7/3hS85ouGRR9iJj/Bg4qghw/sFC4htciZw2ksAM7rcrxpjVJLQiPRNZqMwg4l mH1XVj0Un35Y+e5CuFG20wo6TcTXosUtXJjZY=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=V0Xg39t5oKOWe4GegGfUbohh8A0yAz8Fxaf3rAmiF/SgYLJf7/zmTdHyoee7pV19bZ pdwk6115SXL5EwJsi2+/xmBoSKNp++l/lZDRDdO86gfPIGo1wC8p20t5zybLkgEaKZwh DIRo1cyxpIk61W5HdmhpX0KOAP+ltDCCOe/T0=
- In-reply-to: <48D91C95.5020607@xxxxxxxxxxxxxx>
- References: <BAY113-W4912E6A6C5C28BE8515FFBA4B0@xxxxxxx> <48D91C95.5020607@xxxxxxxxxxxxxx>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
I'd suggest making a clone of pong, and asteroids and maybe missile
command. (They will be easier to write than a shooting platformer, and
be more gradual that jumping right into too much at once )
Your main loop looks something like this:
class Game():
"""game logic class"""
def __init__(self, width=1024, height=768):
# ... snipped ....
def loop(self):
"""main game loop"""
self.bDone = false
while not self.bDone:
# handle events, physics/updates, and render
self.handle_events()
self.update()
self.draw()
def handle_events(self):
"""input"""
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
# event: keydown
elif event.type == KEYDOWN:
# exit on 'escape'
if (event.key == K_ESCAPE): self.bDone = True
def draw(self):
"""render screen"""
# clear screen
self.screen.fill( pygame.color.Color("black") )
# render sprites
# flip
pygame.display.flip()
def update(self):
"""update units, check for collisions(if needed), etc..."""
# ... snipped ...
--
Jake