Game Programming
Game Programming
Aim: Setup DirectX 11, Window Framework and Initialize Direct3D Device
In this practical we are just learning the window framework and initializing a Direct3D device.
Step 1:
i) Create new project, and select “Windows Forms Application”, select .NET Framework as 2.0 in
Visuals C#.
ii) Right Click on properties Click on open click on build Select Platform Target and Select x86.
Step 2: Click on View Code of Form 1.
Step 3:
Go to Solution Explorer, right click on project name, and select Add Reference. Click on Browse and
select the given .dll files which are “Microsoft.DirectX”, “Microsoft.DirectX.Direct3D”, and
“Microsoft.DirectX.DirectX3DX”.
Step 4:
Go to Properties Section of Form, select Paint in the Event List and enter as Form1_Paint.
Step 5:
Edit the Form’s C# code file. Namespace must be as same as your project name.
Input:
using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
usingMicrosoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace GP_P1
{
public partial class Form1 : Form
{
Microsoft.DirectX.Direct3D.Device device;
public Form1()
{
InitializeComponent();
InitDevice();
}
Step 6: Click on Start. And here is the output. We have initialized 3D Device.
Output:
Practical No:2
Aim: Draw a triangle using Direct3D 11.
Input:
using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
usingMicrosoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace GP_P2
{
public partial class Form1 : Form
{
Microsoft.DirectX.Direct3D.Device device;
public Form1()
{
InitializeComponent();
InitDevice();
}
private void InitDevice()
{
PresentParameterspp = new PresentParameters();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this,
CreateFlags.HardwareVertexProcessing, pp);
}
private void Render()
{
CustomVertex.TransformedColored[] vertexes = new
CustomVertex.TransformedColored[3];
Output:
Practical No:3
Aim: Texture the triangle using Direct3D 11
Input:
using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
usingMicrosoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace Gp_prac3
{
public partial class Form1 : Form
{
private Microsoft.DirectX.Direct3D.Device device;
privateCustomVertex.PositionTextured[] vertex = new CustomVertex.PositionTextured[3];
private Texture texture;
public Form1()
{
InitializeComponent();
InitDevice();
}
private void InitDevice()
{
PresentParameterspp = new PresentParameters();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
device = new Device(0,DeviceType .Hardware ,this, CreateFlags.HardwareVertexProcessing, pp);
device.RenderState.Lighting = false;
Output:
Practical No:4
Aim: Programmable Diffuse Lightning using Direct3D 11.
Input:
using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
usingMicrosoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace GP_P2
{
public partial class Form1 : Form
{
device.RenderState.Lighting = false;
device.RenderState.Lighting = true;
device.Lights[0].Type = LightType.Directional;
device.Lights[0].Diffuse = Color.Plum;
device.Lights[0].Direction = new Vector3(0.8f, 0, -1);
device.Lights[0].Enabled = true;
}
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Render();
}
}
}
Output:
Practical No:5
Aim: Loading models into DirectX 11 and rendering
Input:
using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
usingMicrosoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace GP_P5_Loading_Model
{
public partial class Form1 : Form
{
Microsoft.DirectX.Direct3D.Device device;
Microsoft.DirectX.Direct3D.Texture texture;
Microsoft.DirectX.Direct3D.Font font;
public Form1()
{
InitializeComponent();
InitDevice();
InitFont();
LoadTexture();
}
Output:
Practical No:6
Click on 2dphysics.
Click on rigid body.
Then you see in inspector rigid body box created.
We need to create a script for moving our ufo.
Then your ufo speed is so slow then go to your script and add that2 lines
“ Public float speed ;”
“ (movement *speed);”
speed.
Set your speed.
Then go to your scene and 1inch down you see shaded button click on this and
change to wireframe.
Then set you x axis offset size 14.3 and y axis is zero. Box
collider size for x axis 3.3 and y axis is 31.64.
Then copy that component and paste component.
see this…
Then create duplicate our object.
Go to edit and duplicate.
Like this….
Set your objects in game scene your own mind…
Step 7: picking a collectables object..
See we create pick ups object then we need change our script in player module.
Then go inspector see circle collider box the right corner you see setting button
and book manual. Click on book manual
Add “ count =0 ; ”
Count = count+1;
Create gaming uiobject
Like this…
And set that text you want and change y axis also x axis your own mind….
Change the color and font in your choice
G
o
t
o
w
i
n
dow button and open asset store.
Click on Unity essential, then go
to sample projects
Import the pack again
software
The Scene will look like after Importing the Asset -> Select All
Package->Click on Import.
Now Change the Capsule Collider Direction to Z-axis->change the radius and Height also ->
Go to mesh collider
Component inside the
Inspector window->turn off
the Mesh renderer tab
Open the Model-> Select the Mesh Asset->Drag it in to
the Mesh Slot on the Mesh Collider->Turn On the Mesh
Renderer tab-> Select Is Trigger tab
Go to-
You Can Change the Position of Ship By Changing the Tap View
Step 3
:Setting
upthe
maincamera
the scene. andlighting
for
Click on the main camera from hierarchy->Go To Inspector window->go to transform component ->click on
Reset Tab->Now Change the Rotation of x-axis as 90->go to camera view ->click on the projection->set it as
orthographic->Se the size to 10
Go to
camer
a
->
change
the
clear
flags to
Solid
Color->
Change
the
backgro
und
color as
Black
Cha
nge
the
rotat
ion
of
back
axis as 90 grou
Go to nd x-
Mesh
Collider-
Now Add The Texture To Our Background:
Go To Project ->Assets->Texture->Select Nebula
Reset the
scale of
Quad->set
the Scale x as
15 and y as
30
Change the Shedder: go to Shedder ->Unlit->Texture
Now
We
Will Create a new Script to our Player Ship->Click on Player In the Hierarchy ->Go to Inspector
Window->Click on Add Component Tab->select New Script->Give the Name to script as Player
Controller->Click on Create and Add Button.
Go to Assets->Texture->Select FX-
Lazer->
Go to material folder in the asset->Click on Create tab->Choose Material->give the name as Fx-bolt-
orange
Now will add the Texture Into the Material
Go to Inspector Window ->Click on fx-bolt-orange->click on Select->click on the Texture U want to
add into
material
Now
go to
material-
>drag the vfx-
Bolt-Orange
on to the
scene.
Go to
Inspector
window->fs-
bolt-orange->Shader->Mobile->Particles->Additive
Selec
t
Bolt
from
Hier
arch
y-
>Go
to
Insp
ector
-
>Clic
k on
Add
Com
>Rigid Body->Deselect Use Gravity Tab. pone
nt-
>Phy
sics-
Now Go to
Hierarchy->Click
on VFX->Go to
Inspector->Select-
>Mesh Renderer tab
In Inspector Window->Go to mesh Collider->Click on Setting Button->Click on Remove Component
Go to Capsule Collider
Tab in to Inspector
Window->Change the
radius ad 0.03->Height
0.58->Direction asZ-
axis.
Click On Is Trigger tab in Capsule
Collider
into
the
Mov
er
Scrip
t-
>Sav
e the
Scrip
t And
Com
e to
The
unity
Wind
ow
usingUnityEngine;
usingSystem.Collections;
[System.Serializable]
public class Boundary
publicBoundary boundary;
publicGameObject shot; public
Transform shotSpawn; public float
fireRate;
void Update ()
if (Input.GetButton("Fire1") &&Time.time>nextFire)
voidFixedUpdate ()
);
tilt);