PyGame Scrolling Shooter Game Beginner Tutorial in Python - PART 2 | Keyboard Input

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

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

  • @CodingWithRuss
    @CodingWithRuss  3 года назад +11

    Part 3 uploaded, in which I show how to add different animations to the characters. Check it out here: ruclips.net/video/Su5OlLSpJDU/видео.html

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

      I have an error, when I move my character, it goes to the spawn point and moves

    • @gamalielgerona2391
      @gamalielgerona2391 6 месяцев назад +1

      Yay! I love it when it comes to animations!

  • @khargos7602
    @khargos7602 8 месяцев назад +8

    I like how you break it down from the beginning in each video series so people can start on any series in the channel and feel comfortable. For someone like me, who's watching all the videos sequentially, you're reinforcing the foundations again and again, which is helping them stick. Meanwhile if we're revisiting something I feel confident about, I'm either trying to get ahead of you while the video plays, to quiz myself, or thinking about how I'm going to be combining these concepts on my personal projects and trying to identify potential obstacles there.
    I'm excited to get all the way through your PyGame and python content and move on to Godot. I honestly didn't plan on learning Godot at first, but now I'm thinking I'll try it out.

  • @AbdulRahman-w6s
    @AbdulRahman-w6s 2 месяца назад +1

    any one who is learning python dont check any other tutorial , just follow this coding with Russ and watch this tutorial you will learn every thing in a most fun way. i have been watching a lot of useless tutorials that wasted my time. i dont know why i found this great guy so late who is explaining every single thing in detail. thumbs up coding with Russ.

    • @CodingWithRuss
      @CodingWithRuss  2 месяца назад

      Thanks so much, that's really kind :) Glad you like the tutorials.

  • @TrainofThought42
    @TrainofThought42 2 года назад +8

    Russ, these videos are just amazing, thanks for everything you do! Merry Christmas my friend!

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

      Thanks a lot! Merry Christmas to you too :)

  • @FRAMEDSKATEKREW69
    @FRAMEDSKATEKREW69 Год назад +2

    I don't know if you will see this but I LOVE LOVE LOVE the way you explain things so well
    and in a timely manner, I have only finished the second video but I noticed that every time something is
    wrong it is because I did something wrong lol
    Other tutorials will mess up and leave me confused and no way to figure out how its supposed to look

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

      Thanks! I'm glad to hear it :). That's also why I include the source code for each video in the description because it can be really frustrating not being able to figure out what the problem is when you make a small mistake.

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

    The best programming channel ever i thin the next part will be after 2 days

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

      Thanks 😀. Yes I plan to upload it every 2-3 days

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

      @@CodingWithRuss And can you do exe from it? Make a video how to do exe from this game please.

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

      @@CodingWithRuss Where is part 3

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

    Many thanks for this series. I'm just starting with my first pygame game and I was so happy to actually see my character moving around :D I am actually doing a bit of a different type of a game (something sort of The Binding of the Isaac you could say), so my character is moving also upwards and downwards. However I guess the easier part in my case it's that my character won't be doing any jumping😃 Also I was lucky to get the images of my character facing upwards downward left and right so I just changed the image of my character with each movement instead of creating this flip function as you did. Looking forward for next steps. Thanks again :)

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

      Glad you found this useful. Your project sounds really cool! Good luck with it :)

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

    Completed your coin collecting game tutorial and now onto this one. Love these and thank you for creating them!

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

    Thanks 🙏🏻
    This helped me a lot
    Now you have a new subscriber

  • @АнтонНазарук-щ5с
    @АнтонНазарук-щ5с 2 года назад +2

    Thanks a lot!
    Its very inspiring, to do something, and see the results that soon.

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

    this is gold thank you brother

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

    Fantastic!!.. What a great Tutorial.

  • @green_quadrix
    @green_quadrix 3 года назад +5

    kudos to you, great content! you earned a sub😉😊

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

    Man you're awesome, thanks!!

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

    Very nice game, I LOVE it! Please make more videos like this. You earned a SUBSCRIBE!!

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

    This tutorial is great 👍🏾

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

    hello can i ask about the image how did you do that when I'm trying to do that I get such errors and also I already downloaded your files on github but still cant do that can you help me?

  • @Omar-si9px
    @Omar-si9px 3 года назад +2

    How do I make the character flip when moving up and moving down

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

    Best tutorial 👌

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

    Good stuff

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

    Amazing video

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

    Where i put {char_type} because my img 0.png is in ('F:\Softwares\Visual studio\Saves\Shooter\Shooter/0.png') pls tell me where

  • @Nova-xm1me
    @Nova-xm1me 3 года назад +4

    could you show us how to make a leaderboard? trying to make one that would work with sql (for example in the platformer game it takes the time the player beat the game in)

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

      That's a good idea! I haven' done that in this game but that's something I could look at for a future tutorial

  • @milktea.6083
    @milktea.6083 3 года назад +1

    subscribed. more please!

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

      Thanks! Just started uploading another series yesterday and more to follow

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

    how do I download the whole Img folder because i cannot do that and now all my seperate images are just random and i can't call them with the char_type function

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

      Hi! I had the same problem as you, but hoeray! I fixed it! Here is the solution!
      You have to go to the github link in the discription, and click on: "code", the green button and click on: "Download ZIP". After you done that, open the folder/ZIP and click *once* with your mouse on the "img" folder. Click: Ctrl + c, or click with your right mouse button and click "copy". Then go to your folder where your code is at, and click: Ctrl + v, or click with your right mouse button and click "paste". The code should work now.
      Have a nice day,
      @Sid_MC

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

    Hello, I think there is a minor issue when you press the the key "A" and "D" , that behavior will be turn right only. I set "moving_left" and "moving_right“ as i "-1" and "1" when pressing the key, then "direction = moving_left + moving_right". I will test the boolen value of "direction",
    if it's true, then assign the dx = direction * speed , and "self.flip = direcion < 0"

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

      can you explain more clearly bcoz my game is now stuck and not moving when i press a or d

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

      ​@@grazoryt Sorry, I didn't watch youtube recently and I just saw your question. The "issue" I mentioned is "the two if statements" that set the dx value, the second one will overwrite the first. So I made them into one statement, that is "dx = speed * direction“, and the direction is not boolean value, but a integer vaule that is a sum of "left + right" (I set moving_left = -1, and moving_right = 1). I tried this tutorial 4 months ago, I don't remember what I did clearly, if you want to debug why your solider not moving, I just advice you print some value ( speed, the moving_left and moving_right).

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

      @@yasmeteora8508 thank you for spending your time and explaining me but after few days i did resolvethe issue and its now working fine.If u still have the code for this game please reply with the full code bcoz i have some issue called soldier not assosiated with draw, i still didnt finish the full code im still i the 3rd part of the video...

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

      @@grazoryt Sorry, I deleted my code after I gave up this tutorial.

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

      @@yasmeteora8508 oh loll

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

    good job. thank you for all

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

    Is char_type for 3.9 version only?

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

      the f string method was added in python 3.6 so should work with any versions after that

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

      Hmmm my pc is always sus

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

    nice video keep it on

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

    What is the name of the background color, for the RGB value you choose?

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

    How should i put the folders for the img = pygame.image.load(f'img/{self.char_type}/Idle/0.png')?

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

      Copy the folder structure that is on github since that's how it is setup in the code

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

    How could I get that move configuration work for a 2 player game in the same PC? Can't find any answers and have been trying a lot of stuff unsuccessfully

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

      You could try adding extra keys to the event handler for player 2 and then add extra variables for player 1 and player 2 movement so the code knows which player is moving.

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

    sir the char//-type code is not working

  • @Ibrahim-uz6sr
    @Ibrahim-uz6sr 3 года назад +1

    Hey there im new to coding what application are you using to create this game on. Thanks

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

    Really like it but just 1 question, is there any good site to get those simple pixel characters?

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

      itch.io is pretty good, other than that I just google open source images

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

      @@CodingWithRuss tysm for fast response :)

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

    thanks good vidéo

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

    Please can anyone explain to me the directory thing the self.(char_type)

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

    Hello, in the part of the code that reads (f"img/{self.char_type}/Idle/0.png") what is Idle, is it the folder the picture is in.

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

      Yea it's the folder name and it will also tie into the action the player is doing. It will make more sense in later videos as I add different animation types

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

      @@CodingWithRuss Okay, thank you. I was struggling a bit trying to find out what that was.

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

      Hi I’m doing an assignment for school and using this tutorial and so far it’s been really great but for some reason in the same line when I press f it appears in the text string instead of just being f and so does the {self.char_type} sorry if it’s a bit hard to understand what I’m saying. But if I could get some help that’d be great.
      For example at about 18:10 when you type the f it’s blue but when I do it it joins the string and is yellow. That’s the same when you write the {self.char_type}

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

      Is it because I haven’t set up my folders or something?

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

      Nvm I was being silly haha sorry

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

    I could not get the
    "img = pygame.image.load(f'img/{char_type} /Idle/0.png')"
    to work so I changed it to
    "img = pygame.image.load(os.path.join("img",char_type, "Idle", "0.png"))"
    which so far appears to work

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

      Nice, that's a good alternative for it

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

    I can't get this line to work.
    img = pygame.image.load(f'img/{self.char_type}/Idle/0.png')
    I made sure the destination path for the images was right too!
    It keeps saying no such file or directory!
    Please help!
    I'm using Pycharm BTW!

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

    非常感谢

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

    In python IDLE, I don't think you can open an image from outside the python project's folder. And because of this, I don't know what to do instead of img = pygame.image.load(f'img/{self.char.type}/0Idle.png')

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

      I never really used IDLE, why not try an IDE? I use sublime text editor in these videos

    • @HimanshuSingh-yv9qj
      @HimanshuSingh-yv9qj 3 года назад

      @@CodingWithRuss I use visual studio code but still its not working

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

      @@HimanshuSingh-yv9qj I'm not overly familiar with VS code. You may need to do additional setup to load in the images.

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

      its because if you open the folder you can see that its named 1idle.png not 0idle.png, just fix that and then it will work

  • @vs6x3
    @vs6x3 2 месяца назад

    struggled with an indentation issue for hours that caused my player to go down instead of right, gpt fixed for me what i could not spot humanly at all. i followed the git-structions along with this tutorial, line for line. everything looks okay but isn't. thanks for the video.

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

    char type doesnt work. using 3.9.6 version python.

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

    Just giving an Idea, instead of calling this "Shooter" I called this "Lost_In_War" Which I find cooler, just a cool name idea!

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

      Nice name! I should have tried to be more creative than "Shooter" :D

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

    My player image is moving backward but not forward....please somebody help

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

      Sounds like a typo in your movement code. Have a look at the code in the video description and compare - it will help you find the issue

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

      I have the same issue. Can't find the mistake. How did you fix it?
      Edit for those who need it: found the mistake. The #keyboard_pressed section should say event.key, not event.type. Just some stupid typo

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

    Hey for some reason I can move left but then once I press d to turn right I can't turn left again,
    Someone pls help me.

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

    in my system it say speed not defined
    what should i do

  • @Gameplay-st7ve
    @Gameplay-st7ve 10 месяцев назад

    i copied the whole thing yet my keyboard buttons are not working, i don't know why, please help

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

    Really amazing video! I am wondering what if we used something like Tim from 'Tech with Tim' does like keys = pygame.key.get_pressed() I believe as long as the keys still held in next loop it will continue to move and if it is not within the next iteration pygame will know its key up.

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

      Thanks! I did use that method in some of my other games including my previous platformer. In this shooter I wanted to see if I could put all the controls in the event handler in the main loop instead, just to experiment with different approaches.
      In my newer games I have gone back to the method you mentioned as I find it easier.

  • @Ganga-Harshith-Mylapuram
    @Ganga-Harshith-Mylapuram 3 года назад

    Sir, what software did you use for the project?

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

    Thanks sir but i have a question, in class you wrote self.speed and blah blah but how does the computer know that u are referring to speed

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

      The computer doesn't know what any of the variables mean. It is what you do with the variables in the rest of the code that determines what happens.

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

      @@CodingWithRuss so if im making this game for phone with buttons how do i rotate the window horizontally

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

    Save my time Stamps 9:33

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

    Ive coded this part exactly the same but when i press the a key my player doesnt move but when i press the d key it does. how do i fix this?

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

      go through each line of your code in that section again. sometimes when you reuse(copy paste) code there are things u might have missed to change for the a key.
      if event.type == pygame.KEYDOWN:
      if event.key == pygame.K_a:
      moving_left = True
      if event.key == pygame.K_d:
      moving_right = True
      make sure its the same as above and it should work :)

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

    I'm not sure if I'm doing something wrong, but It gives me an error saying that moving_left and moving_right aren't defined. I think my code matches yours, but I don't know what's wrong. The only way for me to fix it is to predefine moving_left and moving_right before loading anything else, but I think that lags out the program somehow, since the program is very laggy.

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

      Nevermind, I figured out what the problem was. as it turns out, if you don't add in the "pygame.quit()" at the very end, it totally lags out the whole program.

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

      Glad you got it working!

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

    is there any other way to open multiple photos , i mean without this f {} (the char type )
    because not working for me and i want to open the enemies
    please help "!!!

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

      You may have an older version of python so you can update it and f{} will work for you. Otherwise you can still use .format() instead. It works in a similar way but you may need to look up the documentation to see how to use it

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

    Do you have to add {self.char_type} because when i typed that I got an error. I only added the name on the picture and that works.

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

      I do that so i can specify the char_type and the code loads either the player or enemy images. If you put the name of the folder in manually then it will only be able to load that image. If it isn't working for you then you might be using an older python installation that doesn't support f string formatting. Try updating your python install and it should work.

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

      Hello, I found the folder from your github the name of "Idle" for player the first letter is upcase, but the enemy's lowcase. I just rename it manually to solve the issue

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

      @@yasmeteora8508 Thanks for pointing this out. It didn't cause any issues for me but seems for some people it gives errors. I have updated the folder names on github now

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

      @@CodingWithRuss i am also facing the same issue please help me in this
      class soldier(pygame.sprite.Sprite):
      def __init__(self,char_type, AD, PD, scale, speed):
      pygame.sprite.Sprite.__init__(self)
      self.char_type = char_type
      self.speed = speed
      self.direction = 1
      self.flip = False
      img = pygame.image.load("ct.png")
      self.image = pygame.transform.scale(img, (int(img.get_width() * scale), int(img.get_height()* scale)))
      self.rect = self.image.get_rect()

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

      i got the enemy but the colour is same please help in this... @coding with Russ

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

    Sir Pls send other parts fast

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

    спасибо

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

      You're welcome

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

      @@CodingWithRuss я попробовала сделать игру по вашим туториалам и у меня почти вышло. огромное вам спасибо!

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

    when i press a it goes left but when press d it does flip but not move pls helpppp

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

      nvm for some reason it was fixed idk how

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

    Я хоть и не понимаю по английски, но понимаю о чем ты говоришь

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

    my player lags alot before moving how do i fix it? anyone?

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

    These tutorials are good but they are outdated, you need to make these in 2022 again because of people that started this years. Updates have changed the programs.

  • @pakravantv1570
    @pakravantv1570 8 месяцев назад +2

    if event.type==pygame.KEYDOWN:
    if event.key==pygame.K_a:
    move_L==True
    if event.key==pygame.K_d:
    move_R==True
    if event.key==pygame.K_ESCAPE:
    run==False
    if event.type==pygame.KEYUP:
    if event.key==pygame.K_a:
    move_L==False
    if event.key==pygame.K_d:
    move_R==False
    is not working

  • @AbdulRehman-qq7uo
    @AbdulRehman-qq7uo 3 года назад

    I am making it for the first time but i cant seem to fix the error:
    Module button not found,
    Please help me

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

      This part of the tutorial doesn't use buttons. Are you following the videos? They explain everything step by step.

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

    how can i view the code with the link. it doenst work

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

    What’s the IDE did you use here?

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

      Sublime Text

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

      you can follow this with anything, i'm using visual code

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

      I don't know but PyCharm is also good

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

    Where is part 3???

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

    yo whats {self.char_type}?

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

      It's a variable for "character type" which I use to tell the difference between the player and the enemies.

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

      @@CodingWithRuss thanks

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

      @@CodingWithRuss its still not working idk if its outdated lol

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

      @@JJr1012 No the code should work fine, it's not outdated

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

      @@CodingWithRuss oh

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

    10:01

  • @Sinister-zm1fb
    @Sinister-zm1fb 3 года назад

    0:20

  • @JyunJyunie.00
    @JyunJyunie.00 2 года назад

    Someone really did get 10 bucks just copying this? 😂

  • @Владислав-я1я
    @Владислав-я1я 2 года назад

    .