Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
scoring issues in pong
#2
You should read through my series of tutorials. You have bottlenecks (loading your images in the main game loop)
Quote:
    win.blit(pygame.image.load('BG.png'),(0, 0))

and magic numbers all over the place.
Quote:
#ball movement
 
    if x1 > 600:
        score1 += 1
        x1 = 305
        y1 = 245
        xvel *= -1
        yvel *= 1
 
         
 
    if x1 < 0:
        score2 += 1
        x1 = 305
        y1 = 245
        xvel *= -1
        yvel *= 1
         
     
    if y1 >= 490:
        yvel *= -1
 
    if y1 <= 10:
        yvel *= -1
 
#paddle collison
 
         
    if x1 >= 560 and (y1 < yp1 +65 and y1 > yp1):
        x1 == 559
        xvel *= -1
        yvel *= 1
 
 
    if x1 <= 25 and (y1 < yp2 +65 and y1 > yp2):
        x1 == 26
        xvel *= -1
        yvel *= 1

You are not using pygame rects for position and drawing at all making it spaghetti code. So its makes it more time consuming to follow flow, in which time i do not have.
Recommended Tutorials:
Reply


Messages In This Thread
scoring issues in pong - by wildbill - Aug-05-2019, 01:29 AM
RE: scoring issues in pong - by metulburr - Aug-05-2019, 01:48 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to send a pong on websocket-client tomtom 0 4,050 Aug-15-2022, 05:58 AM
Last Post: tomtom
  Problem with my pong game code Than999 8 4,219 May-15-2022, 06:40 AM
Last Post: deanhystad
  Pong game buss0140 7 4,368 Dec-27-2020, 07:04 AM
Last Post: ndc85430
  PING PONG GAME akea 0 5,801 May-08-2019, 04:30 PM
Last Post: akea
  Python project "pong" without any makefile sylas 5 5,157 Nov-28-2017, 05:55 PM
Last Post: Larz60+
  ping and pong run both well sylas 1 3,285 Sep-24-2017, 05:14 PM
Last Post: sylas

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020