/// <summary> /// DeleteBallCommad 的實作內容,刪除球項目 /// </summary> private void DeleteBallItem(object o) { ListView ballListView = _mainWindow.BallListView; if (ballListView.SelectedItem != null) { //選擇的BallModel BallModel selectedModelItem = (BallModel)ballListView.SelectedItem; int temp = ballListView.SelectedIndex; ObservableCollection <BallModel> ballCollection = MainViewModel.ProjData.BallCollection; ballCollection.Remove(selectedModelItem); //刪減之後數量若跟舊的索引值一樣,代表選項在最後一個 if (ballCollection.Count == temp) { ballListView.SelectedIndex = ballCollection.Count - 1; } else//不是的話則維持原索引值 { ballListView.SelectedIndex = temp; } ListViewItem item = ballListView.ItemContainerGenerator.ContainerFromIndex(ballListView.SelectedIndex) as ListViewItem; if (item != null) { item.Focus(); } } }
public void Setup(BallModel m) { model = m; CreateVisual(); SetParams(); }
public void AddBallToGrid() { var ball = new BallModel(); grid.AddBall(ball, coOrdinates); grid.GetBall(coOrdinates).ShouldBeSameAs(ball); }
public void DeleteItem(object sender, RoutedEventArgs e) { if (BallListView.SelectedItem != null) { //選擇的BallModel BallModel selectedModelItem = (BallModel)BallListView.SelectedItem; int temp = BallListView.SelectedIndex; ObservableCollection <BallModel> ballCollection = MainViewModel.ProjData.BallCollection; ballCollection.Remove(selectedModelItem); //刪減之後數量若跟舊的索引值一樣,代表選項在最後一個 if (ballCollection.Count == temp) { BallListView.SelectedIndex = ballCollection.Count - 1; } else//不是的話則維持原索引值 { BallListView.SelectedIndex = temp; } ListViewItem item = BallListView.ItemContainerGenerator.ContainerFromIndex(BallListView.SelectedIndex) as ListViewItem; if (item != null) { item.Focus(); } } }
//Clone the collided ball moving at a slightly different angle private void SpawnNewBall(GameObject originalBall) { //Create a new BallModel Vector3 newPosition = originalBall.transform.position; GameObject newBall = Instantiate(app.model.BallPrefab, newPosition, Quaternion.identity); BallType nextBallType = getRandomBallType(); BallModel newModel = createBallModelFromBallType(nextBallType); BallModel originalModel = originalBall.GetComponent <BallView>().model; newModel.lastHitPlayer0 = originalModel.lastHitPlayer0; newBall.GetComponent <BallView>().model = newModel; //Adjust the new BallView Vector2 originalVelocity = originalBall.GetComponent <Rigidbody2D>().velocity; float xShift = 1f; //TODO adjust this Vector2 newDir = new Vector2(originalVelocity.x + xShift, originalVelocity.y).normalized; newBall.GetComponent <Rigidbody2D>().velocity = newDir * newModel.speed; newBall.GetComponent <SpriteRenderer>().color = newModel.color; if (nextBallType == BallType.Large) { newBall.transform.localScale += new Vector3(0.3f, 0.3f, 0); } app.model.totalBalls++; //Debug.Log("NEW BALL!"); //Debug.Log("New Ball Direction: " + newDir); //Debug.Log("New Ball Velocity: " + newBall.GetComponent<Rigidbody2D>().velocity.ToString()); }
public override void Reset() { base.Reset(); selectedBall = GameSettingHelper.GetSelectedBall(); jumpingBall = new JumpingBall(selectedBall.OriginSpritePath, 0, new Vector2(525, 720), 110, 0.2f); jumpingBall.SetOriginToCenterBottom(); }
protected override void Initialize() { // TODO: Add your initialization logic here player = new Player(); objects.Add(player); world = new World(); ballModel = new BallModel(); gameState = new MyGameState(); gameState.CameraMatrix = Matrix.CreateTranslation((_graphics.PreferredBackBufferWidth / 2) - (Player.PlayerSpriteSize / 2), 0, 0); gameState.WorldSize = WorldSize; terrainModel = new TerrainModel(); for (int i = -20; i < 20; i++) { TerrainTile t = new TerrainTile(terrainModel, i, r.Next() % 4); objects.Add(t); } base.Initialize(); }
// Start is called before the first frame update void Start() { _ballModel = GetComponent <BallModel>(); _ballRigidBody = GetComponent <Rigidbody2D>(); //_ballRigidBody.velocity = _ballModel.Direction * _ballModel.Speed; AngleChange(_ballModel.Direction); }
void Start() { var data = GameData.instance; game_model = data.game_model; ball_model = data.ball_model; paddle_model = data.paddle_model; }
public ReboundDirection ShouldRebound(PlayerType Player, BallModel Ball) { if (Player == PlayerType.Host) { if (Ball.Column == Column && Ball.PreviousColumn == Column + 1) { for (int i = 0; i < PlayersPositions.Count; i++) { if (Ball.Row == PlayersPositions[i]) { if (Ball.Power > 0) { if (Ball.PreviousRow == Ball.Row - 1) { return(ReboundDirection.Bottom); } else if (Ball.PreviousRow == Ball.Row + 1) { return(ReboundDirection.Top); } else { return(ReboundDirection.Middle); } } } } } } else { if (Ball.Column == Column && Ball.PreviousColumn == Column - 1) { for (int i = 0; i < PlayersPositions.Count; i++) { if (Ball.Row == PlayersPositions[i]) { if (Ball.Power > 0) { if (Ball.PreviousRow == Ball.Row - 1) { return(ReboundDirection.Bottom); } else if (Ball.PreviousRow == Ball.Row + 1) { return(ReboundDirection.Top); } else { return(ReboundDirection.Middle); } } } } } } return(ReboundDirection.NoRebound); }
public override void Reset() { base.Reset(); listBall = GameSettingHelper.GetListBall(); var selectedBall = GameSettingHelper.GetSelectedBall(); selectingBall = listBall.FirstOrDefault(x => x.Id == selectedBall.Id); UpdateSelectingBall(); }
public void Init() { model = GetComponent <BallModel>(); view = GetComponent <BallView>(); view.MoveInput += OnInput; view.Died += OnDeath; view.Jump += OnJump; }
public MainForm() { InitializeComponent(); ball = new BallModel { BallSpeedSideMin = ballSpeedSideMin, BallSpeedSideMax = ballSpeedSideMax, BallSpeedHeightMin = ballSpeedHeightMin, BallSpeedHeightMax = ballSpeedHeightMax, WidthHeight = WidthHeight, X = ClientSize.Width / 2 - WidthHeight / 2, Y = ClientSize.Height / 2 - WidthHeight / 2 }; movementManager = new PlayersMovingManager(this, firstPlayer, secondPlayer); ballManager = new BallMovementManager(this, firstPlayer, secondPlayer, ball); }
public BallView(BallModel ball, Texture2D sprite) { this.ball = ball; this.sprite = sprite; ballTrails = new List <Vector2>(); maxTrails = 10; lastTrailTime = TimeSpan.Zero; trailRecordRate = TimeSpan.FromMilliseconds(200f); }
public void Initialize() { _ball = _context.Ball; #if UNITY_EDITOR || UNITY_STANDALONE isStandalone = true; #elif UNITY_ANDROID || UNITY_IOS Input.multiTouchEnabled = false; isStandalone = false; #endif }
public Game() { Ball = new BallModel(); Bar1 = new BarModel { PlayerName = "Player1" }; Bar2 = new BarModel { PlayerName = "Player2" }; Reset(); }
public void ReadGridDynmically() { var ball = new BallModel(); grid.Cells.R2C4 = ball; object o = grid.Cells.R2C4; o.ShouldBeSameAs(ball); o = grid.Cells.R1C1; o.ShouldBeType<EmptySpaceModel>(); }
public static bool BallToCircle(CircleModel door, BallModel fridge) { bool result = false; if (fridge.Diameter < door.Diameter) { result = true; } return(result); }
public static bool BallToSquare(SquareModel door, BallModel fridge) { bool result = false; if (fridge.Diameter < door.Height && fridge.Diameter < door.Width) { result = true; } return(result); }
public FieldModel() { Length = GameSettings.FieldLength; Width = GameSettings.FieldWidth; DefenseRodHost = new RodModel(PlayerType.Host, RodType.Defense, GameSettings.DefenseRodHostTag, GameSettings.DefenseRodHostColumn); OffenseRodHost = new RodModel(PlayerType.Host, RodType.Offense, GameSettings.OffenseRodHostTag, GameSettings.OffenseRodHostColumn); DefenseRodGuest = new RodModel(PlayerType.Guest, RodType.Defense, GameSettings.DefenseRodGuestTag, GameSettings.DefenseRodGuestColumn); OffenseRodGuest = new RodModel(PlayerType.Guest, RodType.Offense, GameSettings.OffenseRodGuestTag, GameSettings.OffenseRodGuestColumn); Ball = new BallModel(Width / 2, Length / 2); }
void Start() { var data = GameData.instance; game_model = data.game_model; ball_model = data.ball_model; paddle_model = data.paddle_model; ui_model = data.ui_model; ball_model.pos = ball.transform.position; paddle_model.pos = paddle.transform.position; }
public ProjectData(SerializationInfo info, StreamingContext context) { Name = (string)info.GetValue("Name", typeof(string)); ID = (string)info.GetValue("ID", typeof(string)); Institution = (string)info.GetValue("Institution", typeof(string)); RegFilePath = (string)info.GetValue("RegFilePath", typeof(string)); IsRegInitialized = (bool)info.GetValue("IsRegInitialized", typeof(bool)); IsNavSet = (bool)info.GetValue("IsNavSet", typeof(bool)); Stage1Red = (float)info.GetValue("Stage1Red", typeof(float)); Stage1Green = (float)info.GetValue("Stage1Green", typeof(float)); Stage1Blue = (float)info.GetValue("Stage1Blue", typeof(float)); Stage2Red = (float)info.GetValue("Stage2Red", typeof(float)); Stage2Green = (float)info.GetValue("Stage2Green", typeof(float)); Stage2Blue = (float)info.GetValue("Stage2Blue", typeof(float)); DA = (float)info.GetValue("DA", typeof(float)); FDA = (float)info.GetValue("FDA", typeof(float)); HDA = (float)info.GetValue("HDA", typeof(float)); DD = (float)info.GetValue("DD", typeof(float)); PDD = (float)info.GetValue("PDD", typeof(float)); FirstNavigation = (string)info.GetValue("FirstNavigation", typeof(string)); IsNavDone = (bool)info.GetValue("IsNavDone", typeof(bool)); int count = (int)info.GetValue("BallCollection_Count", typeof(int)); ObservableCollection <BallModel> ballCollection = new ObservableCollection <BallModel>(); for (int i = 0; i < count; i++) { BallModel ballModel = (BallModel)info.GetValue("BallCollection_" + i, typeof(BallModel)); ballModel.CreateBall(); ballCollection.Add(ballModel); } BallCollection = ballCollection; count = (int)info.GetValue("BoneCollection_Count", typeof(int)); ObservableCollection <BoneModel> boneCollection = new ObservableCollection <BoneModel>(); for (int i = 0; i < count; i++) { BoneModel boneModel = (BoneModel)info.GetValue("BoneCollection_" + i, typeof(BoneModel)); boneCollection.Add(boneModel); } BoneCollection = boneCollection; count = (int)info.GetValue("TargetCollection_Count", typeof(int)); ObservableCollection <BoneModel> targetCollection = new ObservableCollection <BoneModel>(); for (int i = 0; i < count; i++) { BoneModel targetModel = (BoneModel)info.GetValue("TargetCollection_" + i, typeof(BoneModel)); targetCollection.Add(targetModel); } TargetCollection = targetCollection; }
public void Draw() { Bitmap flag = new Bitmap(fieldSize, fieldSize); Graphics flagGraphics = Graphics.FromImage(flag); BallView.DrawBall(BallModel.GetBall(), flagGraphics); BlocksView.DrawBlocks(BlockModel.GetBlocks(), flagGraphics); TankView.DrawTanks(TankModel.GetTanks(), flagGraphics); AppleView.DrawApples(AppleModel.GetApples(), flagGraphics); pictureBox.Image = flag; }
public void LoadBalls() { try { string fileContent = File.ReadAllText("./data/balldata.txt"); string[] contentArray = fileContent.Split((string[])null, StringSplitOptions.RemoveEmptyEntries); MainViewModel.ProjData.BallCollection.Clear(); for (int i = 0; i < contentArray.Length; i += 5) { BallModel ball = new BallModel(); var ballContainer = new HelixToolkit.Wpf.SharpDX.MeshBuilder(); ball.BallCenter = new Vector3(Convert.ToSingle(contentArray[i]), Convert.ToSingle(contentArray[i + 1]), Convert.ToSingle(contentArray[i + 2])); ball.BallName = contentArray[i + 3]; ballContainer.AddSphere(ball.BallCenter, 1.5); ball.Geometry = ballContainer.ToMeshGeometry3D(); ball.Material = PhongMaterials.White; if (contentArray[i + 4].Equals("MovedMaxilla")) { ball.ModelType = ModelType.MovedMaxilla; } else if (contentArray[i + 4].Equals("MovedMandible")) { ball.ModelType = ModelType.MovedMandible; } foreach (BoneModel modeltem in MainViewModel.ProjData.BoneCollection) { if (modeltem.ModelType.Equals(ball.ModelType)) { ball.ModelType = modeltem.ModelType; System.Windows.Data.Binding binding = new System.Windows.Data.Binding("Transform"); binding.Source = modeltem; binding.Mode = BindingMode.OneWay; BindingOperations.SetBinding(ball, HelixToolkit.Wpf.SharpDX.Model3D.TransformProperty, binding); } } MainViewModel.ProjData.BallCollection.Add(ball); } } catch { System.Windows.MessageBox.Show("Load檔案失敗"); } }
private void CreateModels(BallView[] ballViews) { _ballModels = new BallModel[ballViews.Length]; for (var i = 0; i < ballViews.Length; i++) { var view = ballViews[i]; IInputSystem inputSystem = new RigidbodyInputSystem(view.Rigidbody, view.Speed); var model = new BallModel(view.transform.position, inputSystem); _ballModels[i] = model; view.Init(model); } }
private void SpawnNewBall() { Vector3 originPosition = new Vector3(); GameObject newBall = Instantiate(app.model.BallPrefab, originPosition, Quaternion.identity); BallModel newModel = createBallModelFromBallType(BallType.Regular); bool isPlayer0Winning = app.model.player0.score > app.model.player1.score; newModel.lastHitPlayer0 = !isPlayer0Winning; newBall.GetComponent <BallView>().model = newModel; Vector2 startingDirection = isPlayer0Winning ? Vector2.down : Vector2.up; newBall.GetComponent <Rigidbody2D>().velocity = startingDirection * newModel.speed; app.model.totalBalls++; }
public void UpdateData(ProjectData projectData) { this.Name = projectData.Name; this.ID = projectData.ID; this.Institution = projectData.Institution; this.RegFilePath = projectData.RegFilePath; this.IsRegInitialized = projectData.IsRegInitialized; this.IsNavSet = projectData._isNavSet; this.Stage1Red = projectData.Stage1Red; this.Stage1Green = projectData.Stage1Green; this.Stage1Blue = projectData.Stage1Blue; this.Stage2Red = projectData.Stage2Red; this.Stage2Green = projectData.Stage2Green; this.Stage2Blue = projectData.Stage2Blue; this.DA = projectData.DA; this.FDA = projectData.FDA; this.HDA = projectData.HDA; this.DD = projectData.DD; this.PDD = projectData.PDD; this.FirstNavigation = projectData.FirstNavigation; this.IsNavDone = projectData.IsNavDone; this.BallCollection.Clear(); for (int i = 0; i < projectData.BallCollection.Count; i++) { BallModel ballModel = projectData.BallCollection[i]; this.BallCollection.Add(ballModel); } this.BoneCollection.Clear(); for (int i = 0; i < projectData.BoneCollection.Count; i++) { BoneModel boneModel = projectData.BoneCollection[i]; this.BoneCollection.Add(boneModel); } this.TargetCollection.Clear(); for (int i = 0; i < projectData.TargetCollection.Count; i++) { BoneModel targetModel = projectData.TargetCollection[i]; this.TargetCollection.Add(targetModel); } }
/* * Checks if the ball is in the reach of the rod */ public bool BallInPlayerReach(BallModel Ball) { //If the ball is not in the reach of the rod column-wise if (Ball.Column != Column && Ball.Column != Column - 1 && Ball.Column != Column + 1) { return(false); } //If the ball is in the reach of the rod row-wise for (int i = 0; i < PlayersPositions.Count; i++) { if (Ball.Row == PlayersPositions[i]) { return(true); } } return(false); }
/* * Kicks the ball */ public bool Kick(int direction, int power, BallModel Ball) { if (!BallInPlayerReach(Ball)) { return(false); } Ball.RowVelocity = direction; if (Player == PlayerType.Host) { Ball.ColumnVelocity = 1; } else { Ball.ColumnVelocity = -1; } Ball.Power = power; shouldKick = true; return(true); }
private void SetStartingValues() { int windowWidth = graphics.PreferredBackBufferWidth; int windowHeight = graphics.PreferredBackBufferHeight; int playerStartingY = windowHeight / 2 - playerHeight / 2; int firstPlayerStartingX = playerSpaceFromEdge; int secondPlayerStartingX = windowWidth - playerSpaceFromEdge - playerWidth; firstPlayer = new PlayerModel { Speed = playerStartingSpeed, X = firstPlayerStartingX, Y = playerStartingY, Width = playerWidth, Height = playerHeight }; secondPlayer = new PlayerModel { Speed = playerStartingSpeed, X = secondPlayerStartingX, Y = playerStartingY, Width = playerWidth, Height = playerHeight }; ball = new BallModel { X = windowWidth / 2 - ballWidth / 2, Y = windowHeight / 2 - ballHeight / 2, Width = ballWidth, Height = ballHeight, SpeedHorizontalMin = ballHorizontalSpeedMin, SpeedHorizontalMax = ballHorizontalSpeedMax, SpeedVerticalMin = ballVerticalSpeedMin, SpeedVerticalMax = ballVerticalSpeedMax }; }
private void moveToNext(BallModel ball, IComponent currentPoint) { if (currentPoint.ComponentType == ComponentTypeEnum.Container) { var container = (currentPoint as ContainerModel); _containerService.AddBallToContainer(ball, container); } else { var endPoint = currentPoint as EndPointModel; if (endPoint.Gate.GateOpenDirection) { this.moveToNext(ball, endPoint.LeftComponent); } else { this.moveToNext(ball, endPoint.RightComponent); } _endPointService.BallThroughEndPoint(endPoint); } }
private void WriteInfo(int score) { StringBuilder info = new StringBuilder(); var ball = BallModel.GetBall(); var tanks = TankModel.GetTanks(); int i = 0; info.Append($"Score: {score}\n\n"); info.Append("Player:\nPosX: " + ball.PosX + "\nPosY: " + ball.PosY + "\n"); foreach (Tank tank in tanks) { info.Append("\nTank[" + i + "]:\nPosX: " + tank.PosX + "\nPosY: " + tank.PosY + "\n" + "Is defeated: " + !tank.IsEnable + "\n"); i++; } InfoTextBox.Text = info.ToString(); }
public void AddBall(BallModel ball, CoOrdinates coOrdinates) { cells[coOrdinates] = ball; }