using System;
using FRB;
using FRB.GUI;
using FRB.Text;
using FRB.Particle;
using FRB.Collections;
using FRB.MSG;
using FRB.Audio;
using FRB.Shapes;
using Math2D;
using Microsoft.DirectX.DirectInput;
namespace GameName
{
public class GameData
{
#region reference to engine managers and data
public GameForm form;
public InputManager inpMan;
public SpriteManager sprMan;
public TextManager textMan;
public GuiManager guiMan;
public Camera camera;
public Cursor cursor;
public Random random;
public ShapeManager shaMan;
public GameName.Screens.ScreenManager screenManager;
#endregion
// declare variables of class scope here
Sprite playerBall;
Sprite NPC;
Joystick joystick;
Sprite rightWall;
Sprite leftWall;
Sprite topWall;
Sprite bottomWall;
Sprite obstacle1;
SpriteArray staticCollidables;
SpriteArray movableCollidables;
public void Initialize(GameForm form)
{
#region initialize engine managers and data
this.form = form;
sprMan = GameForm.sprMan;
inpMan = GameForm.inpMan;
textMan = GameForm.textMan;
guiMan = GameForm.guiMan;
camera = GameForm.camera;
cursor = GameForm.cursor;
random = GameForm.random;
shaMan = GameForm.shaMan;
screenManager = GameForm.screenManager;
#endregion
if (inpMan.joystickArray.Count == 0)
{
inpMan.AddJoystick(
Key.Up, Key.Down, Key.Left, Key.Right,
new Key[] { Key.A, Key.S, Key.D, Key.F });
}
playerBall = sprMan.AddSprite("redball.bmp");
NPC = sprMan.AddSprite("redball.bmp");
NPC.x = -3;
joystick = inpMan.joystickArray[0];
joystick.DeadZone = 200;
float wallScl = 2;
rightWall = sprMan.AddUntexturedSprite();
rightWall.colorOperation = Microsoft.DirectX.Direct3D.TextureOperation.SelectArg2;
rightWall.tintBlue = 255;
rightWall.sclX = wallScl;
rightWall.sclY = 20;
rightWall.x = camera.XEdgeAt(0) - wallScl;
topWall = sprMan.AddUntexturedSprite();
topWall.colorOperation = Microsoft.DirectX.Direct3D.TextureOperation.SelectArg2;
topWall.tintBlue = 255;
topWall.sclX = 30;
topWall.sclY = wallScl;
topWall.y = camera.YEdgeAt(0) - wallScl;
leftWall = rightWall.Clone();
sprMan.AddSprite(leftWall);
leftWall.x = -camera.XEdgeAt(0) + wallScl;
bottomWall = topWall.Clone();
sprMan.AddSprite(bottomWall);
bottomWall.y = -camera.YEdgeAt(0) + wallScl;
obstacle1 = sprMan.AddUntexturedSprite();
obstacle1.colorOperation = Microsoft.DirectX.Direct3D.TextureOperation.SelectArg2;
obstacle1.tintBlue = 255;
obstacle1.x = 5;
obstacle1.sclX = obstacle1.sclY = 2;
obstacle1.rotZ = 1;
// add the objects to the static collidables:
staticCollidables = new SpriteArray();
staticCollidables.Add(topWall);
staticCollidables.Add(bottomWall);
staticCollidables.Add(leftWall);
staticCollidables.Add(rightWall);
staticCollidables.Add(obstacle1);
movableCollidables = new SpriteArray();
movableCollidables.Add(playerBall);
movableCollidables.Add(NPC);
// uncomment this line and pass the qualified string name of the first
// Screen class that the game should show upon execution.
//screenManager.Start("NameSpace.Screens.ScreenClassName");
}
public void Activity()
{
// this can be left uncommented - won't do anything if there are no active Screens
screenManager.Activity();
playerBall.xAcceleration = joystick.x / 40;
playerBall.yAcceleration = joystick.y / 40;
// cap the velocity:
playerBall.xVelocity = Math.Min(10, playerBall.xVelocity);
playerBall.xVelocity = Math.Max(-10, playerBall.xVelocity);
playerBall.yVelocity = Math.Min(10, playerBall.yVelocity);
playerBall.yVelocity = Math.Max(-10, playerBall.yVelocity);
// perform Collisions here:
// assumes all movables are circles, all statics are rectangles
foreach (Sprite movable in movableCollidables)
{
foreach (Sprite staticSprite in staticCollidables)
Collisions.circleBounceRect(movable, staticSprite);
foreach (Sprite otherMovable in movableCollidables)
if (otherMovable != movable)
Collisions.circleBounceBothCircle(movable, otherMovable);
}
}
public void AfterFrameActivity()
{
// usually, the only code that goes here is text printing with the TextManager
// if drawing text, uncomment the following line:
// textMan.BeginDrawing();
}
}
}