Pygame Movement - Pygame RPG Tutorial #2

Поділитися
Вставка
  • Опубліковано 21 січ 2025

КОМЕНТАРІ • 106

  • @ShawCode
    @ShawCode  3 роки тому +13

    Thanks for watching the video! If you found it useful, please leave a like on the video, and if you want to see more Pygame tutorials, then be sure to subscribe! The next Pygame RPG Tutorial will be out next week.

    • @gurnkerk3826
      @gurnkerk3826 3 роки тому

      Hello Shaw!
      I somewhere made a mistake so could you upload your codes so I can find my mistake?

  • @applesauce6644
    @applesauce6644 3 роки тому +7

    Your channel is very underrated. Like it should be illegal for your channel to not have a million subs
    You are helpful, informative, very clear and easy to understand. Thank you for helping me out!

    • @ShawCode
      @ShawCode  3 роки тому +2

      Thanks, I'm glad you are finding these useful!

  • @techwithzaitri9458
    @techwithzaitri9458 3 роки тому +9

    This is my favorite tutorial.
    I hope you will have 1m subs.
    from algeria

    • @ShawCode
      @ShawCode  3 роки тому +1

      Thanks, I'm glad you found it useful!

  • @davysabbe3341
    @davysabbe3341 3 роки тому +5

    You have a real talent for explaining things! Great tutorials, looking forward to the rest of the series!

    • @ShawCode
      @ShawCode  3 роки тому +1

      Thanks, the next tutorial will be coming out today!

  • @MaounGames
    @MaounGames Місяць тому

    Great video man, i've gotten into a pickle trying to use pygame but then you cam along and helped a lot

  • @mattmatzen2730
    @mattmatzen2730 3 роки тому +1

    These tutorials are wonderful! Hands-down, the most easy-to-understand. Keep up the good work, man!

    • @ShawCode
      @ShawCode  3 роки тому

      Thanks, I'm glad you find them useful!

  • @alicemystery5332
    @alicemystery5332 3 роки тому

    Brilliant !!! The description of how everything gets called is helping me a lot. I could never make sense of it before myself. I look forward to seeing the next tutorial.

    • @ShawCode
      @ShawCode  3 роки тому

      Thanks! It's good that you understand it now. The next tutorial will be out next weekend!

  • @kyoujinko
    @kyoujinko 3 роки тому

    I have to say, your style has been better than TechWithTims version of Pygame tutorial. Glad I found your content.

  • @nciscovalencia
    @nciscovalencia 3 роки тому +5

    Nice stuff mate! Greetings from Chile 🤘

  • @GrandPubalicious
    @GrandPubalicious 3 роки тому

    Beautiful, i commented your first part on the tutorial with some problems. Got that fixed and added some music to it aswell. Im hoping next part comes out soon! Big ups on the tutorial!

    • @ShawCode
      @ShawCode  3 роки тому +1

      Thanks, it's cool that you managed to fix the bug!

    • @GrandPubalicious
      @GrandPubalicious 3 роки тому

      @@ShawCode Cheers. Its easy when its fun. Any idea of when #3 is coming cause im kinda stuck. I've successfully replaced the black bakground with a proper one and the red block with random sprite. Now im trying to get animations on the player to work, but i cant seem to figure it out. Would love some insight from you!

    • @ShawCode
      @ShawCode  3 роки тому

      The 3rd tutorial is out, and the next one will be out this weekend. It'll show you how to use images with sprites, and then we might move onto animations.

  • @user-se4ik5kq3k
    @user-se4ik5kq3k 3 роки тому

    @ShawCode - Thank you for this channel. You create some really high class material - Very easy to follow. Cheers!

    • @ShawCode
      @ShawCode  3 роки тому

      You're very welcome!

  • @landsky432
    @landsky432 2 роки тому

    Hi there. At 6:38, can you clarify how the player object gets added to the all_sprites group with line 11? From my understanding, doesn't self.groups get a copy of the value game.all_sprites? Or does line 12 have to do something with adding the player object to all_sprites? Otherwise, great tutorial and thank you!

    • @paul_musique
      @paul_musique 2 роки тому

      I think it's line 12 but I'm not sure

  • @yousefangox3022
    @yousefangox3022 3 роки тому +1

    the movement doesn't work for me
    i check it multiple times but everything should be fine
    please if you now help me

    • @ShawCode
      @ShawCode  3 роки тому

      Please could you copy and paste your code for me to look at?

    • @yousefangox3022
      @yousefangox3022 3 роки тому

      @@ShawCode class Player(pygame.sprite.Sprite):
      def __init__(self, game, x, y):
      self.game = game
      self._layer = PLAYER_LAYER
      self.groups = self.game.all_sprites
      pygame.sprite.Sprite.__init__(self, self.groups)
      self.x = x * TILESIZE
      self.y = y * TILESIZE
      self.width = TILESIZE
      self.height = TILESIZE
      self.x_change = 0
      self.y_change = 0
      self.facing = 'down'

      self.image = pygame.Surface([self.width, self.height])
      self.image.fill(RED)
      self.rect = self.image.get_rect()
      self.rect.x = self.x
      self.rect.y = self.y
      def update(self):
      self.movement()
      self.rect.x += self.x_change
      self.rect.y += self.y_change
      self.x_change = 0
      self.y_change = 0
      def movement(self):
      keys = pygame.key.get_pressed()
      if keys[pygame.K_LEFT]:
      self.x_change -= PLAYER_SPEED
      self.facing = 'left'
      if keys[pygame.K_RIGHT]:
      self.x_change += PLAYER_SPEED
      self.facing = 'right'
      if keys[pygame.K_UP]:
      self.y_change -= PLAYER_SPEED
      self.facing = 'up'
      if keys[pygame.K_DOWN]:
      self.y_change += PLAYER_SPEED
      self.facing = 'down'

    • @ShawCode
      @ShawCode  3 роки тому +3

      @@yousefangox3022 It appears that your update and movement methods are inside of the init method - you need to have them outside of the init method, but still inside the player class.

    • @yousefangox3022
      @yousefangox3022 3 роки тому

      @@ShawCode thank you so much
      it works

  • @menyepy
    @menyepy 3 роки тому

    As always, can't wait for the next episode!

    • @ShawCode
      @ShawCode  3 роки тому

      It will be coming out this weekend, or at the beginning of next week!

  • @jblasutavario9549
    @jblasutavario9549 3 роки тому

    Subbed! Great content, young man! 🙌🌟👏

    • @ShawCode
      @ShawCode  3 роки тому +1

      Thanks for the sub!

  • @LegutGamer
    @LegutGamer 3 роки тому

    Very nice, Shaw! Thank you a lot, from Brazil.

    • @ShawCode
      @ShawCode  3 роки тому

      Glad you liked it!

  • @Sander-Darius-xc4cv4js8c
    @Sander-Darius-xc4cv4js8c 6 місяців тому

    I have a question: How to make characters move keys be w up, s down, a left, d right, and not in capital

    • @Myhair0_0
      @Myhair0_0 4 місяці тому

      instead of pygame.K_UP, pygame.K_LEFT e.t.c
      you have to do pygame.K_w, pygame.K_a e.t.c
      make sure the letters are lowercase

  • @elijahkent3675
    @elijahkent3675 2 роки тому

    error pygame.sprite has no attribute sprite
    please help me

  • @itschris1881
    @itschris1881 3 роки тому +2

    hey bro, very nice thank you so much for your great videos, goodluck

    • @ShawCode
      @ShawCode  3 роки тому

      Glad you like them, thanks!

    • @itschris1881
      @itschris1881 3 роки тому

      @@ShawCodeyour welcome bro, 👌

  • @R3KS9476
    @R3KS9476 3 роки тому +1

    Very helpful thanks very much keep up the good work,
    Btw do you have a Patreon?

    • @ShawCode
      @ShawCode  3 роки тому +1

      I'm glad you found the tutorial useful! I don't have a Patreon, but if you want to support me, a like on the video would help!

  • @a_nexul
    @a_nexul Рік тому

    when i try to run a project i get a "ModuleNotFoundError: No module named 'pygame'"
    how can i fix it?

    • @AnyxReal
      @AnyxReal 15 днів тому

      open command prompt and type "pip install pygame"! it should work!

  • @onlyuriew
    @onlyuriew Рік тому

    Did everything up to this point in pygame 2.4.0. on python 3.11.4. No errors.
    When I run it, the player doesn't move when I press a key. What happened?

    • @Gyrossssssss
      @Gyrossssssss Рік тому

      I had the update function and movement function trapped inside the init function

    • @onlyuriew
      @onlyuriew Рік тому

      @@Gyrossssssss It's okay, I fixed it by writing "keys[pygame.key]:" instead of "keys==[pygame.key]:" in their places.

  • @leem6944
    @leem6944 2 роки тому

    Hi, thanks for the tutorial. I have a problem ... The red square on my screen just moves from left to right. It does not move up and down. Thanks

    • @ShawCode
      @ShawCode  2 роки тому

      Please could you copy and paste your code for me to look at?

    • @daleharrison3774
      @daleharrison3774 2 роки тому

      Did you forget to change x_change to y_change when you copy and pasted it

  • @vibinboyo7663
    @vibinboyo7663 Рік тому +1

    The tutorial's amazing, and I'm glad that I found it as I've been wanting to create something of a RPG as I'm learning Python. Though, for some reason whenever I press my arrow keys, there's no movement. Would I just have to change 'LEFT' to 'A' or something like that?
    update: switched the controls to fit a AWSD format; but for some reason, it doesn't move up or down

    • @riadwumaier719
      @riadwumaier719 6 місяців тому

      same, just moving up left and right but no up and down. checked the video twice

  • @Cjajfbf82938
    @Cjajfbf82938 3 роки тому

    Hi! I have a prolem and please answer. From "self.events()" to i don't know where it gives me the next error:
    self.run = False
    TabError: inconsistent use of tabs and spaces in indentation
    I erased the hole line and rewrite it until here.
    What do I do?

    • @ShawCode
      @ShawCode  3 роки тому

      Which text editor are you using? You can fix this by converting all of your tabs to spaces, or vice versa.

    • @Cjajfbf82938
      @Cjajfbf82938 3 роки тому

      I am using Sublime text 3 and i know what tabs and spaces are and how to find which one which but i don't really want to practically rewrite the whole code

    • @ShawCode
      @ShawCode  3 роки тому

      You don't have to re-write all your code. Just check this link out: stackoverflow.com/questions/22529265/sublime-text-3-convert-spaces-to-tabs

  • @MedTech1
    @MedTech1 3 роки тому +1

    can you make a video about your sublime text settings

    • @ShawCode
      @ShawCode  3 роки тому

      I might do, thanks for the idea!

  • @jaysikotar9860
    @jaysikotar9860 3 роки тому

    Which code editor should I use
    Vs code or pycharm or sublime.

    • @ShawCode
      @ShawCode  3 роки тому +1

      It really just comes down to what you prefer. I use Vim, but out of those three I would go with Visual Studio Code.

  • @АлександрБезпалый-т1й

    Something went wrong, help me, I did it like in the video.
    self.groups = self.game.all_sprites, self.game.blocks
    AttributeError: 'Game' object has no attribute 'all_sprites'

  • @louisstanhope2618
    @louisstanhope2618 2 роки тому

    Your tutorials are really great and easy to follow, thanks :)
    If I wanted to add a system where pressing space caused the player sprite to jump, how would I go about doing that?
    Thanks again!

    • @ShawCode
      @ShawCode  2 роки тому

      Thanks! I'm not sure how jumping would logically work in a top-down RPG like this, but you would have to get the space keypress first, and then once the keypress is detected then a method would be called, maybe making the player appear bigger or something like that?

    • @paul_musique
      @paul_musique 2 роки тому

      @@ShawCode i think he just forgot it was a RPG game lol, like a mario style player

  • @daboxguy3848
    @daboxguy3848 3 роки тому

    Damn that movements smooth. I wonder if pygame has a physics systems or if you have to implement it?

    • @ShawCode
      @ShawCode  3 роки тому +1

      Pygame doesn't have any physics, but it isn't too hard to add.

  • @alexisdurand4008
    @alexisdurand4008 3 роки тому +1

    Awesome 👍🏻

  • @bokkenka
    @bokkenka 3 роки тому

    Nice tutorials. Do you have code in a Git account?

    • @ShawCode
      @ShawCode  3 роки тому

      Thanks! Sorry, I haven't got any of the source code for these tutorials.

  • @kane-uf3yl
    @kane-uf3yl 3 роки тому +1

    nice nice bro

  • @anonymousghost5384
    @anonymousghost5384 3 роки тому

    Cloud you plz make video about bash and c

    • @ShawCode
      @ShawCode  3 роки тому

      Thanks for the idea, I might make that!

  • @chalkcity748
    @chalkcity748 5 місяців тому

    Excelent!!

  • @danielmilhm1981
    @danielmilhm1981 3 роки тому

    Hello man. Im watching ur videos and i literally copied ur code but my "red Square" dont move. Any Idea pf what is happening? Nice video btw!

    • @ShawCode
      @ShawCode  3 роки тому

      Thanks! Please could you copy and paste your code for me to look at?

  • @jaysikotar9860
    @jaysikotar9860 3 роки тому

    Bro please upload more tutorials!

    • @ShawCode
      @ShawCode  3 роки тому

      The next one is coming out at 2 PM today!

  • @Misty0069
    @Misty0069 3 роки тому +3

    Always see your🥰

  • @philtoa334
    @philtoa334 3 роки тому

    Nice

  • @anirbanmittra4033
    @anirbanmittra4033 3 роки тому +1

    Do you have a Discord? I am a big fan of yours

    • @ShawCode
      @ShawCode  3 роки тому +1

      Thanks! I do, you can join here: discord.com/invite/RvNFCymnPn. It is paused at the moment, so you can't talk, but you can still join. It will be open soon.

  • @brawlco3176
    @brawlco3176 3 роки тому

    dam what an absolute chad

  • @Comentad
    @Comentad 3 роки тому

    YEAAAAH

  • @JuusK
    @JuusK 2 роки тому

    1:23

  • @MedTech1
    @MedTech1 3 роки тому

    cool

    • @ShawCode
      @ShawCode  3 роки тому

      I hope you found it useful!

  • @brok3n_bot
    @brok3n_bot 3 роки тому

    noice

  • @oscars1745
    @oscars1745 3 роки тому +1

    Engineer gaming

  • @Not-Braker
    @Not-Braker Рік тому

    100th comment.

  • @salemhosam2715
    @salemhosam2715 3 роки тому

    cool