Support for Qwerty controls
This commit is contained in:
parent
48c083d3ff
commit
9fcefe7030
@ -20,7 +20,6 @@ class Game():
|
|||||||
self.logs = []
|
self.logs = []
|
||||||
|
|
||||||
self.running = True
|
self.running = True
|
||||||
self.init_inputs()
|
|
||||||
self.gameloop = gameloop.GameLoop() # Je crée une boucle de jeu
|
self.gameloop = gameloop.GameLoop() # Je crée une boucle de jeu
|
||||||
def load_image(filename):
|
def load_image(filename):
|
||||||
return pygame.image.load(filename).convert_alpha()
|
return pygame.image.load(filename).convert_alpha()
|
||||||
@ -90,12 +89,13 @@ class Game():
|
|||||||
self.globals["scamerax"] = 0
|
self.globals["scamerax"] = 0
|
||||||
self.globals["scameray"] = 0
|
self.globals["scameray"] = 0
|
||||||
self.globals["players"] = []
|
self.globals["players"] = []
|
||||||
self.globals["hitpose"] = False
|
self.globals["AZERTY"] = True
|
||||||
self.globals["pause"] = False
|
self.globals["pause"] = False
|
||||||
self.globals["finishedlevels"] = [] # Levels where the player went to the end
|
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["completedlevels"] = [] # Levels where the player kicked all non-respawnable ennemies
|
||||||
self.globals["speedrunlevels"] = [] # Levels where the player finished fast enough
|
self.globals["speedrunlevels"] = [] # Levels where the player finished fast enough
|
||||||
self.globals["allunlocked"] = True
|
self.globals["allunlocked"] = True
|
||||||
|
self.init_inputs()
|
||||||
self.scaleCamera()
|
self.scaleCamera()
|
||||||
|
|
||||||
settings = {"sfx":1,"bgm":0.2}
|
settings = {"sfx":1,"bgm":0.2}
|
||||||
@ -150,42 +150,38 @@ class Game():
|
|||||||
self.inputs = {}
|
self.inputs = {}
|
||||||
self.inputs["keys"] = {
|
self.inputs["keys"] = {
|
||||||
"escape":{
|
"escape":{
|
||||||
"timer" : 0, # Timer de la touche
|
"keycode" : [pygame.K_ESCAPE,pygame.K_RETURN] # Code pygame de la touche en question
|
||||||
"realtime" : 0, # Temps réel préssé
|
|
||||||
"pressed" : False,
|
|
||||||
"counted" : False,
|
|
||||||
"keycode" : pygame.K_ESCAPE # Code pygame de la touche en question
|
|
||||||
},
|
},
|
||||||
"left":{
|
"left":{
|
||||||
"timer" : 0, # Timer de la touche
|
"keycode" : [pygame.K_LEFT] # Code pygame de la touche en question
|
||||||
"realtime" : 0, # Temps réel préssé
|
|
||||||
"pressed" : False,
|
|
||||||
"counted" : False,
|
|
||||||
"keycode" : pygame.K_q # Code pygame de la touche en question
|
|
||||||
},
|
},
|
||||||
"right":{
|
"right":{
|
||||||
"timer" : 0, # Timer de la touche
|
"keycode" : [pygame.K_RIGHT] # Code pygame de la touche en question
|
||||||
"realtime" : 0, # Temps réel préssé
|
|
||||||
"pressed" : False,
|
|
||||||
"counted" : False,
|
|
||||||
"keycode" : pygame.K_d # Code pygame de la touche en question
|
|
||||||
},
|
},
|
||||||
"up":{
|
"up":{
|
||||||
"timer" : 0, # Timer de la touche
|
"keycode" : [pygame.K_SPACE,pygame.K_UP] # Code pygame de la touche en question
|
||||||
"realtime" : 0, # Temps réel préssé
|
|
||||||
"pressed" : False,
|
|
||||||
"counted" : False,
|
|
||||||
"keycode" : pygame.K_z # Code pygame de la touche en question
|
|
||||||
},
|
},
|
||||||
"down":{
|
"down":{
|
||||||
"timer" : 0, # Timer de la touche
|
"keycode" : [pygame.K_DOWN] # Code pygame de la touche en question
|
||||||
"realtime" : 0, # Temps réel préssé
|
|
||||||
"pressed" : False,
|
|
||||||
"counted" : False,
|
|
||||||
"keycode" : pygame.K_s # 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"] = {}
|
self.inputs["joysticks"] = {}
|
||||||
|
|
||||||
@ -195,11 +191,12 @@ class Game():
|
|||||||
self.running = False
|
self.running = False
|
||||||
if event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
for i in self.inputs["keys"].keys():
|
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
|
self.inputs["keys"][i]["pressed"] = True
|
||||||
if event.type == pygame.KEYUP:
|
if event.type == pygame.KEYUP:
|
||||||
for i in self.inputs["keys"].keys():
|
for i in self.inputs["keys"].keys():
|
||||||
self.inputs["keys"][i]["pressed"] = False
|
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:
|
if event.type == pygame.JOYDEVICEADDED:
|
||||||
index = event.device_index
|
index = event.device_index
|
||||||
self.inputs["joysticks"][index] = pygame.joystick.Joystick(index)
|
self.inputs["joysticks"][index] = pygame.joystick.Joystick(index)
|
||||||
|
@ -13,6 +13,10 @@ class Pause(BaseObject):
|
|||||||
self.fill.fill([62,33,55])
|
self.fill.fill([62,33,55])
|
||||||
self.fill.set_alpha(100)
|
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.cursor = 0
|
||||||
self.cursorsprite = self.game.sprite_lib["cursor.png"]
|
self.cursorsprite = self.game.sprite_lib["cursor.png"]
|
||||||
|
|
||||||
@ -58,9 +62,14 @@ class Pause(BaseObject):
|
|||||||
def draw(self):
|
def draw(self):
|
||||||
self.game.window.blit(self.fill,[0,0])
|
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
|
# Draw options
|
||||||
for i,v in enumerate(self.optionsorder):
|
for i,v in enumerate(self.optionsorder):
|
||||||
x = self.game.globals["cameraw"]/2
|
|
||||||
y = self.offset+i*(9+self.padding)
|
y = self.offset+i*(9+self.padding)
|
||||||
self.game.lib.drawcenter(self.game,self.sprites[v],x,y)
|
self.game.lib.drawcenter(self.game,self.sprites[v],x,y)
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from gamedata.objects.ingame.movable import Movable
|
from gamedata.objects.ingame.movable import Movable
|
||||||
from gamedata.objects.transition import Transition
|
from gamedata.objects.transition import Transition
|
||||||
from gamedata.objects.ingame.pause import Pause
|
from gamedata.objects.ingame.pause import Pause
|
||||||
|
|
||||||
class Player(Movable):
|
class Player(Movable):
|
||||||
|
|
||||||
@ -312,7 +312,7 @@ class Player(Movable):
|
|||||||
self.game.gameloop.summon(t)
|
self.game.gameloop.summon(t)
|
||||||
|
|
||||||
self.game.addParticle([self.spritehurt],self.rect.center[0],self.rect.center[1],fps=0.6,vely=-1.5,modvely=0.15) # Die sprite
|
self.game.addParticle([self.spritehurt],self.rect.center[0],self.rect.center[1],fps=0.6,vely=-1.5,modvely=0.15) # Die sprite
|
||||||
|
|
||||||
if self.tileset.bgm:
|
if self.tileset.bgm:
|
||||||
self.tileset.bgm.stop()
|
self.tileset.bgm.stop()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user