PrettyPrint

Sunday, 24 February 2013

Creating The Game - 24/02/2013

This week there has been a large amount of work that has been done on the Game but there is still a lot of work to be done on the game. There has also been no meeting between the members of the group as with it being half term some members were unable to attend due to being out of the country, but I have spoken to Stephen during the week and he has given me the completed animation frames for the character allowing me to see for the first time what the character and animation will look like now that it is in the 32x64 dimensions.

This week I myself have concentrated on getting a pseudo gravity system into the game which I severely underestimated on the complexity of the coding that would have to go into this. To start off I figured out how to get a smooth jump from the character instead of just being able to walk up and down whenever the user pleased meaning that they can press the jump key once and the character will the perform the jump, the complex part of this was handling collisions while in the air allowing for the character to come back down if they were to collide with a block above them while jumping, but this was all figured out over the week and has been successfully implemented into the game along with the feature of the character changing its sprite depending on the direction it is facing, this means that if the user presses the left key the character will now face left but there is still no animation within the game, all of these features have been implemented into the game using the code below.

Jumping Gravity + Sprite Change
if ((input.isKeyPressed(Input.KEY_UP) || input.isKeyPressed(Input.KEY_W)) && !jumping){

   if(lastKeyLeft){
    player = jumpLeft;
   } else {
    player = jumpRight;
   }

   gravSpeeds = -12;
   jumping = true;
   }

   if(jumping && gravSpeeds < 12) { 
    gravSpeeds += 0.5; 
   } 

   if (jumping == false){
    gravSpeeds = 12;
    if (lastKeyLeft == true){
     player = moveLeft;
    } else {
     player = moveRight;
    }
   }

   y += gravSpeeds;
   origY = y - gravSpeeds;

   playerPoly.setY(y);
   if (entityCollisionWith()){

    if (jumping && gravSpeeds < ((gravSpeeds * (-1)))){
     gravSpeeds = 0;
     gravSpeeds += 0.5;
     y += gravSpeeds;
    }

    if ( gravSpeeds > 0) {
     gravSpeeds = 0;
     jumping = false;
     y = origY;
     playerPoly.setY(y);
    }  
   } 


   if (input.isKeyDown(Input.KEY_DOWN) || input.isKeyDown(Input.KEY_S))
   {
    y += floatDelta;
    playerPoly.setY(y);
    if (entityCollisionWith()){
     y -= floatDelta;
     playerPoly.setY(y);
    }
   }

   if (input.isKeyDown(Input.KEY_LEFT) || input.isKeyDown(Input.KEY_A))
   {
    lastKeyLeft = true;

    if (jumping){
     player = jumpLeft;
     jumpLeft.update(delta);
    } else {
     player = moveLeft;
     moveLeft.update(delta);
    }
    x -= floatDelta;
    playerPoly.setX(x);
    if (entityCollisionWith()){
     x += floatDelta;
     playerPoly.setX(x);
    }
   } else {
    moveLeft.setCurrentFrame(0);
   }

   if (input.isKeyDown(Input.KEY_RIGHT) || input.isKeyDown(Input.KEY_D))
   {
    lastKeyLeft = false;

    if (jumping){
     player = jumpRight;
     jumpRight.update(delta);
    } else {
     player = moveRight;
     moveRight.update(delta);
    }
    x += floatDelta;
    playerPoly.setX(x);
    if (entityCollisionWith()){
     x -= floatDelta;
     playerPoly.setX(x);
    }
   }
   else {
    moveRight.setCurrentFrame(0);
   }

Animation Code
  player = new Animation();
  player.setAutoUpdate(true);
  Image [] walkRight = {new Image ("data/Sprites/CharStand.png"), 
                        new Image ("data/Sprites/CharStep1.png"), 
                        new Image ("data/Sprites/CharStep2.png")};
  Image [] walkLeft = {new Image ("data/Sprites/CharStandBACKWARDS.png"), 
                       new Image ("data/Sprites/CharStep1BACKWARDS.png"), 
                       new Image ("data/Sprites/CharStep2BACKWARDS.png")};
  Image [] jumpingLeft = {new Image ("data/Sprites/CharJumpBACKWARDS.png")};
  Image [] jumpingRight = {new Image ("data/Sprites/CharJump.png")};

  moveRight = new Animation(walkRight, 200, false);
  moveLeft = new Animation(walkLeft , 200, false);
  jumpRight = new Animation(jumpingRight, 200, false);
  jumpLeft = new Animation(jumpingLeft, 200, false);

  jumpRight.setPingPong(true);
  jumpLeft.setPingPong(true);
  moveRight.setPingPong(true);
  moveLeft.setPingPong(true);

  player = moveRight;

Sunday, 17 February 2013

Creating The Game - 17/02/2013

This week I have been concentrating on getting the collision within the game working, and this was one of the hardest things that I have done with the project to date. But first I will discuss the what was said at the short group discussion that we had. Stephen has created some more tiles for me to use within the map creation but we have decided that we are not going to use them, because of this he has started creating the animation frames for the character walking and jumping that I will use to animate the character in the game. Sam has completed the jump sound which will be played when the character jumps within the game to his liking and has started on a collection sound for picking up coins. Andy has started to create the real flash animation from one of his designs that he has chosen for this and the whole project is still moving in the right direction.

This week as stated before I have been focusing on getting the collision working within the game. This means that the character will not be able to move where there is a block being rendered on the screen. As I had originally thought, this was extremely hard to get the grasp of but finally after looking through many different resources I understand how this is done and have implemented it successfully into the game. The basics of the collision system are that the TileD map that I created is loaded as a blockmap allowing Slick2D to read each tile and see if anything is being drawn there according to a specific tile ID. If there is a tile meant to be there then this is added to an array of entities which store the size of the block and where it is. Once this is done a polygon box is drawn around the players character and all of the blocks that are in the map, when the user is attempting to move the game checks to see if these polygon boxes ever intersect by looking through each object in the array and making sure the co-ordinates never intersect, if they do the movement is blocked and stops the character from moving through this object. All of the code that was written for this is down below.

BlockMap Class
import java.util.ArrayList;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.tiled.TiledMap;
 
public class BlockMap {
	public static TiledMap tmap;
	public static int mapWidth;
	public static int mapHeight;
	private int square[] = {1,1,31,1,31,31,1,31}; //square shaped tile
	public static ArrayList(objects) entities;
 
	public BlockMap(String ref) throws SlickException {
		entities = new ArrayList(objects)();
		tmap = new TiledMap(ref, "data");
		mapWidth = tmap.getWidth() * tmap.getTileWidth();
		mapHeight = tmap.getHeight() * tmap.getTileHeight();
 
		for (int x = 0; x < tmap.getWidth(); x++) {
			for (int y = 0; y < tmap.getHeight(); y++) {
				int tileID = tmap.getTileId(x, y, 0);
				if (tileID == 1) {
					entities.add(
                                        new Block(x * 32, y * 32, square, "square")
                                        );
				}
			}
		}
	}
}

Block Class
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Polygon;
 
public class Block  {
	public Polygon poly;
	public Block(int x, int y, int test[],String type) {
        poly = new Polygon(new float[]{
				x+test[0], y+test[1],
				x+test[2], y+test[3],
				x+test[4], y+test[5],
				x+test[6], y+test[7],
        });   
	}
 
	public void update(int delta) {
	}
 
	public void draw(Graphics g) {
		g.draw(poly);
	}
}

Collision Check Method
	public boolean entityCollisionWith() throws SlickException {
		for (int i = 0; i < BlockMap.entities.size(); i++) {
			Block entity1 = (Block) BlockMap.entities.get(i);
			if (playerPoly.intersects(entity1.poly)) {
				return true;
			}       
		}       
		return false;

	}

Updated Game Code - Movement
		if (input.isKeyPressed(Input.KEY_UP)){
			y -= floatDelta;
			playerPoly.setY(y);
			if (entityCollisionWith()){
				y += floatDelta;
				playerPoly.setY(y);
			}
		}

		if (input.isKeyDown(Input.KEY_DOWN))
		{
			y += floatDelta;
			playerPoly.setY(y);
			if (entityCollisionWith()){
				y -= floatDelta;
				playerPoly.setY(y);
			}
		}

		if (input.isKeyDown(Input.KEY_LEFT))
		{
			x -= floatDelta;
			playerPoly.setX(x);
			if (entityCollisionWith()){
				x += floatDelta;
				playerPoly.setX(x);
			}
		}

		if (input.isKeyDown(Input.KEY_RIGHT))
		{
			x += floatDelta;
			playerPoly.setX(x);
			if (entityCollisionWith()){
				x -= floatDelta;
				playerPoly.setX(x);
			}
		}

	}

Sunday, 10 February 2013

Creating The Game - 10/02/2013

This week there was no meeting due to time restraints from members of the group, but I have been speaking with Stephen as he has now completed the character sprite using the 32x64 dimensions that we discussed last week. I have not spoken with the other two members of the group about their EPQ work but we are still progressing nicely with the project and I am happy overall with the work.

This week I have been concentrating on making the character that I have drawn to the screen moving in certain directions decided by which buttons on the keyboard have been pressed. This was a much harder task than I first thought but after reading through the available documentation for Slick2D and looking once again at the sample code that is available to me I have created a working movement system for the game. The code I have written allows the user to press either WASD or The arrow keys on the keyboard to control the movement of the character, seeing if the keys are being pressed is helpfully implemented with the input class of Slick2D allowing me to easily check if a key is either been pressed or held down which is very handy indeed. If the button is pressed down the variables of Y and X which are the current co-ordinates are adjusted accordingly and then the image is redrawn at these co-ordinates once updated. The code I have written is below:


 public void update(GameContainer gc, int delta) throws SlickException {

  Input input = gc.getInput();
  float floatDelta = delta*0.1f;

  
  if (input.isKeyDown(Input.KEY_UP)){
   y -= floatDelta;
  }

  if (input.isKeyDown(Input.KEY_DOWN))
  {
   y += floatDelta;
  }

  if (input.isKeyDown(Input.KEY_LEFT))
  {
   x -= floatDelta;
  }

  if (input.isKeyDown(Input.KEY_RIGHT))
  {
   x += floatDelta;
  }

 }

Sunday, 3 February 2013

Creating The Game - 03/02/2013

This week I have been successful in rendering a map to the screen using some of the art assets that Stephen has given to me. But first as with every week I will be discussing what has been said within the group meeting on Saturday. This week me and Stephen decided that having the character a 32x32 which is the same size as the blocks used within the map would not look right, because of this we decided that a 32x64 sprite would be better used for the character and this is now what Stephen has set about designing. Sam has completed the first complete draft of the level music which now sounds a lot better after the discussion we had last week, there a a few improvements that he decided that he would like to make but after this he will start working on the sound effects that will be used within the game such as for jumping and collecting coins. Andy has finished his initial designs and has started creating some very early flash animations and posters from these designs to see what these will look like and decide from this which one he will be using.

This week I have as described up above managed to render an image of what the map will be like within the game. First of all to do this I created the map image in a program called TileD. This is a very highly praised program as it allows for the creation of 2D maps very quickly and easily using a painting style interface with the tiles that you import. Once the map has been created the program allows you to export the map as a .TMX file which can then be read instantly by Slick2D and then rendered onto the screen. This is only the image of the map first of all though as such there is no collision or any other features within the game. I have also managed to get a representation of the played rendered on the screen, for which I have just used a 32x64 coloured box until such time that I have the actual character sprite from Stephen. This is some major progress as I now know draw images onto the screen with great ease and how to draw these images at certain points. By next week I hope to have movement working with the sprite that Stephen will be sending me during the week.

Sunday, 27 January 2013

Creating The Game - 27/01/2013

Today I will be showing some of the simple code that I have written within for the game, but first I will be discussing what was spoken about in the weekly group meeting on Saturday. This week Stephen had completed some of the tiles that I am going to be using within the creation of the game, the tiles we decided are going to be 32x32 giving Stephen a big enough space to create something that looks aesthetically pleasing yet still fits the retro genre that we are aiming for. Sam has given me a sample of the level music that he is creating and we decided that it did not fit the sci-fi style techno music that we decided that should have been created, because of this he is going back and changing this music slightly to give it that feel that we would like. Andy is progressing well creating designs for his flash animations and poster that he is going to be creating. Once again I feel the the group is progressing in the right direction with progress being made each week.

I have been playing around with the Slick2D package this week and have got the very basic layout for the games code setup now. This will allow me to keep the code nicely structured and cleaner, it will also allow the game to run once the code has been written and compiled. The code that I have written this week after reading the documentation and looking at some basic examples of game code is :

import org.newdawn.slick.*;

public class SlickTest extends BasicGame {
 
 public SlickTest() {
  super("Jetson's Journey || EPQ Game");
 }

  public void render(GameContainer gc, Graphics g) throws SlickException {
  
 }

  public void init(GameContainer gc) throws SlickException {

  }

  public void update(GameContainer gc, int arg1) throws SlickException {

  }

  public static void main(String[] args) throws SlickException {
  AppGameContainer app = new AppGameContainer(new Game(), 1280, 960, false);
  app.start();
 }


The code above, denoted by the bold and italics, is the basic structure of a Slick2D game, the render method will be used to render assets onto the screen once I have imported them into the project, the init method will initialise everything needed within the game once the game starts this includes all variables, art assets and sound assets, the update method will be the section of code that will update the game logic making everything within the game like movement, collision and collecting coins possible. The last section of code, the main method is what initialises the whole game creating the game window and starting the game code running.

Sunday, 20 January 2013

Game Features and Asset Lists

After another very quick discussion with the other members of the group we have decided to create a list of features and assets so that we know what each person will be creating and also what the game will be able to do. Below is the list of individual assets that we will each create and also a list of feature we agreed that we would like the game to have:

  • Ste:
    • Main Character Sprites
    • Main Character Animation
      • Walking
      • Jumping
    • Level Tiles
    • Level Backgrounds
    • Level Assets
      • Exit
      • Collectables
        • Coins (Most Likely)
        • Diamonds
  • Sam:
    • Level Music
      • Make repeatable so that it can be repeated smoothly within game
    • Sound FX
      • Jumping Sounds
      • Collecting Sounds
      • Death Sounds
  • Andy:
    • Marketing Products
      • Online Products
        • Flash Animation using the sprites from the game
      • Physical Products
        • Poster
    • Plan Testing
      • Beta Test
        • Group of players for when the game has been created.
  • Game Features (Me):
    • General Game Features
      • Gravity
      • Collectables
      • Death
      • Enemies
      • Collision
      • Exit
      • Pause Menu

Creating The Game - 20/01/2013

Today I am going to be talking about the very start of the games development. After talking with the other members of the group we have decided that I will be the one who will be creating the maps as this is required within the coding side of the project to be imported. Due to this I have looked around and found a very helpful tool that I will be using to help with the map creation once the first art assets have been given to me by Stephen. Sam has also started work on the music that will be played while playing the game and it is proceeding nicely, Andy has also started on designing what he will be creating as the Marketing section of the games team and like the rest of the group is also proceeding very well. As a whole I feel the group is getting on well and the work is getting done at a good pace.

I myself have started reading up on the Slick2D documentation which can be found at this link. This is the JavaDoc that contains all of the packages and classes that are contained within Slick2D giving detailed write ups on each method and how they can be used within the project that I am creating. This document is going to be invaluable to me as I can quickly lookup any method that I may need and see clearly how this should be implemented into the code I am writing. The Eclipse SDK that I decided upon has been fully setup on my computer with Slick2D and its dependencies linked with the project that I have created. By next week I hope to have a few very simple lines of code written allowing for a window to be rendered ready for the game to be displayed in.