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

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ก.ย. 2024

ความคิดเห็น • 61

  • @MyFishWillKillU
    @MyFishWillKillU 3 ปีที่แล้ว +6

    Oh my god this video was amazing

  • @anomalouschaz
    @anomalouschaz 6 หลายเดือนก่อน +2

    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  6 หลายเดือนก่อน +1

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

  • @marmont8005
    @marmont8005 3 หลายเดือนก่อน

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

    • @CDcodes
      @CDcodes  3 หลายเดือนก่อน

      Happy to help!

  • @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.

  • @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 2 หลายเดือนก่อน

    Terrific video on an important topic. Very helpful.

  • @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 !!

  • @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 !

  • @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!

  • @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

  • @kirfzatd3524
    @kirfzatd3524 3 ปีที่แล้ว +1

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

  • @kirfzatd3524
    @kirfzatd3524 3 ปีที่แล้ว

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

  • @phoebely2900
    @phoebely2900 ปีที่แล้ว

    Your tutorials are the best I’ve seen!!

    • @CDcodes
      @CDcodes  ปีที่แล้ว

      Thank you!

  • @vmartme
    @vmartme ปีที่แล้ว

    Awesome info! Thank you so much :)

  • @dariomejia877
    @dariomejia877 2 ปีที่แล้ว

    Thank you! What an amazing tutorial.

  • @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 :)

  • @davidbandini3484
    @davidbandini3484 ปีที่แล้ว

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

    • @CDcodes
      @CDcodes  ปีที่แล้ว +1

      Glad you enjoyed, thanks for watching!

  • @asmeticful
    @asmeticful 3 ปีที่แล้ว +7

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

  • @BombasticTom492
    @BombasticTom492 2 ปีที่แล้ว

    underrated.

  • @IrrelevantPride
    @IrrelevantPride 2 ปีที่แล้ว

    What a great video!

    • @CDcodes
      @CDcodes  2 ปีที่แล้ว +1

      Thank you!

  • @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 9 หลายเดือนก่อน

      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.

  • @vanshikabilaiya5344
    @vanshikabilaiya5344 3 ปีที่แล้ว +1

    I was finding this type of vidoe only

  • @sethxplayground379
    @sethxplayground379 2 ปีที่แล้ว +1

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

  • @tristandombroski9677
    @tristandombroski9677 ปีที่แล้ว

    WOAH!

  • @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?

  • @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!

  • @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 7 หลายเดือนก่อน

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

  • @zedoutlast3992
    @zedoutlast3992 2 ปีที่แล้ว +1

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

    • @CDcodes
      @CDcodes  2 ปีที่แล้ว

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

  • @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

  • @LionelvsJapanTV
    @LionelvsJapanTV 2 ปีที่แล้ว

    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 2 ปีที่แล้ว

      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 2 ปีที่แล้ว

    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  2 ปีที่แล้ว +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 ปีที่แล้ว

    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 ปีที่แล้ว +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 :)