Switching in-between tile layers [I STILL NEED HELP]

Started by
0 comments, last by thelegendofzaku 18 years ago
Since I want my game to include multiple levels, I was wondering how I can go about in doing that. I tried to input numbers in my setMap method, but that didn't seem to work. I heard that you can do this by creating a method that merges two tile number arrays, representing the levels, into one, but I'm unsure as to how to proceed. Can someone please get back to me about this. Thank You. Here's my tile layer class (note: there will be more levels besides the ones currently stated):
package de.enough.polish.example;

import javax.microedition.lcdui.game.*;
import javax.microedition.lcdui.*;
public class TheLevels {
    private static final int [][] level1={
    {0,0,0,0,0,0,0,9,10,0,0,0,0,0,0,0,0,0},
    {6,6,6,6,6,6,6,7,8,5,5,5,5,5,5,5,5,5},
    {1,1,1,1,1,1,2,3,3,4,1,1,1,1,1,1,1,1}
    };
    private static final int [][] level2={
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
    {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}
    };
    private int TILE_WIDTH=64;
    private int TILE_HEIGHT=64;
    private int TILE_NUM_ROW = 3;
    private int TILE_NUM_COL = 18;

    private int [][] currentLevel;
    private TiledLayer theBoard;
    private int screenHeight;
    private int bgColor;

    /** Creates a new instance of TheLevels */
    public TheLevels(int screenHeight) throws Exception {
         this.screenHeight = screenHeight;
         setMap(1);
    }
    public void setMap(int level) throws Exception{
        Image tileImages = null;
        switch (level){
             case 1:  tileImages = Image.createImage("/street.png");
                       currentLevel = level1;
                       break;
             case 2:  tileImages = Image.createImage("&#<span class="java-number">47</span>;grass.png"</span>);
                        currentLevel = level2;
            }
            theBoard = <span class="java-keyword">new</span> TiledLayer(TILE_NUM_COL,TILE_NUM_ROW, tileImages, TILE_WIDTH, TILE_HEIGHT);
            <span class="java-keyword">for</span> (<span class="java-primitives">int</span> rows=<span class="java-number">0</span>; rows&lt;TILE_NUM_ROW; rows++) {
              <span class="java-keyword">for</span> (<span class="java-primitives">int</span> columns=<span class="java-number">0</span>; columns&lt;TILE_NUM_COL; columns++) {
                theBoard.setCell(columns,rows,currentLevel[rows][columns]);
                }
            }
        }
        <span class="java-visibilitymodifier">public</span> TiledLayer getBackground(){
            <span class="java-keyword">return</span> theBoard;
        }
        <span class="java-visibilitymodifier">public</span> <span class="java-primitives">int</span> getBackgroundColor() {
            <span class="java-keyword">return</span> bgColor;
        }
        <span class="java-visibilitymodifier">public</span> <span class="java-primitives">int</span> getWidth(){
            <span class="java-keyword">return</span> theBoard.getWidth();
        }
        <span class="java-visibilitymodifier">public</span> <span class="java-primitives">int</span> getHeight(){
            <span class="java-keyword">return</span> theBoard.getHeight();
        }

}


</pre></div><!--ENDSCRIPT--> 

<!--EDIT--><span class=editedby><!--/EDIT-->[Edited by - thelegendofzaku on April 3, 2006 11:35:36 AM]<!--EDIT--></span><!--/EDIT-->
Advertisement
I figured out my problem, had to get rid of default case in my setMap method in my tile layer class. As a result, I was able to switch in between tile layers. Now I have another problem, I can't seem to invoke that method in my game canvas class, it's not working in my constructor, let alone my thread. I'm stumped! I don't have a clue as to where else I should invoke it. I have searched just about everywhere for this and found absolutely nothing.

[Edited by - thelegendofzaku on April 3, 2006 11:55:13 AM]

This topic is closed to new replies.

Advertisement