Python Forum
[PyGame] Basic Snake game (using OOP)
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Basic Snake game (using OOP)
#2
Nice work.

A couple criticisms:
  • Speed is global, this is unnecessary.
  • You are constraining your framerate to 10 fps. This is not a great way to slow your program down.
  • You aren't handling quit events making exiting from the program a little annoying.
  • Your color constants aren't actually necessary; pygame provides all standard html colors already.
  • Loop through objects, not indexes. For example, instead of this:
    This:
  • Try to minimize repeated code like this block:
    Often you can use a dictionary to switch to the correct case in situations like this; the following illustrates the basic idea:
Anyway, all that aside great work and good job trying to make everything work in an object oriented manner.
I have a pretty minimal snake game here which has a very basic scene manager if you want to check it out:
https://github.com/Mekire/Snake/blob/master/snake.py
Reply


Messages In This Thread
Basic Snake game (using OOP) - by PyAlex - Sep-10-2018, 12:24 PM
RE: Basic Snake game (using OOP) - by Mekire - Sep-10-2018, 09:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to add segments to the snake body blacklight 1 2,993 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,249 Jan-30-2022, 04:58 AM
Last Post: hajebazil
  help with snake game blacklight 3 2,706 Jul-30-2020, 01:13 AM
Last Post: nilamo
  Snake Game - obstacle problem Samira 3 5,805 Oct-31-2019, 02:58 PM
Last Post: Samira
  [PyGame] How do I add more balls to basic Pong game? JUtah 2 4,561 Apr-18-2019, 08:40 PM
Last Post: JUtah
  [PyGame] Made my first Python program: Snake. Please help me improve it andrerocha1998 7 6,354 Feb-19-2019, 07:08 PM
Last Post: Windspar
  Creating Snake game in Turtle Shadower 1 8,718 Feb-11-2019, 07:00 PM
Last Post: woooee
  [PyGame] Snake not changing directions in Snake Game Bjdamaster 4 5,082 Aug-13-2018, 05:09 AM
Last Post: Bjdamaster
  [PyGame] Snake controls not working jakegold98 5 6,601 Dec-12-2017, 01:45 AM
Last Post: Windspar

Forum Jump:

User Panel Messages

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