public override bool Comportement(Monde monde) { foreach (Entite ent in monde.Entites) { if (ent is Joueur j) { if (X != j.X && X != j.X - 1 && X != j.X + 1) { float tx = x > j.X ? -1 : 1; Block b = monde.GetBlock((int)(x + tx), (int)y, false); Block b2 = monde.GetBlock((int)(x + tx), (int)y + 1, false); if (b == null || b.CanPassThrough(this, false) || b2 == null || b2.CanPassThrough(this, false)) { Bouger(tx / 2, 0, monde); return(true); } } return(false); } } return(false); }
/// <summary> /// Faire bouger le personnage(déplacement) (maximum 1 block de distance) /// </summary> /// <returns>s'il est bloquer</returns> public virtual bool Bouger(float nx, int ny, Monde monde) { if (nx > 1) { nx = 1; } if (nx < -1) { nx = -1; } if (ny > 1) { ny = 1; } if (ny < -1) { ny = -1; } if (nx != 0 && ny != 0) { ny = 0; } Func <Block, bool, bool> pass = (iblock, byGrav) => { return(iblock == null || iblock.CanPassThrough(this, byGrav)); }; Block block = monde.GetBlock((int)(x + nx), (int)y + ny, true); if (pass(block, false)) { int tomber = -3; x += nx; y += ny; while (pass(monde.GetBlock((int)x, (int)y - 1, true), true)) { y--; tomber++; } if (tomber > 0) { Vie -= tomber; } } else if (ny == 0) { block = monde.GetBlock((int)(x + nx), (int)y + 1, true); Block dessus = monde.GetBlock((int)x, (int)y + 1, true); if (pass(block, false) && pass(dessus, false)) { x += nx; y++; } else { return(true); } } return(false); }