[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Newbie needs help, what's the most efficient (or easiest) way to do this?
- To: pygame-users@xxxxxxxx
- Subject: [pygame] Newbie needs help, what's the most efficient (or easiest) way to do this?
- From: "Charles Christie" <sonicbhoc@xxxxxxxxx>
- Date: Thu, 4 Jan 2007 14:45:56 -0500
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Thu, 04 Jan 2007 14:46:19 -0500
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=el3gBpksbH30SgPMm5ptiF5hyzaMeq1is+lKU9eui1EyiMI+PCa4+gZXndJ7y87CrO5sYltzvnGXwHI3XEk4cvLJPdS/tz3dG+bS1ujyG7dsSwNlgyUxQ6vKGLD0rnzTe7TJTG3zq4gKhCk0YfGbjb47Rl9xWufBKBfUnUyg0TY=
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Hey, I am making a typing game in Python using pygame. I have finally hit a
roadblock, and I think I'm toast. I started this game as my senior project,
and I need to have something to at least demonstrate by June.
I think I screwed myself on this one. I thought I knew a reasonable amount of
programming, but absolutely none of it is coming in handy. I had to ask for
help to get what I have now, and now I've hit a road block.
So, what I need is:
A. To find a way to feed multiple strings into the program. As in, when you
finish one string, instead of starting it over again you instead go to
the next word in the list, which I guessed should be an array of
strings. I'm probably wrong, though. What's the most efficient (or
easiest) way to do this?
B. Two timers, a combo timer and a word timer that count backwards. I
know I can figure out how to do these myself, though.
The code I have so far looks like this:
**************************************************************
#Credit to scriptedfun (http://www.scriptedfun.com) for the help
#Stil a very VERY barebones typing script. Still got one last part of the main
#engine to go before getting to work on part two.
import pygame
from pygame.locals import *
SCREENRECT = Rect(0, 0, 640, 480)
class Textsprite(pygame.sprite.Sprite):
def __init__(self, text):
pygame.sprite.Sprite.__init__(self)
self.text = text
self.pos = 0
self.update()
def update(self):
self.image = pygame.font.Font(None, 36).render(self.text, 1, (0, 0, 0))
self.highlight = pygame.font.Font(None,
36).render(self.text[:self.pos], 1, (0, 0, 255))
self.image.blit(self.highlight, (0, 0))
self.rect = self.image.get_rect()
self.rect.center = pygame.display.get_surface().get_rect().center
def keyin(self, key):
if key == self.text[self.pos]:
self.pos = self.pos + 1
self.combo = self.combo + 1
else:
self.combo = 0
if len(self.text) == self.pos:
self.pos = 0
def main():
pygame.init()
screen = pygame.display.set_mode(SCREENRECT.size)
# make background
background = pygame.Surface(SCREENRECT.size).convert()
background.fill((255, 255, 255))
screen.blit(background, (0, 0))
pygame.display.update()
# keep track of sprites
all = pygame.sprite.RenderUpdates()
# keep track of time
clock = pygame.time.Clock()
textsprite = Textsprite('It works!')
all.add(textsprite)
# game loop
while 1:
# get input
for event in pygame.event.get():
if event.type == QUIT:
return
elif event.type == KEYDOWN:
if event.key == K_ESCAPE:
return
else:
textsprite.keyin(event.unicode)
# clear sprites
all.clear(screen, background)
# update sprites
all.update()
# redraw sprites
dirty = all.draw(screen)
pygame.display.update(dirty)
# maintain frame rate
clock.tick(30)
if __name__ == '__main__': main()
**************************************************************
I've never used a mailing list before. I'm quite new at this. Sorry if
I disobeyed a rule of conduct or did something considered
implite/noobish/stupid.