[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Character Movement



Well... I almost got it. I have the character moving, but it's not moving where it should move! It just keeps moving diagonally! no matter what button you push, it moves diagonally either up or down depending on whether you are adding or subtracting the value that the event cue is sending to it! Here's what I mean:

[stg.py -- where the characters and their actions are defined]
--------------------------------------------

class Player(pygame.sprite.Sprite):
    xmove = 0
    ymove = 0
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.x = pygame.display.get_surface().get_rect().centerx
        self.y = 400
        self.xmove = Player.xmove
        self.ymove = Player.ymove
        self.update()
       
    def update(self):
        self.image = pygame.Surface([30, 45])
        self.image.fill([0, 127, 255])
        self.image.blit(self.image, (0, 0))
        self.rect = self.image.get_rect ()
        self.rect.center = (self.x, self.y)
       
        self.x = self.x - self.xmove
        self.y = self.y - self.ymove
---------------------------------------------------------

[typinggame.py -- the main game, I should change the name of the file to reflect this but I'm too lazy :P]
----------------------------------------------------------
        for event in pygame.event.get():
            if event.type == QUIT:
                sys.exit()
               
            elif event.type == KEYUP:
                if event.key == K_TAB:
                    moving = 0
                    player.xmove = 0
                    player.ymove = 0
                if moving == 1:
                    if event.key == K_e or K_i or K_KP8 or K_d or K_k or K_KP5 or K_KP2:
                        player.xmove = 0
                    if event.key == K_s or K_j or K_KP4 or K_f or K_l or K_KP6:
                        player.ymove = 0
                       
            elif event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    sys.exit()
                elif event.key == K_TAB:
                    moving = 1
                   
                elif event.unicode.isalnum() or event.key == K_SPACE:
                    if moving== 0:
                        textsprite.keyin(event.unicode)
                    if moving == 1:
                        if event.key == K_e or K_i or K_KP8:
                            player.xmove = -3
                        if event.key == K_d or K_k or K_KP5 or K_KP2:
                            player.xmove = 3
                        if event.key == K_s or K_j or K_KP4:
                            player.ymove = -3
                        if event.key == K_f or K_l or K_KP6:
                            player.ymove = 3
------------------------------------------------------

So I don't get why it's moving diagonally down. It doesn't make sense... I'll update the svn repository later with my new code (there's lots of changes) when I get the chance so that you don't have to look at the code in the middle of an e-mail.

On 4/25/07, Charles Christie <sonicbhoc@xxxxxxxxx> wrote:
Well, this thing is due next Friday so I want a few quick-and-dirty hacks to get it running. After school is out I want to REALLY program this game instead of making a crappy proof-of-concept with lame newbie coding errors and lines of spaghetti code that do nothing. :P


On 4/25/07, Luke Paireepinart < rabidpoobear@xxxxxxxxx> wrote:
Kris Schnee wrote:
> Charles Christie wrote:
>> Kris: I did the typing part. Now I want to have a character that the
>> person playing the game can move across the screen.
>
> Would this graphics engine be of any use?
> <http://kschnee.xepher.net/pics/070416island.jpg>
>
> I've got an animated character that can walk and jump around on a
> scrolling tiled landscape loaded from a 1000x1000 image map. (The area
> shown in the minimap is the central island of this "zone":
> <http://kschnee.xepher.net/pics/zone_0_0.png >)
>
> The efficiency, hence speed, is poor because it's currently drawing a
> whole screen's worth of tiles every frame. The graphics shown are ugly
> because I haven't thought of what way to handle transitions between
> terrain types, and because I drew them. (I'm proud of that tree though!)
That's a pretty sweet tree, dude. :D
> Anyway, it's usable to display a large tiled landscape with an
> animated character; you could theoretically hook that up to the typing
> system.
It's a cool engine for sure, but I believe CC is making a Raiden-type
japanese shooter (bullet-dodging type thing.)  Hope you don't mind me
answering for you, Charles.
>
> Kris
>