Jump to content
phreak

Cum sa adaptezi un joc facut in C# cu Xna la tastatura

Recommended Posts

Posted

Acest tutorial este pentru cei care sunt interesati de crearea jocurilor in C# folosind XNA Framework

detalii despre instalarea Xna aici : http://creators.xna.com/Education/GettingStarted.aspx

Tutoriale video le puteti gasi aici : http://creators.xna.com/Education/Tutorials.aspx

Eu am modificat numai functia UpdateInput din tutorialul 2 pentru ca ei il fac special pentru un xbox 360 controller.



// nava se controleaza cu sagetile stanga dreapta sus si pentru a urca sau a cobori tasta "M" si tasta "N"


protected void UpdateInput()
{
KeyboardState newState = Keyboard.GetState();
// (newState.IsKeyDown(Keys.Left) verifica daca tasta sageata
//stanga este apasata daca da atunci nava se va roti la stanga
if (newState.IsKeyDown(Keys.Left))
modelRotation += 1 * 0.05f;
else if(newState.IsKeyDown(Keys.Right))
modelRotation -= 1 * 0.05f;

// Create some velocity if the right trigger is down.
Vector3 modelVelocityAdd = Vector3.Zero;
// aici pastram la fel cum dau si ei in tutorial
// Find out what direction we should be thrusting, using rotation.
modelVelocityAdd.X = -(float)Math.Sin(modelRotation);
modelVelocityAdd.Z = -(float)Math.Cos(modelRotation);
// dupa cum puteti observa modelPosition este un vector 3D ei dau
//doar functiile pentru a se misca in plan dar
//puteti adauga si modelVelocityAdd.Y ca mai jos care va ridica sau
//cobori nava folosind tastele M si N
if (newState.IsKeyDown(Keys.M))
modelPosition.Y -= 0.9f;
if (newState.IsKeyDown(Keys.N))
modelPosition.Y += 0.9f;

if(newState.IsKeyDown(Keys.Up))
modelVelocityAdd *= 0.9f;
else modelVelocityAdd *=0;

//folosind butonul enter resetam pozitia navei

if(newState.IsKeyDown(Keys.Enter))
{
modelPosition = Vector3.Zero;
modelRotation = 0.0f;
modelVelocity = Vector3.Zero;
}

// Finally, add this vector to our velocity.
modelVelocity += modelVelocityAdd;

}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...