[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Re:
- To: pygame-users@xxxxxxxx
- Subject: [pygame] Re:
- From: "Eyal Lotem" <eyal.lotem@xxxxxxxxx>
- Date: Sun, 24 Aug 2008 21:43:07 +0300
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Sun, 24 Aug 2008 14:43:12 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=kqZBm6RysKV22+/gVa/1HbmgxFxk0oZgPuwuGHdYWfk=; b=OXpU7UQSmACGZnC6vh3pJ1J8akgnCPBa763ZHGwKwCO9JCt1wdUFbjA28zon2KLZhc UCAbjpA03tT0+MA27d2qSWz79cKB81XCCZozDWaocD+ndw8yrah2bT4uzk5uOuslFOhM b8iRA8dUSlQsX2I79FqNAsfEXs8lSZKyqJWNM=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=xdK48w9XlFrTCaTfKlRLLK2d1L+SmA1AlAgh6Jtcq4KYefWGYvnXXCQz/fg2JHaTjp xjMhTVq9epiOUi9aK2gTLQKph5bP9qI/VoDhOnvd/CqozNeCxuw/utJCwDdbVaCZej6Y UyGFUfV78SW4ghhnh+XPOPgXvouP+2QbtXY4g=
- In-reply-to: <20080824162431.8F2ACCB6CB@xxxxxxxxxxxxxxxxxxxxxxx>
- References: <20080824162431.8F2ACCB6CB@xxxxxxxxxxxxxxxxxxxxxxx>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Its probably a better idea to move the character as long as its
pressed, and not according to type-matic repeat rate...
I think you can use pygame.key.get_pressed() for this, or note both
K_DOWN and K_UP events to mark your own state - such that you fix the
position at every iteration.
Eyal
On Sun, Aug 24, 2008 at 7:24 PM, yanom @linuxmail.org
<yanom@xxxxxxxxxxxxx> wrote:
> I have a problem with my pygame project:
> i used pygame.key.set_repeat(2,2) to make it so that continually holding down the left or right arrow keys moves a character. i have a problem though:
> whenever i press a key other than left or right, even if i am still holding an arrow key, my character stops moving. here is my code:
>
>
>
>
> import pygame, os, sys
> from pygame.locals import *
> pygame.init()
> clock = pygame.time.Clock()#start the clock
> screen = pygame.display.set_mode((640, 680), 0, 32)#create the screen, conveniently called screen
> enemy = pygame.image.load("enemy.sub.png").convert_alpha()#load sub images
> player = pygame.image.load("player.sub.png").convert_alpha()
> enemyrect = enemy.get_rect() #create rects
> playerrect = player.get_rect()
> playerrect = playerrect.move(500,500)#move the player sub to the bottom of the screen
> bullet = pygame.image.load("bullet.png").convert_alpha()#load the bullet image
> bulletrect = bullet.get_rect()#create bullet rect
> #bulletrect = bulletrect.move(0,780)#move it to the bottom
> speed = [2,0] #top speed of the enemysub
> pygame.key.set_repeat(2,2) #enable key repeat
> while 1:#main game loop
> clock.tick(60)#60 fps max
> enemyrect=enemyrect.move(speed) #bounce |
> if enemyrect.right > 640: speed = [-2, 0]# |
> if enemyrect.left <0: speed = [2, 0]# |
> if bulletrect.top > 600:
> bulletrect.left = enemyrect.left
> bulletrect.top = enemyrect.top
> else:
> bulletrect=bulletrect.move(0,7)
> for event in pygame.event.get(): #event query |
> if event.type == QUIT:# |
> exit()# |
> if event.type == KEYDOWN:# |
> if event.key == K_RIGHT:# |
> playerrect = playerrect.move(2,0)# |
> if event.key == K_LEFT:# |
> playerrect = playerrect.move(-2,0)# |
> screen.fill((0,255,255)) #fill screen
> screen.blit(enemy, enemyrect)#blit enemy
> screen.blit(player, playerrect)#blit player
> screen.blit(bullet,bulletrect)#blit bullet
> pygame.display.update() #update screen
>
>
> how do i solve this problem?
>
> =
> Tecpel - Propel Quality Measurement
> Wide range of quality sources from Taiwan.
> http://a8-asy.a8ww.net/a8-ads/adftrclick?redirectid=d1e2a9b5471fc3d9949f564a2f7d0acf
>
>
> --
> Powered by Outblaze
>