Add controller support
@ -148,63 +148,48 @@ class Game():
|
||||
def init_inputs(self):
|
||||
|
||||
self.inputs = {}
|
||||
self.inputs["unicode"] = ""
|
||||
self.inputs["mouse"] = {
|
||||
"pos" : [0,0], # Position
|
||||
"rel" : [0,0], # Mouvement relatif
|
||||
"click" : 0 # Timer du click
|
||||
}
|
||||
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
|
||||
},
|
||||
"backspace":{
|
||||
"timer" : 0, # Timer de la touche
|
||||
"realtime" : 0, # Temps réel préssé
|
||||
"pressed" : False,
|
||||
"keycode" : pygame.K_BACKSPACE # Code pygame de la touche en question
|
||||
},
|
||||
"enter":{
|
||||
"timer" : 0, # Timer de la touche
|
||||
"realtime" : 0, # Temps réel préssé
|
||||
"pressed" : False,
|
||||
"keycode" : 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
|
||||
},
|
||||
"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
|
||||
},
|
||||
"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
|
||||
},
|
||||
"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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
self.no_unicode = [pygame.K_ESCAPE,pygame.K_BACKSPACE,pygame.K_RETURN]
|
||||
|
||||
self.inputs["joysticks"] = {}
|
||||
|
||||
def check_events(self):
|
||||
self.inputs["unicode"] = ""
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
self.running = False
|
||||
@ -212,31 +197,63 @@ class Game():
|
||||
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
|
||||
self.inputs["keys"][i]["pressed"] = True
|
||||
else:
|
||||
if event.key not in self.no_unicode:
|
||||
self.inputs["unicode"] = event.unicode # Je récupère la "lettre" de la touche préssée
|
||||
if event.type == pygame.KEYUP:
|
||||
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
|
||||
self.inputs["keys"][i]["pressed"] = False
|
||||
if event.type == pygame.JOYDEVICEADDED:
|
||||
index = event.device_index
|
||||
self.inputs["joysticks"][index] = pygame.joystick.Joystick(index)
|
||||
if event.type == pygame.JOYDEVICEREMOVED:
|
||||
index = event.instance_id
|
||||
del(self.inputs["joysticks"][index])
|
||||
|
||||
self.inputs["mouse"]["pos"] = pygame.mouse.get_pos() # Position
|
||||
self.inputs["mouse"]["rel"] = pygame.mouse.get_rel() # Déplacement par rapport à la frame précédente
|
||||
# Check for controller input
|
||||
for i in self.inputs["keys"].keys():
|
||||
self.inputs["keys"][i]["counted"] = False
|
||||
for joy in self.inputs["joysticks"].values():
|
||||
nbhats = joy.get_numhats()
|
||||
for i in range(nbhats):
|
||||
x,y = joy.get_hat(i)
|
||||
if x==-1:
|
||||
self.inputs["keys"]["left"]["counted"] = True
|
||||
if y==1:
|
||||
self.inputs["keys"]["up"]["counted"] = True
|
||||
if x==1:
|
||||
self.inputs["keys"]["right"]["counted"] = True
|
||||
if y==-1:
|
||||
self.inputs["keys"]["down"]["counted"] = True
|
||||
nbaxis = joy.get_numaxes()
|
||||
if nbaxis>=2:
|
||||
x = joy.get_axis(0)
|
||||
y = joy.get_axis(1)
|
||||
deadzone = 0.2
|
||||
if x<-deadzone:
|
||||
self.inputs["keys"]["left"]["counted"] = True
|
||||
if x>deadzone:
|
||||
self.inputs["keys"]["right"]["counted"] = True
|
||||
if y>deadzone*3:
|
||||
self.inputs["keys"]["down"]["counted"] = True
|
||||
nbbuttons = joy.get_numbuttons()
|
||||
for i in range(8):
|
||||
if nbbuttons>=i and joy.get_button(i)==1:
|
||||
if i==0: # A button
|
||||
self.inputs["keys"]["up"]["counted"] = True
|
||||
if i>0 and i<=3: # B,X, and Y buttons
|
||||
self.inputs["keys"]["down"]["counted"] = True
|
||||
if i>5: # Start and Select
|
||||
self.inputs["keys"]["escape"]["counted"] = True
|
||||
|
||||
for i in self.inputs["keys"].keys():
|
||||
self.inputs["keys"][i]["counted"] = self.inputs["keys"][i]["counted"] or self.inputs["keys"][i]["pressed"]
|
||||
|
||||
# Augmente le timer si la touche est préssée, le reset sinon
|
||||
for i in self.inputs["keys"].keys():
|
||||
if self.inputs["keys"][i]["pressed"]:
|
||||
if self.inputs["keys"][i]["counted"]:
|
||||
self.inputs["keys"][i]["timer"]+=1
|
||||
self.inputs["keys"][i]["realtime"]+=self.dt
|
||||
else:
|
||||
self.inputs["keys"][i]["timer"]=0
|
||||
self.inputs["keys"][i]["realtime"]=0
|
||||
# Timer du click
|
||||
boutons = pygame.mouse.get_pressed()
|
||||
if boutons[0]: # Si click gauche
|
||||
self.inputs["mouse"]["click"]+=1
|
||||
else:
|
||||
self.inputs["mouse"]["click"] = 0
|
||||
|
||||
def init_assets(self,path,function,recursive=True):
|
||||
dico = {}
|
||||
|
BIN
gamedata/maps/Level 3/background0.png
Normal file
After Width: | Height: | Size: 7.6 KiB |
BIN
gamedata/maps/Level 3/background1.png
Normal file
After Width: | Height: | Size: 8.4 KiB |
BIN
gamedata/maps/Level 3/background2.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
gamedata/maps/Level 3/background3.png
Normal file
After Width: | Height: | Size: 6.5 KiB |
BIN
gamedata/maps/Level 3/background4.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
gamedata/maps/Level 3/background5.png
Normal file
After Width: | Height: | Size: 9.4 KiB |
BIN
gamedata/maps/Level 3/base.png
Normal file
After Width: | Height: | Size: 33 KiB |
BIN
gamedata/maps/Level 3/bgm.mp3
Normal file
BIN
gamedata/maps/Level 3/filler.png
Normal file
After Width: | Height: | Size: 11 KiB |
2838
gamedata/maps/Level 3/map.json
Normal file
@ -1583,7 +1583,7 @@
|
||||
{"x": 512, "y": 96},
|
||||
{"x": 640, "y": 144}
|
||||
],
|
||||
"values": {"0": "Beginning;18", "1": "The Docks;18"}
|
||||
"values": {"0": "Beginning;18", "1": "The Docks;18", "2": "Tiny Island;20"}
|
||||
},
|
||||
{"name": "Ripple", "id": 1, "_eid": "76589705", "x": 368, "y": 192, "originX": 0, "originY": 0},
|
||||
{"name": "Ripple", "id": 2, "_eid": "76589705", "x": 224, "y": 176, "originX": 0, "originY": 0},
|
||||
|
@ -24,6 +24,8 @@ class Squid(Ennemy):
|
||||
# Offset it correctly
|
||||
self.rect[1] += 8-self.rect[3]/2
|
||||
|
||||
self.collisions = False
|
||||
|
||||
# Movement boundaries
|
||||
if self.nodes:
|
||||
self.endpoints = [x["y"] for x in self.nodes[:2]] # Get only the two first y positions
|
||||
|
@ -124,7 +124,7 @@ class Player(Movable):
|
||||
self.horspd = 0
|
||||
if canmove:
|
||||
if self.canmove:
|
||||
self.horspd=(keys["right"]["pressed"]-keys["left"]["pressed"])*self.game.dt*self.speed
|
||||
self.horspd=(keys["right"]["counted"]-keys["left"]["counted"])*self.game.dt*self.speed
|
||||
self.game.globals["timer"]+=self.game.dt
|
||||
if self.game.inputs["keys"]["escape"]["timer"]==1:
|
||||
self.game.globals["pause"] = True
|
||||
|