SunsetHigh.Projectile.setCollideEvent C# (CSharp) Method

setCollideEvent() public method

public setCollideEvent ( ProjectileCollideEvent e ) : void
e ProjectileCollideEvent
return void
        public void setCollideEvent(ProjectileCollideEvent e)
        {
            mEvent = e;
        }

Usage Example

Example #1
0
        public override void update(float elapsed)
        {
            base.update(elapsed);

            if (isAggressive)
            {
                switch (attackPattern)
                {
                    case 0: //star burst
                        attackTimer1 += elapsed;
                        if (attackTimer1 > 0.5)
                        {
                            for (float angle = 0; angle < 2 * Math.PI; angle += (float)Math.PI / 4)
                            {
                                Projectile proj = new Projectile(this.getXCenter() + (int)(this.getWidth() / 2 * Math.Cos(angle)),
                                    this.getYCenter() - (int)(this.getHeight() / 2 * Math.Sin(angle)), 300f, angle);
                                proj.setImage(Sprite.getCommonImage(Directories.SPRITES + "projectile"));
                                proj.setCollideEvent(new ProjectileCollideEvent(braceBulletCollideEvent));
                                WorldManager.enqueueObjectToCurrentRoom(proj);
                            }
                            attackTimer1 = 0.0f;
                        }
                        break;
                    case 1: //spiral
                        attackTimer2 += elapsed;
                        if (attackTimer2 > 0.15)
                        {
                            attackAngleCounter2 += 0.35f;
                            Projectile proj = new Projectile(this.getXCenter() + (int)(this.getWidth() / 2 * Math.Cos(attackAngleCounter2)),
                                this.getYCenter() - (int)(this.getHeight() / 2 * Math.Sin(attackAngleCounter2)), 300f, attackAngleCounter2);
                            proj.setImage(Sprite.getCommonImage(Directories.SPRITES + "projectile"));
                            proj.setCollideEvent(new ProjectileCollideEvent(braceBulletCollideEvent));
                            WorldManager.enqueueObjectToCurrentRoom(proj);
                            attackTimer2 = 0.0f;
                        }
                        break;
                    case 2: //snipe
                        attackTimer3 += elapsed;
                        if (attackTimer3 > 0.40)
                        {
                            int dx = Hero.instance.getXCenter() - this.getXCenter();
                            int dy = -(Hero.instance.getYCenter() - this.getYCenter());
                            float angle = (float)Math.Atan2(dy, dx);
                            Projectile proj = new Projectile(this.getXCenter() + (int)(this.getWidth() / 2 * Math.Cos(angle)),
                                this.getYCenter() - (int)(this.getHeight() / 2 * Math.Sin(angle)), 300f, angle);
                            proj.setImage(Sprite.getCommonImage(Directories.SPRITES + "projectile"));
                            proj.setCollideEvent(new ProjectileCollideEvent(braceBulletCollideEvent));
                            WorldManager.enqueueObjectToCurrentRoom(proj);
                            attackTimer3 = 0.0f;
                        }
                        break;
                    case 3: //firing squad
                        if (!initializeFire)
                        {
                            Vector2[] chooseLoc = new Vector2[4];   //list for four corners
                            chooseLoc[0] = new Vector2(ROOM_MARGIN/2, ROOM_MARGIN/2);
                            chooseLoc[1] = new Vector2(WorldManager.m_currentRoom.background.Width * Room.TILE_SIZE - ROOM_MARGIN, ROOM_MARGIN/2);
                            chooseLoc[3] = new Vector2(ROOM_MARGIN/2, WorldManager.m_currentRoom.background.Height * Room.TILE_SIZE - ROOM_MARGIN);
                            chooseLoc[2] = new Vector2(WorldManager.m_currentRoom.background.Width * Room.TILE_SIZE - ROOM_MARGIN,
                                WorldManager.m_currentRoom.background.Height * Room.TILE_SIZE - ROOM_MARGIN);
                            int choose = rand.Next(4);
                            nextDestFiring = chooseLoc[(choose + 1) % 4];
                            if (choose == 0) fireDirection = Direction.South;
                            else if (choose == 1) fireDirection = Direction.West;
                            else if (choose == 2) fireDirection = Direction.North;
                            else fireDirection = Direction.East;
                            this.moveToDestination((int)chooseLoc[choose].X, (int)chooseLoc[choose].Y, delegate()
                            {
                                readyToFire = true;
                            });
                            initializeFire = true;
                        }
                        if (readyToFire)
                        {
                            if (!initializeFire2)
                            {
                                this.moveToDestination((int)nextDestFiring.X, (int)nextDestFiring.Y, delegate()
                                {
                                    initializeFire = false;
                                    initializeFire2 = false;
                                    readyToFire = false;
                                    attackPattern = 0;
                                });
                                initializeFire2 = true;
                            }
                            attackTimer4 += elapsed;
                            if (attackTimer4 > 0.2f)
                            {
                                float angle = SunsetUtils.convertDirectionToAngle(fireDirection);
                                Projectile proj = new Projectile(this.getXCenter() + (int)(this.getWidth() / 2 * Math.Cos(angle)),
                                    this.getYCenter() - (int)(this.getHeight() / 2 * Math.Sin(angle)), 300f, angle);
                                proj.setImage(Sprite.getCommonImage(Directories.SPRITES + "projectile"));
                                proj.setCollideEvent(new ProjectileCollideEvent(braceBulletCollideEvent));
                                WorldManager.enqueueObjectToCurrentRoom(proj);
                                attackTimer4 = 0.0f;
                            }
                        }
                        break;
                }

                if (isMovingRandomly && attackPattern != 3)
                {
                    moveRandomTimer += elapsed;
                    if (moveRandomTimer > 0.30)
                    {
                        int xbound = WorldManager.m_currentRoom.background.Width * Room.TILE_SIZE;
                        int ybound = WorldManager.m_currentRoom.background.Height * Room.TILE_SIZE;
                        this.moveToDestination(rand.Next(xbound), rand.Next(ybound), null);
                        moveRandomTimer = 0.0f;
                    }
                }

                attackPatternSwitchTimer += elapsed;
                if (attackPatternSwitchTimer > 5.0f && attackPattern != 3)
                {
                    attackPatternSwitchTimer = 0.0f;
                    attackPattern = (attackPattern + 1) % 4;
                    isMovingRandomly = rand.Next(2) == 1;
                    //attackPattern = 3;
                    this.cancelMoveToDestination();
                }
            }
        }
All Usage Examples Of SunsetHigh.Projectile::setCollideEvent