public void Initialize(Player player, Texture2D textura, Texture texturaFrameProyectil, float daño, Vector2 pos, Vector2 incremento, Colision colision) { _player = player; _textura = textura; _daño = (int)daño; _pos = pos; _colision = colision; _incremento = incremento; //Datos de color de la textura _texturaFrame = textura; textureData = new Color[_texturaFrame.Width * _texturaFrame.Height]; _texturaFrame.GetData(textureData); }
private void AsignarControles() { Player p1 = new Player(_game); _listaPlayers.Add(p1); //Detectar controles conectados; _listaPlayers[0]._controller = new Controller("teclado"); _listaPlayers[0]._colision=_colision; _listaPlayers[0]._pos = new Vector2(75, 320); _listaPlayers[0]._texturaProyectil = Content.Load<Texture2D>("graphics/Proyectil/Proyectil"); _listaPlayers[0]._rumble = new Rumble(_listaPlayers[0]._controller); _numMandos[0] = true; if (GamePad.GetState(PlayerIndex.One).IsConnected) { Player p2 = new Player(_game); _listaPlayers.Add(p2); _listaPlayers[1]._controller = new Controller("mando1"); _listaPlayers[1]._colision = _colision; _listaPlayers[1]._pos = new Vector2(850, 320); _listaPlayers[1]._texturaProyectil = Content.Load<Texture2D>("graphics/Proyectil/Proyectil"); _listaPlayers[1]._rumble = new Rumble(_listaPlayers[1]._controller); _numMandos[1] = true; } if (GamePad.GetState(PlayerIndex.Two).IsConnected) { Player p3 = new Player(_game); _listaPlayers.Add(p3); _listaPlayers[2]._controller = new Controller("mando2"); _listaPlayers[2]._colision = _colision; _listaPlayers[2]._pos = new Vector2(850, 320); _listaPlayers[2]._texturaProyectil = Content.Load<Texture2D>("graphics/Proyectil/Proyectil"); _listaPlayers[2]._rumble = new Rumble(_listaPlayers[2]._controller); _numMandos[2] = true; } if (GamePad.GetState(PlayerIndex.Three).IsConnected) { Player p4 = new Player(_game); _listaPlayers.Add(p4); _listaPlayers[3]._controller = new Controller("mando3"); _listaPlayers[3]._colision = _colision; _listaPlayers[3]._pos = new Vector2(850, 320); _listaPlayers[3]._texturaProyectil = Content.Load<Texture2D>("graphics/Proyectil/Proyectil"); _listaPlayers[3]._rumble = new Rumble(_listaPlayers[3]._controller); _numMandos[3] = true; } }
/* * player: jugador que hace la comprobacion, no debemos colisionar con nosotros mismos * pos: posicion donde comprobar la colision. * textura: textura del objeto del cual vamos a comprobar la colision * daño: daño que producira la colision en el objeto colisionado */ public bool updateColision(Entidad entity, Player player) { bool colision = false; Rectangle rectangle1; Rectangle rectangle2; Color[] dataMap; int x = 0, y = 0; Vector2 entityOrigin = new Vector2(entity._texturaFrame.Width / 2, entity._texturaFrame.Height / 2); Matrix entityTransform = Matrix.CreateTranslation(new Vector3(-entityOrigin, 0.0f)) * Matrix.CreateRotationZ(-MathHelper.ToRadians(entity._anguloRotacion)) * Matrix.CreateTranslation(new Vector3(entity._pos, 0.0f)); rectangle1 = CalculateBoundingRectangle(new Rectangle(0, 0, entity._texturaFrame.Width, entity._texturaFrame.Height), entityTransform); for (int i = 0; i < _listaPlayers.Count; i++) { if (_listaPlayers[i] != player) { Vector2 entityOrigin2 = new Vector2(_listaPlayers[i]._texturaFrame.Width / 2, _listaPlayers[i]._texturaFrame.Height / 2); Matrix entityTransform2 = Matrix.CreateTranslation(new Vector3(-entityOrigin2, 0.0f)) * Matrix.CreateRotationZ(-MathHelper.ToRadians(_listaPlayers[i]._anguloRotacion)) * Matrix.CreateTranslation(new Vector3(_listaPlayers[i]._pos, 0.0f)); rectangle2 = CalculateBoundingRectangle(new Rectangle(0, 0, _listaPlayers[i]._texturaFrame.Width, _listaPlayers[i]._texturaFrame.Height), entityTransform2); if(rectangle1.Intersects(rectangle2)) { if (IntersectPixels(entityTransform, entity._texturaFrame.Width, entity._texturaFrame.Height, entity.textureData, entityTransform2, _listaPlayers[i]._texturaFrame.Width, _listaPlayers[i]._texturaFrame.Height, _listaPlayers[i].textureData)) { _impacto.Play(); _listaPlayers[i]._vida -= entity._daño; //_listaPlayers[i]._rumble.RumbleDisparo(); if (_listaPlayers[i]._vida <= 0) { _listaPlayers[i]._activo = false; //_listaPlayers.RemoveAt(i); } colision = true; } } } } for (x = 0; x < _solidos.Width; x++) { for (y = 0; y < _solidos.Height; y++) { Tile tile = _solidos.Tiles[x, y]; if (tile != null) { Vector2 entityOrigin2 = new Vector2(20, 20); Matrix entityTransform2 = Matrix.CreateTranslation(new Vector3(new Vector2(x*mapa.TileWidth, y*mapa.TileHeight), 0.0f)); rectangle2 = new Rectangle(x*mapa.TileWidth, y*mapa.TileHeight, 40,40); if (rectangle1.Intersects(rectangle2)) { dataMap = ExtraerFrame(tile.Texture, tile.Source); if (IntersectPixels(entityTransform, entity._texturaFrame.Width, entity._texturaFrame.Height, entity.textureData, entityTransform2, 40, 40, dataMap)) { colision = true; break; } } } } } return colision; }