Game Design and Artificial Intelligence - Bournemouth University

Game Design and Artificial Intelligence - Bournemouth University Game Design and Artificial Intelligence - Bournemouth University

ncca.bournemouth.ac.uk
from ncca.bournemouth.ac.uk More from this publisher
28.10.2014 Views

Game Design and Artificial Intelligence David Hopkins fig 2.3 – The bridge of the ship with the player character and the AI pilot Space Combat The space Combat was where most effort was based during the production of this project. For the demo, all though there was not enough time to implement a three dimensional version, it was possible to work on a two dimensional approach, with an x and y axis. Three attempts were made at producing the AI for the ships. The first experiment was creating a ship that would follow a target around. This was done by calculating the distance between the ship and the target in both x and y axis, calculating the angle between them and adding a velocity based on the angle. Much of this was taken from my previous programming project from last year, as this used the same theory to have an object always look towards a target. However there was a drawback with this. The ships could only rotate 360 degrees. Once the angle reached over 360 degrees, the object would have to rotate all the way round the other way as the object believes the angle to be a small value (as the value over 360 would then switch to 0). This method required some tweaking which would allow the object to follow an object by rotating around the quickest way. The way this was solved, was through working out the difference between the current ship rotation and the desired angle. If this difference is less than and absolute value of 180 degrees, the ship can rotate based on whether angle is smaller or larger. However if the difference is bigger than 180, then we have to reverse this situation as the target has gone full circle. This took a while to discover, but it is fairly effective. if((rotation­angle)>180) { if((rotation­angle)>0) rotation+=(70.0*TIMER); } if((rotation­angle)

Game Design and Artificial Intelligence David Hopkins } Fig 2.4 – Both ships will always be aiming to look at each other. The ships can carry different speeds, and potentially different rotational speeds aswell. I have tried to demonstrate this in the demo by having two types of enemy ships, fighters and scouts. The scouts are three times faster, but do less damage. Using the STL this allowed a better organization of the objects in the scene. All the objects the player can target (ships, navpoints and planets) are in one list. Each one of these objects are inherited from the base class c_spaceObject, and by using the method of casting down, all the objects could easily be pushed into a standard list (which is effectively a linked list for c++). This list is then accessed several times through the program. Once for drawing the objects, updating them and filtering for a target. The Player defines the target to aim towards through filtering through this list. The damage to the ship is calculated through a random number roll(between 0­100) against the pilot workrate statistic(calculated in the crewAI). Damage against other ships uses the gunner rating verses a roll. The Heads up Display “ I find the interface is one of the hardest aspects of game design. It should be intuitive and icons should be kept to a minimum. I have never got an interface right (the) first time. It'sone of those things that should be tested and tested until everyone is happy with it.” ­ Peter Molyneux. P47 [Molyneux00] Page 17 of 22

<strong>Game</strong> <strong>Design</strong> <strong>and</strong> <strong>Artificial</strong> <strong>Intelligence</strong><br />

David Hopkins<br />

fig 2.3 – The bridge of the ship with the player character <strong>and</strong> the AI pilot<br />

Space Combat<br />

The space Combat was where most effort was based during the production of this project. For the<br />

demo, all though there was not enough time to implement a three dimensional version, it was<br />

possible to work on a two dimensional approach, with an x <strong>and</strong> y axis. Three attempts were made at<br />

producing the AI for the ships. The first experiment was creating a ship that would follow a target<br />

around. This was done by calculating the distance between the ship <strong>and</strong> the target in both x <strong>and</strong> y<br />

axis, calculating the angle between them <strong>and</strong> adding a velocity based on the angle. Much of this<br />

was taken from my previous programming project from last year, as this used the same theory to<br />

have an object always look towards a target. However there was a drawback with this. The ships<br />

could only rotate 360 degrees. Once the angle reached over 360 degrees, the object would have to<br />

rotate all the way round the other way as the object believes the angle to be a small value (as the<br />

value over 360 would then switch to 0). This method required some tweaking which would allow<br />

the object to follow an object by rotating around the quickest way. The way this was solved, was<br />

through working out the difference between the current ship rotation <strong>and</strong> the desired angle. If this<br />

difference is less than <strong>and</strong> absolute value of 180 degrees, the ship can rotate based on whether angle<br />

is smaller or larger. However if the difference is bigger than 180, then we have to reverse this<br />

situation as the target has gone full circle. This took a while to discover, but it is fairly effective.<br />

if((rotation­angle)>180)<br />

{<br />

if((rotation­angle)>0)<br />

rotation+=(70.0*TIMER);<br />

}<br />

if((rotation­angle)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!