First of all I have finished the creation of the second level for the game. This was a much simpler process that first thought as the code used from the first level directly copied over to this level allowing for 85% of the base code to already be complete, but there are some slight changes in this level that needed to be added. First of all a new BlockMap and Block class needed to be created for this level to use, The code for these is shown below:
BlockMap2 Class
import java.util.ArrayList;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.tiled.TiledMap;
public class BlockMap2 {
public static TiledMap tmaps;
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(Object) entitiestwo;
public BlockMap2(String ref) throws SlickException {
entitiestwo = new ArrayList(Object)();
tmaps = new TiledMap(ref, "data");
mapWidth = tmaps.getWidth() * tmaps.getTileWidth();
mapHeight = tmaps.getHeight() * tmaps.getTileHeight();
for (int x = 0; x < tmaps.getWidth(); x++) {
for (int y = 0; y < tmaps.getHeight(); y++) {
int tileID = tmaps.getTileId(x, y, 0);
if ((tileID == 3) || (tileID == 11)) {
entitiestwo.add(
new Block2(x * 32, y * 32, square, "square")
);
}
}
}
}
}
Block2 Class
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Polygon;
public class Block2 {
public Polygon poly;
public Block2(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);
}
}
As you can see the BlockMap2 Class is slightly different from the original as this is using different tile IDs to create the BlockMap as there have been different tiles used within the creation of this level. After this was done The AI in the second level also had to be changed as there are many more AI used in this level. The new AI code is shown below:
Initialising The AI:
ai1 = enemyLeft;
ai2 = enemyRight;
ai3 = enemyLeft;
ai4 = enemyRight;
ai5 = enemyLeft;
ai6 = enemyRight;
AIPoly1 = new Polygon(new float[]{
x,y,
x+32,y,
x+32,y+32,
x,y+32
});
AIPoly2 = new Polygon(new float[]{
x,y,
x+32,y,
x+32,y+32,
x,y+32
});
AIPoly3 = new Polygon(new float[]{
x,y,
x+32,y,
x+32,y+32,
x,y+32
});
AIPoly4 = new Polygon(new float[]{
x,y,
x+32,y,
x+32,y+32,
x,y+32
});
AIPoly5 = new Polygon(new float[]{
x,y,
x+32,y,
x+32,y+32,
x,y+32
});
AIPoly6 = new Polygon(new float[]{
x,y,
x+32,y,
x+32,y+32,
x,y+32
});
Drawing The AI:
g.drawAnimation(ai1, AI1x , AI1y);
g.drawAnimation(ai2, AI2x , AI2y);
g.drawAnimation(ai3, AI3x , AI3y);
g.drawAnimation(ai4, AI4x , AI4y);
g.drawAnimation(ai5, AI5x , AI5y);
g.drawAnimation(ai6, AI6x , AI6y);
AI Logic Code:
AIPoly1.setY(AI1y);
AIPoly2.setY(AI2y);
AIPoly3.setY(AI3y);
AIPoly4.setY(AI4y);
AIPoly5.setY(AI5y);
AIPoly6.setY(AI6y);
if(enemyR1){
AI1x -= floatDelta;
ai1 = enemyLeft;
enemyLeft.update(delta);
AIPoly1.setX(AI1x);
if(entityAICollisionWith(AIPoly1)){
enemyR1 = false;
}
} else {
AI1x += floatDelta;
ai1 = enemyRight;
enemyRight.update(delta);
AIPoly1.setX(AI1x);
if(entityAICollisionWith(AIPoly1)){
enemyR1 = true;
}
}
if(enemyR2){
AI2x += floatDelta;
ai2 = enemyRight;
enemyRight.update(delta);
AIPoly2.setX(AI2x);
if(entityAICollisionWith(AIPoly2)){
enemyR2 = false;
}
} else {
AI2x -= floatDelta;
ai2 = enemyLeft;
enemyLeft.update(delta);
AIPoly2.setX(AI2x);
if(entityAICollisionWith(AIPoly2)){
enemyR2 = true;
}
}
if(enemyR3){
AI3x -= floatDelta;
ai3 = enemyLeft;
enemyLeft.update(delta);
AIPoly3.setX(AI3x);
if(entityAICollisionWith(AIPoly3)){
enemyR3 = false;
}
} else {
AI3x += floatDelta;
ai3 = enemyRight;
enemyRight.update(delta);
AIPoly3.setX(AI3x);
if(entityAICollisionWith(AIPoly3)){
enemyR3 = true;
}
}
if(enemyR4){
AI4x += floatDelta;
ai4 = enemyRight;
enemyRight.update(delta);
AIPoly4.setX(AI4x);
if(entityAICollisionWith(AIPoly4)){
enemyR4 = false;
}
} else {
AI4x -= floatDelta;
ai4 = enemyLeft;
enemyLeft.update(delta);
AIPoly4.setX(AI4x);
if(entityAICollisionWith(AIPoly4)){
enemyR4 = true;
}
}
if(enemyR5){
AI5x -= floatDelta;
ai5 = enemyLeft;
enemyLeft.update(delta);
AIPoly5.setX(AI5x);
if(entityAICollisionWith(AIPoly5)){
enemyR5 = false;
}
} else {
AI5x += floatDelta;
ai5 = enemyRight;
enemyRight.update(delta);
AIPoly5.setX(AI5x);
if(entityAICollisionWith(AIPoly5)){
enemyR5 = true;
}
}
if(enemyR6){
AI6x += floatDelta;
ai6 = enemyRight;
enemyRight.update(delta);
AIPoly6.setX(AI6x);
if(entityAICollisionWith(AIPoly6)){
enemyR6 = false;
}
} else {
AI6x -= floatDelta;
ai6 = enemyLeft;
enemyLeft.update(delta);
AIPoly6.setX(AI6x);
if(entityAICollisionWith(AIPoly6)){
enemyR6 = true;
}
}
if(playerPoly.intersects(AIPoly1) || playerPoly.intersects(AIPoly2) ||
playerPoly.intersects(AIPoly3) || playerPoly.intersects(AIPoly4)||
playerPoly.intersects(AIPoly5) || playerPoly.intersects(AIPoly6)){
dead = true;
Level2.stop();
death.play();
}
}
After this code was completed I also Added an exit to this level allowing the player to complete the level of the game. This was done once again by adding some simple Code and then displayed the End Screen that Stephen had created to the user. The code for this is shown below:
Initialising The Door And End Menu:
door = new Image("data/Exit.png");
endMenu = new Image("data/END.png");
Drawing The Door And End Menu(Updated Render Cycle: if (!paused && !dead && !end){
BG.draw(0,0);
BlockMap2.tmaps.render(0, 0);
door.draw(1215, 865);
g.drawAnimation(player, x , y);
g.drawAnimation(ai1, AI1x , AI1y);
g.drawAnimation(ai2, AI2x , AI2y);
g.drawAnimation(ai3, AI3x , AI3y);
g.drawAnimation(ai4, AI4x , AI4y);
g.drawAnimation(ai5, AI5x , AI5y);
g.drawAnimation(ai6, AI6x , AI6y);
}else if(paused){
pauseMenu.draw(0,0);
}else if(dead){
deadMenu.draw(0,0);
}else if(end){
endMenu.draw(0,0);
}
}
Using The End Menu: if(end && !paused && !dead){
if((mouseX > 1025.0 && mouseX < 1245.0) && (mouseY > 842.0 && mouseY < 928.0)){
if (input.isMousePressed(Input.MOUSE_LEFT_BUTTON)){
Level2.stop();
Menu.MainMusic.loop();
sbg.enterState(0);
}
}
}
Completing The Level: if((x > 1214 && x < 1216) && (y > 863 && y < 867)){
end = true;
x = 57.0f;
y = 853.0f;
}
After the code for Level 2 was fully complete I went back to the first level and added the code to continue to the second level in. The code that I added is shown below:
Completing The First Level:
if((x > 1215 && x < 1217) && (y > 575 && y < 577)){
Level1.stop();
Play2.Level2.loop();
sbg.enterState(2);
y = 32f;
x= 32f;
}
After this code had been added to the Game it was fully complete from this I thought what had been completed and what had been scrapped from the original idea and I will be discussing this in the next post that will be put up after this one.
No comments:
Post a Comment