Support for Qwerty controls
This commit is contained in:
parent
48c083d3ff
commit
9fcefe7030
@ -20,7 +20,6 @@ class Game():
|
||||
self.logs = []
|
||||
|
||||
self.running = True
|
||||
self.init_inputs()
|
||||
self.gameloop = gameloop.GameLoop() # Je crée une boucle de jeu
|
||||
def load_image(filename):
|
||||
return pygame.image.load(filename).convert_alpha()
|
||||
@ -90,12 +89,13 @@ class Game():
|
||||
self.globals["scamerax"] = 0
|
||||
self.globals["scameray"] = 0
|
||||
self.globals["players"] = []
|
||||
self.globals["hitpose"] = False
|
||||
self.globals["AZERTY"] = True
|
||||
self.globals["pause"] = False
|
||||
self.globals["finishedlevels"] = [] # Levels where the player went to the end
|
||||
self.globals["completedlevels"] = [] # Levels where the player kicked all non-respawnable ennemies
|
||||
self.globals["speedrunlevels"] = [] # Levels where the player finished fast enough
|
||||
self.globals["allunlocked"] = True
|
||||
self.init_inputs()
|
||||
self.scaleCamera()
|
||||
|
||||
settings = {"sfx":1,"bgm":0.2}
|
||||
@ -150,42 +150,38 @@ class Game():
|
||||
self.inputs = {}
|
||||
self.inputs["keys"] = {
|
||||
"escape":{
|
||||
"timer" : 0, # Timer de la touche
|
||||
"realtime" : 0, # Temps réel préssé
|
||||
"pressed" : False,
|
||||
"counted" : False,
|
||||
"keycode" : pygame.K_ESCAPE # Code pygame de la touche en question
|
||||
"keycode" : [pygame.K_ESCAPE,pygame.K_RETURN] # Code pygame de la touche en question
|
||||
},
|
||||
"left":{
|
||||
"timer" : 0, # Timer de la touche
|
||||
"realtime" : 0, # Temps réel préssé
|
||||
"pressed" : False,
|
||||
"counted" : False,
|
||||
"keycode" : pygame.K_q # Code pygame de la touche en question
|
||||
"keycode" : [pygame.K_LEFT] # Code pygame de la touche en question
|
||||
},
|
||||
"right":{
|
||||
"timer" : 0, # Timer de la touche
|
||||
"realtime" : 0, # Temps réel préssé
|
||||
"pressed" : False,
|
||||
"counted" : False,
|
||||
"keycode" : pygame.K_d # Code pygame de la touche en question
|
||||
"keycode" : [pygame.K_RIGHT] # Code pygame de la touche en question
|
||||
},
|
||||
"up":{
|
||||
"timer" : 0, # Timer de la touche
|
||||
"realtime" : 0, # Temps réel préssé
|
||||
"pressed" : False,
|
||||
"counted" : False,
|
||||
"keycode" : pygame.K_z # Code pygame de la touche en question
|
||||
"keycode" : [pygame.K_SPACE,pygame.K_UP] # Code pygame de la touche en question
|
||||
},
|
||||
"down":{
|
||||
"timer" : 0, # Timer de la touche
|
||||
"realtime" : 0, # Temps réel préssé
|
||||
"pressed" : False,
|
||||
"counted" : False,
|
||||
"keycode" : pygame.K_s # Code pygame de la touche en question
|
||||
"keycode" : [pygame.K_DOWN] # Code pygame de la touche en question
|
||||
}
|
||||
}
|
||||
if self.globals["AZERTY"]: # Azerty controls
|
||||
self.inputs["keys"]["left"]["keycode"].append(pygame.K_q)
|
||||
self.inputs["keys"]["right"]["keycode"].append(pygame.K_d)
|
||||
self.inputs["keys"]["up"]["keycode"].append(pygame.K_z)
|
||||
self.inputs["keys"]["down"]["keycode"].append(pygame.K_s)
|
||||
else: # Qwerty controls
|
||||
self.inputs["keys"]["left"]["keycode"].append(pygame.K_a)
|
||||
self.inputs["keys"]["right"]["keycode"].append(pygame.K_d)
|
||||
self.inputs["keys"]["up"]["keycode"].append(pygame.K_w)
|
||||
self.inputs["keys"]["down"]["keycode"].append(pygame.K_s)
|
||||
|
||||
}
|
||||
|
||||
for key in self.inputs["keys"].keys():
|
||||
self.inputs["keys"][key]["timer"] = 0
|
||||
self.inputs["keys"][key]["realtime"] = 0
|
||||
self.inputs["keys"][key]["pressed"] = False
|
||||
self.inputs["keys"][key]["counted"] = False
|
||||
|
||||
self.inputs["joysticks"] = {}
|
||||
|
||||
@ -195,10 +191,11 @@ class Game():
|
||||
self.running = False
|
||||
if event.type == pygame.KEYDOWN:
|
||||
for i in self.inputs["keys"].keys():
|
||||
if event.key == self.inputs["keys"][i]["keycode"]: # Vérifie si une des touches du dico est préssée
|
||||
if event.key in self.inputs["keys"][i]["keycode"]: # Vérifie si une des touches du dico est préssée
|
||||
self.inputs["keys"][i]["pressed"] = True
|
||||
if event.type == pygame.KEYUP:
|
||||
for i in self.inputs["keys"].keys():
|
||||
if event.key in self.inputs["keys"][i]["keycode"]: # Vérifie si une des touches du dico est préssée
|
||||
self.inputs["keys"][i]["pressed"] = False
|
||||
if event.type == pygame.JOYDEVICEADDED:
|
||||
index = event.device_index
|
||||
|
@ -13,6 +13,10 @@ class Pause(BaseObject):
|
||||
self.fill.fill([62,33,55])
|
||||
self.fill.set_alpha(100)
|
||||
|
||||
self.trash = game.sprite_lib["trash.png"]
|
||||
txt = "Cleared : "+str(self.game.globals["trashes"])+" / "+str(self.game.globals["totaltrashes"])
|
||||
self.trashcounter = self.game.getchars(txt)
|
||||
|
||||
self.cursor = 0
|
||||
self.cursorsprite = self.game.sprite_lib["cursor.png"]
|
||||
|
||||
@ -58,9 +62,14 @@ class Pause(BaseObject):
|
||||
def draw(self):
|
||||
self.game.window.blit(self.fill,[0,0])
|
||||
|
||||
# Draw clear counter
|
||||
x = self.game.globals["cameraw"]/2
|
||||
self.game.lib.drawcenter(self.game,self.trashcounter,x,50)
|
||||
self.game.lib.drawcenter(self.game,self.trash,x-100,50)
|
||||
self.game.lib.drawcenter(self.game,self.trash,x+100,50)
|
||||
|
||||
# Draw options
|
||||
for i,v in enumerate(self.optionsorder):
|
||||
x = self.game.globals["cameraw"]/2
|
||||
y = self.offset+i*(9+self.padding)
|
||||
self.game.lib.drawcenter(self.game,self.sprites[v],x,y)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user