I have troubles with events in Pygame again (Pygame seems to "avoid" loop
I can't seem to get indented conditions to be detected in my event loop:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == MOUSEBUTTONDOWN:
print 'mb'
if event.type == KEYDOWN: #NOT DETECTED
print 'keydown'
if event.key == K_e:
print 'key_e_pressed'
if event.type == variables.set_ennemies_dest:
print 'moves
I made sure that I was using event.type and event.key as appropriate, that my indentation was correct. I removed all my code from there and replaced it by print statements to make sure the problem didn't come from somewhere else.
Any help would be very welcome !
If the above look fine this is my full game loop:
import pygame, sys, variables
from pygame.locals import *
from classes import *
from instances import *
from functions import *
pygame.init()
clock = pygame.time.Clock()
pygame.time.set_timer(variables.set_ennemies_dest, 10000) #for ennemi movement
#game loop
while True:
clock.tick(60)
variables.screen.fill((0,0,0)) #make background black
for event in pygame.event.get(): #setting up quit
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == MOUSEBUTTONDOWN:
get_offset(hero,event) # sets the movement offset for the iteration
print 'mb'
if event.type == KEYDOWN:
print 'keydown'
if event.key == K_e:
for i in variables.item_list:
i.use(hero)
if event.type == variables.set_ennemies_dest:
print 'moves'
for o in variables.char_list:
if isinstance(o, Ranger): #moves characters
o.set_rand_dest()
for o in variables.char_list:
if isinstance(o, Ranger): #moves characters
o.move()
#offset checks
group_collision_check(variables.all_sprites_list,hero) #edits the offest based on hero collision
group_offset(variables.building_list) #new building position using offset
group_push(variables.item_list,hero)
scroll_map.offset() #offsets grass background map
group_offset(variables.ennemi_list)
variables.screen.blit(scroll_map.image, scroll_map.rect) # blits the grass map to new pos
variables.building_list.draw(variables.screen) #blits the buildings to new pos
#blitting characters
variables.screen.blit(hero.image, hero.rect) #blits hero to screen center
for o in variables.ennemi_list:
variables.screen.blit(o.image, o.rect)
variables.item_list.draw(variables.screen)
pygame.display.update()
variables.offset_time -= 1 #removes on step from the offset counter to keep track of when
#offset needs to be reset to 0, i.e. position is reached