+ 1

# pygame scoring progress bar x y coordinates and syntax help

very new to programing how would you code this in python3 https://drive.google.com/file/d/1MnnM_TdheeSENGp9xd6wKjR3_WoxD2jM/view?usp=sharing writing a pygame app and i need to have a score progress bar were if player scores they get a green block and if they are wrong they get a red block i cant figure out a good way to know the location to put the blocks in the right order as i don't know when they will score green block or fail to score red block some code i wrote trying to work it out i think the best way would be to use a dictionary or list of coordinates to. be able place the blocks ?? https://code.sololearn.com/cBrJ2gZeGref i know theirs got to be a way to do this i cant figure it out i'm to new

12th Jan 2020, 9:50 PM
userx
3 Respuestas
+ 2
I don't know how the scoring works, but I would use a list with simply 3 different items: ("red", "green", None). In beginning the list is just full of Nones. Also the list length and the size of the progress bar is needed to know, if the points need gaps, also the gap sizes are needed to know. Let list length be 10. points = [None, None, None, None, None, None, None, None, None, None] count_points = 10 point_palette = {None: (255, 255, 255), "red": (255, 0, 0), "green": (0, 255, 0)} Let progress bar rect be (50, 95, 100, 10) (posx, posy, width, height) #Rect progressbar_rect = (50, 95, 100, 10) Let gap widths be 1: gap_width = 1
13th Jan 2020, 12:42 AM
Seb TheS
+ 2
Size of the point rectangle sizes can be calculated, we would have simply divided progress bar width by the amount of points, but we need to subtract the total width of all gaps: point_size = (progressbar_rect[2] - gap_width * (count_points - 1)) // count_points, progressbar_rect[3]) Then we iterate through the list the xposition will start from the progress bar position and increase by the sum of point width and gap width.: for i in range(count_points): point_pos = (progressbar_pos[0] + (point_size[0] + gap_width) * i, progressbar_pos[1]) point_rect = point_pos + point_size point_color = point_palette[points[i]] <pygame.draw.rect would be used here to draw the rectangle>
13th Jan 2020, 12:50 AM
Seb TheS
+ 1
nice thank you totally different from how i was trying to do it
13th Jan 2020, 1:09 AM
userx