Go Back   High Impact Halo Forum and Fansite Non-Halo Discussion Forum Gaming and Console Discussion
Gaming and Console Discussion Non-Halo related gaming discussion goes here. Any platform, any game.
Notices
 
 
Thread Tools Display Modes
  #1  
Old   
Daleks United's Avatar
Daleks United Offline
Plug 'n' Pray
 
Posts: 3,715
Join Date: Mar 2006
Location: England
Send a message via MSN to Daleks UnitedSend a message via Skype™ to Daleks United
XNA Tutorials - First Update - 02-19-2007 , 01:48 PM


Hog Racing - Update 1
Source




Not quite what you expected? Despite this looking nothing like it may finally do, many of the concepts are already there. I'm going to presume you have XNA installed (if you don't, look at the tutorial below) and have opened up the source files.

If you've tried to create a game before, you will realise that some of the code is pregenerated - most of this remains unchanged, but has been added to.

First, some concepts:

X and Z are 'horizontal', Y is up/down

A wheel needs to know where it is in relation to it's car.
A wheel does not need to know where other wheels are.
A wheel does not need to know what a car looks like.

A car has 4 wheels.
A car does not need to know what the wheels look like
A car should know it's speed and location.
A car should be able to look after itself
A car shouldn't need to know about other cars (until we do collisions)

The world needs to have cars in.
The world does not care where these cars are, or how fast they are moving
The world does not need to know where the cars wheels are.

Everything -should- use the same physics.

To this end, classes have been created. The best way to describe classes it to look at real life. A 'human' would be a class, as we all have the same basic features. The traits, however, are different.

A car is similar to this - they all need the same things, but the exact values of these things does not matter. They need a speed and a position, but that can be anything.

Because of this, a Car class has been created. This can be found in Car.cs.

Code:
 
#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion
That bit, at the top of the file, allows us access to the XNA framework from inside the file

Code:
 
namespace Hog_Racing
{
 
class Car
{
//information about the car
Model model;
Vector3 position;
Vector3 speed;
Vector3 rotation;
Int16 player;
//the physics system we will use, doing this would allow us to have cars with different physics.
Physics physics;
//Where the wheels will eventually be stored.
Wheel[] wheels = new Wheel[4];
int mass;
This section of code basically says "There is a class called 'Car'.
It also says that the Car class has members of things like speed (Should be velocity), position, rotation etc. This is what it know about itself. The word before the name is the type of information it knows about itself. A Vector3 is essentially three numbers held together in one piece of information, and these are assigned the names X,Y and Z and can quite handily match up to the three dimensions we usually use. :)

int stands for a 32 bit integer, which is a whole number. float can be used if we want decimals. Int16 is a 16 bit integer, which I have used as I doubt we will ever have that many players! (16 bit is still 65536 possible values).

Then it gets a bit odd. Wheel[] wheels = new Wheel[4] does two things. It tells the code that there exists a member called wheels of class Wheel, but because it's an array (a grouping, denoted by []), we also say that it is an array of 4 things of a Wheel class. This can also be done, and will be seen elsewhere with integers. E.g
int temporaryinteger = 0;
where the integer is created and set to 0 immediately.

Physics physics; is a little confusing, but it just means that there is a member called physics which is of the class Physics. More on this later.

Code:
 
public Car(Vector3 position1, Vector3 rotation1, Int16 player1, Physics physics1, int mass1)
{
//'save' the starting settings for the car
position = position1;
rotation = rotation1;
physics = physics1;
player = player1;
mass = mass1;
}
This is called the Constructor of the class - note how the name before the brackets is the same as the name of the Class, and there is no 'type' (void/int/Vector3) that can be seen in other functions. The 5 this inside the brackets are variable that we pass to the code when it 'builds' the care for us. Noting much is done with that, but notice how the car assigns it's own members the values of the passed variables. Otherwise, once this function (up to the }) stops executing, the passed variables will be lost.

Code:
 
public void update(GamePadState input)
{
//update everything to do with the 'car' - calculate it's new speed, use the speed to modify the position and then use the speed to work out the rotation of the ball
speed += physics.findacceleration(new Vector3(input.ThumbSticks.Right.X, 0, input.ThumbSticks.Right.Y), mass); 
position += speed; 
rotation += (speed / (MathHelper.TwoPi)) * MathHelper.TwoPi;
}
This is the update function of the car. We pass it a variable of the type GamePadState (more on this later) and it does some pretty things with it. GamePadState refers to the current state a 360 controller is in, so we can find out which buttons are pressed, the thumbstick position etc.

It is a public void, which means it can be called from code not in the class Car but does not return anything.

'speed += ...' is shorthand for saying 'speed = speed +' - we are not overwriting the value, we are modifying it. physics is a variable holding a class Physics - the same one that got passed to the Constructor. '.findacceleration' is a function call to a function of the physics class called 'findacceleration' (Physics.cs). This is a public, but it is not a void. It is a public Vector3, which means it returns a Vector3. Because of this, it can be used instead of a Vector3 variable in an equation, as it is here. We are adding it to our Vector3 of speed, which just means it adds the X, Y and Z components individually. It takes two 'arguments' (things we pass to it), a Vector 3 of 'forces' and the mass of the object. Because we want to use the position of the thumbsticks to act as the value of forces, we have to use 'new Vector3(...)' to 'mash' them into a Vector3. Note how we put them into the X and Z sections of the Vector3 - we don't want flying cars!.

The code then adds the speed to the position, thereby moving the object. The next line is just for fun, and can be worked out if you want to (ball radius 1). This just makes the ball appear to spin.

Code:
 
public Vector3 getposition()
{
//tell me where the car is!
return position;
}
As with the find acceleration, this is not a void but a Vector3 function. It allows things that know of the cars existance (like the world) to find out the position.


Code:
 
class Physics
{
public Physics()
{
}
public Vector3 findacceleration(Vector3 force, int mass)
{
//Using F=ma
Vector3 temp = Vector3.Zero;
// a = F/m (*Cringe*, don't make me do that again)
temp = force / mass;
//send back the acceleration in the 3 directions
return temp;
}
This is the Physics class - note how the contructor is blank, as it doen't need to remember anything but we could easily pass it gravity if we wanted that to be alterable.

This is the fabled findacceleration function - we pass it a force and a mass and it uses Newton's second law to calculate the acceleration, which it returns.

From Game.cs

Code:
 
//An array holding all the cars, so far only 1.
Car[] Cars = new Car[1];
Model terrain;
Physics physics;
protected override void Initialize()
{
//set the global physics to be a Physics class (see Physics.cs)
physics = new Physics();
// TODO: Add your initialization logic here
//Create a new car, Starting position 1,1,1 (The ball's radius is 1), no rotation, playernumber 1 and the same physics as the global, mass 100
// The array of cars has one item in it, address '0'
Cars[0] = new Car(Vector3.One, Vector3.Zero, 1, physics, 100); 
base.Initialize();
}
Game.cs is a class just like the car, it just occupies a special place (in out hearts). Instead of wheels, we have an array of cars. We care not about the wheels, the individual cars can cope with that :). Although the array is not at the top of the class, it is also not within a function and so it doesn't matter upon the exact positioning - it's here for ease of use.

Cars[0] = new Car(Vector3.One, Vector3.Zero, 1, physics, 100);
Creates one car by calling the constructor. If you scoll back up, you will see that this means that the position is 1,1,1 (Vector3.One is a default thing 1,1,1), with no rotation, player number 1, a physics class (so we can make sure all cars use the same one) and a mass of 100.

Code:
 
protected override void LoadGraphicsContent(bool loadAllContent)
{
if (loadAllContent)
{
// TODO: Load any ResourceManagementMode.Automatic content
//terrain = content.Load<Model>("Models//480polygonsnookerball");
terrain = content.Load<Model>("Terrain//flatground");
Model temp = content.Load<Model>("Models//480polygonsnookerball");
//set the car model to this
Cars[0].setmodel(temp); 
}
// TODO: Load any ResourceManagementMode.Manual content
}
This is where we load graphical things '//' means the line is commented out and is ignored when running the program. We load a model for the car, and pass it to the first car and also a model for the ground.

So far, all these functions have been run once when the game loads (XNA handles calling them). These next two functions are called by XNA every cycle (60 times/second)

Code:
 
protected override void Update(GameTime gameTime)
{
// Allows the default game to exit on Xbox 360 and Windows
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();

//Update all the cars, see tutorial 1
for (int i = 0; i < Cars.GetLength(0); i++)
{
Cars[i].update(GamePad.GetState(PlayerIndex.One));
}
//The camera is pointing at the first 'car', see the function getposition in the Car class
cameraTarget = Cars[0].getposition();
//Use the left stick and buttons to adjust where the camera is.
cameraPosition.X += GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X;
cameraPosition.Z += GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y;
if (GamePad.GetState(PlayerIndex.One).Buttons.LeftShoulder == ButtonState.Pressed)
cameraPosition.Y -= 1;
if (GamePad.GetState(PlayerIndex.One).Buttons.RightShoulder == ButtonState.Pressed)
cameraPosition.Y += 1;
// TODO: Add your update logic here
base.Update(gameTime);
}
This is of the functions that -has- to be there. 'this' always refers to the class that the code is in, so this.Exit() calles the exit function of the class (you can't see it) which ends the game.

Gamepad.GetState(Playerindex.One) returns the current state of the Gamepad as a Gamepadstate, so we can assign it to a Gamepadstate variable and pass it to our car for that to look at. If you look, the car never knows which gamepad it's looking at, it just know the current state of the one the world tells it about.

for (int i = 0; i < Cars.GetLength(0); i++)
{
...
}

is a loop. There are three things that we tell it - it's looping using a variable called 'i' which begins at 0, it can continue while i is less than Cars.GetLength(0) (How big the Car array is, in this case '1') and each time it runs it should add 1 to i (i++) Because i has to be less than 1, this loop currently only runs once, while i equals 0. In this time, it updates the Car in the array position i, or Car[0] by calling it's update function which we've already looked at. If there were two cars, it would run twice without me having to edit this code :)

The next bit uses the state of controller 1 to move the camera - there are 'if' statements there, but they have their own section below.

Finally

Code:
 
protected override void Draw(GameTime gameTime)
{
//Clear screen
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
//Prewritten code from helpfiles ---VVVVV
Matrix[] transforms = new Matrix[terrain.Bones.Count];
terrain.CopyAbsoluteBoneTransformsTo(transforms);
//Draw the model, a model can have multiple meshes, so loop
foreach (ModelMesh mesh in terrain.Meshes)
{
//This is where the mesh orientation is set, as well as our camera and projection
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.DiffuseColor = Color.Green.ToVector3() ;
effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationX(MathHelper.ToRadians(180))
* Matrix.CreateTranslation(Vector3.Zero);
effect.View = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);
effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),
aspectRatio, 1.0f, 10000.0f);
}
//Draw the mesh, will use the effects set above.
mesh.Draw();
}
//Prewritten ----- ^^^^^
//Draw all the cars, see updating for more information.
for (int i = 0; i < Cars.GetLength(0); i++)
{
//calls the draw function of each car in turn, see Car.cs
Cars[i].draw(cameraPosition, cameraTarget, aspectRatio);
}


base.Draw(gameTime);
}
is where everything appears on screen :) It begins by wiping the screen, and then drawing the terrain model - the help files can explain this best.
effect.DiffuseColor = Color.Green.ToVector3() ;
means that the untextured surface reflects green light, making it look green. Color.Green is a predefined colour like Vector3.One, but this property does not like colours and instead insists on Vector3s where XYZ = RGB. No matter, the Color class can convert to it with the function 'toVector3()'

Once again a loop calls the draw function of the cars, where each will eventually do the same to their wheels. This way, the world does not need to know anything about the wheels of the car :).

Code:
 
effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationZ(-rotation.X) * Matrix.CreateRotationY(rotation.Y) * Matrix.CreateRotationX(rotation.Z)
* Matrix.CreateTranslation(position);
This line, from the car draw is different. It is what makes the model appear in the place that it is, using matrices. Translation matrices move an object, rotational matrices rotate it. In this we translate it to it's position, and then rotate it. To work out rotation, imagine driving a pole through a ball along one of the axes. The ball can then only spin in one direction. We know where we want the ball to spin, but it's not on the axes you think.

If statements:

If statements are possibly the most useful thing and are required for a computer to be Turing Complete. In C#, they have the following basic outline:
if (<something>)
{
<do this>
}
else
{
<do this if not something>
}

If you only need one line of <do this>, then the {} can be ommited as seen in the camera movement code.

<something> can be more than one thing, linked with operators.
(variable == 6) will <do this> is the variable equals 6 (DON'T USE '='!!!)
!= means does not equal
(var1 == 5 && var2 == 3) means that var1 must equal 5 AND var2 must equal 3.
(var1 == 4 || var2 == 3) means 'or' - there are a few more, but they can be looked up.

Booleans are a variable type, like integer or Vector3 that can only either be True or False. Because of this, in if statements a shorthand can be used. if (boolean) will <do this> if the boolean is set to true - there is no need to say ==true.



This thread took a fair while to write, so there may be errors. Post any questions you have in this thread, or any suggestions/ideas/works of your own/ammendments. If you are unsure about anything ask so it can be clarified.

All the source code is available (link at top) and we expect an update from the 3D modeller soon regarding the track! There may be another upate in a few hours, there may not be.
http://www.bathgatehall.co.uk/webcam1.php may occaisionally have a live video feed of something - I'll post if it does.

Controls -
RB/LB = Camera Up/Down
Left Stick = Camera Move
Right Stick = Apply force to ball


Below is a previous tutorial by Mikleran written while I was writing some code for walls >_>.


Quote:
Originally Posted by Mikleran
Tutorial 1: Drawing a Spaceship in 3d and make it fire an arrow!

Hopefully this is what you will get if you follow the tutorial! Don't be put off by how complex that looks; it's surprisingly easy!

Stage 1: Getting XNA
XNA is a totally free add-on for C# to allow very easy creation of games for both Windows and the Xbox 360. C# Express Edition is a free download from Microsoft.com as well; downloadable from here. To download the XNA add-on, go here.
You will be very surprised at how easy it is to create a 3D game in it; this tutorial has been written with a programming and modelling n00b in mind so even if you don't have any programming experience this will hopefully help you with your first step. I'm still learning how to do this myself, so if you spot any errors/better ways to do things then please just post it here!

Stage 2: The Very Basic Rules of XNA / C#
1) Everything has to be in the right case: If you have something called 'Ball', but try to call it 'ball' somewhere else C# won't recognise it. Everything has to be in the same case.
2) Like most programming languages out there, most lines of code have to end in a semicolon (some exceptions).
These are probably the two most common rules to break. The semicolon is quite easy to forget so be wary!

Stage 3: Creating a Windows Game and making it do something!
Run 'XNA Game Studio Express'. You will be prompted by the Visual C# 2005 Start Page. Ignore it; click 'File>>New Project' and select 'Windows Game' from the list avaliable. Call it whatever name you want; it doesn't matter!

A page of code called 'Game1.cs' should be open on your screen, with a lot of green and some blue/black writing. The green writing are comments; they are ignored by the program when it is compiling and are just there so you can annotate your code. All the commented out items have '//' at the front of them; this is what tells C# to ignore it.

You will also notice that there there are several lines of code called things such as 'public Game1()' and 'protected override void Initialize()' These are individual routines; esentially routines of code which the game repeats often.
Below the 2nd to top line, 'public class Game1 : Microsoft.XNA.Framework.Game', you will see two lines of code:

GraphicsDeviceManager graphics;
ContentManager content;

This is where you declare the variables you use in the game. Variables in C# have many different vareties; here is a list of the most useful:


float - A float is esentially just a number. It can have any value, and can be a decimal. However, if you set a float value which is a decimal, you have to put an 'f' at the end of the decimal: e.g. 'float1 = 0.5f;'
int - an int is an integer. It can't do decimals, and it's maximum value is 65536.. but it is more efficiant than a float. If your value is a whole number less than 65536, use an 'int' rather than a float
double - A double is a whole number which can be any value- not limited like an int is. This is mainly for use when you have a large number, bigger than 65536.
Vector2 - This is a 2 dimensional vector. It carries an X and a Y value in it; which are floats. So, if you are setting a vector's value to a decimal, you need to put the 'f' at the end of it again: e.g. '(0.5f, 0.5f)'
Vector3 - 3 dimensional vector. Carries a X, Y and Z value in it.
Vector4 - 4 dimensional vector(!). Carries a W, X, Y and Z value in it.
Model - This is just a model. Will come onto it later.
bool - Is either 'true' or 'false'!


Stage 4: Adding Models to the Project
Download these models: http://s15.quicksharing.com/v/330399...odels.zip.html
These are the 3d models required to make the spaceship draw in XNA. In there, there is the model for the spaceship and the model for the triangular arrow, as well as the texture for the spaceship.

Now, you have to add these to your project. In the solution explorer (should be on the right hand side of the screen), right click on the name of your game in bold, and click 'Add>> New Folder'. Name this folder 'Content'.

Go to Windows Explorer, and open up your project files from where you told it to save when you created the project. By default, this should be in 'My Documents\Visual Studio 2005\Projects\'. You should see these folders:



Open up the content folder, and copy the extracted folders from ^^ zip file into it. You should have two folders in the content folder now; models and textures.
Go back to XNA; you have to do more. Right click on the 'Content' folder you have just created, and add a new folder in that called 'Models' (with the capital M).
Then, right click on that, but this time click 'Add>> Existing Item'. Browse until you find the "\Content\Models\" folder. Select the two fbx files in there, and add them to your project.
You should now have this in your solution explorer:



If you see that, you have added them to your project sucessfully! (the textures folder doesn't have to be included in the project because the code isn't using it!)

Stage 5: Using the Models in the Code

Firstly you have to declare the models at the top of your project. This is very easy to do under 'ContentManager content;', add:

Model Spaceship;
Model Arrow;

Secondly, you have to assign these variables to be the models which you have added to your project. Add this code to the 'protected override void LoadGraphicsContent(bool loadAllContent)', below the 'if (loadAllContent)' statement but between the two curly brackets:

Spaceship = content.Load<Model>("Content\\Model s\\P1_Wedge");
Arrow = content.Load<Model>("Content\\Model s\\arrow");

Thirdly, you have to create some variables before you can draw them; for example the model's positions on the screen.

Vector3 spaceshipPosition = Vector3.Zero;
Vector3 arrowPosition = new Vector3(500.0f, 50.0f, 50.0f);
Vector3 cameraPosition = new Vector3(0.0f, 50.0f, 5000.0f);
float aspectRatio = 800.0f / 600.0f;

These are just simple declarations of variables; using different ways of setting their values. The aspect ratio is the aspect ratio that the items on the screen must be drawn at; there is no need to change it. The cameraPosition is where abouts in the world the camera is, and the other two are obvious. The Vector3.Zero is just a 3d Vector with values (0,0,0); so the spaceship will be drawn at the centre of your world!
Finally, you have to tell XNA to draw these models on screen! This is the code to do it; you should add this below the 'graphics.GraphicsDevice.Clear(Colo r.###);' inside the 'protected override void Draw(GameTime gameTime).

Matrix[] transforms = new Matrix[Spaceship.Bones.Count + Arrow.Bones.Count];
Spaceship.CopyAbsoluteBoneTransform sTo(transforms);

foreach (ModelMesh spaceshipmesh in Spaceship.Meshes)
{
foreach (BasicEffect effect in spaceshipmesh.Effects)
{
effect.EnableDefaultLighting();
effect.World = transforms[spaceshipmesh.ParentBone.Index]
* Matrix.CreateTranslation(spaceshipP osition);
effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
effect.Projection = Matrix.CreatePerspectiveFieldOfView (MathHelper.ToRadians(45.0f),
aspectRatio, 1.0f, 10000.0f);
}
spaceshipmesh.Draw();
}
Arrow.CopyAbsoluteBoneTransformsTo( transforms);
foreach (ModelMesh arrowmesh in Arrow.Meshes)
{
foreach (BasicEffect effect in arrowmesh.Effects)
{
effect.World = transforms[arrowmesh.ParentBone.Index]
* Matrix.CreateTranslation(arrowPosit ion);
effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
effect.Projection = Matrix.CreatePerspectiveFieldOfView (MathHelper.ToRadians(45.0f),
aspectRatio, 1.0f, 10000.0f);
}

arrowmesh.Draw();
}

TBH I'm not sure what all of it does; but i'll give a small explanation of the basics. The matrix up the top is essentially creating a Matrix for you to draw your items in. This doesn't change.

You then have to start looping through all the meshes inside the models, and then the effects for each mesh! There, we tell it where to draw, where to rotate and the lighting on it amongst other things.

If you now press run on your program, you should now come up with this on the screen!:



!! If that's what come's up on your screen, Congratulations! You've drawn a 3D model!

Stage 6: Taking Input from the Xbox 360 Controller/Keyboard

If you've got a Wired Xbox 360 controller, you can use that on the PC in your XNA Games! To do this though, you must install the drivers for it: follow this tutorial!

If you don't have a wired 360 controller, but want to create programs in XNA, i would highly reccommend getting one! It is easier to use, and is more fun to play with (IMO anyway!). However, i will include code here to take input from the keyboard and mouse, because i'm nice! :D
Go to the 'protected override void Update(GameTime gameTime). Beneath where it tells the program to quit if you press the back button, put this code in if you are using a 360 Wired controller.

cameraPosition.X = (float)(Math.Cos(MathHelper.ToRadia ns(90 + 180 * GamePad.GetState(PlayerIndex.One).T humbSticks.Right.X)) * 5000);
cameraPosition.Z = (float)(Math.Sin(MathHelper.ToRadia ns(90 + 180 * GamePad.GetState(PlayerIndex.One).T humbSticks.Right.X)) * 5000);

If you are using the Keyboard and Mouse, put this code in:

cameraPosition.X = (float)(Math.Cos(MathHelper.ToRadia ns(270 + 180 * (((float)(Mouse.GetState().X))/400 - 400))) * 5000);
cameraPosition.Z = (float)(Math.Sin(MathHelper.ToRadia ns(270 + 180 * (((float)(Mouse.GetState().X)) / 400 - 400))) * 5000);

Now if you run the program, and either move the mouse or the right thumbstick, the model should rotate around!! (well, it's tricking you because you're actually moving around the object). If anyone want's an explanation as to why that code does that, feel free to ask. It's not too difficult.

Stage 7: Make The Arrow Fire!

This is the final part of this project that i am going to talk about; and it still surpringly easy!
Firstly, you have to declare a new variable up where you declared the positions and models.. this one is a bool saying whether the arrow is moving or not!

bool ArrowMoving;

Now, by default that value is going to be 'false'. So we have to get it to change it's state when we press a button! If you're using a 360 pad, here is the code:

if (GamePad.GetState(PlayerIndex.One). Buttons.A == ButtonState.Pressed)
ArrowMoving = true;

Or if it's the Mouse, use this:

if (Mouse.GetState().LeftButton == ButtonState.Pressed)
ArrowMoving = true;

These are basic 'if' statements. They are very common things in all programming; they're even in MS Excel! All that is doing is saying that if something equals something else, do something!
Well, now that we've got it to know when to move the arrow, we should get it to move it! All we have to do is tell the program to update the position of the arrow as long as the ArrowMoving = True!

if (ArrowMoving == true)
arrowPosition.Z -= 20;

Now that should make the arrow move! Run the program, and then press A on the controller or left click the mouse. The arrow should start moving forward!
One final bit of code; we could make the arrow reset if we right click or press 'X'. Again, this is just a basic 'If' statement. For the 360 controller, the code is this:

if (GamePad.GetState(PlayerIndex.One). Buttons.X ==ButtonState.Pressed)
{
ArrowMoving = false;
arrowPosition.Z = 0;
}

and for the mouse it is this:

if (Mouse.GetState().RightButton == ButtonState.Pressed)
{
ArrowMoving = false;
arrowPosition.Z = 0;
}

This 'if' statement is slightly different to the previous one; you have to create the curly brackets to be able to extend it to do more than one thing. If you are just changing one value, you can ignore the brackets, but if you change 2+ things you must use those brackets. Again, all of that code goes in the 'protected override void Update(GameTime gameTime)', where all of stage 6 and 7 have gone!

If this has worked, congrats! You have s creation in XNA! It's a simple concept i know but it's a start and quite a cool one at that!

If there is a demand i will do another one at some point with a more complicated idea! If anyone else wants to write something like this feel free to post it in here!

  #2  
Old   
Mikleran's Avatar
Mikleran Offline
 
Posts: 57
Join Date: Jul 2006
02-19-2007 , 02:47 PM


Well, it looks like i'm going to be the MEE in this project. The Mister Everything Else does all the bits that noone else is willing to do, basically!

The first job I've got is to make the map: it's pretty much needed once the basic physics has been done (like Daleks has done in the first post), and since our modeller couldn't be arsed to do it today, it was left to me.

Well, as a big F1 fan, i've decided to make the map an F1 track. We decided that the track had to be flat, as it would be impossible to figure out and implement the physics in 5 days, and would be a nightmare for a tutorial!

The track that I decided to do is called 'Albert Park'; It's been the host of the Australian Formula One Grand Prix since 1996. It's quite a nice track, with a couple of longish straights in it, but also a nice number of corners with varying degrees of steepness.

To create the model, I started out by scanning in a card containing a plan of AlberT Park in through ABBYYFine. About 600DPI was adequate, since that's roughly what the printer used. It's got slightly skewed proportions, with the track being about 3 times wider than it should be; which is excellent! It means that the track is only going to be about half a mile long, rather than 3 and a half!

For creating this model, I used Google Sketchup; a free download from http://sketchup.google.com. I imported the texture, made a box about the right size for it and textured it! The end result was something like this:



In that picture, i've outlined the track using the pen tools. This means that i can delete the texture inside the track and replace it with a much higher resolution asphalt one in the future. In fact, i pretty much outlined everything in the map, from the graveltraps to the tyrewalls to the grandstands. I then removed their textures, and replaced them with generic ones for now (simple colours). I've also made the Grandstand's 3D, and made the lake blue with the islands raised up inside it.

This was a fairly easy job; it just takes time. If you've got any questions, don't hesitate to ask!

The result as of 5 mins ago:



It's all very basic for now, and looks awful. But it will improve! ;)

  #3  
Old   
Daleks United's Avatar
Daleks United Offline
Plug 'n' Pray
 
Posts: 3,715
Join Date: Mar 2006
Location: England
Send a message via MSN to Daleks UnitedSend a message via Skype™ to Daleks United
02-20-2007 , 07:41 PM


Hog Racing - Update 2
Source



First, I'd like to thank everyone for their support and overwhelming interest in this thread

Anyway, as you can see from this 5 hour old screen shot, we now have a track to race around! (The car is bigger now)

http://daleks.bathgatehall.co.k/XNA/Melbourne.JPG is a top down map that we use later for some easy collision detection, but should give you a good idea of what is going on.


Most of the changes have been fairly superficial like that, althoguh the update tomorrow should be good.

A few major changes have occured -

effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),
aspectRatio, 1.0f, 100000000.0f);



The large number in there is now even larger - that is the draw distance, and is so you can see the entire map at the same time.

In Car.cs, the code car movement code has been changed to have the left and right triggers as acceleration, using the direction of the car as the forward point. The maths is fairly intermediate, if someone wants me to go through it I'll do it in the update tomorrow.

The camera code has also been altered slightly to make it easier, and the car now starts in the middle of the track.


The new map requires textures, which were not required before. The textures are put in a subfolder, but that is to do with the porgram used to export them. If you open the .fbx file you will see the path names to the textures - these can be altered if so required.


The main jobs last night was the modelling of the map and the 2D version - now that is complete, we can move on to collisions with the environment. (After wheels of course!)



To err is human, to screw things up completely requires a computer.
Forum Problems? Spam? Need help? Think I've been a harsh, evil, unfair git? PM me

  #4  
Old   
Mikleran's Avatar
Mikleran Offline
 
Posts: 57
Join Date: Jul 2006
02-20-2007 , 08:30 PM


Well, I did almost nothing new yesterday, apart from learning what a complete pile of poopoo Google SketchUp is for Exporting models to FBX format.

I've had to redo the entire model; first attempt took 5 hours and in the new model i've done about 3. The latest model is slightly better,: this is a picture of the first corner:



Dalek doesn't have that model in game yet so the screens above are missing some of the detail. The grandstands will look better in the final model! :)

The corner is famous for Ralf Schumacher's crash there in 2002(?). It was a pretty huge shunt..



And c'mon, people said they wanted this thread; yet no responses!

  #5  
Old   
Daleks United's Avatar
Daleks United Offline
Plug 'n' Pray
 
Posts: 3,715
Join Date: Mar 2006
Location: England
Send a message via MSN to Daleks UnitedSend a message via Skype™ to Daleks United
02-21-2007 , 07:56 PM


Hog Racing - Update 3
Source


We get closer to looking like a game today, with the addition of cubes to aid movement. Lots of behind the scenes posturing to work out how to sort of do the next bit too.

One major thing that may encourage someone to ask a question is the inclusion of keyboard control - so you don't need a 360 controller to play (although you don't have -full- control). This code can be found in Game.cs and Car.cs.

Code:
 
if (Keyboard.GetState().IsKeyDown(Keys.A))
cameraPosition.Y -= 10;
This is a small example, and works in a similar way to the Gamepad code. The controls are essentially duplicated for the camera, but there is an 'If' statement in the Car class to prevent the use of both. It looks to see if a controller is plugged in - if it isn't, it looks at the keyboard state.

Wheels have also been added since the last update. The same way that the game calls update on the cars, so the cars update and draw their own wheels. The are created with the car, and get told their relative position. This is converted into a distance and an angle from the centre of the car. Each time the wheel is drawn, it takes that into account using trig to keep the wheel in the correct place.

The wheels do spin, but the wrong way sometime. Working on it. Any suggested fixes could be sent in a PM :) The back wheels also need to reverse in spin direction, ala Hog. See program :P

Tomorrow should be audio and the use of wheels to turn - anyone who has downloaded it (I know ONE person has) will have noticed the not very much friction like environment - that should be fixed tomorrow:

I will look at the direction of the driving wheels, and apply forces to the car based on this and the speed. I can cancel out any movement by applying a force equal to the negative speed multiplied by the mass, as the mass is cancelled out in the equation leaving an instant decceleration. If I use a percentage of the mass, I can control the skid of the car.


To err is human, to screw things up completely requires a computer.
Forum Problems? Spam? Need help? Think I've been a harsh, evil, unfair git? PM me

  #6  
Old   
Mikleran's Avatar
Mikleran Offline
 
Posts: 57
Join Date: Jul 2006
02-21-2007 , 07:56 PM


Latest Build:



When the hog model is added it should look acceptable! ;)

  #7  
Old   
Mikleran's Avatar
Mikleran Offline
 
Posts: 57
Join Date: Jul 2006
02-21-2007 , 09:12 PM



  #8  
Old   
Mikleran's Avatar
Mikleran Offline
 
Posts: 57
Join Date: Jul 2006
02-23-2007 , 06:54 AM


*bump*

Both of our copies of Crackdown came yesterday so nothing got done! :lol:

Since there seems to be very little interest in this thread there doesn't seem to be much point in finishing it any time soon either. We'll see what time we get; but some interest would be nice!

  #9  
Old   
AAaargh!'s Avatar
AAaargh! Offline
 
Posts: 901
Join Date: Mar 2006
Location: London
02-23-2007 , 05:30 PM


Wwwwwwwwwwwwwwwwwwwwwaaaaaaaaaaaaaa aaaaaaawh. This looks like ALOT of work, wish I could afford the XNA subscription

  #10  
Old   
Daleks United's Avatar
Daleks United Offline
Plug 'n' Pray
 
Posts: 3,715
Join Date: Mar 2006
Location: England
Send a message via MSN to Daleks UnitedSend a message via Skype™ to Daleks United
02-23-2007 , 08:46 PM


Everything we did here is FREE - the subscription lets you play it on the 360, whereas this game is coded (at the moment) for PC.


To err is human, to screw things up completely requires a computer.
Forum Problems? Spam? Need help? Think I've been a harsh, evil, unfair git? PM me

  #11  
Old   
KJdog23's Avatar
KJdog23 Offline
 
Posts: 336
Join Date: Aug 2006
Send a message via AIM to KJdog23Send a message via Skype™ to KJdog23
02-24-2007 , 03:07 PM


Amazing, wish i could help but I don't know much about this stuff.

  #12  
Old   
Mikleran's Avatar
Mikleran Offline
 
Posts: 57
Join Date: Jul 2006
02-24-2007 , 05:36 PM


Quote:
Originally Posted by KJdog23
Amazing, wish i could help but I don't know much about this stuff.
Download XNA and try it then! The aim of this is to try and get people interested and using XNA, rather than just to create a Hog racing game!

BTW:



In Game ;) *ahem*

  #13  
Old   
ZuP's Avatar
ZuP Offline
<3
 
Posts: 1,275
Join Date: Mar 2006
Send a message via AIM to ZuPSend a message via MSN to ZuPSend a message via Yahoo to ZuP
03-04-2007 , 02:18 PM


Whoa, seriously? You have to be pulling my leg.



  #14  
Old   
Daleks United's Avatar
Daleks United Offline
Plug 'n' Pray
 
Posts: 3,715
Join Date: Mar 2006
Location: England
Send a message via MSN to Daleks UnitedSend a message via Skype™ to Daleks United
03-05-2007 , 08:33 PM


I think he was making a joke about some of the 'in game videos' that have been released. Too bad it sucked :P [I haven't see that level of detail anyway :P]


To err is human, to screw things up completely requires a computer.
Forum Problems? Spam? Need help? Think I've been a harsh, evil, unfair git? PM me

  #15  
Old   
scurty's Avatar
scurty Offline
 
Posts: 3,886
Join Date: Mar 2006
03-06-2007 , 12:07 AM


I'm inexperienced on this stuff but it is very interesting. I would like for this to be completed. Not right away obviously, but in the future.

  #16  
Old   
Daleks United's Avatar
Daleks United Offline
Plug 'n' Pray
 
Posts: 3,715
Join Date: Mar 2006
Location: England
Send a message via MSN to Daleks UnitedSend a message via Skype™ to Daleks United
03-07-2007 , 08:23 PM


Yeah, I think it will be. Unfortunatley, magical Friday hit so life came back again :(

Friday we have a 3 hour programming competition (www.olympiad.org.uk) and a 1 hour Physics one, www.dreambuildplay.com has a slightly greater incentive to do things quickly and I was up till 2AM doing Calculus last night :)


To err is human, to screw things up completely requires a computer.
Forum Problems? Spam? Need help? Think I've been a harsh, evil, unfair git? PM me

  #17  
Old   
Mikleran's Avatar
Mikleran Offline
 
Posts: 57
Join Date: Jul 2006
03-10-2007 , 04:24 PM


Quote:
Originally Posted by Daleks United
Yeah, I think it will be. Unfortunatley, magical Friday hit so life came back again :(

Friday we have a 3 hour programming competition (www.olympiad.org.uk) and a 1 hour Physics one, www.dreambuildplay.com has a slightly greater incentive to do things quickly and I was up till 2AM doing Calculus last night :)
n00b! ;)

We have what we think would be a cool idea for a game and so we are going to try and make it for the DreamBuildPlay competition. I doubt anything will be posted in here anytime soon, but it will be a cool game if we finish it.

@Whole Ingame screenshot thing.. LOL! That's just a Google Earth pic of the section i showed in a true ingamescreen earlier. I made the track about 3-4x wider than it actually is in reality and then shrunk it down so that a lap of the track wouldn't take about 20mins! We will finish the project sometime.. although don't be surprised if it isn't after July 2nd!

  #18  
Old   
AquaEchoiii's Avatar
AquaEchoiii Offline
Gues Ill wear pants today
 
Posts: 2,137
Join Date: Mar 2006
03-17-2007 , 12:45 AM


I want to try this, but all I have done with gamemaking is just gamemaker. I did some slight coding in that, but that's it. I hope there are good tuts? Because this looks interesting.
EDIT: Does XNL work with Visual Basic? Because I got that one because it sounded simple.

-Aqua

Last edited by AquaEchoiii; 03-18-2007 at 12:30 AM. .

  #19  
Old   
foxtrotpudding Offline
 
Posts: 6
Join Date: Mar 2007
03-30-2007 , 03:45 PM


Wow. O_O That looks fantastic

I would love to do something like that myself, I just have no idea where to even begin.

  #20  
Old   
Mikleran's Avatar
Mikleran Offline
 
Posts: 57
Join Date: Jul 2006
03-30-2007 , 08:03 PM


Have a go at reading the tutorial! If it's too complicated/far too difficult looking just say and it'll help if we can be arsed to do a revision of it. :lol:

 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Forum Jump



Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com
Skin modified for HIH by Ducain


HIH : Halo 1, Halo 2, and Halo 3 forum, fansite, tricks, glitches, and videos - Privacy Statement - Top
no new posts