[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Help Starting/doing The Main Code



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