fix bug in movement handling when only one of the directions was stopped
This commit is contained in:
parent
8360689edb
commit
b1b585515c
1 changed files with 52 additions and 13 deletions
65
pyshoot.py
65
pyshoot.py
|
@ -7,7 +7,7 @@
|
|||
import pygame
|
||||
from pygame.locals import *
|
||||
import os
|
||||
|
||||
import random
|
||||
|
||||
|
||||
# constants
|
||||
|
@ -97,20 +97,24 @@ class Player(Object):
|
|||
""" initiate moving sequence """
|
||||
globals.moving_objects.add(self)
|
||||
self.speed = (self.speed[0] + vector[0], self.speed[1] + vector[1])
|
||||
if not globals.moving_objects.has(self):
|
||||
print "error should contain self after start_move"
|
||||
|
||||
def stop_move(self):
|
||||
def stop_move(self, vector):
|
||||
""" stop moving sequence """
|
||||
globals.moving_objects.remove(self)
|
||||
self.speed = (0, 0)
|
||||
if globals.moving_objects.has(self):
|
||||
print "error should NOT contain self after stop_move"
|
||||
self.speed = (self.speed[0] - vector[0], self.speed[1] - vector[1])
|
||||
|
||||
if self.speed == (0, 0):
|
||||
globals.moving_objects.remove(self)
|
||||
|
||||
def start_shoot(self):
|
||||
self.shoot()
|
||||
|
||||
def stop_shoot(self):
|
||||
pass
|
||||
|
||||
def init_gfx():
|
||||
"""graphics initialisation"""
|
||||
|
||||
globals.screen = pygame.display.set_mode((SCREEN_X, SCREEN_Y))
|
||||
globals.screen = pygame.display.set_mode((SCREEN_X, SCREEN_Y), HWSURFACE|DOUBLEBUF)
|
||||
globals.screen.fill(0)
|
||||
pygame.display.flip()
|
||||
|
||||
|
@ -123,9 +127,11 @@ def init():
|
|||
pygame.init()
|
||||
init_gfx()
|
||||
globals.clock = pygame.time.Clock()
|
||||
random.seed()
|
||||
#globals.event_type = {'create_enemeny' : create_enemey, 'vanish_object': vanish_object()}
|
||||
|
||||
|
||||
|
||||
def create_enemy(type):
|
||||
""" create an enemy """
|
||||
pass
|
||||
|
@ -163,17 +169,48 @@ def process_key(event, player):
|
|||
player.start_shoot()
|
||||
if event.type == KEYUP:
|
||||
if event.key == K_UP:
|
||||
player.stop_move()
|
||||
player.stop_move((0, -1))
|
||||
elif event.key == K_DOWN:
|
||||
player.stop_move()
|
||||
player.stop_move((0, 1))
|
||||
elif event.key == K_LEFT:
|
||||
player.stop_move()
|
||||
player.stop_move((-1, 0))
|
||||
elif event.key == K_RIGHT:
|
||||
player.stop_move()
|
||||
player.stop_move((1,0))
|
||||
elif event.key == K_x:
|
||||
player.stop_shoot()
|
||||
|
||||
|
||||
def transition(type):
|
||||
""" transition selector """
|
||||
|
||||
if type == 0:
|
||||
transition_disintegrate()
|
||||
elif type == 1:
|
||||
transition_fade_to_black()
|
||||
elif type == 2:
|
||||
transition_fade_to_white()
|
||||
|
||||
def transition_disintegrate():
|
||||
""" put black pixels at randoom location"""
|
||||
for i in range(0, 200000):
|
||||
x = random.randint(0, SCREEN_X)
|
||||
y = random.randint(0, SCREEN_Y)
|
||||
globals.screen.set_at((x, y), (0,0,0, 255))
|
||||
if i % 1000 == 0 :
|
||||
pygame.display.update()
|
||||
globals.screen.fill((0, 0, 0))
|
||||
pygame.display.update()
|
||||
|
||||
|
||||
def transition_fade_to_black():
|
||||
""" darken every pixels on screen """
|
||||
array = pygame.PixelArray(globals.screen)
|
||||
pass
|
||||
|
||||
def transition_fade_to_white():
|
||||
""" lighten every pixels on screen """
|
||||
pass
|
||||
|
||||
##
|
||||
# Main
|
||||
##
|
||||
|
@ -228,6 +265,8 @@ while not globals.die:
|
|||
# reinitializing moving objects list
|
||||
#globals.moving_objects = pygame.sprite.RenderUpdates()
|
||||
|
||||
# transition(0)
|
||||
|
||||
print "frames : %d" % nbframe
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue