• Why won't pygame work?
    10 replies, posted
Ok so im new to programming like a few months here and there but i found this pong game and thought i could make it better here is the code. import pygame from pygame.locals import * from sys import exit import random pygame.init() screen=pygame.display.set_mode((640,480),0,32) pygame.display.set_caption("Pong Pong!") #Creating 2 bars, a ball and background. back = pygame.Surface((640,480)) background = back.convert() background.fill((0,0,0)) bar = pygame.Surface((10,50)) bar1 = bar.convert() bar1.fill((0,0,255)) bar2 = bar.convert() bar2.fill((255,0,0)) circ_sur = pygame.Surface((15,15)) circ = pygame.draw.circle(circ_sur,(0,255,0),(15/2,15/2),15/2) circle = circ_sur.convert() circle.set_colorkey((0,0,0)) # some definitions bar1_x, bar2_x = 10. , 620. bar1_y, bar2_y = 215. , 215. circle_x, circle_y = 307.5, 232.5 bar1_move, bar2_move = 0. , 0. speed_x, speed_y, speed_circ = 250., 250., 250. bar1_score, bar2_score = 0,0 #clock and font objects clock = pygame.time.Clock() font = pygame.font.SysFont("calibri",40) while True: for event in pygame.event.get(): if event.type == QUIT: exit() if event.type == KEYDOWN: if event.key == K_UP: bar1_move = -ai_speed elif event.key == K_DOWN: bar1_move = ai_speed elif event.type == KEYUP: if event.key == K_UP: bar1_move = 0. elif event.key == K_DOWN: bar1_move = 0. score1 = font.render(str(bar1_score), True,(255,255,255)) score2 = font.render(str(bar2_score), True,(255,255,255)) screen.blit(background,(0,0)) frame = pygame.draw.rect(screen,(255,255,255),Rect((5,5),(630,470)),2) middle_line = pygame.draw.aaline(screen,(255,255,255),(330,5),(330,475)) screen.blit(bar1,(bar1_x,bar1_y)) screen.blit(bar2,(bar2_x,bar2_y)) screen.blit(circle,(circle_x,circle_y)) screen.blit(score1,(250.,210.)) screen.blit(score2,(380.,210.)) bar1_y += bar1_move # movement of circle time_passed = clock.tick(30) time_sec = time_passed / 1000.0 circle_x += speed_x * time_sec circle_y += speed_y * time_sec ai_speed = speed_circ * time_sec #AI of the computer. if circle_x >= 305.: if not bar2_y == circle_y + 7.5: if bar2_y < circle_y + 7.5: bar2_y += ai_speed if bar2_y > circle_y - 42.5: bar2_y -= ai_speed else: bar2_y == circle_y + 7.5 if bar1_y >= 420.: bar1_y = 420. elif bar1_y <= 10. : bar1_y = 10. if bar2_y >= 420.: bar2_y = 420. elif bar2_y <= 10.: bar2_y = 10. #since i don't know anything about collision, ball hitting bars goes like this. if circle_x <= bar1_x + 10.: if circle_y >= bar1_y - 7.5 and circle_y <= bar1_y + 42.5: circle_x = 20. speed_x = -speed_x if circle_x >= bar2_x - 15.: if circle_y >= bar2_y - 7.5 and circle_y <= bar2_y + 42.5: circle_x = 605. speed_x = -speed_x if circle_x < 5.: bar2_score += 1 circle_x, circle_y = 320., 232.5 bar1_y,bar_2_y = 215., 215. elif circle_x > 620.: bar1_score += 1 circle_x, circle_y = 307.5, 232.5 bar1_y, bar2_y = 215., 215. if circle_y <= 10.: speed_y = -speed_y circle_y = 10. elif circle_y >= 457.5: speed_y = -speed_y circle_y = 457.5 pygame.display.update() i know i have seen this somewhere else but i still cant figure it out i know i have to add something. whenever i open it pygame just sits there and if i try to close it it goes all not resposive. i need detailed advice not just stuff that makes no sense please help me i am so confused.
where? what code? all of it? im really confused right now.
would it be better if i just put the link to the pong file and you can see the filke yourself the one i posted is like i said one that i was going to work on but cant get running maybe you can check it out and then show me. [editline]18th July 2015[/editline] [url]http://www.mediafire.com/download/igmkm0mt04a/pong+v1.0.py[/url] [editline]18th July 2015[/editline] i tryed that it said code not defined
[QUOTE=mcmaxx16;48240562]would it be better if i just put the link to the pong file and you can see the filke yourself the one i posted is like i said one that i was going to work on but cant get running maybe you can check it out and then show me. [...][/QUOTE] It really would be easier for everyone if you just put it in [code] tags, like Rocket said.
Because he's obviously not going to do it [code] import pygame from pygame.locals import * from sys import exit import random pygame.init() screen=pygame.display.set_mode((640,480),0,32) pygame.display.set_caption("Pong Pong!") #Creating 2 bars, a ball and background. back = pygame.Surface((640,480)) background = back.convert() background.fill((0,0,0)) bar = pygame.Surface((10,50)) bar1 = bar.convert() bar1.fill((0,0,255)) bar2 = bar.convert() bar2.fill((255,0,0)) circ_sur = pygame.Surface((15,15)) circ = pygame.draw.circle(circ_sur,(0,255,0),(15/2,15/2),15/2) circle = circ_sur.convert() circle.set_colorkey((0,0,0)) # some definitions bar1_x, bar2_x = 10. , 620. bar1_y, bar2_y = 215. , 215. circle_x, circle_y = 307.5, 232.5 bar1_move, bar2_move = 0. , 0. speed_x, speed_y, speed_circ = 250., 250., 250. bar1_score, bar2_score = 0,0 #clock and font objects clock = pygame.time.Clock() font = pygame.font.SysFont("calibri",40) while True: for event in pygame.event.get(): if event.type == QUIT: exit() if event.type == KEYDOWN: if event.key == K_UP: bar1_move = -ai_speed elif event.key == K_DOWN: bar1_move = ai_speed elif event.type == KEYUP: if event.key == K_UP: bar1_move = 0. elif event.key == K_DOWN: bar1_move = 0. score1 = font.render(str(bar1_score), True,(255,255,255)) score2 = font.render(str(bar2_score), True,(255,255,255)) screen.blit(background,(0,0)) frame = pygame.draw.rect(screen,(255,255,255),Rect((5,5),( 630,470)),2) middle_line = pygame.draw.aaline(screen,(255,255,255),(330,5),(3 30,475)) screen.blit(bar1,(bar1_x,bar1_y)) screen.blit(bar2,(bar2_x,bar2_y)) screen.blit(circle,(circle_x,circle_y)) screen.blit(score1,(250.,210.)) screen.blit(score2,(380.,210.)) bar1_y += bar1_move # movement of circle time_passed = clock.tick(30) time_sec = time_passed / 1000.0 circle_x += speed_x * time_sec circle_y += speed_y * time_sec ai_speed = speed_circ * time_sec #AI of the computer. if circle_x >= 305.: if not bar2_y == circle_y + 7.5: if bar2_y < circle_y + 7.5: bar2_y += ai_speed if bar2_y > circle_y - 42.5: bar2_y -= ai_speed else: bar2_y == circle_y + 7.5 if bar1_y >= 420.: bar1_y = 420. elif bar1_y <= 10. : bar1_y = 10. if bar2_y >= 420.: bar2_y = 420. elif bar2_y <= 10.: bar2_y = 10. #since i don't know anything about collision, ball hitting bars goes like this. if circle_x <= bar1_x + 10.: if circle_y >= bar1_y - 7.5 and circle_y <= bar1_y + 42.5: circle_x = 20. speed_x = -speed_x if circle_x >= bar2_x - 15.: if circle_y >= bar2_y - 7.5 and circle_y <= bar2_y + 42.5: circle_x = 605. speed_x = -speed_x if circle_x < 5.: bar2_score += 1 circle_x, circle_y = 320., 232.5 bar1_y,bar_2_y = 215., 215. elif circle_x > 620.: bar1_score += 1 circle_x, circle_y = 307.5, 232.5 bar1_y, bar2_y = 215., 215. if circle_y <= 10.: speed_y = -speed_y circle_y = 10. elif circle_y >= 457.5: speed_y = -speed_y circle_y = 457.5 pygame.display.update() [/code]
[QUOTE=TeamEnternode;48256065]Because he's obviously not going to do it [...][/QUOTE] That's currently practically unreadable, considering Python is indentation-sensitive and almost all of that is missing.
[QUOTE=Tamschi;48256566]That's currently practically unreadable, considering Python is indentation-sensitive and almost all of that is missing.[/QUOTE] He didn't put any indentation in the OP either so that doesn't help.
[QUOTE=TeamEnternode;48267464]He didn't put any indentation in the OP either so that doesn't help.[/QUOTE] Technically it's there, you just have to quote it to see it. That said, I wasn't sure whether the OP was still current and didn't bother to download it from MediaFire which is why I didn't do it myself.
Sorry, you need to Log In to post a reply to this thread.