public FrmStart()
 {
     this.InitializeComponent();
     ninja = new Ninja("Ninja");
     this.prgrsEnergy.Maximum = this.ninja.TotalEnergy;
     this.prgrsEnergy.Value = this.ninja.CurrentEnergy;
 }
 public frmStart()
 {
     InitializeComponent();
     ninja = new Ninja("Ninja");
     prgrsEnergy.Maximum = ninja.TotalEnergy;
     prgrsEnergy.Value = ninja.CurrentEnergy;
 }
Exemple #3
0
    static void Main(string[] args)
    {
        Ninja n = new Ninja(25, "Andrew");
        Duck d = new Duck(10, "Programmer");

        List<IAttack> atl = new List<IAttack>();

        for (int i = 0; i < 5; i++)
        {
            atl.Add(n);
            atl.Add(d);
        }

        foreach (IAttack aia in atl)
        {
            aia.Fight();

        }

        foreach (IStats sta in atl)
        {
            Console.WriteLine("Current objects health is: " + sta.Health.ToString());

        }

        Console.Read();
    }
Exemple #4
0
 void OnTriggerEnter2D(Collider2D col)
 {
     if(col.gameObject.layer == _playerLayer)
     {
         ninjaComp = col.GetComponent<Ninja>();
         EKey.Instance.Activate();
     }
 }
Exemple #5
0
 void OnTriggerExit2D(Collider2D col)
 {
     if(ninjaComp != null && ninjaComp.gameObject == col.gameObject)
     {
         ninjaComp = null;
         EKey.Instance.Deactivate();
     }
 }
            public Ninja NewNinja()
            {
                var ninja=new Ninja
                {

                };
                _context.Ninjas.Add(ninja);
                return ninja;
            }
            public override CommandProcessor Given()
            {
                id = Guid.NewGuid();

                activeUnit = new Ninja { Id = id, X = 0, Y = 0, Range = 1 };

                FirstPlayer.Units.Add(activeUnit);

                return new CommandProcessor(Calculator, State);
            }
        public static Ninja CreateNinja(string clanName, string key, string name, int level)
        {
            var entity = new Ninja
            {
                Key  = key,
                Clan = new Clan {
                    Name = clanName
                },
                Name  = name,
                Level = level
            };

            return(entity);
        }
Exemple #9
0
        // GET: Ninjas/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Ninja ninja = db.Ninjas.Find(id);

            if (ninja == null)
            {
                return(HttpNotFound());
            }
            return(View(ninja));
        }
        public IHttpActionResult DeleteNinja(int id)
        {
            Ninja ninja = db.Ninjas.Find(id);

            if (ninja == null)
            {
                return(NotFound());
            }

            db.Ninjas.Remove(ninja);
            db.SaveChanges();

            return(Ok(ninja));
        }
Exemple #11
0
 public IActionResult addNinja(Ninja item, int dojo_id)
 {
     if (ModelState.IsValid)
     {
         Dojo dojo = dojoFactory.GetById(dojo_id);
         item.Dojo = dojo;
         System.Console.WriteLine(JsonConvert.SerializeObject(item));
         ninjaFactory.Add(item);
         return(RedirectToAction("NinjaHome"));
     }
     ViewBag.ninjas = ninjaFactory.GetAll();
     ViewBag.dojos  = dojoFactory.GetAll();
     return(View("ninjas"));
 }
Exemple #12
0
 public IActionResult addNinja(Ninja ninja)
 {
     if (ModelState.IsValid)
     {
         ninjaFactory.Add(ninja);
         return(RedirectToAction("Index"));
     }
     else
     {
         ViewBag.allDojos  = dojoFactory.FindAll();
         ViewBag.allNinjas = ninjaFactory.FindAll();
         return(View("Index"));
     }
 }
Exemple #13
0
        public IActionResult Result(string name, string location, string language, string comment)
        {
            ViewData["Message"] = "Your result page.";

            Ninja tom = new Ninja()
            {
                Name          = name,
                     Location = location,
                     Language = language,
                     Comment  = comment,
            };

            return(View(tom));
        }
        public IActionResult AddNinja(Ninja nin)
        {
            Ninja ninja = new Ninja
            {
                name        = nin.name,
                level       = nin.level,
                description = nin.description,
                dojo_id     = nin.dojo_id
            };

            _dContext.ninjas.Add(ninja);
            _dContext.SaveChanges();
            return(RedirectToAction("Ninjas"));
        }
        public IActionResult CreateNinja(Ninja ninja)
        {
            if (!ModelState.IsValid)
            {
                return(View("Ninjas", new NinjaBundle(_context, ninja)));
            }
            else
            {
                _context.ninjas.Add(ninja);
                _context.SaveChanges();

                return(RedirectToAction("Ninjas"));
            }
        }
 public IActionResult Create(Ninja ninja)
 {
     if (ModelState.IsValid)
     {
         // create a ninja in the db!
         string q = $@"
             INSERT INTO ninjas (Name, Color, Email, SecretCode, Bio) 
             VALUES ('{ninja.Name}', '{ninja.Color}', '{ninja.Email}', '{ninja.SecretCode}', '{ninja.Bio}')
         ";
         DbConnector.Execute(q);
         return(RedirectToAction("Index"));
     }
     return(View("New"));
 }
Exemple #17
0
        private void AddNinja()
        {
            var ninja = Ninja.ToModel();

            using (var context = new NinjaEntities())
            {
                context.Ninjas.Add(ninja);
                context.Entry(ninja).State = EntityState.Added;
                context.SaveChanges();
            }

            _ninjaListVM.NinjasOC.Add(Ninja);
            _ninjaListVM.HideAddNinja();
        }
        public IActionResult Create(Ninja model)
        {
            if (model.Location == "Seattle")
            {
                ModelState.AddModelError("Location", "No Seattles allowed");
            }

            if (ModelState.IsValid)
            {
                return(Json(model));
            }

            return(View("Index"));
        }
Exemple #19
0
        public async Task <IActionResult> CreateAsync([FromBody] Ninja ninja)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var createdNinja = await _ninjaService.CreateAsync(ninja);

            return(CreatedAtAction(
                       nameof(ReadOneAsync),
                       new { clan = createdNinja.Clan.Name, key = createdNinja.Key },
                       createdNinja
                       ));
        }
        public void DefaultBindingsAreUsed()
        {
            this.kernel.Settings.InjectNonPublic = true;
            this.kernel.Bind <IWarrior>().To <Ninja>();
            var warrior = this.kernel.Get <IWarrior>();

            Assert.IsType <Ninja>(warrior);
            Assert.IsType <Shuriken>(warrior.Weapon);

            Ninja ninja = warrior as Ninja;

            Assert.IsType <Shuriken>(ninja.OffHandWeapon);
            Assert.IsType <Shuriken>(ninja.SecondaryWeapon);
            Assert.IsType <Shuriken>(ninja.VerySecretWeaponAccessor);
        }
Exemple #21
0
        public IActionResult Update(Ninja ninja, int ninjaId)
        {
            if(ModelState.IsValid)
            {
                // query for a ninja to update
                var toUpdate = dbContext.Ninjas.FirstOrDefault(ni => ni.NinjaId == ninjaId);
                toUpdate.Name = ninja.Name;
                toUpdate.Bio = ninja.Bio;
                toUpdate.Color = ninja.Color;

                dbContext.SaveChanges();
                return RedirectToAction("Index");
            }
            return View("Ninja");
        }
Exemple #22
0
        // GET: Ninjas/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Ninja ninja = _repo.GetNinjaById(id.Value);

            if (ninja == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ClanId = new SelectList(_repo.GetClanList(), "Id", "ClanName", ninja.ClanId);
            return(View(ninja));
        }
Exemple #23
0
 private void BuyItem(object parameter)
 {
     using (var context = new LeagueOfNinjasEntities())
     {
         Ninja n = context.Ninjas.Find(NinjaList.SelectedNinja.ToModel().Id);
         Gear  g = context.Gears.Find(SelectedItem.ToModel().Id);
         n.Gears.Add(g);
         n.Gold         -= SelectedItem.Price;
         n.Intelligence += g.Intelligence;
         n.Strength     += g.Strength;
         n.Agility      += g.Agility;
         context.SaveChanges();
     }
     NinjaList.SelectedNinja.AddItem(SelectedItem);
 }
Exemple #24
0
 public IActionResult addNinja(Ninja ninja, int dojoID)
 {
     if (ModelState.IsValid)
     {
         Console.WriteLine("THERE WERE NO ERRORS!");
         ninja.Dojo_Id = dojoID;
         // ninjaFactory.Add(ninja);
         return(Redirect("/"));
     }
     else
     {
         Console.WriteLine("THERE WAS ERRORS IN YOUR FORM!");
         return(View("index", ninja));
     }
 }
Exemple #25
0
        private void AddNinja()
        {
            using (var context = new NinjaDBEntities())
            {
                Ninja n = new Ninja {
                    Name = Name, Gold = Gold
                };

                context.Ninjas.Add(n);
                context.SaveChanges();
                _mainModel.Ninjas.Add(n.ToPoCo());
            }

            _mainModel.CloseAddNinja();
        }
Exemple #26
0
        // GET: Ninjas/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Ninja ninja = db.Ninjas.Find(id);

            if (ninja == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ClanID = new SelectList(db.Clans, "Id", "ClanName", ninja.ClanID);
            return(View(ninja));
        }
Exemple #27
0
 public IActionResult CreateNinja(NinjaVM model)
 {
     if (ModelState.IsValid)
     {
         Ninja ninja = new Ninja {
             name        = model.name,
             level       = model.level,
             dojo_id     = model.dojo_id == 0 ? null : model.dojo_id,
             description = model.description,
         };
         _ninjaFactory.Create(ninja);
         return(RedirectToAction("Index"));
     }
     return(View("Index"));
 }
Exemple #28
0
        public static void InsertNinja()
        {
            var ninja = new Ninja
            {
                Name             = "Luk 2",
                ServedInOniwaban = true,
                ClanId           = 1
            };

            using (var context = new NinjaContext())
            {
                context.Ninjas.Add(ninja);
                context.SaveChanges();
            }
        }
Exemple #29
0
        static async Task Main(string[] args)
        {
            var razor = new RazorLightEngineBuilder()
                        .DisableEncoding()
                        .UseEmbeddedResourcesProject(Assembly.GetExecutingAssembly(), "Templates.BuildSystems")
                        .UseMemoryCachingProvider()
                        .Build();

            var project       = new GameProject();
            var configuration = new Configuration();

            project.Configure(configuration);
            var ninja          = new Ninja();
            var generatedFiles = await ninja.Generate(razor, project, configuration);

            foreach (var file in generatedFiles)
            {
                Directory.CreateDirectory(Path.GetDirectoryName(file.Path));
                File.WriteAllText(file.Path, file.Content);
            }

            {
                var typesAssembly = Assembly.GetAssembly(typeof(TestClassA));
                Debug.Assert(typesAssembly != null);

                var razorEngine = new RazorLightEngineBuilder()
                                  .UseEmbeddedResourcesProject(Assembly.GetExecutingAssembly(), "Templates.CodeGen")
                                  .UseMemoryCachingProvider()
                                  .Build();

                var templates = new[] { "Types.h" };
                foreach (string template in templates)
                {
                    Console.WriteLine($"Rendering template {template}...");
                    string namespacedTemplate = template.Replace('/', '.');
                    string compiledSrc        = await razorEngine.CompileRenderAsync(namespacedTemplate, typesAssembly);

                    string outFilePath  = Path.Combine(Options.CodeGenRoot, template);
                    string outDirectory = Path.GetDirectoryName(outFilePath) ?? "";
                    if (!string.IsNullOrWhiteSpace(outDirectory))
                    {
                        Directory.CreateDirectory(outDirectory);
                    }

                    File.WriteAllText(outFilePath, compiledSrc);
                }
            }
        }
        public virtual void Add_should_not_add_existing_ninja()
        {
            // Arrange
            var expectedNinja = new Ninja {
                Kills = 200
            };

            // Act
            sut.Add(expectedNinja);
            sut.Add(expectedNinja);

            // Assert
            Assert.Collection(sut.Members,
                              ninja => Assert.Same(expectedNinja, ninja)
                              );
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null)
            {
                return(null);
            }

            var jObject = JObject.Load(reader);
            var target  = new Ninja();

            using (JsonReader jObjectReader = CopyReaderForObject(reader, jObject))
            {
                serializer.Populate(jObjectReader, target);
            }
            return(target);
        }
 public IActionResult Ninja(Ninja ninja)
 {
     if (ModelState.IsValid)
     {
         scroll.Create(ninja);
         return(Redirect("/"));
     }
     else
     {
         ViewBag.Ninjas    = scroll.Ninjas;
         ViewBag.Jutsus    = scroll.Jutsus;
         ViewBag.AllNinjas = scroll.Ninjas
                             .Include(n => n.KnownJutsu);
         return(View("Index"));
     }
 }
Exemple #33
0
 private void BtnOKClick(object sender, EventArgs e)
 {
     try
     {
         //this.ninja.SetNinjaName(this.txtName.Text);
         ninja = new Ninja(txtName.Text);
         this.btnOK.Visible   = false;
         this.lblName.Text    = this.txtName.Text;
         this.txtName.Visible = false;
         this.lblName.Visible = true;
     }
     catch (ArgumentException ex)
     {
         MessageBox.Show(ex.Message.ToString());
     }
 }
        public void Map_NinjaEntity_to_Ninja_should_delegate_to_NinjaEntityToNinjaMapper()
        {
            // Arrange
            var ninjaEntity   = new NinjaEntity();
            var expectedNinja = new Ninja();

            NinjaEntityToNinjaMapperMock
            .Setup(x => x.Map(ninjaEntity))
            .Returns(expectedNinja);

            // Act
            var result = ServiceUnderTest.Map(ninjaEntity);

            // Assert
            Assert.Same(expectedNinja, result);
        }
        static void Main(string[] args)
        {
            Human  nibbles = new Human("Mr. Nibbles");
            Wizard benny   = new Wizard("Benny Bob");

            benny.Attack(nibbles);
            Ninja adam = new Ninja("Adam");

            adam.Attack(benny);
            Samurai bob = new Samurai("Bob");

            bob.Attack(benny);
            Wizard ken = new Wizard("Ken");

            ken.Heal(benny);
        }
Exemple #36
0
 public void Add(Ninja ninja)
 {
     using (IDbConnection dbConnection = Connection) {
         dbConnection.Open();
         if (ninja.dojos_id == 0)
         {
             string query = "INSERT INTO ninjas(name, level, description) VALUES (@name, @level, @description)";
             dbConnection.Execute(query, ninja);
         }
         else
         {
             string query = "INSERT INTO ninjas(name, level, description, dojos_id) VALUES (@name, @level, @description, @dojos_id)";
             dbConnection.Execute(query, ninja);
         }
     }
 }
Exemple #37
0
        public override string defender(Guerreiro guerreiro, List <Defensor> defensores, List <Ofensor> ofensores, List <Ofensor> ofensoresAdversarios)
        {
            string parcial = String.Empty;

            parcial += (this.getNome() + "(" + this.getTipo() + ") DEFENDE!") + "\n";
            parcial += ("Energia pos defesa: " + this.getEnergia()) + "\n";
            if (this.getEnergia() <= 0)
            {
                Ninja ninja = new Ninja(this.getNome(), this.getIdade(), this.getPeso(), 100);
                ofensores.Add(ninja);
                parcial += (this.getNome() + "(" + this.getTipo() + ")" + " Morreu") + "\n";
                parcial += (this.getNome() + " se transformou em Ninja") + "\n";
                defensores.Remove(this);
            }
            return(parcial);
        }
Exemple #38
0
    public void StartDemoMatch()
    {
        string[] plSel;
        string[] clSel;
        Ninja[] plScr;

        plSel = new string[4];
        plScr = new Ninja[4];
        for(int i=0;i<numPlr; i++){
            if(cSel[i]==YARA)
                plSel[i]="Yara";
            else if(cSel[i]==SERENITY)
                plSel[i]="Serenity";
            else if(cSel[i]==KIROCH)
                plSel[i]="Kiroch";
        }
        GameObject pl1 = Instantiate(Resources.Load(plSel[0])) as GameObject;
        GameObject pl2 = Instantiate(Resources.Load(plSel[1])) as GameObject;
        //GameObject stage = Instantiate(Resources.Load("StRuins")) as GameObject;
        GameObject hud;
        if(debugMode)
            hud = Instantiate (Resources.Load ("debugHud")) as GameObject;
        else
            hud = Instantiate (Resources.Load ("matchHud")) as GameObject;
        DontDestroyOnLoad(pl1);
        DontDestroyOnLoad(pl2);
        //DontDestroyOnLoad(stage);
        DontDestroyOnLoad(hud);
        //Stage stScr = stage.GetComponent ("stRuins") as stRuins;

        plScr[0].SetPNum(1);
        plScr [1].SetPNum (2);
        plScr[0].debugModeOn=debugMode;
        plScr[1].debugModeOn = debugMode;
        plScr [0].stats.damage = 150.0f;
        plScr[1].stats.damage = 150.0f;

        //stScr.player[0]=plScr[0];
        //stScr.player[1]=plScr[1];

        //set physics vars here
        SetPhysVars (plScr [0]);
        SetPhysVars (plScr [1]);
        //Application.LoadLevel("fightmatch");
        Application.LoadLevel("stonyruins");
    }
Exemple #39
0
    public bool AttackDetect(Ninja plr)
    {
        //projectile checks
        SPoint[] pHdr = new SPoint[8];
        SPoint[] plBox;
        plBox = plr.GetHitBox();
        int hbLen=4;
        float[] plAng ={0, Mathf.PI/2, Mathf.PI, -Mathf.PI/2};
        bool hitflag = true;
                for (int i=0; i<8; i++)
                        pHdr [i] = new SPoint (v [i].x + pos.x, v [i].y +pos.y);
        float atkLen = GetVNum ();
                for (int j = 0; j < atkLen; j++)
                        if (!CheckAxis(pHdr [0], ang [j], pos, plBox, hbLen)) //no axis intersection
                                hitflag = false;

                if((hitflag)) {

                        return true;
                }

                return false;
    }
 public Ninja Edit(Ninja ninja)
 {
     return ninja;
 }
Exemple #41
0
    void WinScreen(Ninja wnr)
    {
        if(matchModeOn){//not demo
            if(gameWon==false){

                GameObject wp = GameObject.FindGameObjectWithTag("MenuCursor").GetComponent<PauseMenuDemo>().winPanel;
                wp.SetActive(true);

                gameWon=true;}
            for(int i=0;i<numPlr;i++){
                player[i].stats.flags.mBusy=true;
                player[i].stats.flags.aBusy=true;
                if(player[i].gCont.Tapped(GameController.START)){
                    foreach (GameObject o in Object.FindObjectsOfType<GameObject>()) {
                        Destroy(o);}
                    Application.LoadLevel ("menu");

                //	player[i].gCont.Pressed(GameController.START)=false;
                }
            }
        }
    }
Exemple #42
0
    public SPoint ExitDistN(int iInd, SPoint origin, float dir, Ninja plr, int ifGrab)
    {
        // helper function for the Separating Axis Theorem that takes an axis defined by origin and dir
        //re-conditioned to handle the parameters of the attack box
        bool isHit = true;
        float projMin, projMax, hitMin, hitMax, distSq, projVal, cVal;
        float dHitMinSq = 1000;
        float dHitMaxSq = 0;
        float dPrMinSq = 1000;
        float dPrMaxSq = 0;
        SPoint projVec, nVec, rVec, cVec;
        projVec = new SPoint();
        SPoint moveVec = new SPoint();
        projMin = STAGE_LIMIT;
        projMax = -STAGE_LIMIT;
        hitMin = STAGE_LIMIT;
        hitMax = -STAGE_LIMIT;
        moveVec.x = plr.GetPos().x - plr.GetLastPos().x;
        moveVec.y = plr.GetPos().y - plr.GetLastPos().y;
        SPoint[] plBox;
        int hbLen = 4;
        if (ifGrab < 0)
        {//implies groundCheck
            plBox = plr.GetHitBox();
            hbLen = 4;
        }
        else
        {
            plBox = plr.GetCurrentColBox();
            hbLen = 6;
        }

        for (int i = 0; i < tBox.GetJlength(iInd); i++)
        {
            projVec.x = tBox.GetSPoint(iInd, i).x - origin.x;
            projVec.y = tBox.GetSPoint(iInd, i).y - origin.y;

            distSq = projVec.x * projVec.x + projVec.y * projVec.y;
            nVec = projVec.GetNormal();

            cVec = new SPoint(Mathf.Cos(dir + Mathf.PI / 2), Mathf.Sin(dir + Mathf.PI / 2));

            cVal = -cVec.Dot(nVec);
            //projVal = sin(rAng)*abs(sin(rAng))*distSq;
            projVal = cVal * Mathf.Abs(cVal) * distSq;

            if (projVal < projMin){
                projMin = projVal;
                dPrMinSq = distSq;
            }
            if (projVal > projMax) {
                projMax = projVal;
                dPrMaxSq = distSq;
            }
        }
        if (dPrMinSq != 0)
            projMin = projMin / Mathf.Sqrt(dPrMinSq);
        if (dPrMaxSq != 0)
            projMax = projMax / Mathf.Sqrt(dPrMaxSq);
        if (dHitMinSq != 0)
            hitMin = hitMin / Mathf.Sqrt(dHitMinSq);
        if (dHitMaxSq != 0)
            hitMax = hitMax / Mathf.Sqrt(dHitMaxSq);
        for (int i = 0; i < hbLen; i++)
        {
            projVec.x = plBox[i].x - origin.x;
            projVec.y = plBox[i].y - origin.y;
            distSq = projVec.x * projVec.x + projVec.y * projVec.y;
            cVec = new SPoint(Mathf.Cos(dir + Mathf.PI / 2), Mathf.Sin(dir + Mathf.PI / 2));
            nVec = projVec.GetNormal();
            cVal = -cVec.Dot(nVec);
            //projVal = sin(rAng)*abs(sin(rAng))*distSq;
            projVal = cVal * Mathf.Abs(cVal) * distSq;
            if (projVal < hitMin){
                hitMin = projVal;
                dHitMinSq = distSq;
            }if (projVal > hitMax){
                hitMax = projVal;
                dHitMaxSq = distSq;
            }
        }
        if ((hitMax <= projMin) || (projMax <= hitMin))
            isHit = false;
        if ((Mathf.Abs(projMax - hitMin) < EPS) || (Mathf.Abs(hitMax - projMin) < EPS))
            isHit = false;

        //determine exit vector here
        float moveAng = Mathf.Atan2(moveVec.y, moveVec.x);
        float angDiff = Mathf.Abs(moveAng - (dir - Mathf.PI/2)) ;
        if(angDiff > Mathf.PI)
            angDiff = Mathf.Abs(angDiff - Mathf.PI*2);
        float moveDist=0;
        if(isHit){
            if(angDiff < Mathf.PI/2) //moveVector in direction of exit vector
                moveDist = -Mathf.Abs(hitMax - projMin)/2;
            else
                moveDist = Mathf.Abs(projMax - hitMin)/2;
        }
        moveVec.x = moveDist*Mathf.Cos(dir - Mathf.PI/2);
        moveVec.y = moveDist*Mathf.Sin(dir - Mathf.PI/2);
        if(!isHit){
            moveVec.x = 0;
            moveVec.y = 0;
        }

        return moveVec;
    }
Exemple #43
0
    public virtual void AttackDetect(Ninja plr)
    {
        bool multiHitFlag = false;
        string hitText;
        //std::stringstream log;
        bool hitflag = true;
        int atkLen;
        int spI=0;
        int spJ=0;
        int hbLen=4;
        SPoint[] plBox;
        SPoint[][] spBox;
        float[] plAng ={0, Mathf.PI/2, Mathf.PI, -Mathf.PI/2};
        int il = 0;

            il = attackBox.trackList[fHelper.atkType].iLength;//num of tracks
        AttkTrack aBox = new AttkTrack();

        int polyHit=-1;
        plBox = plr.GetHitBox();//loads victim hitbox into plBox
        //each side is made from the vertices [i] and [+1]
        int numPoly = 0; //number of polygons in a track;
        int pInd = 0;//polygon index
        SPoint[] pHdr = new SPoint[8];

        il = 1;
        if(!atkTmr.IsReady()){//only continue if an attack is out

            //attack checks

            for(int t=0;t<il;t++){//iterate through all sub tr

                //if(plr.CharName().CompareTo("PsySword")==0)
                //	int ds=2;//checkpt
                if((fHelper.seqInd!=0)&&((fHelper.seqInd-1)!=t)){
                    hitflag=false;//do nothing, for now
                }else {
                    aBox= new AttkTrack();
                    aBox.noHit=false;
                        if(attackBox.trackList[fHelper.atkType].trackType==AttkBox.FLASH){
                            if(fHelper.frame>lastFlash){

                                for(AttkVtx av = attackBox.trackList[fHelper.atkType].aVtx[0][0]; av!=null;av=av.next){
                                    if((av.frame==lastFlash)&&(av.next!=null)){
                                        lastFlash=av.next.frame;
                                        attackBox.flashAtkRdy=true;
                                        attackBox.ResetHits (fHelper.atkType);
                                        while(av.next!=null)
                                            av=av.next;
                                        //av=null;//force exit
                                    }
                                }
                            }
                        }
                    attackBox.FetchFrame(fHelper.atkType, atkTmr.GetLen(), fHelper.frame, t, new SPoint(GetPos().x, GetPos().y), fHelper.IsFacingRight(), aBox);//fetches frame into aBox

                        //aBox has its polygons separated into different tracks for efficiency
                    //make a new SPoint array, spBox, to use checkAxis.

                    hitflag=true;
                    if(aBox.noHit==false){

                        //if(plr.CharName().CompareTo("PsySword")==0)
                        //	int d2s=2;//checkpt
                        spBox=new SPoint[aBox.iLength][];
                        for(int i=0;i<aBox.iLength;i++)
                            spBox[i]=new SPoint[aBox.jLength[i]];
                        aBox.FetchSPArr(spBox);
                            if(ClashCheck(plr, spBox, aBox.atkAng)){
                            SPoint p1Vel = new SPoint(GetPos().x - plr.GetPos().x, GetPos().y - plr.GetPos().y).GetNormal();
                            float cRat = 0.2f;
                            stats.motion.vel.x = p1Vel.x*cRat;
                            stats.motion.vel.y = p1Vel.y*cRat;
                            plr.stats.motion.vel.x = -p1Vel.x*cRat;
                            plr.stats.motion.vel.y = -p1Vel.y*cRat;
                            fHelper.airborne = true;
                            plr.fHelper.airborne = true;
                            return;
                            }

                        numPoly=aBox.iLength;
                            bool hitCheck = false;
                        for(pInd=0;pInd<numPoly;pInd++){//iterate per poly
                                hitflag=true;
                            atkLen =  aBox.GetJlength(pInd);
                            for(int j = 0; j < atkLen; j++)
                                if(!CheckAxis(aBox.aVtx[pInd][j].pos, aBox.atkAng[pInd][j], plBox, spBox[pInd], hbLen, aBox.GetJlength(pInd)) ) //no axis intersection
                                    hitflag = false;

                            if(hitflag)//test on the axis of the player hit box to confirm
                                for(int j = 0; j < 4; j++)
                                    if(!CheckAxis(plBox[j], plAng[j], plBox, spBox[pInd], hbLen, aBox.GetJlength(pInd))) //no axis intersection
                                        hitflag = false;
                            if(hitflag)
                                    hitCheck=true;

                        }
                            hitflag=hitCheck;
                        //log.str(std::string());
                        /*	for(int i=0;i<aBox.iLength;i++){//tidy up
                            if(!aBox.noHit)
                                delete [] spBox[i];
                        }
                        if(aBox.iLength==0){
                            int ee = 2;
                            //log.str(std::string());
                        }
                        else if(!aBox.noHit){//make sure it was hit
                            if(aBox.iLength>1)
                                delete [] spBox;
                            else
                                delete spBox;
                            spBox=NULL;
                        }*/
                    }else
                        hitflag=false;//abandon
                    if(hitflag){
                        AttkData retOb  = new AttkData(aBox.GetJlength(t));//initilize for holding vals
                        Attack(plr, t, aBox, retOb);
                        if(!retOb.noHit){

                            plr.GetHit(retOb);
                            multiHitFlag=true;
                            t=il;//force exit; one track hit
                        }

                    }

                }
            }
        }
        //seems the ideal place to determine pushback
        //if the difference in z is less than their average width
        if((Mathf.Abs(plr.GetPos().x-GetPos().x) < (plr.stats.size.x+stats.size.x)/2  )
           &&(Mathf.Abs(plr.GetPos().y-GetPos().y) < (plr.stats.size.y+stats.size.y)/2)
           &&(!fHelper.airborne)&&(!plr.fHelper.airborne))
        if(plr.GetPos().x-GetPos().x>0){
            stats.motion.move.x-=0.1f;
            plr.stats.motion.move.x+=0.1f;}
        else{
            stats.motion.move.x+=0.1f;
            plr.stats.motion.move.x-=0.1f;}
    }
Exemple #44
0
    public bool GroundTrack(Ninja plr)
    {
        //specialized collision detection function
        //ensures the Ninja keeps flush with the floor
        bool hitflag = true;
        bool indflag = true;
        bool pAxisFlag = false;
        float hitInd = -1;
        int polyIndex = -1;
        SPoint[] plBox = new SPoint[4];
        SPoint[] plLast = new SPoint[4];
        for(int i=0;i<4;i++){
            plBox[i]=new SPoint();
            plLast[i]=new SPoint();
        }
        float[] plAng = {0, Mathf.PI/2, Mathf.PI, -Mathf.PI/2};
        int hbLen=4;

                //modified from colision detect to move the player down

        FillCollisionBox(plBox, new SPoint(plr.GetPos().x, plr.GetPos().y-plr.stats.size.y/2), plr.stats.size.y, plr.stats.size.x);
        FillCollisionBox(plLast, new SPoint(plr.GetPos().x, plr.GetPos().y+plr.stats.size.y/2), plr.stats.size.y, plr.stats.size.x);
        //holds default angles

        for(int i = 0; i < tBox.iLength; i++){
            hitflag = true;
            for(int j = 0; j < tBox.GetJlength(i); j++)
                if(!plr.CheckAxis(tBox.GetSPoint(i, j), tBox.GetAng(i, j), plBox,tBox.pBounds[i], hbLen, tBox.jLength[i]) ) //no axis intersection
                    hitflag = false;
            if(hitflag)
                for(int j = 0; j < 4; j++)
                    if(!plr.CheckAxis(plBox[j], plAng[j], plBox,tBox.pBounds[i], hbLen, tBox.jLength[i]) ) //no axis intersection
                        hitflag = false;
            if(hitflag)
                polyIndex = i;
        }
        int hitIndex = -1;
        if(polyIndex >= 0){
            hitflag = true;
            float moveDist = 0;
            for(int i = 0; i < tBox.GetJlength(polyIndex); i++){
                if(!plr.CheckAxis(tBox.GetSPoint(polyIndex, i), tBox.GetAng(polyIndex, i), plLast,tBox.pBounds[polyIndex], hbLen, tBox.jLength[polyIndex])){
                    hitIndex = i;
                }
            }
            if(hitIndex == -1){
                //check player angs to find the axis
                for(int i  = 0; i < 4; i++){
                    if(!plr.CheckAxis(plLast[i], plAng[i], plLast, tBox.pBounds[polyIndex], hbLen, tBox.jLength[polyIndex]) ){
                        hitIndex = i;
                        pAxisFlag = true;
                    }
                }
            }

            bool floorHit = false;
            SPoint floorVec=new SPoint(0,0);
            plr.stats.motion.pos.y-=plr.stats.size.y/2;
            if(!pAxisFlag)
                floorVec = ExitDist(polyIndex, tBox.GetSPoint(polyIndex, hitIndex), tBox.GetAng(polyIndex, hitIndex), plr, -1);
            else
                floorVec = ExitDist(polyIndex, plBox[hitIndex], plAng[hitIndex], plr, -1);
            float wallAng = Mathf.Atan2(floorVec.y, floorVec.x)-Mathf.PI/2;
            float wallDist=Mathf.Sqrt(floorVec.SqDistFromOrigin());
            if((floorVec.x==0)&&(floorVec.y==0))
                plr.stats.motion.pos.y+=plr.stats.size.y/2;
            else if(Mathf.Cos(wallAng)!=0){
                plr.stats.motion.pos.y+=(wallDist)/Mathf.Cos(wallAng);
                floorHit=true;
            }
            else{
                plr.stats.motion.pos.y+=plr.stats.size.y/2;
                floorHit=true;
            }
            if((floorHit)&&(!plr.fHelper.airborne)){
                plr.Land(tBox.GetAng(polyIndex, hitIndex));

                return true;
            }
        }
        return false;
    }
Exemple #45
0
        static void Main(string[] args)
        {
            Ninja n = new Ninja();
            Duck d = new Duck();

            List<IDamageable> fighters = new List<IDamageable>();
            fighters.Add(n);
            fighters.Add(d);

            Console.WriteLine("Ninja and Duck got into a fight!");
            Console.WriteLine("Ninja has " + n.health + " chi remaining.");
            Console.WriteLine("Duck has " + d.health + " feathers remaining.");
            for (int i = 0; i < 50; i++)
            {
                foreach(IDamageable f in fighters)
                {
                    f.takeDamage(3);
                }

                Console.WriteLine("Each fighter takes 3 damage.");
                Console.WriteLine("Ninja has " + n.health + " chi remaining.");
                Console.WriteLine("Duck has " + d.health + " feathers remaining.");

                if (d.health <= 0)
                {
                    Console.WriteLine("Duck has no more feathers; Ninja is the winner!");
                    Console.WriteLine("Press any key to exit.");
                    Console.ReadKey();
                    Environment.Exit(0);
                }
                if (n.health <= 0)
                {
                    Console.WriteLine("Ninja has no more chi; Duck is the winner!");
                    Console.WriteLine("Press any key to exit.");
                    Console.ReadKey();
                    Environment.Exit(0);
                }
            }
            Console.ReadLine();
        }
Exemple #46
0
    public SPoint ExitDist(int iInd, SPoint origin, float dir, Ninja plr, int ifGrab)
    {
        //plBox must contain 4 vertices!!!
        bool isHit = true;
        float rAng, distSq, projVal, moveDist;
        SPoint moveVec = new SPoint();
        moveVec.x = plr.GetPos().x - plr.GetLastPos().x;
        moveVec.y = plr.GetPos().y - plr.GetLastPos().y;
        SPoint[] plBox;
        int hbLen = 4;

            if (ifGrab < 0)
            {//implies groundCheck
                plBox = plr.GetHitBox();
                hbLen = 4;
            }
            else
            {
                plBox = plr.GetCurrentColBox();
                hbLen = 6;
            }

        float dHitMinSq = 1000;
        float dHitMaxSq = 0;
        float dPrMinSq = 1000;
        float dPrMaxSq = 0;
        SPoint projVec = new SPoint();
        float projMin = STAGE_LIMIT * STAGE_LIMIT;
        float projMax = -STAGE_LIMIT * STAGE_LIMIT;
        float hitMin = STAGE_LIMIT * STAGE_LIMIT;
        float hitMax = -STAGE_LIMIT * STAGE_LIMIT;
        for (int i = 0; i < tBox.GetJlength(iInd); i++)
        {
            projVec.x = tBox.GetSPoint(iInd, i).x - origin.x;
            projVec.y = tBox.GetSPoint(iInd, i).y - origin.y;
            distSq = projVec.x * projVec.x + projVec.y * projVec.y;
            if (distSq < EPS * EPS)
                rAng = dir; //Do NOT take atan2(0, 0)
            else
                rAng = dir - Mathf.Atan2(projVec.y, projVec.x);
            projVal = Mathf.Sin(rAng) * distSq;
            if (projVal < projMin){
                projMin = projVal;
                dPrMinSq = distSq;
            }if (projVal > projMax){
                projMax = projVal;
                dPrMaxSq = distSq;
            }
        }
        for (int i = 0; i < hbLen; i++)
        {
            projVec.x = plBox[i].x - origin.x;
            projVec.y = plBox[i].y - origin.y;
            distSq = projVec.x * projVec.x + projVec.y * projVec.y;
            if (distSq < EPS * EPS)
                rAng = dir; //Do NOT take atan2(0, 0)
            else
                rAng = dir - Mathf.Atan2(projVec.y, projVec.x);
            projVal = Mathf.Sin(rAng) * distSq;
            if (projVal < hitMin){
                hitMin = projVal;
                dHitMinSq = distSq;
            } if (projVal > hitMax) {
                hitMax = projVal;
                dHitMaxSq = distSq;
            }
        }
        if (dPrMinSq != 0)
            projMin = projMin / Mathf.Sqrt(dPrMinSq);
        if (dPrMaxSq != 0)
            projMax = projMax / Mathf.Sqrt(dPrMaxSq);
        if (dHitMinSq != 0)
            hitMin = hitMin / Mathf.Sqrt(dHitMinSq);
        if (dHitMaxSq != 0)
            hitMax = hitMax / Mathf.Sqrt(dHitMaxSq);
        if ((hitMax <= projMin) || (projMax <= hitMin))
            isHit = false;
        if ((Mathf.Abs(projMax - hitMin) < EPS) || (Mathf.Abs(hitMax - projMin) < EPS))
            isHit = false;
        //determine exit vector here
        float moveAng = Mathf.Atan2(moveVec.y, moveVec.x);
        float angDiff = Mathf.Abs(moveAng - (dir - Mathf.PI / 2));
        if (angDiff > Mathf.PI)
            angDiff = Mathf.Abs(angDiff - Mathf.PI * 2);
        moveDist = 0;
        if (isHit)
        {
            if (angDiff < Mathf.PI / 2) //moveVector in direction of exit vector
                moveDist = -Mathf.Abs(hitMax - projMin);
            else
                moveDist = Mathf.Abs(projMax - hitMin);
        }
        moveVec.x = moveDist * Mathf.Cos(dir - Mathf.PI / 2);
        moveVec.y = moveDist * Mathf.Sin(dir - Mathf.PI / 2);

        return moveVec;
    }
            public override CommandProcessor Given()
            {
                id = Guid.NewGuid();
                activeUnit = new Ninja { Id = id, X = 0, Y = 0 };
                otherUnit = new Ninja { Id = Guid.NewGuid(), X = 1, Y = 1 };

                FirstPlayer.Units.Add(activeUnit);
                SecondPlayer.Units.Add(otherUnit);

                State.Turn = State.Players.IndexOf(SecondPlayer); // not first player's turn

                return new CommandProcessor(Calculator, State);
            }
Exemple #48
0
    public virtual void FrameUpdate(float timeLapsed)
    {
        if (stage.ProjectileDetect(this))
        {
            Stick();
            // effects[0].Play();
            // Destroy(effects[2]);
            //ttl.SetTimer(1.0f);
        }
        if((!active)&&(ttl.IsReady()))
            if(AttackDetect(thrower))
                Recover();

        transform.Translate(new Vector3(-vel.x, vel.y,0));
        pos.x -= vel.x;
        pos.y += vel.y;

            for (int i = 0; i < NinjaList.Length; i++)
            {
            if (ClashCheck(NinjaList[i])){
                effects[3].Play();
                SPoint nDir = new SPoint(pos.x - thrower.GetPos().x, pos.y - thrower.GetPos().y).GetNormal();
                vel.x = nDir.x * speed;
                vel.y = nDir.y * speed;
                thrower = NinjaList[i];
                NinjaList = NinjaList[i].NinjaList;
                return;
            }

                if((active)&&(AttackDetect(NinjaList[i]))) {

                    //active = false;
                if (NinjaList[i].InParry()){
                    NinjaList[i].starCount++;
                    Destroy(gameObject);
                }else{
                        NinjaList[i].GetHit(hitdata);
                        Detonate();
                    }

                }
            }

        if (ttl.RunTimer(timeLapsed))
        {

            Destroy(gameObject);
            Destroy(this);
        }
    }
Exemple #49
0
 protected AttkVtx InterpVert(AttkVtx vI, AttkVtx vO, Ninja plr)
 {
     //returns an interpolated vertec between vI (vertex inside player hitbox),
     //vO(vertex outside player hitbox), where plr is the player
     AttkVtx retVtx = new AttkVtx();
     float itpWgt = 1.1f;
     if(vO.pos.x > plr.Right()){
         retVtx.pos.x=plr.Right();
         itpWgt = (plr.Right() - vI.pos.x)/(vO.pos.x-vI.pos.x);
         retVtx.pos.y = itpWgt*vI.pos.y + (1-itpWgt)*vO.pos.y;//solve rest
     }else if(vO.pos.x < plr.Left()){
         retVtx.pos.x=plr.Left();
         itpWgt = (plr.Left() - vI.pos.x)/(vO.pos.x-vI.pos.x);
         retVtx.pos.y = itpWgt*vI.pos.y + (1-itpWgt)*vO.pos.y;//solve rest
     }
     if(itpWgt>1){
         if(vO.pos.y > plr.Top()){
             retVtx.pos.y=plr.Top();
             itpWgt = (plr.Top() - vI.pos.y)/(vO.pos.y-vI.pos.y);
             retVtx.pos.x = itpWgt*vI.pos.x + (1-itpWgt)*vO.pos.x;//solve rest
         }
         else if(vO.pos.y > plr.Bottom()){
             retVtx.pos.y=plr.Bottom();
             itpWgt = (plr.Bottom() - vI.pos.y)/(vO.pos.y-vI.pos.y);
             retVtx.pos.x = itpWgt*vI.pos.x + (1-itpWgt)*vO.pos.x;//solve rest
         }
     }
     retVtx.mag = itpWgt*vI.mag + (1-itpWgt)*vO.mag;
     retVtx.dir = itpWgt*vI.dir + (1-itpWgt)*vO.dir;
     retVtx.dmg = itpWgt*vI.dmg + (1-itpWgt)*vO.dmg;
     retVtx.wgt = itpWgt*vI.wgt + (1-itpWgt)*vO.wgt;
     return retVtx;
 }
        private void btnLoad_Click(object sender, EventArgs e)
        {
            OpenFileDialog openDialog = new OpenFileDialog();
            openDialog.Filter = "Ninja Files | *.ninja";

            if (openDialog.ShowDialog() == DialogResult.OK)
            {
                using (Stream file = openDialog.OpenFile())
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    ninja = (Ninja)formatter.Deserialize(file);
                    btnOK.Visible = false;
                    lblName.Text = ninja.Name;
                    txtName.Visible = false;
                    lblName.Visible = true;
                }
            }
            BtnHomeClick(sender, e);
        }
Exemple #51
0
    public void StartQuickMatch()
    {
        string[] plSel;
        string[] clSel;
        Ninja[] plScr;

        plSel = new string[2];
        plScr = new Ninja[2];
        plSel[ 0]="Yara";
        plSel[1]="Serenity";
        cSel [0] = YARA;
        cSel [1] = SERENITY;
        GameObject pl1 = Instantiate(Resources.Load(plSel[0])) as GameObject;
        GameObject pl2 = Instantiate(Resources.Load(plSel[1])) as GameObject;
        //GameObject stage = Instantiate(Resources.Load("StRuins")) as GameObject;
        GameObject hud;
        if(debugMode)
            hud = Instantiate (Resources.Load ("debugHud")) as GameObject;
        else
            hud = Instantiate (Resources.Load ("matchHud")) as GameObject;
        DontDestroyOnLoad(pl1);
        DontDestroyOnLoad(pl2);
        //DontDestroyOnLoad(stage);
        DontDestroyOnLoad(hud);
        //Stage stScr = stage.GetComponent ("stRuins") as stRuins;

        plScr[0].SetPNum(1);
        plScr [1].SetPNum (2);
        plScr [0].SetStunMult (stunMult);
        plScr [1].SetStunMult (stunMult);
        plScr[0].debugModeOn=debugMode;
        plScr[1].debugModeOn = debugMode;
        plScr [0].stats.damage = 150.0f;
        plScr[1].stats.damage = 150.0f;

        //set physics vars here
        SetPhysVars (plScr [0]);
        SetPhysVars (plScr [1]);

        Application.LoadLevel("stonyruins");
    }
Exemple #52
0
    public void OnUpdate()
    {
        count += Time.deltaTime;
        ui.UpdateKillCount(killCount);
        if (currentState == State.TRANS)
        {
            if (count > .4f)
            {
                count = 0;
                p.GetHealth();
            }
            return;
        }
        bool noMoreSpawns = true;
        for (int enemyType = 0; enemyType < Enum.GetValues(typeof(EnemyTypes)).Length; enemyType++)
            if (spawnCounts[(EnemyTypes)enemyType] > 0)
            {
                noMoreSpawns = false;
                break;
            }
        if (noMoreSpawns)
        {
            if (numEnemiesSpawned == killCount)
            {
                wave++;
                string nextMap = GetWaveMap();
                wave--;
                if ("Maps/" + nextMap != map.actualMapName)
                    LoadNewMap(nextMap);
                else
                    NextWave();
            }
        }
        lastSpawnTime += Time.deltaTime;
        if (lastSpawnTime > SPAWN_INTERVAL)
        {
            lastSpawnTime = 0;
            for (int i = 0; i < Mathf.Min(50, spawnPerWave * (wave > 5 ? wave - 4 : 1)); i++)
            {
                if (numEnemiesSpawned - killCount > MAX_ENEMIES_AT_ONCE)
                    break;
                noMoreSpawns = true;
                for (int enemyType = 0; enemyType < Enum.GetValues(typeof(EnemyTypes)).Length; enemyType++)
                    if (spawnCounts[(EnemyTypes)enemyType] > 0)
                    {
                        noMoreSpawns = false;
                        break;
                    }
                if (noMoreSpawns)
                {
                    if (numEnemiesSpawned == killCount)
                    {
                        wave++;
                        string nextMap = GetWaveMap();
                        wave--;
                        if ("Maps/" + nextMap != map.actualMapName)
                            LoadNewMap(nextMap);
                        else
                            NextWave();
                    }
                    break;
                }

                int j = RXRandom.Int(Enum.GetValues(typeof(EnemyTypes)).Length);
                while (spawnCounts[(EnemyTypes)j] <= 0)
                    j = RXRandom.Int(Enum.GetValues(typeof(EnemyTypes)).Length);
                switch ((EnemyTypes)j)
                {
                    case EnemyTypes.NORMAL:
                        Enemy e = new Enemy(this, 1);
                        SpawnEnemy(e);
                        break;
                    case EnemyTypes.BIG:
                        Enemy e2 = new Enemy(this, 2);
                        SpawnEnemy(e2);
                        break;
                    case EnemyTypes.NINJA:
                        Ninja n = new Ninja(this);
                        SpawnEnemy(n);
                        break;
                }
                numEnemiesSpawned++;
                spawnCounts[(EnemyTypes)j]--;

            }
        }
        foreach (FutilePlatformerBaseObject o in objects)
        {
            if (o is Enemy)
            {
                ((Enemy)o).CheckPlayerCollision(p);
            }
            if (o is Attack)
            {
                ((Attack)o).CheckObjectCollision(objects);
            }
            if (o is AttackWide)
            {
                ((AttackWide)o).CheckObjectCollision(objects);
            }
            if (o is Ninja)
            {
                ((Ninja)o).CheckPlayerCollision(p);
            }
        }
    }
Exemple #53
0
    protected virtual void Attack(Ninja plr,int tr, AttkTrack aBox, AttkData data)
    {
        //pHit is a bool array of flags that tell whether a sub-poly held collision
        //aBox is a modified track taken from current frame
        //plr is the player hit
        //check pnum else we cut Serenuity's sword
        if((plr.stats.id.num<100)&&(attackBox.trackList[fHelper.atkType].hit[tr][plr.stats.id.num])){//if this attack was recorded already
            data.noHit=true; //flag so this does not trigger impact
            return;//don't hit again
        }
        attackBox.trackList[fHelper.atkType].hit[tr][plr.stats.id.num]=true;

        bool isInBox=false;
        bool vNextInBox=false;
        AttkVtx iVt;
        bool[] cornerFlag = new bool[4];
        SPoint[] hb = plr.GetHitBox();// double[4]
        for(int i=0;i<4;i++){
            cornerFlag[i]=true;
            hb[i].x = hb[i].x-GetPos().x;//translate to origin
            hb[i].y = hb[i].y-GetPos().y;
        }
        bool emptyFlag = true;
        bool fullFlag =true;//assume true, disprove by counterexample
        SPoint vPos = new SPoint ();
        SPoint opp = new SPoint();
        int vNext,vLast,jl, il;
        float nX, nY, lY=0, lX=0, vX, vY, ppX, ppY, ph2, pw2, diDist,vDir, vDmg, vMag, vWgt = 0;
        //add poitional value (for wgt=0) into data
        opp.x=plr.GetPos().x-GetPos().x;//used to store the centerpoint
        if(fHelper.IsFacingRight())      //for input into data
            opp.x-=(aBox.centre.pos.x);
        else
            opp.x+=(aBox.centre.pos.x);
        opp.y=plr.GetPos().y-GetPos().y+aBox.centre.pos.y;
        data.SetAVals(opp);
        il = aBox.iLength;
        //set data.abds as an sPoint holding the vertices for aBox.vtx
        //this is done purely for debug rendering
        //which will later handle 'data'
        data.aBds = new SPoint[il][];
        for(int j=0;j<il;j++){
            data.aBds[j] = new SPoint[aBox.GetJlength(j)];
            for(int i=0;i<aBox.GetJlength(j);i++)
                data.aBds[j][i] = new SPoint(aBox.aVtx[j][i].pos.x-GetPos().x, aBox.aVtx[j][i].pos.y-GetPos().y);
        }

        emptyFlag=true;
        fullFlag=true;
        ph2 = plr.stats.size.y/2;
        pw2 = plr.stats.size.x/2;
        ppX = plr.GetPos().x;
        ppY = plr.GetPos().y+ph2;
        for(int i=0;i<4;i++)//assume true then prove false
            cornerFlag[i]=true;
        for(int p=0; p<aBox.iLength;p++){
            jl = aBox.GetJlength(p);
            for(int v = 0; v < jl;v++){//loop through the second index
                vPos = aBox.aVtx[p][v].pos;//use this vertex to check whether it falls
                if((Mathf.Abs(vPos.x-ppX)<pw2)&&(Mathf.Abs(vPos.y-ppY)<ph2))// within hitbox
                    emptyFlag = false;//can't be empty
                else
                    fullFlag = false;//can't be full
            }
            if(fullFlag){
                for(int v = 0; v < jl;v++){
                    int before = v-1;
                    if(before<0)
                        before=jl-1;
                    diDist = Mathf.Sqrt(Mathf.Pow(aBox.aVtx[p][before].pos.x-aBox.aVtx[p][v].pos.x, 2) + Mathf.Pow(aBox.aVtx[p][before].pos.y-aBox.aVtx[p][v].pos.y, 2));
                    vMag = aBox.aVtx[p][v].mag;
                    vDir = aBox.aVtx[p][v].dir;
                    vDmg = aBox.aVtx[p][v].dmg;
                    vWgt = aBox.aVtx[p][v].wgt;
                    data.addVal(aBox.aVtx[p][v].pos, vMag, vDir, diDist, vDmg, vWgt);
                    for(int i=0;i<4;i++)
                        cornerFlag[i]=false;//none possible to be included
                }
            }
            else if(emptyFlag){
                for(int j = 0;j<jl;j++){
                    diDist=1;
                    vMag = aBox.aVtx[p][j].mag;
                    vDir = aBox.aVtx[p][j].dir;
                    vDmg = aBox.aVtx[p][j].dmg;
                    vWgt = aBox.aVtx[p][j].wgt;
                    vPos = aBox.aVtx[p][j].pos;
                    vPos.x-=GetPos().x;
                    vPos.y-=GetPos().y;
                    data.addVal(vPos, vMag, vDir, diDist, vDmg, vWgt);
                }
            }
            else
            for(int v = 0; v < jl;v++){
                vNext = (v+1)%jl;//circular array
                vPos = aBox.aVtx[p][vNext].pos;
                vNextInBox = ((Mathf.Abs(vPos.x-ppX)<pw2)&&(Mathf.Abs(vPos.y-ppY)<ph2));
                vLast=v-1;
                if(vLast<0)
                    vLast=jl-1;
                vMag = aBox.aVtx[p][v].mag;
                vDir = aBox.aVtx[p][v].dir;
                vDmg = aBox.aVtx[p][v].dmg;
                vWgt = aBox.aVtx[p][v].wgt;
                vPos = aBox.aVtx[p][v].pos;
                vX = aBox.aVtx[p][v].pos.x-GetPos().x;//all values translated to origin
                vY = aBox.aVtx[p][v].pos.y-GetPos().y;
                if(v==0){
                    lX=vX;//mustdefine these ahead of time
                    lY=vY;//so the first dir is properly averaged
                }     //in case the loop below is not entered
                if((Mathf.Abs(vPos.x-ppX)<pw2)&&(Mathf.Abs(vPos.y-ppY)<ph2)){//within the victim's hitbox
                    diDist = Mathf.Sqrt( (lX-vX)*(lX-vX) + (lY-vY)*(lY-vY));
                    data.addVal(new SPoint(vX, vY), vMag, vDir, diDist, vDmg, vWgt);
                    lX=vX;
                    lY=vY;
                    if(!vNextInBox){
                        iVt = InterpVert(aBox.aVtx[p][v], aBox.aVtx[p][vNext], plr);
                        iVt.pos.x-=GetPos().x;//all values translated to origin
                        iVt.pos.y-=GetPos().y;
                        diDist = Mathf.Sqrt(Mathf.Pow(iVt.pos.x-vX, 2)+Mathf.Pow(iVt.pos.y-vY, 2));
                        data.addVal(iVt.pos, iVt.mag, iVt.dir, diDist, iVt.dmg, iVt.wgt);
                        lX=iVt.pos.x;
                        lY=iVt.pos.y;
                    }
                }
                else {
                    if(vNextInBox){
                        iVt = InterpVert(aBox.aVtx[p][vNext], aBox.aVtx[p][v], plr);
                        iVt.pos.x-=GetPos().x;//all values translated to origin
                        iVt.pos.y-=GetPos().y;
                        diDist = Mathf.Sqrt(Mathf.Pow(iVt.pos.x-lX, 2)+Mathf.Pow(iVt.pos.y-lY, 2));
                        data.addVal(iVt.pos, iVt.mag, iVt.dir, diDist, iVt.dmg, iVt.wgt);
                        lX=iVt.pos.x;
                        lY=iVt.pos.y;
                    }
                }
                for(int i = 0; i<4;i++){//check player corner axis
                    vX = aBox.aVtx[p][v].pos.x-GetPos().x-hb[i].x;//all values translated to origin
                    vY = aBox.aVtx[p][v].pos.y-GetPos().y-hb[i].y;
                    nX = aBox.aVtx[p][vNext].pos.x-GetPos().x-hb[i].x;
                    nY = aBox.aVtx[p][vNext].pos.y-GetPos().y-hb[i].y;
                    if((fHelper.IsFacingRight())&&(nX*vY-vX*nY<0))//second part is a shortcut formula
                        cornerFlag[i]=false;
                    else if((!fHelper.IsFacingRight())&&(nX*vY-vX*nY>0))
                        cornerFlag[i]=false;
                }
            }
            //last step; add corners that retained their flag
            if(emptyFlag){//for now ; TODO: add case later
                for(int i=0;i<4;i++)
                if(cornerFlag[i]){
                    iVt = InterpCorner(aBox.aVtx[p], aBox.GetJlength(p), plr.GetPos());
                    iVt.pos.x-=GetPos().x;//all values translated to origin
                    iVt.pos.y-=GetPos().y;
                    diDist = Mathf.Sqrt(Mathf.Pow(iVt.pos.x-lX, 2)+Mathf.Pow(iVt.pos.y-lY, 2));
                    data.addVal(iVt.pos, iVt.mag, iVt.dir, diDist, iVt.dmg,iVt.wgt);
                    lX=iVt.pos.x;
                    lY=iVt.pos.y;
                }
            }
        }

        data.rollIntoAvg();
        if (attackBox.trackList [fHelper.atkType].isVacuum) {
            data.isVacuum=true;
        }

        data.SetConOrigin(aBox.centre.pos);
        data.PlayerHitBoxInput(hb);
    }
Exemple #54
0
 protected void SetPhysVars(Ninja plr)
 {
     //sanitize
     if (DI_reduce == 0)
         DI_reduce = 1;//avoid div/0
     plr.SetPhysVars (tumble_ReboundThresh, tumble_RollThresh, tumble_bounceRatio, magnitude_scale, DI_scale, DI_reduce);
 }
Exemple #55
0
 public ActionResult Edit(Ninja ninja)
 {
     var updatedNinja = this.allNinjas.Edit(ninja);
     return new JsonpResult { Data = updatedNinja};
 }
Exemple #56
0
    protected void OnTriggerStay2D(Collider2D col)
    {
        if (col.gameObject.layer == _playerLayer)
        {
            Vector3 dir = col.transform.position - transform.position;
            float distanceFromPlayer = dir.magnitude;
            dir.Normalize();
            Debug.DrawRay(transform.position, dir * distanceFromPlayer, Color.red);
            RaycastHit2D[] hits = Physics2D.RaycastAll(transform.position, dir, distanceFromPlayer);

            bool wallDetected = false;
            foreach(RaycastHit2D hit in hits)
            {
                int hitLayer = hit.collider.gameObject.layer;
                if(hitLayer == _blockingLayer)
                {
                    wallDetected = true;
                }
            }

            if(wallDetected)
            {
                if (_playerSeen)
                {
                    _playerSeen = false;
                    _playerLost = true;
                    _wayToPlayerLastPosition = NavigationManager.Instance.FindWay(transform.position, col.transform.position);
                    _currentTarget = null;
                    NextPatrolWaypoint();
                    _currentIndexToPlayer = 0;
                }
            }
            else
            {
                if (!_playerSeen)
                {
                    _playerLost = false;
                    _playerSeen = true;
                    if(_player == null)
                    {
                        _player = col.gameObject.GetComponent<Ninja>();
                    }
                }
            }
        }
    }
Exemple #57
0
    protected bool ColDetect(Ninja plr)
    {
        if (gameWon) {

        if(Input.anyKey){
                Application.LoadLevel ("menu");
                foreach (GameObject o in Object.FindObjectsOfType<GameObject>()) {
                    Destroy(o);}
                Application.LoadLevel ("menu");
            }
        return false;
        }

        bool hitflag=false;
        int polyIndex = -1;//to keep record of which polygon caused the collision
        int hitIndex = -1;//to keep record of which side of the polygon caused collision
        SPoint[] plBox, plLast;
        bool retFlag=false;//holds the return value
        //this loads plBox[] and plLast[] with the player's hitboc this
        //and last frame respectively
        int hbLen=4;
        SPoint posDiff = new SPoint(plr.GetPos().x-plr.GetLastPos().x, plr.GetPos().y-plr.GetLastPos().y);
        if(posDiff.SqDistFromOrigin()!=0){
            plBox = plr.GetCurrentColBox();
            plLast=plr.GetCurrentColBox();
            hbLen = 6;
            for(int i=0;i<hbLen;i++){
                plLast[i].x-=posDiff.x;
                plLast[i].y-=posDiff.y;
            }
        }else{
            plBox = plr.GetHitBox();
            plLast=plr.GetHitBox();
            hbLen=4;
        }
        if((plr.GetPos().x>9)&&(plr.GetPos().x-posDiff.x<9))
            hbLen= hbLen;

        SPoint hld;
        float[] plAng = new float[hbLen];
        for(int i=0;i<hbLen-1;i++){
            plAng[i]= new SPoint(plBox[i].x-plBox[i+1].x,plBox[i].y-plBox[i+1].y).GetDir();
        }
        plAng[hbLen-1] = new SPoint(plBox[hbLen-1].x-plBox[0].x,plBox[hbLen-1].y-plBox[0].y).GetDir();
        // FillCollisionBox(plBox, plr->GetPos(), plr->stats.size.y, plr->stats.size.x);
        // FillCollisionBox(plLast, plr->stats.motion.lastPos, plr->stats.size.y, plr->stats.size.x);
        //set up angles here for easy acces along with the hitboxes above.

        for(int i = 0; i < tBox.iLength; i++){
            hitflag = true;//assume true, then prove false.
            for(int j = 0; j < tBox.GetJlength(i); j++)
            if(!plr.CheckAxis(tBox.GetSPoint(i, j), tBox.GetAng(i, j), plBox,tBox.pBounds[i], hbLen, tBox.jLength[i])){ //no axis intersection
                hitflag = false;
                j=tBox.GetJlength(i);//exit loop early
            }
            if(hitflag)//possible collision; check against other polygon axise
            for(int j = 0; j < hbLen; j++){
                if(!plr.CheckAxis(plBox[j], plAng[j], plBox, tBox.pBounds[i], hbLen, tBox.jLength[i])){ //no axis intersection
                    hitflag = false;
                    j=hbLen;//exit loop early
                }
            }
            if(hitflag){//all checks are done, collision is sure
                polyIndex = i;//keep record of the last polygon caused the flag
                i=tBox.iLength;//Collision detected, end loop early
            }

        }

        SPoint prV=new SPoint();
        SPoint pCtr;

                //extra added to detect and destroy any projectiles on-screen
        int cv;
        bool pHitFlag = true;

        float flAng = 1.55f;
        if(polyIndex!=-1){
            //hitflag = true;//force to true to return
            retFlag=true;
            //see which side has collided
            for(int i = 0; i < tBox.GetJlength(polyIndex); i++){
                if(!plr.CheckAxis(tBox.GetSPoint(polyIndex, i), tBox.GetAng(polyIndex, i), plLast, tBox.pBounds[polyIndex], hbLen, tBox.jLength[polyIndex])){
                    hitIndex = i;
                    i=tBox.GetJlength(polyIndex);//end loop prematurely
                }
            }
            bool pAxisFlag=false;
            if(hitIndex == -1){
                for(int i  = 0; i < hbLen; i++){//check player angs to find the axis
                    if(!plr.CheckAxis(plLast[i], plAng[i], plLast, tBox.pBounds[polyIndex], hbLen, tBox.jLength[polyIndex]) ){
                        hitIndex = i;
                        pAxisFlag = true;
                    }
                }//do collision detection again for this particular index on the polygon
            }//to get the exit vector

            SPoint axP = new SPoint();
            if(hitIndex>=0){

                if (!pAxisFlag){//using poly axis
                    axP = ExitDist(polyIndex, tBox.GetSPoint(polyIndex, hitIndex), tBox.GetAng(polyIndex, hitIndex), plr, 0);
                    flAng=tBox.GetAng(polyIndex, hitIndex);
                                       }
                else{//using player axis
                    axP = ExitDist(polyIndex, plBox[hitIndex], plAng[hitIndex], plr, 0);

                    flAng=plAng[hitIndex];
                }

                if ((axP.x == 0) && (axP.y == 0))
                {
                polyIndex = polyIndex;// V-jank fix, add a check to get this answer in the first place
                    axP = ExitDist(polyIndex, tBox.GetSPoint(polyIndex, hitIndex+2), tBox.GetAng(polyIndex, hitIndex+2), plr, 0);
                }
            }else
                retFlag=false;
            if (polyIndex == 2)
                polyIndex = 2;
            if (polyIndex == 1)
                polyIndex = 1;
            plr.stats.motion.pos.x+=axP.x;
            plr.stats.motion.pos.y+=axP.y;
            //for walking
            float axAng = Mathf.Atan2(axP.y, axP.x);
            float wallAng = Mathf.Atan2(plr.GetVel().y, plr.GetVel().x);
            float wallDist = Mathf.Sqrt(Mathf.Pow(plr.GetVel().x, 2) + Mathf.Pow(plr.GetVel().y, 2) );
            wallAng -= axAng;

            //separate cases for wall collision
            //depend on whether player is tumbling

            //non-reounding

                if((axAng>0)&&(axAng < Mathf.PI))
                    plr.Land(flAng);
                plr.stats.motion.vel.x -= Mathf.Cos(wallAng)*wallDist*Mathf.Cos(axAng);
                plr.stats.motion.vel.y -= Mathf.Cos(wallAng)*wallDist*Mathf.Sin(axAng);
            if (( Mathf.Abs(  Mathf.Abs(axAng) - Mathf.PI )< 0.1f) && (plr.fHelper.airborne))
                plr.WallHang(axAng);
            else if  ((Mathf.Abs(axAng) < 0.1f) && (plr.fHelper.airborne))
                    plr.WallHang(axAng);

        }

        if ((!plr.fHelper.airborne)&&(!retFlag)&&(!plr.tPortFlag))
            if(!GroundTrack(plr))//ground tracking done here
                plr.Fall();

        if((plr.GetPos().x > uBound.x)||(plr.GetPos().y > uBound.y)||(plr.GetPos().x < lBound.x)||(plr.GetPos().y < lBound.y)){
            if((plr.stats.stocks>0)||(!matchModeOn)){
            //SetPlStart(plr);
            plr.stats.stocks--;
            plr.stats.motion.vel = new SPoint(0,0);
            plr.stats.damage=0;}
        }
        if (retFlag)
            ColDetect (plr);
        return retFlag;
    }
            public override CommandProcessor Given()
            {
                activeUnit = new Ninja { Id = id, X = 0, Y = 0 };
                activeUnit.Range = 1;

                FirstPlayer.Units.Add(activeUnit);

                return new CommandProcessor(Calculator, State);
            }
 public void DeleteCurrentNinja(Ninja ninja)
 {
     _context.Ninjas.Remove(ninja);
     Save();
 }
Exemple #60
0
    public bool ClashCheck(Ninja opp, SPoint[][] pBox, float[][] pAng)
    {
        if (opp.atkTmr.IsReady ())
            return false;
        SPoint[][] oBox=null;
        float [][] oAngs=null;

        oBox = opp.GetClashBox (oBox);
        int pLen = pBox.Length;
        //abox = obox
        //plBox = pBox;
        if (oBox == null)
                        return false;
        oAngs = opp.GetClashAngs (oAngs);
        int numPoly = pBox.Length;
        bool hitCheck = false;
        bool hitflag = false;
        int atkLen = 0;
        int pInd = 0;

        for(int oInd=0;oInd<numPoly;oInd++){//iterate per poly
            hitflag=true;
            atkLen =  pBox[oInd].Length;
            for(int j = 0; j < atkLen; j++)
                if(!CheckAxis(oBox[oInd][j], oAngs[oInd][j], pBox[pInd], oBox[oInd], pLen, oBox[oInd].Length) ) //no axis intersection
                    hitflag = false;

            if(hitflag)//test on the axis of the player hit box to confirm
                for(int j = 0; j < pLen; j++)
                    if(!CheckAxis(pBox[pInd][j], pAng[pInd][j], pBox[pInd], oBox[oInd], pLen, oBox[oInd].Length)) //no axis intersection
                        hitflag = false;
            if(hitflag)
                hitCheck=true;

        }
        hitflag=hitCheck;

        if (hitCheck) {

            if(GetCurPriority()>=opp.GetCurPriority())
                opp.Recoil (1);
            if(GetCurPriority()<=opp.GetCurPriority()){
                Recoil(1);
                return true;
            }else
                return false;
        }else
                        return false;
    }