Ennemies knock the player
This commit is contained in:
parent
030c4be957
commit
919cb82707
@ -2481,10 +2481,14 @@
|
|||||||
{"x": 576, "y": 160}
|
{"x": 576, "y": 160}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{"name": "Crate", "id": 4, "_eid": "16023910", "x": 832, "y": 240, "originX": 0, "originY": 0},
|
{"name": "Crate", "id": 9, "_eid": "16023910", "x": 592, "y": 192, "originX": 0, "originY": 0},
|
||||||
{"name": "Crate", "id": 6, "_eid": "16023910", "x": 896, "y": 240, "originX": 0, "originY": 0},
|
{"name": "Crate", "id": 10, "_eid": "16023910", "x": 608, "y": 192, "originX": 0, "originY": 0},
|
||||||
{"name": "Crate", "id": 7, "_eid": "16023910", "x": 864, "y": 240, "originX": 0, "originY": 0},
|
{"name": "Crate", "id": 11, "_eid": "16023910", "x": 624, "y": 192, "originX": 0, "originY": 0},
|
||||||
{"name": "Crate", "id": 8, "_eid": "16023910", "x": 672, "y": 144, "originX": 0, "originY": 0}
|
{"name": "Crate", "id": 12, "_eid": "16023910", "x": 640, "y": 192, "originX": 0, "originY": 0},
|
||||||
|
{"name": "Crate", "id": 13, "_eid": "16023910", "x": 640, "y": 208, "originX": 0, "originY": 0},
|
||||||
|
{"name": "Crate", "id": 14, "_eid": "16023910", "x": 624, "y": 208, "originX": 0, "originY": 0},
|
||||||
|
{"name": "Crate", "id": 15, "_eid": "16023910", "x": 608, "y": 208, "originX": 0, "originY": 0},
|
||||||
|
{"name": "Crate", "id": 16, "_eid": "16023910", "x": 592, "y": 208, "originX": 0, "originY": 0}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -11,6 +11,8 @@ class Crate(Ennemy):
|
|||||||
|
|
||||||
self.rect[2],self.rect[3] = self.sprite.get_size()
|
self.rect[2],self.rect[3] = self.sprite.get_size()
|
||||||
|
|
||||||
|
self.canhit = False
|
||||||
|
|
||||||
def step(self):
|
def step(self):
|
||||||
super().step()
|
super().step()
|
||||||
|
|
||||||
|
@ -16,6 +16,8 @@ class Ennemy(Movable):
|
|||||||
self.particleoffsetx = 0
|
self.particleoffsetx = 0
|
||||||
self.particleoffsety = 0
|
self.particleoffsety = 0
|
||||||
|
|
||||||
|
self.canhit = True
|
||||||
|
|
||||||
self.dustparticles = game.getSpriteDir("particles/dust/")
|
self.dustparticles = game.getSpriteDir("particles/dust/")
|
||||||
|
|
||||||
def step(self):
|
def step(self):
|
||||||
@ -26,6 +28,15 @@ class Ennemy(Movable):
|
|||||||
if not self.player:
|
if not self.player:
|
||||||
self.player = next(iter(self.game.gameloop.findname("Player")),None)
|
self.player = next(iter(self.game.gameloop.findname("Player")),None)
|
||||||
else:
|
else:
|
||||||
|
if self.canhit:
|
||||||
|
if self.rect.colliderect(self.player):
|
||||||
|
# Knock it horizontally
|
||||||
|
if self.player.rect[0]>self.rect[0]:
|
||||||
|
hor = 1
|
||||||
|
else:
|
||||||
|
hor = -1
|
||||||
|
self.player.horkb = hor*6
|
||||||
|
self.player.verkb = self.player.gravityway*-3
|
||||||
if self.player.canhit:
|
if self.player.canhit:
|
||||||
if self.rect.colliderect(self.player.hitrect):
|
if self.rect.colliderect(self.player.hitrect):
|
||||||
# Die
|
# Die
|
||||||
|
@ -37,7 +37,7 @@ class Player(Movable):
|
|||||||
self.horkb = 0
|
self.horkb = 0
|
||||||
self.verkb = 0
|
self.verkb = 0
|
||||||
|
|
||||||
self.reducekb = 50
|
self.reducekb = 15
|
||||||
self.multkb = 1
|
self.multkb = 1
|
||||||
|
|
||||||
self.attackstate = None
|
self.attackstate = None
|
||||||
@ -82,8 +82,11 @@ class Player(Movable):
|
|||||||
self.leaptimer = self.leapmaxtimer # Outside, reset the timer
|
self.leaptimer = self.leapmaxtimer # Outside, reset the timer
|
||||||
|
|
||||||
if not self.game.globals["hitpose"]:
|
if not self.game.globals["hitpose"]:
|
||||||
|
|
||||||
|
canmove = (abs(self.verkb)+1)*(abs(self.horkb)+1)<2
|
||||||
keys = self.game.inputs["keys"]
|
keys = self.game.inputs["keys"]
|
||||||
if self.controlled:
|
self.horspd = 0
|
||||||
|
if self.controlled and canmove:
|
||||||
self.horspd=(keys["right"]["pressed"]-keys["left"]["pressed"])*self.game.dt*self.speed
|
self.horspd=(keys["right"]["pressed"]-keys["left"]["pressed"])*self.game.dt*self.speed
|
||||||
if self.attackstate:
|
if self.attackstate:
|
||||||
self.attackstate(self) # Si je suis sur le sol
|
self.attackstate(self) # Si je suis sur le sol
|
||||||
@ -138,9 +141,11 @@ class Player(Movable):
|
|||||||
|
|
||||||
# Reducing the knockback
|
# Reducing the knockback
|
||||||
if self.horkb>0:
|
if self.horkb>0:
|
||||||
self.horkb = max(0,self.horkb-self.reducekb)*self.game.dt
|
self.horkb -= self.reducekb*self.game.dt
|
||||||
|
self.horkb = max(0,self.horkb)
|
||||||
if self.horkb<0:
|
if self.horkb<0:
|
||||||
self.horkb = min(0,self.horkb+self.reducekb)*self.game.dt
|
self.horkb += self.reducekb*self.game.dt
|
||||||
|
self.horkb = min(0,self.horkb)
|
||||||
if self.verkb>0:
|
if self.verkb>0:
|
||||||
self.verkb = max(0,self.verkb-self.reducekb)*self.game.dt
|
self.verkb = max(0,self.verkb-self.reducekb)*self.game.dt
|
||||||
if self.verkb<0:
|
if self.verkb<0:
|
||||||
|
Loading…
Reference in New Issue
Block a user