KierenHughes.com General, Coding, The Web etc.

11Mar/120

Ruby and Rails

Hey guys,

Ruby on Rails

Recently came across some useful tutorials for Ruby and Rails:

Both of the above are really useful interactive tutorials and teach you some of the basics of Ruby and Rails programming.

Defo recommend!

Kieren

11Mar/120

Simple jQuery Slider

Hey guys!

Since my last post I've began work as a website developer at Daydream Designs. Really enjoying it!

Recently I was developing a website that needed a simple jQuery slider (fade in and out effect). So I just thought I'd share some code that could be useful to anyone needing to create a simple jQuery slider that isn't too difficult to edit!

            var timeinterval = 0;
	    var timers = new Array();

	    $(document).ready(function() {
		timedCount();
	    });

	    function timedCount(){

                if(timeinterval>0){
		     timeinterval = 0;
		     clearTimeout(restartMethod);
		}

               for(i=2; i<6; i++){
                    timeinterval = timeinterval + 5000;
                    timers[i] = setTimeout("$('li#slider" + i + "').fadeIn(1000);", timeinterval);
                }
                timeinterval = timeinterval + 5000;
		a=setTimeout("fadeAndReset(); clearTimeout(a);",timeinterval);

		restartMethod = setTimeout("timedCount()", timeinterval);
	}

	function fadeAndReset(){
             for(i=2; i<5; i++){
                  $('li#slider' + i).fadeOut(0);
		  clearTimeout(timers[i]);
	     }
	     $('li#slider5').fadeOut(1000);
             clearTimeout(timers[5]);
	}

So to explain how to use the above code.

The above code will currently only allow the use of 5 slider images on any given webpage, in order to change the number of sliders, you must alter the following lines:

  • Line 15: Change i is less than 6 to i is less than whatever number of sliders you have plus 1 (i.e. i is less than 6 is for 5 slider images)
  • Line 26: Change i is less than 5 to i is less than whatever number of sliders you have (i.e. i is less than 5 is for 5 slider images)
  • Line 30: li#slider5 should be changed to li#slider followed by the number of the last image (i.e. if there were 10 images you would change this to li#slider10).
  • Line 31: timers[5] should be changed to timers[whatever number of sliders there are]

In order to change the speed of the slider (i.e. how quickly (or slowly) the images change):

  • Line 16 and 19: Change 5000 to whatever number of milliseconds you want the slider to change at (e.g. 5000 is 5 seconds, 10000 is 10 seconds).

The code for the actual slider within the html should be as follows:

	<li id="slider1"><img src="image1.jpg" alt="" /></li>
	<li id="slider2"><img src="image2.jpg" alt="" /></li>
	<li id="slider3"><img src="image3.jpg" alt="" /></li>
	<li id="slider4"><img src="image4.jpg" alt="" /></li>
	<li id="slider5"><img src="image5.jpg" alt="" /></li>

Within the css for each of the list items above, all but 'slider1' should have display set to "none", e.g.

li#slider2{
     display: none;
}

All of the images should be the same width/height too. Obviously, add more list items if more slider images are required. Note that it is important that the slider ids are in the format sliderslidernumber (e.g. slider1, slider2 etc.).

I know it's not the easiest code to use (as it's not a plugin), however if you follow the steps above, it should work fine!

Remember to insert the javascript code within the head of the html page within the usual javascript 'script' tags. And also remember to link to jQuery using:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

Hope that's of some use to someone! If you have any problems, leave a comment below and I'll see what I can do!

Kieren

24Aug/111

I’m Back

Hey guys,

Just thought I'd provide an update regarding what I've been upto lately...

I've now graduated from uni, so I've been busy searching for a job, hence why I haven't updated in a while! I've also been on holiday for 2 weeks and stuff, so yeah...I think it's safe to say I've been a bit preoccupied.

On the job front, not much luck reeeally. I've got some freelance work with Thomson Reuters and also, following getting through a telephone interview for Accenture, I have a second (and final) interview in London in September! Fingers crossed!

In relation to the game, I haven't spent too much time on it recently. I'm currently waiting for my brother to design all of the sprites/artwork for it. Following that, I'm planning to start the game from scratch (using code snippets from the previous version). The reason for this is, that it will allow me to build the game up slowly by editing the code snippets I already have while focusing on increasing the performance of the overall game. I also hope to incorporate some of the features I didn't have time to implement during my university project.

In other news...I'm currently awaiting the delivery of a 17" Macbook Pro :) . I've always been an avid Windows user, however given the reliability I've had with Windows lately, I've decided to make the switch. I will however dualboot Windows and OS X Lion. Owning a Mac will also allow me to potentially create the game for iPhone as well...

Anyhow, will update again soon!

Kieren

Filed under: Uncategorized 1 Comment
23Mar/119

PK Guy – Adding the Jump Feature

The player's 'jump' ability was added to the game a long time ago, however after being asked how I did it, I feel documenting how I did it will be beneficial to those of you looking into adding the jump ability to your games!

So, this feature proved pretty problematic and my implementation of the feature is by no means, the cleanest way of doing it. However, it works.

So, below is my 'jump' method:

public void jump(AnimatedSprite sprite){
	if(!jumping){
		jumping = true;
		body.setLinearVelocity(new Vector2(5,0));
		body.applyLinearImpulse(mTempVector.set(0,-60), new Vector2(10,10));
	}
}

So, to explain the above method:

When the player 'taps the screen' the 'jump' method is called. I then have a boolean value called 'jumping' which is set to 'false' by default.

The 'if' method then checks to see if the played is 'not jumping' (i.e. jumping is false). If the player is not jumping, jumping is set to true (i.e. the player is jumping) and a linear impulse is applied to the physics body of the player (causing the player to be thrusted into the air). The above method also has the body's linear velocity being set. This is just to slow the player down as my game moves quite quickly and I found that leaving the player's velocity as fast as it is when the player is 'on the ground' meant that the player jumped too far a distance when the screen was tapped.

Sure, the above method makes the player jump, but the next issue I encountered was that the user could repeatedly tap the screen causing the player to 'jump' and 'jump' again and again etc.

I solved this issue (so that the player could only jump again once the player had returned to the ground) through the use of a ContactListener:

ContactListener contactListener;

contactListener = new ContactListener(){
	@Override
	public void beginContact(Contact contact) {
		jumping = false;
		body.setLinearVelocity(new Vector2(7,0));
	}
	@Override
	public void endContact(Contact contact)
	{
	}
};

The above method checks to see whether any object in the PhysicsWorld makes contact with another object in the PhysicsWorld. If contact occurs, the 'beginContact' method is called. So, when the player 'lands on the ground' after jumping, the beginContact method is called which sets the boolean value (used in the 'jump' method) to false, therefore allowing the 'if' statement in the 'jump' method to succeed again. The velocity is set again to increase the speed, as the 'jump' method slowed the speed down for reasons I mentioned earlier.

I hope this helps anyone who is having trouble implementing the jump feature.

The above method is appropriate for my game and works a treat!

Kieren

22Mar/114

Progress Update – 22nd March ’11

PK Guy in action!

There hasn't been a large amount of progress over the past few days, however I thought I'd update you all anyway! I also thought it was about time I provided you with a teaser image of the game in action (though the graphics are definitely subject to change!).

New updates:

  • The player can now collect coins and their score increases as a result. This is a welcome update since previously the coins were 'killing' the player!
  • Removed a bug with the game 'pause' feature so that it pauses the music as well as the game itself.

Not the most exciting updates ever, but they're steps in the right direction at least!

Opinions on the current state of the game judging by the screenshot in this post would be much appreciated!

Please note that the 'player' sprite shown in the screenshot will not be used in the final game. The one used above is taken from the AndEngineExamples resources and is currently acting as a 'filler' until I decide to design the game character properly!

Anyhow, I'll update again soon!

Kieren

17Mar/110

Progress Update – 17th March ’11

Having been up for an entire night working on my final year project, a good portion of the first level is now finished. I'm hoping to have a beta version of the game finished within the next 2 weeks, as following that I will need to be working on my final year project report.

Once the report is done however, I will be working on the game as much as possible with the hope that the game can be fully released by July.

Anyhow...onto the updates!

Significant updates include:

  • Collision detection resulting in player death when colliding with an obstacle or 'falling down a hole'; the level restarts if either of these events occur.
  • Increased frame rate (from ~35fps to 55-60fps).
  • Implementation of High Scores table (though game logic resulting in these high scores is not yet implemented).
  • HUD added. With 'Score: 100', for example, displayed in the top left hand corner.
  • Addition of game enemies (I've yet to implement the functionality to 'kill' these enemies, though they can kill you).
  • Addition of 'coins', these will be collected by the player, thus increasing the high score. They are not yet collectable as the player currently 'collides' with them, resulting in player death!

I will update you all with a video of the current game within the next few days. Anyhow, better get going, lecture soon!

Kieren

21Feb/110

AndEngine

AndEngine

I am using AndEngine to produce my game (alongside the standard Android API), and I honestly can't recommend it enough! It has been (and still is) highly useful for creating what I have created so far.

The one issue I have found with the engine, is that it has VERY little documentation to support you when trying to learn to use it. You have to rely heavily on the AndEngine forums for help and advise regarding problems you may run into (and even on the forums you're pretty lucky if you get a reply).

Luckily however, the learning curve isn't bad when using AndEngine and there are a number of examples that you can look at and 'butcher' if need be.

Check it out at:

AndEngine.org

Ciao for now,

Kieren

19Feb/118

‘Programmer Graphics’

'Programmer Graphics' syndrome?

While the main focus of my project is to produce a fully-functioning game, I always feel graphics are as important as functionality. Noone wants to play a game that 'looks bad'....or at least I don't. I probably shouldn't waste too much time on graphics though, as my degree is about programming, not creating graphics, and consequently no marks are awarded for fancy looking sprites etc.

However, recently I have been working on the game menus from an aesthetic point of view, and while the graphical side is by no means 'finished', I would like people's opinions on the 'style' I have adopted. Programmers have a reputation for creating 'bad' graphics in-house and technically proper graphics designers should produce them. However, I obviously have to produce my own for the project as plagerism is not something I want to be accused of!

Anyhow, opinions please?

Mucho gracias!

Kieren

18Feb/112

The Game – What is it?

I just thought it'd be a good idea to let you all know what the game I am producing is and more importantly what the various features I will (hopefully) be implementing are!

So...

The game will be called 'PK Guy' (PK' standing for 'Parkour'). For those of you that don't know what Parkour is, it is 'an athletic discipline, in which practitioners traverse any environment in the most efficient way possible using their physical abilities, and which commonly involves running, jumping, vaulting, rolling and other similar physical movements' (credits: Wikipedia).

So the basic idea of the game is that there is a constantly moving character whom the user has no control over, other than 'jump' etc. I say 'etc' as I am hoping to implement various different inputs that result in the character using a different physical ability. The aim of the game will be to traverse the environment without hitting any obstacles etc. using these different physical abilities depending on the obstacle in their path.

There will be 5-10 levels initially of progressive difficulty. An interesting requirement I have is that this progressive difficulty should be 'unique' to the user. That is to say, players that are extremely good at the game will be faced with EXTREMELY hard levels, while players who are not so good, will have an easier time completing levels. I'm not yet sure how to implement this feature, as it will require each level to be created dynamically as the game goes on.

I also would like to implement multiplayer. I'm not yet sure whether this will be over WiFi or Bluetooth, however I'm hoping to implement two multiplayer modes: Versus and Co-operative.

Versus mode would see the players racing against one another to reach the end of the level first. However, I am thinking that to add to the competitive nature of this, I may allow the user to control the player's movement as well as physical abilities, allowing them to obstruct each other!

Co-operative would see each player take turns for certain segments of each level.

I also hope to implement a 'versus the computer' mode, however this will be very demanding, especially given the size of this project as it is. I say it will be demanding as this will require artificial intelligence, which is not something I am very familiar with (yet).

Other features:

  • High scores (local and global).
  • Personal preferences.

Any opinions/ideas regarding the project would be much appreciated!

Kieren

18Feb/110

Welcome to KierenHughes.com!

Hi there,

So...a little bit about me. I'm Kieren Hughes, a 20 year old final year student studying Computer Science in Cardiff University. Loving every minute of it, both socially and academically. No idea what I want to do with my life afterwards however!

I'm currently in the process of completing my final year project worth a large amount of my degree and I will be using this blog to discuss the progress and various problems/resolves I come across during the project. Hopefully this blog will become useful when documenting my project work, but also useful to people who are having similar problems to the ones I've faced during implementation of my game.

The aim of my project is to create a game for Android devices. I'm hoping that once it's completed I will be able to release it onto the market, however, primarily it's purpose is gaining myself a large part of my degree.

The blog will also act as a place for me to post random stuff too, so it won't all be geeky computer-related stuff for all you technophobes out there!

Anyhow, I will post again soon, but ciao for now!

Kieren

Filed under: General No Comments