Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #72173 > unrolled thread
| Started by | funky <benjaminhernacki@gmail.com> |
|---|---|
| First post | 2014-05-28 10:32 -0700 |
| Last post | 2014-05-28 16:37 -0500 |
| Articles | 6 — 6 participants |
Back to article view | Back to comp.lang.python
need help with this code please fix it or at least tell me what im doing wrong funky <benjaminhernacki@gmail.com> - 2014-05-28 10:32 -0700
Re: need help with this code please fix it or at least tell me what im doing wrong Gary Herron <gary.herron@islandtraining.com> - 2014-05-28 10:53 -0700
Re: need help with this code please fix it or at least tell me what im doing wrong John Gordon <gordon@panix.com> - 2014-05-28 18:33 +0000
Re: need help with this code please fix it or at least tell me what im doing wrong Grant Edwards <invalid@invalid.invalid> - 2014-05-28 19:08 +0000
Re: need help with this code please fix it or at least tell me what im doing wrong Ian Kelly <ian.g.kelly@gmail.com> - 2014-05-28 14:49 -0600
Re: need help with this code please fix it or at least tell me what im doing wrong Mark H Harris <harrismh777@gmail.com> - 2014-05-28 16:37 -0500
| From | funky <benjaminhernacki@gmail.com> |
|---|---|
| Date | 2014-05-28 10:32 -0700 |
| Subject | need help with this code please fix it or at least tell me what im doing wrong |
| Message-ID | <8bc01036-ee9e-4de9-b569-7039dcc05d9c@googlegroups.com> |
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()
[toc] | [next] | [standalone]
| From | Gary Herron <gary.herron@islandtraining.com> |
|---|---|
| Date | 2014-05-28 10:53 -0700 |
| Message-ID | <mailman.10412.1401300104.18130.python-list@python.org> |
| In reply to | #72173 |
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
[toc] | [prev] | [next] | [standalone]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Date | 2014-05-28 18:33 +0000 |
| Message-ID | <lm5a4u$kmf$1@reader1.panix.com> |
| In reply to | #72173 |
In <8bc01036-ee9e-4de9-b569-7039dcc05d9c@googlegroups.com> funky <benjaminhernacki@gmail.com> writes: 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... -- John Gordon Imagine what it must be like for a real medical doctor to gordon@panix.com watch 'House', or a real serial killer to watch 'Dexter'.
[toc] | [prev] | [next] | [standalone]
| From | Grant Edwards <invalid@invalid.invalid> |
|---|---|
| Date | 2014-05-28 19:08 +0000 |
| Message-ID | <lm5c7v$i2b$2@reader1.panix.com> |
| In reply to | #72173 |
On 2014-05-28, funky <benjaminhernacki@gmail.com> wrote:
[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.
--
Grant Edwards grant.b.edwards Yow! PUNK ROCK!! DISCO
at DUCK!! BIRTH CONTROL!!
gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2014-05-28 14:49 -0600 |
| Message-ID | <mailman.10421.1401310198.18130.python-list@python.org> |
| In reply to | #72173 |
On Wed, May 28, 2014 at 11:32 AM, funky <benjaminhernacki@gmail.com> wrote: > 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.
[toc] | [prev] | [next] | [standalone]
| From | Mark H Harris <harrismh777@gmail.com> |
|---|---|
| Date | 2014-05-28 16:37 -0500 |
| Message-ID | <lm5ku7$19r$1@speranza.aioe.org> |
| In reply to | #72173 |
On 5/28/14 12:32 PM, funky wrote: > 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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web