Python Hangman Tutorial #2 - Pygame Mouse Events & Collision

preview_player
Показать описание
This pygame hangman tutorial talks about pygame mouse events and pygame collision. We will continue to work on our python hangman game and handle button presses and mouse collision.

◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾

💰 Courses & Merch 💰

🔗 Social Medias 🔗

🎬 My YouTube Gear 🎬

🎤 XLR Microphone (Rode NT1): Not available

◾ 💸 Donations 💸 ◾
◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾

⚡ Please leave a LIKE and SUBSCRIBE for more content! ⚡

⭐ Tags ⭐
- Tech With Tim
- Pygame Tutorial
- Pygame Collision
- Pygame Mouse Events
- Python Pygame
- Python Pygame Tutorial

⭐ Hashtags ⭐
#python #pygame
Рекомендации по теме
Комментарии
Автор

I wrote the button position a little differently, and I think it's easier to understand. To get both the initial position and the spacing between each button, you can essentially treat each position in the window as as intersection on an evenly spaced grid. This makes startx and the spacing just equal to WIDTH // 14 for 14 spaces between 13 buttons. This way you don't even need to define gaps, and you can play around with the radius without messing with the spacing.

# button variables
RADIUS = 20
letters = []
startx = WIDTH // 14
starty = 400
for i in range(26):
x = startx + startx * (i % 13)
y = starty + (startx * (i // 13))
letters.append([x, y])

If you wanted to put a margin on each end, you could write it like this too by using a MARGIN variable to define the frame you want the buttons to fit into and then kind of doing the same thing. Though for this, the initial x position and the spacing between buttons need to be different.

# button variables
RADIUS = 20
letters = []
MARGIN = 100
FRAME = WIDTH - MARGIN
SPACING = FRAME // 14
startx = MARGIN // 2 + SPACING
starty = 400
for i in range(26):
x = startx + SPACING * (i % 13)
y = starty + (SPACING * (i // 13))
letters.append([x, y])

nnjsquirrels
Автор

Hey Tim, thanks for these great tutorials. Just minor comments from my side. At 7:10 I believe it should be startx = round((WIDTH - (RADIUS * 2 + GAP) * 12 - 2* RADIUS) / 2) and at 8:30 x = startx + RADIUS + ((RADIUS * 2 + GAP) * (i % 13)). The difference cannot be seen cause difference between RADIUS and GAP is only 5, but if you would give higher values, the difference would be higher and viewed on the screen clearly. Cheers.

zeaglee
Автор

I opened my computer and a notification came! What is it? Tech With Tim uploaded: Python Hangman Tutorial #2 - Pygame Mouse Events & Collision! Is this a dream! I was waiting for this for long! 🐱‍💻😊

sakmancap
Автор

I found the drawings a little complicated so I made my own! I am super proud of that because making my own logic was very satisfying. It wasn't the most efficitent one but if someone wants to see it here it is:
A=65
FONT = pygame.font.SysFont("comicsans", 40)
def buttonDraw():
for x in range(45, 800, 60):
pygame.draw.circle(win, BLACK, (x, 390), 25, 3)
letter = chr(int(((x-45)/60)+A)) #this determines the letter we wanna put on each circle
text = FONT.render(letter, 1, BLACK)
win.blit(text, ((x-10), (390-10)))
for z in range(45, 800, 60):
pygame.draw.circle(win, BLACK, (z, 460), 25, 3)
letter = chr(int(((z-45)/60)+A+13)) #this determines the letter we wanna put on each circle
text = FONT.render(letter, 1, BLACK)
win.blit(text, ((z-10), (460-10)))

vihashah
Автор

Saw the notification left my all work and came here to watch it !! Not going to do this right now cause I'm on working my own project But still here cause I love the way you explain, I love your voice !! I'm currently following your Selenium Tutorials !!! You are my favourite youtuber Tim ! Stay safe and Keep uploading videos! !!

imherovirat
Автор

Man, you inspire me to get into the python, you are my idol bro. Take lots of love, and keep giving us your lessons. love you man <3

toufiqulislamimran
Автор

The way this is presented makes it really easy to understand, thanks a lot!

Vancha
Автор

started learning pygame. you save alot of my time ♥. its always easier to look up a video than reading alot of documentation.

shahzaibali
Автор

This tutorial is actually very hard but the way you explain makes it really easy to understand!!!

sudhar
Автор

I don't know if you noticed it but there's only 12 gaps between the 13 buttons that may explain why you had to add 2*gap to center the buttons

bonjouraussi
Автор

Hey man, I've been watching your tutorials for about a month now and you explain things so well you are awesome and give great detail on everything!!

yotypicalgamer
Автор

A channel with this much effort deserves a million subs

DOOMElite
Автор

Hi Tim!
You are the best teacher I ever seen before. Thanks for learning me everything about Python and other languages

kemenesmark
Автор

I'm 12 and new to python, and in the first 12 minuets of the video you have taught me more than all my math teachers. Keep up the good work...







I still don't know why you don't have subs for your tutorials

flaminfox
Автор

The Math module was imported at 26:02 but I feel like it was there from the beginning of the video

m.amunimjinan
Автор

Which software do you use for free hand drawing the sketches explanations? Awesome tutorial BTW.

YouGuto
Автор

The only one who have goob video on python ...thx a lot
( and please make a video on mario or metal slug but please video on pygame witv differente animation!!

tcgvsocg
Автор

Thank you for #2 I'm definitely waiting for TUT #3.

thanyaniinnocent
Автор

hey, i found out another way to make the button disappear is:
if dis < RADIUS:

same result and you don't need to add another variable True in the letters
but i don't know am i right??? but the best way is to follow Tim' instructions <3

NguyenTu-xgoy
Автор

If you are stuck on the math and whatever he is saying is going over your head, Don't panic. Lock yourself in the room, turn on the lights, Grab a paper and pencil draw the whole thing and just listen him and draw it in your paper, Pretty simple math.

imherovirat