Posts Tagged ‘programming’

h1

So Far, So Good.

October 21, 2008

I guess that I’ve done enough of the second year to get a grip on how things are going… it’s now the fourth week, and things seem to be going fairly smoothly course-wise. Well, nearly.

By far my favourite module this year is Games Software Development 1 – Keith is a fantastic lecturer, and seeing as we’re working with then API that he wrote himself, he’s completely knowledgeable on the module content. I’m also enjoying Middleware quite a bit, playing around with Unreal Editor is certainly more interesting than using Maya like last year. Windows GUI Programming is growing on me as well – Graham is a stern teacher at times, but he certainly knows his stuff, and everything is structured just right. I’m staying behind for half an hour or so after practicals so I can finish my C# projects ^^

However, not all modules are fun. 4 weeks in, and I still don’t know what we’re actually doing in the Tools Programming for Games module – coding Windows in C++ just seems too damn complicated after doing it all in C#. And as for Algorithms & Data Structures… boring code, with a practical tutor that doesn’t even know how to use a computer. Great ¬¬

It’s still an improvement over last year’s modules, though. This time they’re all relavent, and I’m producing small projects that can actually go towards a portfolio… which is still in construction, actually. It’s a shame my HTML is kinda crappy, but you can check it out over at http://www.nearlyphil.co.uk/ if you so wish. Now, to get around to filling out my placement year application form… *sigh*

h1

From The Mind Of A Programmer…

May 12, 2008

For moving a point on a grid randomly, you could set it to randomly generate a movement range from -50 to +50, but you’d have the point bumping into walls, or generating a negative number such as -20 when the x value is already at 0, not moving at all because validation limits the cooordinate values between 0 and 100 (if thinking about it in real-life it would move into a wall 20 times). I like to think my points have a little more… intelligence.

Can you class this as my first AI code? Maybe. It’s designed to first detect how far away the point is from the outside boundaries (limited to 50 units away), use this for the random function’s range, and then offset the value with the bottom difference value to align the movement range properly. This takes the random out of it (so it’s always likely to go away from the closest wall and rarely go to the edges, but it’s cool nonetheless. It took me a while to get working properly, so enjoy (if you can find fun in looking at code, heh…)

int moveX, moveY, topdiff, bottomdiff, range;
topdiff = 100 - position.getX();
if (topdiff > 50)
     topdiff = 50;
bottomdiff = position.getX();
if (bottomdiff > 50)
     bottomdiff = 50;
range = topdiff + bottomdiff + 1;
moveX = (rand()%range) - bottomdiff;

topdiff = 100 - position.getY();
     if (topdiff > 50)
topdiff = 50;
bottomdiff = position.getY();
     if (bottomdiff > 50)
bottomdiff = 50;
range = topdiff + bottomdiff + 1;
moveY = (rand()%range) - bottomdiff;
position.adjust(moveX, moveY);