[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Newbie needs help, what's the most efficient (or easiest) way to do this?
Alright my friends, I am in need of a little more help....
I tried to have the game count combos but it's not displaying it on
screen. (After I get this working, I'll also try to get it to display
how many words you typed and how many words are left, and later
convert that into an HP bar, but that's thinking too far ahead)
*********************
#Credit to scriptedfun (http://www.scriptedfun.com) for the help with
the typing portion
#Still a very VERY barebones typing script. Next I have to work on
#the basic shoot-em-up part and get the scoring in place
import pygame
from pygame.locals import *
import helpers
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.current_string = 0
self.poscmb = 0
self.stringcmb = 0
self.update()
def update(self):
self.image = pygame.font.Font(None,
36).render(self.text[self.current_string], 1, (0, 0, 0))
self.highlight = pygame.font.Font(None,
36).render(self.text[self.current_string][:self.pos], 1, (0, 0, 255))
self.stringcombo = pygame.font.Font(None, 18).render('Words
correctly typed in a row:' + str(self.stringcmb), 1, (255, 0, 0))
self.poscombo = pygame.font.Font(None, 18).render('Letters
correctly typed in a row:' + str(self.poscmb), 1, (0, 255, 0))
self.image.blit(self.highlight, (0, 0))
self.stringcombo.blit(self.stringcombo, (50,50))
self.poscombo.blit(self.poscombo, (50, 150))
self.rect = self.image.get_rect()
self.stringcmbrect = self.stringcombo.get_rect()
self.poscmbrect = self.poscombo.get_rect()
self.rect.center = pygame.display.get_surface().get_rect().center
self.stringcmbrect.center =
pygame.display.get_surface().get_rect().center
self.poscmbrect.center = pygame.display.get_surface().get_rect().center
def keyin(self, key):
if key == self.text[self.current_string][self.pos]:
self.pos = self.pos + 1
self.poscmb = self.poscmb + 1
else:
self.poscmb = 0
if len(self.text[self.current_string]) == self.pos:
self.pos = 0
if self.current_string +1 == len(self.text):
self.current_string = 0
else:
self.current_string = self.current_string + 1
self.stringcmb = self.stringcmb + 1
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(["test string1", "another test!", "can you
type this?", "Hey Mr Ottman!", "It works!"])
all.add(textsprite)
#Set moving to false
moving = 0
# game loop
while 1:
# get input
for event in pygame.event.get():
if event.type == QUIT:
return
elif event.type == KEYUP:
if event.key == K_TAB:
moving = 0
elif event.type == KEYDOWN:
if event.key == K_ESCAPE:
return
elif event.key == K_TAB:
moving = 1
elif moving == 0:
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()
*********************
So, I can't figure out why the words aren't appearing on screen... I
looked through the pygame API documentation to make sure I was doing
it right, but it didn't help. Well, actually it kinda did (I had to
convert the numbers to a string and it helped me there) but yeah, the
words don't actually show up. I wonder why?
On 1/29/07, Charles Christie <sonicbhoc@xxxxxxxxx> wrote:
The game would be about typing english words as fast as possible to
damage the boss, while moving around the bullet pattern it fires at
you.
The thing is that moving would be mapped, on a qwerty keyboard:
WASD, IKJL, and the up, 5, left and right buttons on a numpad.
I've never even seen a DVORAK keyboard so I would have no clue on how
to set it up for those.
I'm having a little more trouble but I'll ask about it later - I have
3D art class now, not senior project.
On 1/29/07, Luke Paireepinart <rabidpoobear@xxxxxxxxx> wrote:
> Charles Christie wrote:
> > Oh, and Luke, the game will be Open Source. So go ahead and modify it
> > for DVORAK or whatever. Do you really need to do that though? won't it
> > work fine with any kind of keyboard? Well, aside from the moving
> > parts. That would need modification for different keyboard types.
> Yeah, it works fine for all kinds of keyboards. but think about it:
> stage 1 for qwerty:
> ffff jjjj ffff jjjj fjfjfjfj jfjfjfj etc.
>
> stage 2:
> df fd jk kj etc.
>
> stage 1 on a dvorak:
> uh huh uh huh etc.
>
> stage 2 on a dvorak:
> the hut het teh tut etc.
>
> The layouts are different so the order in which you learn the keys is
> different...
> Unless your typing program is really just a speed test, then it doesn't
> matter what layout it's for -
> except that if you use english words us dvorak people will probably beat
> you qwertyers ;)
> I feel like that tale about the guy going up against the steam engine. :D
>
> I hope this has enlightened you ;)
> -Luke
>
- References:
- Re: [pygame] Newbie needs help, what's the most efficient (or easiest) way to do this?
- Re: [pygame] Newbie needs help, what's the most efficient (or easiest) way to do this?
- Re: [pygame] Newbie needs help, what's the most efficient (or easiest) way to do this?
- Re: [pygame] Newbie needs help, what's the most efficient (or easiest) way to do this?
- Re: [pygame] Newbie needs help, what's the most efficient (or easiest) way to do this?
- Re: [pygame] Newbie needs help, what's the most efficient (or easiest) way to do this?
- Re: [pygame] Newbie needs help, what's the most efficient (or easiest) way to do this?
- Re: [pygame] Newbie needs help, what's the most efficient (or easiest) way to do this?
- Re: [pygame] Newbie needs help, what's the most efficient (or easiest) way to do this?
- Re: [pygame] Newbie needs help, what's the most efficient (or easiest) way to do this?