// *********************** // // On Move handlers: // *********************** // // Move the object: void OnMove_Object(CMovable movable) { // Removing object from previous position: RemoveObjectFromMap(movable.PrevX, movable.PrevY, movable.Width, movable.Height); // Setting back object: SetObjectOnMap(movable); }
// Sets Projectile on map: void OnMove_Projectile(CMovable p) { int x = (int)(p.X / cellSize); int y = (int)(p.Y / cellSize); int prevx = (int)(p.PrevX / cellSize); int prevy = (int)(p.PrevY / cellSize); // Deleting previous position: if ((prevx != x) || (prevy != y)) { mapProjectiles[prevx, prevy] = null; } // Check if somethig is on new position: var p2 = mapProjectiles[x, y]; // If yes then destroy both: if (p2 != null) { // Enemy projectiles cant destory each other: if ((p2 != p) && !(((p as CProjectile).Owner is CTankEnemy) && ((p2 as CProjectile).Owner is CTankEnemy))) { p.Destroyed = true; p2.Destroyed = true; } } else { // else take position: mapProjectiles[x, y] = (CProjectile)p; } }
// Check position ahead: bool OnCheck_CanMoveForward(CMovable o) { // int object_width = (int)o.Width / cellSize; int object_height = (int)o.Height / cellSize; int oX = (int)o.X; // + o.VectorX * o.Speed; int oY = (int)o.Y; // + o.VectorY * o.Speed; // CGameObject tmp; // Check X: switch (o.VectorX) { // check right side: case 1: if (oX >= maximumXY) { return(false); } else { // int x = (int)(oX / cellSize); int y = (int)(oY / cellSize); // for (int i = 0; i < object_height; i++) { tmp = mapMain[x + object_height, y + i]; if ((tmp != null) && (tmp != o)) { return(false); } } } break; // check left side: case -1: if (oX <= minimumXY) { return(false); } else { // int x = (int)((oX - 1 * o.Speed) / cellSize); int y = (int)(oY / cellSize); // for (int i = 0; i < object_height; i++) { tmp = mapMain[x, y + i]; if ((tmp != null) && (tmp != o)) { return(false); } } } break; } // Check Y: switch (o.VectorY) { // check bottom side: case 1: if (oY >= maximumXY) { return(false); } else { int x = (int)(oX / cellSize); int y = (int)(oY / cellSize); for (int i = 0; i < object_width; i++) { tmp = mapMain[x + i, y + object_width]; if ((tmp != null) && (tmp != o)) { return(false); } } } break; // check top side: case -1: if (oY <= minimumXY) { return(false); } else { int x = (int)(oX / cellSize); int y = (int)((oY - 1 * o.Speed) / cellSize); for (int i = 0; i < object_width; i++) { tmp = mapMain[x + i, y]; if ((tmp != null) && (tmp != o)) { return(false); } } } break; } // If nothing in front, return true: return(true); }