[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?



Aww.... it still doesn't work... am I doin' it right?

********************
#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.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.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

class Poscombosprite(pygame.sprite.Sprite):
   def __init__(self):
       pygame.sprite.Sprite.__init__(self)
       self.update()
   def update(self):
       self.poscombo = pygame.font.Font(None, 18).render('Letters
correctly typed in a row:' + str(Textsprite.poscmb), 1, (0, 255, 0))
       self.poscombo.blit(self.poscombo, (50, 150))
       self.poscmbrect = self.poscombo.get_rect()
       self.poscmbrect.center = pygame.display.get_surface().get_rect().center

class Stringcombosprite(pygame.sprite.Sprite):
   def __init__(self):
       pygame.sprite.Sprite.__init__(self)
       self.update()
   def update(self):
       self.stringcombo = pygame.font.Font(None, 18).render('Words
correctly typed in a row:' + str(Textsprite.stringcmb), 1, (255, 0,
0))
       self.stringcombo.blit(self.stringcombo, (50,50))
       self.stringcmbrect = self.stringcombo.get_rect()
       self.stringcmbrect.center =
pygame.display.get_surface().get_rect().center

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()
********************

On 1/30/07, Charles Christie <sonicbhoc@xxxxxxxxx> wrote:
Yeah, that's a good idea, actually. But that would require a LOT more
strategy as to how to program the bullet patterns and gameplay itself.
I have, however, thought of a way to do the basic idea of yours. The
hard part would be the bullet patterns. They obviously wouldn't be
bullet hell, even on the hardest levels. I think my idea would be
easier to program but yours definitely, if I could think of a
practical idea for more of the game play, would be more... innovative.
Different. And different, as I always say, is good.

On 1/30/07, Luke Paireepinart <rabidpoobear@xxxxxxxxx> wrote:
> Charles Christie wrote:
> > Oh. :P
> >
> > Interesting idea, but I really have no clue on how to program
> > something like that...
> Another, probably more managable idea, is to lay words out on a +, so
> you type the up word to move up,
> the down word to move down, and some extra word if you want to shoot /
> bomb... etc.
> obviously when i say 'down word' i don't actually mean the word 'down.'
> >
> > On 1/30/07, Luke Paireepinart <rabidpoobear@xxxxxxxxx> wrote:
> >> Charles Joseph Christie II wrote:
> >> > Actually, you would only move if you held the "TAB" button, else you'd
> >> > type.
> >> >
> >> He was suggesting an intriguing alternate control scheme,
> >> not asking how your game worked :)
> >> -Luke
> >> >>> 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.
> >> >>>
> >> >> There's an interesting idea in there somewhere. Suppose
> >> >> movement was *only* done using alphabetic keys. Then the
> >> >> words you typed would have the side effect of moving you
> >> >> around in various ways. To allow you some freedom of
> >> >> movement, you'd have a set of words to choose from at any
> >> >> moment. The game would then be to choose which word to
> >> >> type next to move you in the direction you want to go...
> >> >>
> >> >> --
> >> >> Greg
> >> >>
> >> >
> >> >
> >>
> >>
> >
>
>