public static Vector2 GetCollisionCenter(Node node) { Bounds2 bounds = new Bounds2 (); node.GetlContentLocalBounds (ref bounds); Vector2 center = node.LocalToWorld (bounds.Center); return center; }
public EnemySpawnEvent(double triggerTime, Enemy.EnemyType enemyType, Node parentLayer, PlayerCreature player) { this.triggerTime = triggerTime; this.enemyType = enemyType; this.parent = parentLayer; this.player = player; }
// METHODS --------------------------------------------------------------------------------- public void Destroy() { parent = null; this.UnscheduleAll(); this.RemoveAllChildren(true); this.Parent.RemoveChild(this, true); }
// METHODS ---------------------------------------------------------------------- public void ApplyUI( Node pNode, int pVariant ) { if (pNode is SpriteBase) { (pNode as SpriteBase).Color = uiPalette[pVariant]; } else { (pNode as Label).Color = uiPalette[pVariant]; } }
protected IconPopupManager() { icon = Support.SpriteFromFile("/Application/assets/images/icons/icons.png"); iconSize = (icon as SpriteTile).CalcSizeInPixels(); // icon.Pivot = Vector2.One; #if DEBUG Console.WriteLine(GetType().ToString() + " created" ); #endif }
public override void CollideFrom(GameEntity owner, Node collider) { base.CollideTo(owner, collider); Type type = owner.GetType(); if (type == typeof(EnemyTurtle)) { //collied enemy } }
public MainScene() { this.ScheduleUpdate (); SceneCamera = (Camera2D)Camera; SceneCamera.SetViewFromHeightAndCenter (_screenSize.Y, _screenSize / 2.0f); //_background = new Layer (SceneCamera, 0.1f, 0.1f); //_main = new Layer (SceneCamera); _main = new Node (); /* _physics = new PhysicsScene(); _physics.InitScene(); */ _playerCreature = new PlayerCreature (); _playerCreature.sprite.Position = Camera.CalcBounds ().Center; // _player.PositionAll = SceneCamera.CalcBounds().Center; /* _block = new PhysicalSpriteUV(new TextureInfo("/Application/assets/floor.png"), _physics); _block.PositionAll = new Vector2(SceneCamera.CalcBounds().Center.X + 10, SceneCamera.CalcBounds().Center.Y - 100); _physics.sceneBodies[_block.BodyIndex].SetBodyStatic(); _physics.restitutionCoeff = 0.9f; _physics.sceneMax = new Vector2(10000, 10000); _physics.sceneMin = new Vector2(-10000, -10000); */ //AddChild (new SpriteUV(new TextureInfo("/Application/king_water_drop.png"))); //_main.AddChild (_player); var background = new SpriteUV (new TextureInfo ("/Application/assets/background.png")); background.Quad.S = background.TextureInfo.TextureSizef; background.CenterSprite (); //_physics.Gravity = new Vector2(0.0f, -98f); background.Position = SceneCamera.CalcBounds ().Center; //_background.AddChild(background); //AddChild(_background); //AddChild(_block); AddChild (_main); _main.AddChild (background); _main.AddChild (_playerCreature.sprite); _enemies = new ArrayList (); // enemy sprite test code var fish0 = new FishEnemy (new Vector2 (30.0f, 30.0f), _playerCreature); var fish1 = new FishEnemy (new Vector2 (15.0f, 15.0f), _playerCreature); var fish2 = new FishEnemy (new Vector2 (100.0f, 70.0f), _playerCreature); _enemies.Add (fish0); _enemies.Add (fish1); _enemies.Add (fish2); // _main.AddChild (FishEnemy.spriteList); }
public override void CollideTo(GameEntity owner, Node collider) { base.CollideTo(owner, collider); Type type = owner.GetType(); if (type == typeof(EnemyBase)) { // Logger.Debug("[PlayerBullet] Collied to Enemy"); Destroy(); } }
// CONSTRUCTORS ---------------------------------------------------------- public NodeCrystallonEntity(Scene pScene, GamePhysics pGamePhysics, PhysicsShape pShape = null) : base(pScene, pGamePhysics) { _node = new Node(); if (pShape != null) { _body = _physics.RegisterPhysicsBody(pShape, 0.1f, 0.01f, _node.Position); } else { _body = null; } Scheduler.Instance.Schedule(_node, Update, 0, false, 0); }
public override void CollideTo(GameEntity owner, Node collider) { base.CollideTo(owner, collider); Type type = owner.GetType(); if (type == typeof(EnemyTurtle)) { Logger.Debug("[PlayerBullet] Collied to Enemy"); CollisionDatas.RemoveAll( (x) => x.owner==this ); Velocity *= 0.3f; SetAnimation(BodySprite, "Explosion"); } }
public EventManager(Node parent, PlayerCreature player) { _eventList = new List<Event>(); EnemySpawnEvent enemySpawn0 = new EnemySpawnEvent(1.0f, Enemy.EnemyType.ENEMY_TYPE_FISH, parent, player); EnemySpawnEvent enemySpawn1 = new EnemySpawnEvent(5.0f, Enemy.EnemyType.ENEMY_TYPE_FISH, parent, player); EnemySpawnEvent enemySpawn2 = new EnemySpawnEvent(15.0f, Enemy.EnemyType.ENEMY_TYPE_FISH, parent, player); _eventList.Add(enemySpawn0); _eventList.Add(enemySpawn1); _eventList.Add(enemySpawn2); _currentIndex = 0; _startTime = Director.Instance.DirectorTime; }
protected void SpawnIcons(ICrystallonEntity pParent, Dictionary<string,int> pQualities, Vector4 pColor) { icon = null; Sequence sequence = new Sequence(); foreach( string key in pQualities.Keys) { if (icon != null) { continue; } if(key=="Orientation") { continue; } switch(key){ case("Color"): icon = ColorIcon.Instance; break; default: int ix = (int)EnumHelper.FromString<Crystallography.Icons>(key); icon = Support.TiledSpriteFromFile("/Application/assets/images/icons/icons.png", 4, 2 ); (icon as SpriteTile).TileIndex1D = ix; (icon as SpriteBase).RegisterPalette((int)FMath.Floor(GameScene.Random.NextFloat()*3)); break; } } icon.Position = pParent.Parent.Parent.Position.Xy - iconSize/2.0f; if(icon.Parent != null){ icon.Parent.RemoveChild(icon, false); } GameScene.Layers[2].AddChild(icon); sequence.Add( new DelayTime(0.1f)); sequence.Add( new CallFunc( () => {icon.Visible = false;})); sequence.Add (new DelayTime(0.05f)); sequence.Add( new CallFunc( () => {icon.Visible = true;})); sequence.Add( new DelayTime(0.1f)); sequence.Add( new CallFunc( () => {icon.Visible = false;})); sequence.Add (new DelayTime(0.05f)); sequence.Add( new CallFunc( () => {icon.Visible = true;})); sequence.Add( new DelayTime(0.75f)); sequence.Add( new CallFunc( () => {icon.Visible = false;})); sequence.Add(new CallFunc( () => { icon.Visible = true; GameScene.Layers[2].RemoveChild(icon, true); })); icon.RunAction(sequence); }
/// <summary>Add an action to the ActionManager.</summary> public void AddAction( ActionBase action, Node target /*, bool paused = false*/ ) { // remove action from whatever list it is currently in RemoveAction( action ); // add node to the set of nodes that have actions, // new the node ActionBase list if necessary if ( !m_nodes.Contains( target ) ) { m_nodes.Add( target ); if ( target.m_action_entries == null ) target.m_action_entries = new List< ActionBase >(); } // add it to the new list action.set_target( target ); target.m_action_entries.Add( action ); }
private static Node Initialize() { _instance = new Node(); SpriteTile[] pieces = { Support.TiledSpriteFromFile("/Application/assets/images/icons/icons.png", 4, 2), Support.TiledSpriteFromFile("/Application/assets/images/icons/icons.png", 4, 2), Support.TiledSpriteFromFile("/Application/assets/images/icons/icons.png", 4, 2) }; pieces[0].Position = new Vector2(-2.0f, 19.0f); pieces[1].Position = new Vector2(23.0f, -21.0f); pieces[2].Position = new Vector2(-25.0f, -21.0f); for (int i = 0; i < pieces.Length; i++) { pieces[i].TileIndex1D = 1; pieces[i].RegisterPalette(i); _instance.AddChild(pieces[i]); } return _instance; }
// protected Label inside; public ScorePopup(Node pParent, int pPoints) : base(pPoints.ToString(), map) { parent = pParent; if (pPoints < 10) { offset = DoubleDigitOffset; } else { offset = SingleDigitOffset; } // velocity = Vector2.Zero; Position = parent.LocalToWorld(parent.Position) + offset; // this.RegisterPalette(0); Color = Support.ExtractColor("333330"); Pivot = new Vector2(0.5f, 0.5f); // HeightScale = 1.0f; // inside = new Label() { // Text = pPoints.ToString(), // FontMap = map, // Pivot = Vector2.One/2.0f, //// Position = Vector2.One //// Scale = new Vector2(0.9f, 0.9f) // }; // inside.Color = LevelManager.Instance.BackgroundColor; // this.AddChild(inside); Sequence sequence = new Sequence(); sequence.Add( new DelayTime( 0.1f ) ); GameScene.Layers[2].AddChild(this); sequence.Add( new CallFunc( () => { Scheduler.Instance.ScheduleUpdateForTarget(this,0,false); } ) ); this.RunAction(sequence); #if DEBUG Console.WriteLine (GetType().ToString() + " created" ); #endif }
public override void CollideFrom(GameEntity owner, Node collider) { base.CollideFrom(owner, collider); var enemyKiller = owner as EnemyKiller; if (enemyKiller!=null) { // Logger.Debug("[PlayerBullet] Collied from PlayerBullet"); CollisionDatas.RemoveAll( (x) => x.owner==this ); Velocity *= 0.0f; //spawn pieces { int nextKillerGen = enemyKiller.Generation + 1; int pieceCount = GlobalParams.EnemyPieceCount; for(int i=0; i<pieceCount; i++) { var pos = Position; var targetPos = pos + Game.Instance.Random.NextVector2( GlobalParams.EnemyPieceMoveLength ); var enemyPiece = new EnemyPiece( pos, targetPos, GlobalParams.EnemyPieceLifeTime ); enemyPiece.Generation = nextKillerGen; Game.Instance.AddQueue.Add(enemyPiece); } } //add score Game.Instance.ScoreManager.AddScore(2, enemyKiller.Generation); Game.Instance.EnemySpawner.EnemyDeadCountTotal ++ ; Game.Instance.RemoveQueue.Add(this); } }
internal void invalidate() { m_node = null; m_func = null; }
void schedule_internal( Node target, DSchedulerFunc func, float interval, int priority ) { Entry entry = add_entry( target, func, interval ); m_groups[ max_priority + priority ].Add( entry ); }
void invalidate_entry( Node node, DSchedulerFunc func ) { if ( !m_nodes.Contains( node ) ) return; // no such node foreach ( Entry entry in node.m_scheduler_entries ) { if ( entry.m_func == func ) entry.invalidate(); } }
void invalidate_all_entries( Node node ) { if ( !m_nodes.Contains( node ) ) return; invalidate_all_entries( ref node.m_scheduler_entries ); }
Entry add_entry( Node node, DSchedulerFunc func, float interval ) { Entry entry = new Entry() { m_node = node, m_func = func, m_interval = interval, }; if ( !m_nodes.Contains( node ) ) m_nodes.Add( node ); if ( node.m_scheduler_entries == null ) node.m_scheduler_entries = new List< Entry >(); node.m_scheduler_entries.Add( entry ); return entry; }
/// <summary> /// Remove a function from the scheduler. /// </summary> /// <param name="target">The target node for the removed function.</param> /// <param name="func">The function to remove.</param> public void Unschedule( Node target, DSchedulerFunc func ) { invalidate_entry( target, func ); }
/// <summary> /// Schedule a Node's Update function to be called everyframe. /// </summary> /// <param name="target">The target node.</param> /// <param name="priority">Priority of the Update function in the scheduler.</param> /// <param name="paused">The scheduler paused stated for that node.</param> public void ScheduleUpdateForTarget( Node target, int priority, bool paused ) { schedule_internal( target, target.Update, 0.0f, priority ); target.SchedulerPaused = paused; }
/// <summary> /// Register a Node function in the scheduler. /// </summary> /// <param name="target">The target node for the scheduled function.</param> /// <param name="func">The scheduled function.</param> /// <param name="interval">Period at which the function should be called (in seconds). Zero means "everyframe".</param> /// <param name="paused">Set the scheduler paused state for that node.</param> public void Schedule( Node target, DSchedulerFunc func, float interval, bool paused, int priority = DefaultPriority ) { schedule_internal( target, func, interval, priority ); target.SchedulerPaused = paused; }
void remove_action_from_target_if( Node target, DRemoveCondition cond ) { List< ActionBase > actions = target.m_action_entries; if ( actions == null ) return; for ( int i=0; i< actions.Count; ++i ) { if ( cond( actions[i] ) ) { actions[i].Stop(); actions[i].set_target( null ); // "remove" Action from m_action_entries => nullify its target node actions.RemoveAt( i ); break; } } if ( actions.Count == 0 ) m_nodes.Remove( target ); }
// Remove all actions involving Node 'target'. If 'update_node_set' is true, remove // node from m_nodes. public void remove_all_actions_from_target( Node target, bool update_node_set ) { List< ActionBase > actions = target.m_action_entries; if ( actions != null ) { foreach ( ActionBase action in actions ) { action.Stop(); action.set_target( null ); // "remove" Action from m_action_entries => nullify its target node } actions.Clear(); } if ( update_node_set && m_nodes.Contains( target ) ) m_nodes.Remove( target ); }
/// <summary> /// Remove all functions related to a given node from the scheduler. /// </summary> public void UnscheduleAll( Node target ) { invalidate_all_entries( target ); }
/// <summary> /// Remove a Node's Update function from the scheduler. /// </summary> public void UnscheduleUpdateForTarget( Node target ) { Unschedule( target, target.Update ); }
private void Initialize() { FontMap map = FontManager.Instance.GetMap( FontManager.Instance.GetInGame("Bariol", 25, "Bold") ); FontMap bigMap = FontManager.Instance.GetMap( FontManager.Instance.GetInGame("Bariol", 44, "Bold") ); // CREATE PAUSE MENU pausePanel = new PausePanel(_scene); _scene.DialogLayer.AddChild(pausePanel); pausePanel.Hide(); // CREATE THE HUD BAR AT THE TOP OF THE SCREEN GameHudBar = new Node(){ Position = new Vector2(0.0f, 473.0f) }; this.AddChild(GameHudBar); HudBarMask = Support.UnicolorSprite("white", 255, 255, 255, 255); HudBarMask.Color = LevelManager.Instance.BackgroundColor; HudBarMask.Scale = new Vector2(60.0f, 4.4375f); GameHudBar.AddChild(HudBarMask); // CREATE THE LEVEL TITLE HUD levelTitle = new LevelTitleMkTwo() { SlideInDirection = SlideDirection.RIGHT, SlideOutDirection = SlideDirection.LEFT, Offset = new Vector2(0.0f, 0.0f), // Lifetime = 4.0f }; this.AddChild(levelTitle, -1); // CREATE THE END-OF-LEVEL DROP-DOWN PANEL if (GameScene.currentLevel == 999) { // INFINITE MODE VERSION _nextLevelPanel = new InfiniteModeEndPanel(){ Offset = new Vector2(Director.Instance.GL.Context.Screen.Width-248.0f, 0.0f), }; } else { // PUZZLE/TUTORIAL MODE VERSION _nextLevelPanel = new NextLevelPanel(){ Offset = new Vector2(510.0f, 0.0f), }; } GameHudBar.AddChild(_nextLevelPanel, -1); // CREATE MESSAGE PANEL _messagePanel = new MessagePanel(920.0f, 148.0f ){ SourceObject = this, Offset = new Vector2(20.0f, 0.0f), Position = new Vector2(0.0f, -148.0f), Lifetime = 0.0f }; this.AddChild(_messagePanel); _messagePanel.body = GamePhysics.Instance.RegisterPhysicsBody(GamePhysics.Instance.SceneShapes[4], float.MaxValue, 0.0f, _messagePanel.Position / GamePhysics.PtoM); _messagePanel.AdHocDraw += () => { _messagePanel.body.Position = _messagePanel.Position / GamePhysics.PtoM; }; // SCORE STUFF // ScoreIcon = Support.SpriteFromFile("/Application/assets/images/handIcon.png"); ScoreIcon = Support.SpriteFromAtlas("crystallonUI", "handIcon.png"); ScoreIcon.Position = new Vector2(184.0f, 16.0f); ScoreIcon.RegisterPalette(1); GameHudBar.AddChild(ScoreIcon); ScoreTitleText = new Label("score", map); ScoreTitleText.Position = new Vector2(287, 25.0f); ScoreTitleText.RegisterPalette(1); BlueBox = Support.UnicolorSprite("white", 255,255,255,255); BlueBox.Scale = new Vector2(6.25f, 4.4375f); BlueBox.Position = new Vector2(354.0f, 0.0f); BlueBox.RegisterPalette(2); ScoreText = new Label("", bigMap) { Position = SCORE_TEXT_POS }; ScoreText.RegisterPalette(1); GameHudBar.AddChild(ScoreText); // CUBE STUFF // CubeIcon = Support.SpriteFromFile("/Application/assets/images/stopIcon.png"); CubeIcon = Support.SpriteFromAtlas("crystallonUI", "stopIcon.png"); CubeIcon.Position = new Vector2(20.0f,16.0f); CubeIcon.RegisterPalette(2); GameHudBar.AddChild(CubeIcon); CubesTitleText = new Label("cubes", map); CubesTitleText.Position = new Vector2(63.0f, 25.0f); CubesTitleText.RegisterPalette(2); RedBox = Support.UnicolorSprite("white", 255,255,255,255); RedBox.Position = new Vector2(130.0f, 0.0f); RedBox.Scale = new Vector2(6.25f, 4.4375f); RedBox.RegisterPalette(1); CubeText = new Label("", bigMap){ Position = CUBES_TEXT_POS }; CubeText.RegisterPalette(2); GameHudBar.AddChild(CubeText); // TIMER & STRIKES STUFF GameTimer = new TimerEntity(); if (GameScene.currentLevel == 999) { // ------------------- IF CHALLENGE MODE if(GameScene.gameTimeLimit > 0.0f) { GameTimer.Position = new Vector2(348.0f, 16.0f); // ----- ADD THE TIME BAR GameHudBar.AddChild(GameTimer); } else { BonusBar = new BonusTimer() { // Position = new Vector2(348.0f, 44.0f) Position = new Vector2(348.0f, 16.0f) }; GameHudBar.AddChild(BonusBar); } Strikes = new StrikeHud() { Position = new Vector2(395.0f, 44.0f) }; GameHudBar.AddChild(Strikes); } // PAUSE BUTTON PauseButton = new BetterButton("/Application/assets/images/UI/BetterButtonTransparent.png", 115.0f, 71.0f) { Text = "", // Icon = Support.SpriteFromFile("Application/assets/images/UI/pause.png"), Icon = Support.SpriteFromAtlas("crystallonUI", "pause.png"), // Position = new Vector2(845.0f, 473.0f), Position = new Vector2(845.0f, 0.0f) }; // this.AddChild(PauseButton); GameHudBar.AddChild(PauseButton); PauseButton.background.RegisterPalette(2); PauseButton.background.Scale = new Vector2(115.0f/32.0f, 71.0f/16.0f); PauseButton.Icon.RegisterPalette(2); PauseButton.ButtonUpAction += HandlePauseButtonButtonUpAction; // HIT ME BUTTON HitMeButton = new BetterButton("/Application/assets/images/UI/BetterButtonTransparent.png", 115.0f, 71.0f) { Text = "", // Icon = Support.SpriteFromFile("Application/assets/images/UI/plus.png"), Icon = Support.SpriteFromAtlas("crystallonUI", "plus.png"), // Position = new Vector2(720.0f, 473.0f), Position = new Vector2(720.0f, 0.0f) }; HitMeButton.On(!LevelManager.Instance.HitMeDisabled); // this.AddChild(HitMeButton); GameHudBar.AddChild(HitMeButton); HitMeButton.background.RegisterPalette(1); HitMeButton.background.Scale = new Vector2(115.0f/32.0f, 71.0f/16.0f); HitMeButton.Icon.RegisterPalette(1); HitMeButton.ButtonUpAction += HandleHitMeButtonButtonUpAction; HudBarLine = Support.UnicolorSprite("white", 255, 255, 255, 255); HudBarLine.RegisterPalette(0); HudBarLine.Scale = new Vector2(60.0f, 0.125f); GameHudBar.AddChild(HudBarLine); _initialized = true; }
// 初期化 public void Initialize() { // GameEngine2D 画面クリアー色の設定 Director.Instance.GL.Context.SetClearColor (Colors.Grey20); // 画面解像度情報 // ScreenSize = new Vector2i (854, 480); ScreenSize = new Vector2i (960, 544); // 効果音の設定 var soundObj = new Sound ("/Application/assets/se.wav"); Sound = soundObj.CreatePlayer (); // BGMの設定 bgm = new Bgm ("/Application/assets/bgm.mp3"); player = bgm.CreatePlayer (); player.Loop = true; // リピート再生する // BGMの再生 player.Play (); // シーン生成(ノードのルートになる) var scene = new Sce.PlayStation.HighLevel.GameEngine2D.Scene (); // 2Dゲーム向けにカメラを設定 scene.Camera.SetViewFromViewport (); // GameEngine2Dを実行 Director.Instance.RunWithScene (scene, true); Pause = false; World = new Node (); // Interface = new Node (); // シーンにWorldを追加する scene.AddChild (World); // シーンにInterface(UIで利用する)を追加する // scene.AddChild (Interface); // 背景登録 for (int y = 0; y < 7; y++) { for (int x = 0; x < 6; x++) { var backGround = new BackGround (new Vector2 (x * 192, y * 128)); World.AddChild (backGround); } } // 自機(プレイヤー)登録 Player = new Player (new Vector2 (Game.Instance.ScreenSize.X/2, 100)); World.AddChild (Player); // 敵機(ボス)登録 Boss = new Boss (new Vector2 (Game.Instance.ScreenSize.X/2, 250)); World.AddChild (Boss); // UI登録 UI = new UI (); //Interface.AddChild (UI); scene.AddChild (UI); // 当たり判定処理の生成 HitTest = new HitTest (); // 登録キュー AddQueue = new List<GameEntity> (); // 削除キュー RemoveQueue = new List<GameEntity> (); }