you are the Bob Ross of programming and I live for it
@ShawCode2 жыл бұрын
Lmao, unfortunately I'm not rocking the afro anymore tho ;(
@katrinabest31293 жыл бұрын
Hi Caleb, I am a recent subscriber and a third year uni student studying stats, but I've really enjoyed the way that you've described using Pygame. I am building a game personally and I just wanted to mention a bug and a fix that I found regarding colliding with the border blocks. With the current code, if you try going out of bounds, the character stays but the camera will move, hence unfortunately trying to recenter your camera. It's a small fix, but if you also change all of the sprites movement to counteract the movement of the camera, then it will not move at all, just like the player. Here is the code that I have found works (I placed it in Player.collide_blocks) but I hope this helps! if self.x_change > 0: self.rect.x = hits[0].rect.left - self.rect.width for sprite in self.game.all_sprites: sprite.rect.x += PLAYER_SPEED if self.x_change < 0: self.rect.x = hits[0].rect.right for sprite in self.game.all_sprites: sprite.rect.x -= PLAYER_SPEED
@ShawCode3 жыл бұрын
Thanks for pointing this out, I will definitely add this in the next tutorial!
@MsLorrainia3 жыл бұрын
The fix worked perfect! Thank you! (for those who are still having issues, make sure you place the code ShawCode showed first, then add the same code as shown above in the collide_blocks. Don't forget to add to the y coords too : def collide_blocks(self, direction): if direction == 'x': hits = pygame.sprite.spritecollide(self, self.game.blocks, False) if hits: if self.x_change > 0: for sprite in self.game.all_sprites: sprite.rect.x += PLAYER_SPEED self.rect.x = hits[0].rect.left - self.rect.width if self.x_change < 0: for sprite in self.game.all_sprites: sprite.rect.x -= PLAYER_SPEED self.rect.x = hits[0].rect.right if direction == 'y': hits = pygame.sprite.spritecollide(self, self.game.blocks, False) if hits: if self.y_change > 0: for sprite in self.game.all_sprites: sprite.rect.y += PLAYER_SPEED self.rect.y = hits[0].rect.top - self.rect.height if self.y_change < 0: for sprite in self.game.all_sprites: sprite.rect.y -= PLAYER_SPEED self.rect.y = hits[0].rect.bottom
@sndksnebfuiw10 ай бұрын
@@MsLorrainia Bro, thanks for the help with the camera. Now she doesn't fly away XD. But I got another one, when I rearrange the player's spawn point, the camera remains in the previous place, and the player is at the spawn point. What to do? How do I focus on the player?
@alicemystery55203 жыл бұрын
I am surprised at how much this is helping me understand how to program in python. Along with separating the code into various files and folders. Which almost none of the tutorials explain like your series is doing. Thanks man!
@ShawCode3 жыл бұрын
Glad it helped!
@tomasdelpino9329 ай бұрын
What I have done to make the camera not move in case of a collision is the following: Inside the collide_blocks method create an else statement where if it doesnt hit and x_change > 0 or whichever the case is, it calls a move_camera method, and within that method you write the for loop that's in this video. Do this for all 4 directions
@МастерОтступник3 жыл бұрын
Finally U have done the tilemap game! Наконец-то ты закончил тайлмап игру! 👏🏼from empty to game из пустоты в игру
@ShawCode3 жыл бұрын
:D
@beronicous70862 жыл бұрын
This is the most simple and best tutorial about cameras! How do you make the map bigger, though?
@ShawCode2 жыл бұрын
Thanks! To increase the map size, you just add more rows and columns to your tilemap list.
@jademendes5572 Жыл бұрын
Thank you for coming up with such a simple solution for the camera!! This will help me greatly
@ShawCode Жыл бұрын
Glad I could help!
@hhh-yh8wn10 ай бұрын
I first tried working with offsets when you create a vector2() and then subtract it from the current pos and it becomes the offset_pos and then you have to center the player. And then you find out that you can not interact with objects because their possitions remained default (kinda). I am a begginer and that seemed a bit complex this code of yours is 10 times simpler and I will never get confused
@s.dh293 жыл бұрын
Ayyyy, your back! Loved this tutorial as much I loved all ur other videos :)
@ShawCode3 жыл бұрын
Thanks :D
@abd_cheese73532 жыл бұрын
Seems great, though im wondering if this affects performance very much? Or if there is a more optimized way to do this?
@ShawCode2 жыл бұрын
Good question - it may have a slight impact on performance, but this is my solution to creating a camera in pygame. Someone will probably have a better way of doing it, but unfortunately unlike other game engines there isn't a simple way to add a real camera.
@abd_cheese73532 жыл бұрын
@@ShawCode I see, thanks for the reply
@jakecastle44263 жыл бұрын
Hey, so i toyed with the code i was left with a while back (you may remember me), and got shooting and walking around with following camera, finally figured out how to write and implement A* Pathfinding (the whole game is passed 1000 lines at the moment). It needs a rewrite, cuz ive learned so much since i started.. So with your help, im rewriting a new game from scratch because i need the core to work differently. Im confident i can do it too, thanks to you.
@ShawCode3 жыл бұрын
Nice job! Adding pathfinding to the enemies is really quite complicated, well done!
@yousefangox30223 жыл бұрын
you're tutorials are nice when you collide with a block and hold down the arrow key the camera keep moving if there's a solution for that it will be awesome
@ShawCode3 жыл бұрын
I gave a fix to that in my latest video!
@itschris18813 жыл бұрын
very very good thanks so much dear bro
@ShawCode3 жыл бұрын
Thanks!
@itschris18813 жыл бұрын
@@ShawCode your welcome bro
@MyriadColorsCM Жыл бұрын
Is there a way of making the "camera" no longer move if your character collide? I tried setting up a collide detection check but it didnt work.
@simplyhypixel687610 ай бұрын
This is probably a somewhat brute force method but you can try doing something like making a list of all the rects that the player can collide with and then put that in a for loop and check if the player.rect is colliding with anything at a given moment and then go ahead and put that if statement above the camera movement logic
@MsLorrainia3 жыл бұрын
So, I noticed that when I add this 'camera' functionality, if I hit a wall, and keep running against it, the camera keeps going until there's nothing on the screen. Is there a way to stop the camera from continuing to scroll off map?
@MsLorrainia3 жыл бұрын
Oops! I saw someone asked this already! look forward to the fix!
@ShawCode3 жыл бұрын
The next tutorial will show you how to do this!
@edgar123456789P3 жыл бұрын
hey whats up shawcode, thanks for the video, I had a quick question and was hoping you could help, once we collide with a wall, the camera keeps going on its own as long as we keep pressing against the wall, is there a way to stop that?
@ShawCode3 жыл бұрын
I will be fixing this in a future tutorial - it is quite an easy fix!
@markbenjamin62993 жыл бұрын
Is it possible to use a bigger map than the window and have more of it show up as the camera moves instead of black?
@ShawCode3 жыл бұрын
Sure, you just increase the size of the tile map list!
@aminezouaoui58343 жыл бұрын
How can we do that using only the mouse and without any Sprite ?? I mean in case that you have a Map and you want to scroll all over it with a camera following ur mouse cursor . It will be really amazing if you help me with that it's for a project !!
@ShawCode3 жыл бұрын
Did you manage to figure this out with help the discord server? If you still need help, let me know!
@aminezouaoui58343 жыл бұрын
@@ShawCode I still have a problem , Didn't get how to redraw the blac background after redrawing my tileMap.
@lpmittheo99042 жыл бұрын
could you please make a tutorial how to stop the camera if the player colides with a rock
@ShawCode2 жыл бұрын
Yes, I fix this bug in the final tutorial!
@charchitdahiya9863 жыл бұрын
Will there be levels in the game
@ShawCode3 жыл бұрын
I won't be adding them in this series, but all you will have to do is create more tilemaps, and draw a different tilemap onto the screen for a new level!
@sahilakhtar88153 жыл бұрын
Hey Show, Just one question from where did you learn Python?
@ShawCode3 жыл бұрын
From internet tutorials like these!
@sahilakhtar88153 жыл бұрын
@@ShawCode nice brother
@DopeAK72 жыл бұрын
For me, the for loop in the movement method moves the enemies with the player too, how do i fix this?
@ShawCode2 жыл бұрын
Could you copy and paste all your code for me please?
@DopeAK72 жыл бұрын
by copy and paste, what do you mean because I dont think my code can fit here
@ShawCode2 жыл бұрын
@@DopeAK7 Could you please copy and paste each file as a separate reply? It should be able to fit that way.
@kuchtwotimes3 жыл бұрын
hey im having an issue where in my tilemap, if I put P, there will be two instances of my character. and if my tilemap doesnt have P at all, a character in the top left of the screen will spawn. i dont know how to get rid of the one that isnt on the tilemap.
@ShawCode3 жыл бұрын
Please could you copy and paste your main.py for me? I think you are creating another instance of the Player class somewhere in your code.
@kuchtwotimes3 жыл бұрын
@@ShawCode I figured it out! Thank you though, you're right. In the main.py I never ended up deleting the self.player = Player(self, 1, 2). Got it now! I'm impressed you keep up with the comments. Thanks a lot.
@ShawCode3 жыл бұрын
@@kuchtwotimes Nice job!
@pythonista_3333 жыл бұрын
at the end of the video i've noticed that the camera still moves when the player collides with the wall
@ShawCode3 жыл бұрын
Thanks for pointing this out, I will be fixing it in one of the next tutorials!
@clarkkellis55483 жыл бұрын
You should do some research on the pygame subset for Android because with it you can turn your pygame into an Android mobile game. I would appreciate it if you could figure it out and make a tutorial series on it because I can't find much about it on KZbin.
@ShawCode3 жыл бұрын
Thanks for the idea, it looks interesting!
@thequocnguyen13413 жыл бұрын
thanks you. I learn many thing from you. Can you help me, i have many pdf file, i want to convert them to latex, but i can't do it.
@ShawCode3 жыл бұрын
Thanks! Sorry, I don't know much about latex.
@thequocnguyen13413 жыл бұрын
@@ShawCode thank you for reply, your video is helpful with me ! (my english is not good)
@akashramgir48663 жыл бұрын
i want to learn logic building in programming how ?