Pokemon

The game I created is a spin off of the popular game pokemon, i uses basic principles such as the pokeball and the specific pokemon Mewtwo but as you will find out is very different from the actual game.

Controls

The controls for the game are simple, arrow keys to move the character, space bar to summon a pokeball and again use the arrow keys to throw it. You can control the direcion of the pokeball but not for too long. The challenge is to hit the pokemon enough times to essentially capture it.

Click here to play

Coding the game

What took the longest

One of the painstakingly long tasks with making the game was the movement of the character. Every direction the character walks in has three separate images that makes the characters movement look realistic.There is also a count that keeps track of what step the charcater is on. While coding the movement wasn’t too much of a challenge itself. It took a very long time to do.

 

public void walk()
{
// the smaller the number count is the faster the pictures change
count++;

if (!Greenfoot.isKeyDown(“right”) && !Greenfoot.isKeyDown(“left”) &&
!Greenfoot.isKeyDown(“up”) && !Greenfoot.isKeyDown(“down”))
{
if (direction == 0)
{
setImage(“D1.png”);
}

if (direction == 1)
{
setImage(“R1.png”);
}

if (direction == 2)
{
setImage(“L1.png”);
}

if (direction == 3)
{
setImage(“U1.png”);
}

if (direction == 4)
{
setImage(“D1.png”);
}
}

if (Greenfoot.isKeyDown(“right”))
{

// direction int is used to keep picture when not hitting a key
direction = 1;
if (count <= 5) { setImage(“R2.png”); } else if (count > 5 && count <= 10) { setImage(“R1.png”); } else if (count > 10)
{
setImage(“R3.png”);
if (count>15)
{
count = 0;
}
}

}
if (Greenfoot.isKeyDown(“left”))

{
direction = 2;
if (count <= 5) { setImage(“L1.png”); } else if (count > 5 && count <= 10) { setImage(“L2.png”); } else if (count > 10)
{
setImage(“L3.png”);
if (count>15)
{
count = 0;
}
}

}
if (Greenfoot.isKeyDown(“up”))
{
direction = 3;
if (count <= 5) { setImage(“U1.png”); } else if (count > 5 && count <= 10) { setImage(“U2.png”); } else if (count > 10)
{
setImage(“U3.png”);
if (count>15)
{
count = 0;
}
}

}
if (Greenfoot.isKeyDown(“down”))
{
direction = 4;
if (count <= 5) { setImage(“D1.png”); } else if (count > 5 && count <= 10) { setImage(“D2.png”); } else if (count > 10)
{
setImage(“D3.png”);
if (count>15)
{
count = 0;
}
}

}

The direction int is set so that when no key is being hit the character remains in the position he is facing in.

 

 

Problems I faced while coding it

I faced many minor problems while coding the game, by far the hardest thing was collision detection. The map had many ledges that cant be climbed by the character, to have the character detect walls I went on adobe photoshop and cut out picture from the map and made them into objects.


public boolean touching_wall1()
{
{
Actor wall1 = getOneObjectAtOffset(0, 0, wall1.class);
if(wall1 != null)
{
//System.out.println("now");
return true;

}

return false;
}
}

public boolean touching_wall2()
{
{
Actor wall2 = getOneObjectAtOffset(0, 0, wall2.class);
if(wall2 != null)
{
//System.out.println(“now”);
return true;

}

return false;
}
}

public boolean touching_wall3()
{

{
Actor wall3 = getOneObjectAtOffset(0, 0, wall3.class);
if(wall3 != null)
{
//System.out.println(“now”);
return true;

}

return false;
}

}

public boolean touching_wall4()
{
{
Actor wall4 = getOneObjectAtOffset(0, 0, wall4.class);
if(wall4 != null)
{
//System.out.println(“now”);
return true;

}

return false;
}
}

// if touching_wall restrictions are put on the characters movement
public void charmovement()
{

if (touching_wall1())
{

if (Greenfoot.isKeyDown(“left”))
{
setLocation(getX()-3,getY());

}

if (Greenfoot.isKeyDown(“up”))
{
setLocation(getX(),getY()-3);

}

if (Greenfoot.isKeyDown(“down”))
{
setLocation(getX(),getY()+3);

}

}

else if (touching_wall2())
{
if (Greenfoot.isKeyDown(“right”))
{

setLocation(getX()+3,getY());
}

if (Greenfoot.isKeyDown(“left”))
{
setLocation(getX()-3,getY());

}

if (Greenfoot.isKeyDown(“down”))
{
setLocation(getX(),getY()+3);

}

}

else if (touching_wall3())
{

if (Greenfoot.isKeyDown(“left”))
{
setLocation(getX()-3,getY());

}

if (Greenfoot.isKeyDown(“up”))
{
setLocation(getX(),getY()-3);

}

if (Greenfoot.isKeyDown(“down”))
{
setLocation(getX(),getY()+3);

}
}

else if (touching_wall4())
{
if (Greenfoot.isKeyDown(“right”))
{

setLocation(getX()+3,getY());
}

if (Greenfoot.isKeyDown(“left”))
{
setLocation(getX()-3,getY());

}

if (Greenfoot.isKeyDown(“down”))
{
setLocation(getX(),getY()+3);

}
}
// nothing being touched no restrictions
else
{
if (Greenfoot.isKeyDown(“right”))
{

setLocation(getX()+3,getY());
}

if (Greenfoot.isKeyDown(“left”))
{
setLocation(getX()-3,getY());

}

if (Greenfoot.isKeyDown(“up”))
{
setLocation(getX(),getY()-3);

}

if (Greenfoot.isKeyDown(“down”))
{
setLocation(getX(),getY()+3);

}
}
}

 

The collision code took a very long time and was extremely repetitive. Other collision In my code is when the pokeball hits the pokemon but that was significantly easier.

 

 

 

What I would have done if I had more time

If I had more time on the project I would have made the collision code more effective. Sometimes the character can walk through the walls. Also I would have given mewtwo some sort of attack to make the game more challenging. I didn’t have to to get to this because it took too many days to cut the character out and make the walking look realistic.

My biggest accomplishment

The part that I was most proud of was the throwing of the pokeball hit and capture. It took a while to work out the numbers for catching the pokemon and figuring out the most efficient way to create a new pokeball, which is by creating it in the characters editor.

Leave a Reply

Your email address will not be published. Required fields are marked *