using FarseerPhysics.SamplesFramework;␍␊ |
using Microsoft.Xna.Framework;␍␊ |
using Microsoft.Xna.Framework.Graphics;␍␊ |
using Axios.Engine.Extenions;␍␊ |
using Axios.Engine.Extensions;␍␊ |
using Axios.Engine.UI;␍␊ |
using Axios;␍␊ |
using System;␍␊ |
|
␍␊ |
namespace axios_tennis␍␊ |
{␍␊ |
class GameConsole : AxiosCommandConsole␍␊ |
{␍␊ |
public GameConsole(AxiosGameScreen gameScreen)␍␊ |
: base(gameScreen)␍␊ |
{␍␊ |
␍␊ |
}␍␊ |
␍␊ |
public override void InitializeCustomCommands()␍␊ |
{␍␊ |
base.InitializeCustomCommands();␍␊ |
␍␊ |
CmdObject reset = new CmdObject();␍␊ |
reset.Command = "reset";␍␊ |
reset.CommandHelp = "Resets the game";␍␊ |
reset.CommandHelpDetailed = "reset";␍␊ |
reset.CmdEvent += new Action<string[]>(reset_CmdEvent);␍␊ |
AddCommand(reset);␍␊ |
}␍␊ |
␍␊ |
void reset_CmdEvent(string[] obj)␍␊ |
{␍␊ |
((TennisScreen)GameScreen).ResetGame();␍␊ |
}␍␊ |
␍␊ |
protected override void LoadContent()␍␊ |
{␍␊ |
LoadDefault();␍␊ |
base.LoadContent();␍␊ |
}␍␊ |
}␍␊ |
class TennisScreen : AxiosGameScreen ␍␊ |
{␍␊ |
private Ball _ball;␍␊ |
|
private Wall _ewall;␍␊ |
private int _pscore = 0;␍␊ |
private int _escore = 0;␍␊ |
public bool Play = false;␍␊ |
␍␊ |
private SpriteFont _sf;␍␊ |
␍␊ |
public void ResetGame()␍␊ |
{␍␊ |
_ball.ResetBall();␍␊ |
_pscore = 0;␍␊ |
_escore = 0;␍␊ |
_epaddle.BodyPart.Position = Vector2.Zero;␍␊ |
_epaddle.PaddleJoint.MotorSpeed = 0f;␍␊ |
Play = false;␍␊ |
␍␊ |
}␍␊ |
␍␊ |
public TennisScreen()␍␊ |
{␍␊ |
|
AddGameObject(_ppaddle);␍␊ |
AddGameObject(_border);␍␊ |
AddGameObject(_ball);␍␊ |
AddGameObject(new GameConsole(this));␍␊ |
}␍␊ |
␍␊ |
void b_MouseDown(object sender, AxiosGameScreen gameScreen, InputState input)␍␊ |
|
␍␊ |
public override void HandleInput(GameTime gameTime, InputState input)␍␊ |
{␍␊ |
base.HandleInput(gameTime, input);␍␊ |
␍␊ |
␍␊ |
//This must be handled in the screen because there are multiple paddles␍␊ |
␍␊ |
if (_ppaddle != null)␍␊ |
#if WINDOWS␍␊ |
if (Console == null || !AxiosCommandConsole.Active || (AllowKeyboardWhileConsoleIsActive && AxiosCommandConsole.Active))␍␊ |
#endif␍␊ |
{␍␊ |
if (input.VirtualState.ThumbSticks.Left.Y > 0 ||␍␊ |
input.CurrentGamePadStates[0].ThumbSticks.Left.Y > 0 ||␍␊ |
input.CurrentKeyboardStates[0].IsKeyDown(Keys.Down)␍␊ |
)␍␊ |
base.HandleInput(gameTime, input);␍␊ |
␍␊ |
␍␊ |
//This must be handled in the screen because there are multiple paddles␍␊ |
␍␊ |
if (_ppaddle != null)␍␊ |
{␍␊ |
_ppaddle.PaddleJoint.MotorSpeed = -40f;␍␊ |
}␍␊ |
else if (input.VirtualState.ThumbSticks.Left.Y < 0 ||␍␊ |
input.CurrentGamePadStates[0].ThumbSticks.Left.Y < 0 ||␍␊ |
input.CurrentKeyboardStates[0].IsKeyDown(Keys.Up)␍␊ |
)␍␊ |
{␍␊ |
_ppaddle.PaddleJoint.MotorSpeed = 40f;␍␊ |
}␍␊ |
else␍␊ |
{␍␊ |
_ppaddle.PaddleJoint.MotorSpeed = 0f;␍␊ |
if (input.VirtualState.ThumbSticks.Left.Y > 0 ||␍␊ |
input.CurrentGamePadStates[0].ThumbSticks.Left.Y > 0 ||␍␊ |
input.CurrentKeyboardStates[0].IsKeyDown(Keys.Up)␍␊ |
)␍␊ |
{␍␊ |
_ppaddle.PaddleJoint.MotorSpeed = -40f;␍␊ |
}␍␊ |
else if (input.VirtualState.ThumbSticks.Left.Y < 0 ||␍␊ |
input.CurrentGamePadStates[0].ThumbSticks.Left.Y < 0 ||␍␊ |
input.CurrentKeyboardStates[0].IsKeyDown(Keys.Down)␍␊ |
)␍␊ |
{␍␊ |
_ppaddle.PaddleJoint.MotorSpeed = 40f;␍␊ |
}␍␊ |
else␍␊ |
{␍␊ |
_ppaddle.PaddleJoint.MotorSpeed = 0f;␍␊ |
}␍␊ |
}␍␊ |
}␍␊ |
}␍␊ |
|
{␍␊ |
base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);␍␊ |
␍␊ |
if (_epaddle.BodyPart.Position.Y < _ball.BodyPart.Position.Y && _epaddle.PaddleJoint.MotorSpeed != 40f)␍␊ |
_epaddle.PaddleJoint.MotorSpeed += 5f;␍␊ |
else if (_epaddle.BodyPart.Position.Y > _ball.BodyPart.Position.Y && _epaddle.PaddleJoint.MotorSpeed != -40f)␍␊ |
_epaddle.PaddleJoint.MotorSpeed -= 5f;␍␊ |
if (Play)␍␊ |
if (_epaddle.BodyPart.Position.Y < _ball.BodyPart.Position.Y && _epaddle.PaddleJoint.MotorSpeed != 40f)␍␊ |
_epaddle.PaddleJoint.MotorSpeed += 5f;␍␊ |
else if (_epaddle.BodyPart.Position.Y > _ball.BodyPart.Position.Y && _epaddle.PaddleJoint.MotorSpeed != -40f)␍␊ |
_epaddle.PaddleJoint.MotorSpeed -= 5f;␍␊ |
/*else␍␊ |
if (_epaddle.PaddleJoint.MotorSpeed == 40f)␍␊ |
_epaddle.PaddleJoint.MotorSpeed -= 1f;␍␊ |