private void WaitForCollectingHalfTheTreasureToRevealEndGoal() { HalfOfTheTreasureCollected = delegate { // ding ding ding - end of level revealed HalfOfTheTreasureCollected = null; Assets.Default.Sounds.revealed.play(); EgoView.Image.FadeOut( delegate { TheGoldStack.AddTo(EgoView.Sprites); // cuz we removed and then added, we have to manually update // pov info, otherwise we need to wait // until we collect another treasure // for the endlevel to show up EgoView.UpdatePOV(true); CompassContainer.FadeIn( delegate { EgoView.Image.FadeIn(); } ); } ); //this.WriteLine("game goal is now there"); }; }
private void InitializeMap() { #region fill map Assets.Default.stuff.ToBitmapDictionary( f => { this.WriteLine("init: stuff"); StuffDictionary = f; CreateMapFromMaze(); Func <string, Texture64> t = texname => f[texname + ".png"]; Func <string, string, Texture64> mix = (a, b) => { var ia = f[a + ".png"]; var ib = f[b + ".png"]; var u = new Bitmap(ia.bitmapData.clone()); u.bitmapData.draw(ib); return(u); }; #region game goal TheGoldStack = CreateDummy(f["life.png"]); TheGoldStack.RemoveFrom(EgoView.Sprites); WaitForCollectingHalfTheTreasureToRevealEndGoal(); TheGoldStack.Position.To(maze.Width - 1.25, maze.Height - 1.25); TheGoldStack.Range = 0.6; TheGoldStack.ItemTaken += delegate { if (EndLevelMode) { return; } if (HalfOfTheTreasureCollected != null) { throw new Exception("should not reach here"); } Assets.Default.Sounds.yeah.play(); // show stats this.WriteLine("TheGoldStack -> EnterEndLevelMode"); EnterEndLevelMode(); }; GoldSprites.Add(TheGoldStack); #endregion EgoView.Map.Textures = new Dictionary <uint, Texture64> { { graywall_achtung, mix("graywall", "achtung") }, { graywall_verboten, mix("graywall", "verboten") }, { graywall, t("graywall") }, { woodwall_achtung, mix("woodwall", "achtung") }, { woodwall_verboten, mix("woodwall", "verboten") }, { woodwall, t("woodwall") }, { woodwall_books, t("woodwall_books") }, { bluewall, t("bluewall") }, { greenwall, t("greenwall") }, }; // EgoView.RenderScene(); InitializeWeaponOverlay(f); #region heads Assets.Default.head.Items.OrderBy(k => k.FileName).Select(k => k.Data).ToImages( heads => { var head = default(Bitmap); 1000.AtInterval( tt => { if (head != null) { head.Orphanize(); } if (heads.Length > 0) { if (GoldTakenCounter > 0) { GoldTakenCounter--; head = heads.Last(); } else { head = heads.AtModulus(tt.currentCount % 3); } head.filters = new[] { new DropShadowFilter() }; head.scaleX = 2; head.scaleY = 2; head.MoveTo(4, DefaultControlHeight - head.height - 4).AttachTo(HudContainer); } } ); } ); #endregion InitializeCompass(); InitializeKeyboard(); AttachMovementInput(EgoView, true, false); #region focus logic this.focusIn += e => { this.MovementEnabled_IsFocused = true; //WriteLine("focusIn"); //if (this.MovementEnabled_IsAlive) // this.filters = null; }; this.focusOut += delegate { this.MovementEnabled_IsFocused = false; //if (this.MovementEnabled_IsAlive) // this.filters = new[] { Filters.GrayScaleFilter }; //WriteLine("focusOut"); }; this.focusRect = null; this.mouseChildren = false; this.tabEnabled = true; #endregion //this.stage.focus = this; ResetEgoPosition(); AddPortals(); AddIngameEntities( delegate { this.WriteLine("init: AddIngameEntities done"); 1000.AtInterval( delegate { var u = new PointInt32 { X = EgoView.ViewPosition.x.Floor(), Y = EgoView.ViewPosition.y.Floor() }; if (this.EgoView.Map.WallMap[u.X, u.Y] != 0) { ResetEgoPosition(); } } ); stage.enterFrame += e => { ApplyNextViewVector(); if (EgoView.Image.alpha > 0) { EgoView.RenderScene(); } }; this.WriteLine("init: AddIngameEntities + ReadyWithLoadingCurrentLevel"); this.ReadyWithLoadingCurrentLevel(); } ); } ); #endregion }
private void InitializeWeaponOverlay(Dictionary <string, Bitmap> f) { Func <int, Bitmap> id = _id => f[_id + ".png"]; var hand = new Sprite(); var noweapon = f["hand.png"].AttachTo(hand); var gun_index = 0; var gun = new[] { id(326), id(327), id(328), id(329), id(330), }; this.SwitchToHand = delegate { gun.First().Orphanize(); noweapon.AttachTo(hand); }; //var hand = f["330.png"]; const int handsize = 4; var hand_x = (DefaultControlWidth - 64 * handsize) / 2; var hand_y_default = DefaultControlHeight - 64 * handsize; var hand_y = hand_y_default; hand.x = hand_x; hand.y = hand_y; hand.scaleX = handsize; hand.scaleY = handsize; hand.AttachTo(HudContainer); #region make it float (1000 / 24).AtInterval( tt => { hand.x = hand_x + Math.Cos(tt.currentCount * 0.2) * 6; hand.y = hand_y + Math.Abs(Math.Sin(tt.currentCount * 0.2)) * 4; } ); #endregion var WeaponChangeSpeed = handsize * 4; Action <Action> BringWeaponUp = ChangeDone => { (1000 / 24).AtInterval( tt => { hand_y -= WeaponChangeSpeed; if (hand_y <= hand_y_default) { tt.stop(); hand_y = hand_y_default; // ready to fire ChangeDone(); } } ); }; Action <Action, Action> BringWeaponDown = (MomentOfChange, ChangeDone) => { (1000 / 24).AtInterval( tt => { hand_y += WeaponChangeSpeed; if (hand_y >= DefaultControlHeight - (32 * handsize)) { // hand is off screen // lets switch to a weapon MomentOfChange(); tt.stop(); BringWeaponUp(ChangeDone); } } ); }; Action SwitchToWeaponDefault = delegate { // disable this function SwitchToWeapon = delegate { }; BringWeaponDown( delegate { noweapon.Orphanize(); gun.First().AttachTo(hand); } , delegate { WeaponIsActive = true; } ); }; SwitchToWeapon = SwitchToWeaponDefault; var PlayFireAnimationTimer = default(Timer); Action <Action> PlayFireAnimation = done => { PlayFireAnimationTimer = FrameRate_FireWeapon.AtInterval( tt => { gun[gun_index].Orphanize(); gun_index++; if (gun_index == gun.Length) { // done gun_index = 0; tt.stop(); PlayFireAnimationTimer = null; done(); } gun[gun_index].AttachTo(hand); } ); }; FireWeapon = delegate { if (EndLevelMode) { return; } if (!WeaponIsActive) { return; } // we can fire only if the animation has stopped if (PlayFireAnimationTimer != null) { return; } if (WeaponAmmo <= 0) { WeaponIsActive = false; SwitchToWeapon = delegate { }; BringWeaponDown(SwitchToHand, delegate { SwitchToWeapon = SwitchToWeaponDefault; } ); return; } if (Sync_FireWeapon != null) { Sync_FireWeapon(); } Assets.Default.Sounds.gunshot.play(); WeaponAmmo--; // add damage to sprites // we need to find out the one we are shooting at! // try adding damage to all //WriteLine("fire:"); var PossibleTargets = from p in EgoView.Sprites let fragile = p as SpriteInfoExtended where fragile != null where fragile.Health > 0 where fragile.TakeDamage != null select p; var query = from k in EgoView.GetVisibleSprites(15.DegreesToRadians(), PossibleTargets) let VisiblePercentage = k.LastRenderedClip.width / k.LastRenderedZoom where VisiblePercentage > 0.5 orderby k.Distance let fragile = k.Sprite as SpriteInfoExtended select new { k, fragile }; var first = query.FirstOrDefault(); WriteLine("" + new { PossibleTargets = PossibleTargets.Count(), Targets = query.Count() /*, first.fragile.ConstructorIndexForSync */ }); //foreach (var q in query) //{ // WriteLine("" + new { q.k.LastRenderedClip.width, q.k.LastRenderedZoom, vis = q.k.LastRenderedClip.width / q.k.LastRenderedZoom } ); //} if (first != null) { var DamageToBeTaken = 1 / first.k.Distance; //WriteLine("hit: " + DamageToBeTaken); first.fragile.TakeDamage(DamageToBeTaken, EgoWeaponIdentity); } PlayFireAnimation( delegate { if (WeaponAmmo <= 0) { // dude, we are out of ammo!! WeaponIsActive = false; Action ReadyForMoreAmmo = delegate { SwitchToWeapon = SwitchToWeaponDefault; }; SwitchToWeapon = delegate { SwitchToWeapon = delegate { }; // the animation has not yet stopped but we found the ammo // when we are ready we switch back for the gun // this can be tested if the hand movement is really slow ReadyForMoreAmmo = SwitchToWeaponDefault; }; BringWeaponDown(SwitchToHand, delegate { ReadyForMoreAmmo(); } ); } } ); }; }
private void TrackGoldSpritePickup() { #region Track gold pickup var LastPosition = new Point(); EgoView.ViewPositionChanged += delegate { if (!EnableItemPickup) { return; } if (EndLevelMode) { return; } if (EgoView.SpritesFromPointOfView == null) { return; } // only check for items each 0.5 distance travelled if ((EgoView.ViewPosition - LastPosition).length < PlayerRadiusMargin) { return; } Action Later = null; Action ItemTaken = null; int ItemsPickedUp = 0; EgoView.UpdatePOV(true); foreach (var Item in EgoView.SpritesFromPointOfView) { var Item_Sprite = Item.Sprite as SpriteInfoExtended; if (Item_Sprite != null) { if (!Item_Sprite.IsTaken) { if (Item.Distance < Item_Sprite.Range) { if (GoldSprites.Contains(Item_Sprite)) { // ding-ding-ding! Item_Sprite.IsTaken = true; this.WriteLine("gold taken: " + Item_Sprite.ConstructorIndexForSync); Later += delegate { GoldTakenCounter = (GoldTakenCounter + 1).Min(1); if (Item_Sprite != null) { if (Item_Sprite.ItemTaken != null) { ItemTaken += () => Item_Sprite.ItemTaken(); } if (Sync_TakeGold != null) { Sync_TakeGold(Item_Sprite.ConstructorIndexForSync); } } EgoView.Sprites.Remove(Item_Sprite); GoldSprites.Remove(Item_Sprite); }; } } } } } if (Later != null) { FlashColors(0xffff00); Later(); } LastPosition = EgoView.ViewPosition; if (ItemTaken != null) { ItemTaken(); } }; #endregion }
public void AddPortals() { ResetPortals(); FrameRate_PortalRefresh.AtInterval( tt => { if (EgoView.SpritesFromPointOfView == null) { return; } if (Portals.Count > 0) { foreach (var p in this.Portals) { var v = EgoView.GetVisibleSprites(60, new[] { p.Sprite }); if (v.Any()) { p.View.RenderLowQualityWalls = EgoView.RenderLowQualityWalls; p.Update(); } } } } ); var LastPortalExit = default(PortalInfo); var LastPosition = new Point(); EgoView.ViewPositionChanged += delegate { // only check for items each ~ distance travelled if ((EgoView.ViewPosition - LastPosition).length < PlayerRadiusMargin) { return; } foreach (var Portal in Portals) { if (NextViewVectorDirty) { continue; } if (Portal == LastPortalExit) { continue; } var p = EgoView.SpritesFromPointOfView.SingleOrDefault(i => i.Sprite == Portal.Sprite); if (p != null) { if (p.Distance < Portal.Sprite.Range) { // we are going thro the portal, show it new Bitmap(EgoView.Buffer.clone()) { scaleX = DefaultScale, scaleY = DefaultScale }.AttachTo(this).FadeOutAndOrphanize(1000 / 24, 0.2); Assets.Default.Sounds.teleport.play(); // fixme: should use Ego.MovementDirection instead // currently stepping backwarads into the portal will behave recursivly //EgoView.ViewPosition = Portal.View.ViewPosition; //.MoveToArc(EgoView.ViewDirection, Portal.Sprite.Range + p.Distance); //EgoView.ViewDirection = Portal.View.ViewDirection; NextViewPosition = Portal.View.ViewPosition; NextViewDirection = Portal.View.ViewDirection; ApplyNextViewVector(); Smooth_DisableJoin(); NextViewVectorDirty = true; WriteLine("portal used"); if (Sync_PortalUsed != null) { Sync_PortalUsed(); } var o = DualPortals.SingleOrDefault(k => k.Blue == Portal); if (o == null) { LastPortalExit = DualPortals.SingleOrDefault(k => k.Orange == Portal).Blue; } else { LastPortalExit = o.Orange; } 5000.AtDelayDo( delegate { LastPortalExit = null; } ); break; } } } LastPosition = EgoView.ViewPosition; }; //EgoView.ViewDirectionChanged += () => Portals.ForEach(Portal => Portal.View.ViewDirection = Portal.Sprite.Direction); }