need help with this code please fix it or at least tell me what imdoing wrong

F

funky

import pygame
import random
import time
import sys
black = (0, 0, 0)
white = (255, 255, 255)
red = (255, 0, 0)

class Block(pygame.sprite.Sprite):
def __init__(self, color, width, height):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface([width, height])
self.image.fill(color)
self.rect = self.image.get_rect()
def reset_pos(self):
self.rect.y = -20
self.rect.x = random.randrange(700)


def update(self):
self.rect.y +=1
if self.rect.y > 410:
self.rect.y = -20
self.rect.x = random.randrange(700)


pygame.init()

screen_width = 700
screen_height = 400
screen = pygame.display.set_mode([screen_width, screen_height])
block_list = pygame.sprite.Group()
wall_list = pygame.sprite.Group()
all_sprites_list = pygame.sprite.Group()


for i in range(50):
color = (random.randint(40, 255), random.randint(40, 255), random.randint(40, 255))
block = Block(color, 20, 15)
block.rect.x = random.randrange(screen_width)
block.rect.y = random.randrange(screen_height)
block_list.add(block)
all_sprites_list.add(block)


player = Block(red, 20, 15)
all_sprites_list.add(player)


done = False
clock = pygame.time.Clock()
score = 0
minutes = 0
seconds = 0
time_start = 0
while done == False:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done == True
while True:
sys.stdout.write("\r{minutes} Minutes {seconds} Seconds".format(minutes=minutes, seconds=seconds))
sys.stdout.flush()
time.sleep(1)
seconds = int(time.time() - time_start) - minutes * 60



for x in range(1, 1000):
screen.fill(white)


blocks_hit_list = pygame.sprite.spritecollide(player, block_list, False)

for block in blocks_hit_list:
if block > 0:
score += 1
print score
block.reset_pos()

font = pygame.font.Font(None, 25)
text2 = font.render("time left: " + str(seconds), True, black)
text = font.render("Score: " + str(score), True, black)
screen.blit(text, [20, 20])
screen.blit(text2,[0, 20])

pos = pygame.mouse.get_pos()
player.rect.x=pos[0]
player.rect.y=pos[1]
block_list.update()



all_sprites_list.draw(screen)
clock.tick(120)
pygame.display.flip()
if seconds == 60:
pygame.quit()
 
G

Gary Herron

On 05/28/2014 10:32 AM, funky wrote:
<100+ lines of code removed.>

No way. This is not a paid service, but rather a community of Python
users. You can get lots of help here, but you have to put in some
work. Please take the time to tell us:
What this code should do.
What it actually does.
Why you think it's wrong.

You should also tell us what version of Python you are using, and on
what platform you are running it.

Moreover, please reduce down to a bare minimum, the amount of code
needed to show us the part that fails.

Gary Herron
 
J

John Gordon

What do you want the program to do?
What is it doing instead?
Do you get any error messages?

Don't just throw code at us and ask us to fix it...
 
G

Grant Edwards

[program that apparently doesn't work]

I'll fix it for you. My rates are $150/hour with a 4-hour minimum
paid up-front.
 
I

Ian Kelly

while done == False:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done == True

Here is one fairly obvious bug; you used "==" where you presumably
intended to do an assignment. As it stands it will just compare done
to True and then discard the result.

That's not necessarily the only issue, but if you want more detailed
help then as others have stated you're going to have to tell us in
what way the code isn't working as expected.
 
M

Mark H Harris

import pygame <========== a very good place to start
import random
import time
import sys


http://www.pygame.org/wiki/tutorials


My hourly rate is $295.00 /hour, w/2hour minimum, happy to send you a
contract of engagement and a copy of my document of understanding. Sign
both and arrange payment through paypal and I'll give you a call --- the
first 30 minutes consultation is free.

marcus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,831
Latest member
HealthSmartketoReviews

Latest Threads

Top