Pygame Game States Tutorial: Creating an In-game Menu using States

Поделиться
HTML-код
  • Опубликовано: 29 дек 2024

Комментарии • 61

  • @anomalouschaz
    @anomalouschaz 10 месяцев назад +3

    man I have rewatched this video so many times this weekend, you made me change my whole code
    this video literally took me out of tutorial hell, 100% recommended
    I never understood inheritance and how to pass a whole game object into another engine object until now... you made me convert all of my noob code into very concise functions...
    this is one of the best tutorials and channels I've found so far about pygame, thanks! please keep the videos coming you're an amazing teacher!

    • @CDcodes
      @CDcodes  10 месяцев назад +2

      Love to hear that this video was able to help! Cheers : )

  • @urdaibayc
    @urdaibayc 3 года назад +3

    love your content! thanks a bunch.

    • @CDcodes
      @CDcodes  3 года назад +3

      Appreciate it : )

  • @chalkypj
    @chalkypj 3 года назад +2

    Really helpful thank you. Hope to see more soon

    • @CDcodes
      @CDcodes  3 года назад +2

      Happy to help! Working on a new video, will hopefully be out soon.

  • @robertm.schwab5800
    @robertm.schwab5800 6 месяцев назад

    Terrific video on an important topic. Very helpful.

  • @danwalker1494
    @danwalker1494 3 года назад +3

    This is fantastic!!! I wish you would make a series around this simple concept. Like two small tile maps (or images) that you toggle between when you reach an edge (is that a new state? ). Or using text with a changing menu box size. Ex. If you expand magic maybe you’ve earned fire so one size box and later get healing. How do you automatically change the menu size instead of manually coding a different box. Or making a long string of text auto return inside a standard box for dialogue.
    I think your videos are best because it feels like you are setting us up to make large polished complicated games.

  • @SxUranus
    @SxUranus 2 года назад

    OMG I am currently participating in a game jam and your tutorials are SO USEFUL !!! thank you so much for doing them ! you deserve so much more views !

  • @effedebe
    @effedebe 2 года назад

    Very thx you for your tutorials.
    Very clean/clear. I appreciate to observe your organisation/structuration of your code too.
    Thx a lot !!

  • @phoebely2900
    @phoebely2900 2 года назад

    Your tutorials are the best I’ve seen!!

  • @marmont8005
    @marmont8005 7 месяцев назад

    Thank you very much, bro!
    Excellent and clearly understandable example

    • @CDcodes
      @CDcodes  7 месяцев назад

      Happy to help!

  • @kamon242
    @kamon242 2 года назад

    Excellent tutorial! I've been looking into game screens using state pattern and this is really helpful.
    The only thing I missed was a state diagram showing the state and their transitions, without it it's too magical (too much on-the-mind vs on-the-world knowledge) to know where to put the key handlers + enter_state calls.

    • @CDcodes
      @CDcodes  2 года назад

      Good point, that would have been nice to include in the video. One of these days I can try to make one and leave it in the description

  • @nickbubuioc
    @nickbubuioc 3 года назад +9

    I love your tutorials , they are very clear and helpful for newbies, could you make a inventory system tutorial in pygame ? Thanks

    • @CDcodes
      @CDcodes  3 года назад +4

      Thank you! And yeah I can keep that in mind for future videos!

  • @vmartme
    @vmartme Год назад

    Awesome info! Thank you so much :)

  • @dariomejia877
    @dariomejia877 2 года назад

    Thank you! What an amazing tutorial.

  • @davidbandini3484
    @davidbandini3484 2 года назад

    thank you so much for this video! you are the best!!

    • @CDcodes
      @CDcodes  2 года назад +1

      Glad you enjoyed, thanks for watching!

  • @asmeticful
    @asmeticful 3 года назад +7

    Epic
    I have no idea about anything you said in this video.

  • @christopher3121
    @christopher3121 Год назад

    Thanks a lot for this! I 've been learning to program with pygame and its been hard. Your explanations are good and i just changed it a little to fit my first project.
    I also run self.state_stack[-1].events() in main loop events so i can control diferent set of keys :)

  • @kirfzatd3524
    @kirfzatd3524 3 года назад

    I love the words " hi there " so much 🤣🤣🤣 it's so cute

  • @BombasticTom492
    @BombasticTom492 3 года назад

    underrated.

  • @Milkymalk
    @Milkymalk 2 года назад +2

    This really brings some structure into my game loop. But I still have 3 questions:
    1. What do we use the game.state_stack variable for? I understand that it represents the state stack, but why do we need it when all the state instances are chained together?
    2. Why do we check if the state stack's length is > 1 before we add the entering state on top? Wouldn't that mean that if its length is exactly 1, nothing would ever be added?
    3. Game.update() only says "pass" - how is control transferred to the various states?

    • @matthewg3056
      @matthewg3056 Год назад

      usually checking list lengths prevents an indexing error, for example, if you wanted to index a list length 0 you'd get an error, so you first verify that the list is populated. In this example, i think it assumes that the base state is always populated and when you call for the index [-1] you'd get an error if the last index is also the first, therefore the list would have to be at least 2.

  • @IrrelevantPride
    @IrrelevantPride 3 года назад

    What a great video!

    • @CDcodes
      @CDcodes  3 года назад +1

      Thank you!

  • @kirfzatd3524
    @kirfzatd3524 3 года назад +1

    Why does it have so few views?? I think everyone should learn from this video

  • @sethxplayground379
    @sethxplayground379 2 года назад +1

    I did this and now idk how to continue, are any videos continuing parts of this one?

  • @GProgress
    @GProgress 2 года назад

    Great tutorial and explanation! I have a quick question: using this OOP template, how would one add text to menus?

  • @smarmy790
    @smarmy790 Год назад

    Great tutorial! Do you have any idea how to add a txt map to the game world?

  • @tristandombroski9677
    @tristandombroski9677 Год назад

    WOAH!

  • @DopeAK7
    @DopeAK7 2 года назад

    I watched your video on how to create a tilemap but how would i implement it into something like this

  • @jovinull4549
    @jovinull4549 11 месяцев назад

    Hey friend, how do I create usable items, like potions, in PyGame?

  • @zedoutlast3992
    @zedoutlast3992 3 года назад +1

    Thanks for this. Can I ask, how to apply collision for the player?

    • @CDcodes
      @CDcodes  3 года назад

      Here's a really good article on the subject. It has some pseudocode you can use: jonathanwhiting.com/tutorial/collision/

  • @vanshikabilaiya5344
    @vanshikabilaiya5344 3 года назад +1

    I was finding this type of vidoe only

  • @desxzornavarro4406
    @desxzornavarro4406 2 года назад

    it doesn't work can u help me ? i want to change the player where can I found it ? and I want to add more menu

  • @hexagonalcat8480
    @hexagonalcat8480 3 года назад

    Awesome video! Question though, you wrote from states.state import State in the title.py module because it refers to the top level script?

    • @CDcodes
      @CDcodes  3 года назад +1

      Thanks! All of the states inherit from the State class in state.py, so title.py (along with all the other state files) need to import it so that it can be used. Hope that helps!

  • @LionelvsJapanTV
    @LionelvsJapanTV 3 года назад

    What is 'states.state'. It doesnt seem to be working for me. saying something like
    ' from states.Title import Title
    ModuleNotFoundError: No module named 'states.Title'; 'states' is not a package'

    • @Joana-dv9mm
      @Joana-dv9mm 3 года назад

      hey, he called states.state because he had a directory called states. if you dont have write only 'from title import Title', but dont write 'states.' something
      Hope you understand

  • @meeteera
    @meeteera 3 года назад

    I was pausing and typing in your code along with the video. I'm using Sublime, so I'm running the game from the terminal. I kept getting a black screen, so I started searching for errors. I gave up and just copy and pasted all your code. I'm still just getting a blank pygame window when I run it. Any suggestions?

    • @CDcodes
      @CDcodes  3 года назад

      Are you getting the pygame window to at least show up or is the screen just completely blank?

    • @meeteera
      @meeteera 3 года назад

      @@CDcodes the pygame window is showing up!

    • @CDcodes
      @CDcodes  3 года назад

      Gotcha. Did you make sure to get the states and assets folders as well?

    • @meeteera
      @meeteera 3 года назад

      @@CDcodes I did! :'(

    • @CDcodes
      @CDcodes  3 года назад +1

      Strange. Head over to my discord and maybe me or someone else can help you out with a bit more context

  • @Mattwgg
    @Mattwgg 3 года назад

    Hey Christian, thank you for all that videos, they was very helpful for me.
    I'm creating the Plants vs Zombies in Pygame. It's almost done, but I need to implement a leaderboard function in this project, using SQLite (DataBase).
    Can you have any idea to how can I create this ?
    Thanks for the help!!

    • @CDcodes
      @CDcodes  3 года назад +2

      Hi! I don't have too much experience other than some MySQL, but Corey Shafer has some great videos on the subject. Check him out!

  • @kirfzatd3524
    @kirfzatd3524 3 года назад

    please make a video on how to create mario game with pygame . Pleaseee, i need you help

    • @CDcodes
      @CDcodes  3 года назад +1

      Here's a popular Github repository for a Mario clone made in Pygame: github.com/mx0c/super-mario-python

    • @kirfzatd3524
      @kirfzatd3524 3 года назад

      Thank you so much

  • @brettrogers4208
    @brettrogers4208 2 года назад

    Honestly one of the worst tutorials for someone who has already been building a game for a while, hard to implement and pair up variables from your specific use case, to mine.

    • @phoebely2900
      @phoebely2900 2 года назад +6

      That’s probably because this video wasn’t intended for someone who has been working on a game for a while. Cdcodes is teaching others how to structure a new game. No need to be rude! I’m sure you’ll find your solution somewhere :)