Python Forum
[PyGame] Snake controls not working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Snake controls not working
#6
You are learning a very ugly way.
What do you want to know ? I an others will help you.
Here are some example of boiler plates.
# simple pygame boiler plate
import pygame

def main():
	pygame.init()
	pygame.display.set_caption("Simple Pygame Boiler Plate")
	screen = pygame.display.set_mode((720, 460))
	clock = pygame.time.Clock()
	
	running = True
	while running:
		for event in pygame.event.get():
			if event.type == pygame.QUIT:
				running = False
			elif event.type == pygame.KEYDOWN:
				if event.key == pygame.K_ESCAPE:
					running = False
		
		screen.fill((0,0,40))
		# draw code here
		
		pygame.display.flip()
		clock.tick(30)
		
	pygame.quit()
	
if __name__ == '__main__':
	main()
# class base boiler plate
import pygame

class Game:
	SIZE = None
	
	def __init__(self, caption, size, ):
		Game.SIZE = size
		pygame.display.set_caption(caption)		
		self.screen = pygame.display.set_mode(size)
		self.clock = pygame.time.Clock()
		
	def loop(self):
		self.running = True
		while self.running:
			for event in pygame.event.get():
				if event.type == pygame.QUIT:
					self.running = False
				elif event.type == pygame.KEYDOWN:
					if event.key == pygame.K_ESCAPE:
						self.running = False
			
			self.screen.fill((0,0,40))
			# draw code here
			
			pygame.display.flip()
			self.clock.tick(30)
			
		pygame.quit()

def main():
	pygame.init()
	game = Game('Class Boiler Plate', (720, 460))
	game.loop()
	
if __name__ == '__main__':
	main()
This is my intense boiler plate.
My Boiler Plate Github
99 percent of computer problems exists between chair and keyboard.
Reply


Messages In This Thread
Snake controls not working - by jakegold98 - Dec-11-2017, 06:00 PM
RE: Snake controls not working - by Windspar - Dec-11-2017, 08:50 PM
RE: Snake controls not working - by metulburr - Dec-11-2017, 09:02 PM
RE: Snake controls not working - by jakegold98 - Dec-11-2017, 10:17 PM
RE: Snake controls not working - by metulburr - Dec-11-2017, 10:26 PM
RE: Snake controls not working - by Windspar - Dec-12-2017, 01:45 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to add segments to the snake body blacklight 1 2,928 Sep-13-2023, 07:33 AM
Last Post: angelabarrios
  [PyGame] Snake game: how to get an instance for my snake's body multiple times? hajebazil 2 2,186 Jan-30-2022, 04:58 AM
Last Post: hajebazil
  help with snake game blacklight 3 2,635 Jul-30-2020, 01:13 AM
Last Post: nilamo
  [PyGame] Terrible Sprite controls, need help. michael1789 16 5,481 Dec-18-2019, 10:32 PM
Last Post: michael1789
  Snake Game - obstacle problem Samira 3 5,684 Oct-31-2019, 02:58 PM
Last Post: Samira
  [PyGame] Made my first Python program: Snake. Please help me improve it andrerocha1998 7 6,240 Feb-19-2019, 07:08 PM
Last Post: Windspar
  Creating Snake game in Turtle Shadower 1 8,672 Feb-11-2019, 07:00 PM
Last Post: woooee
  [PyGame] Basic Snake game (using OOP) PyAlex 1 12,588 Sep-10-2018, 09:02 PM
Last Post: Mekire
  [PyGame] Snake not changing directions in Snake Game Bjdamaster 4 4,995 Aug-13-2018, 05:09 AM
Last Post: Bjdamaster

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020