Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (497)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Designing maps for a platform game  (Read 1516 times)
0 Members and 1 Guest are viewing this topic.
Avenger
Guest
« Posted 2006-03-15 21:59:25 »

Hello , I am trying to make a 2D platform game ... as simple as it can go ..... a Mario style game.So I was told I should design the maps inside a .txt file. I did that and made a class TileMapMaker which reads each line and stores each character in a 2D Array of chars.The problem I am having is that when I read the array , I want to match each array positio with a 16x16 pixels tile.Well how do I do that for parts of the screen which are not yet visible?I mean parts of the screen which the player will have to explore.

The whole thing is not very accurately planned in my mind.I am a little confused.Any help ?
Offline Kova

Senior Member





« Reply #1 - Posted 2006-03-16 02:21:12 »

Can you explain that .txt mapping and array a bit further? Give some small example, don't quite get it what is stored it that .txt file or how should be rendered on screen.
Avenger
Guest
« Reply #2 - Posted 2006-03-16 02:33:44 »

Ofcourse! Well look as I was trying to think and searching on the net on how to make the map for a platform game .. a Mario clone or something like that I was told to make the map in a .txt file.The .txt would be like that:

##################################################
####################BBBBBBBBB####################
##################################################
###########BBBBB#################################
##################################################
##################################################
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG

So I read every line of it and put in a 2D array of chars ..... and when I read the array I translate each char .... # for nothing , B for a tile of a Brick G for Grass e.t.c.  and I am a little buffled as to how I am going to draw it on the screen.On how to match pixels and tiles.Each tile is 16x16 pixels btw as I made it.

I am really not sure if this is the way to make a mario clone platform game ... but that is what I was told would do the trick and like it as an idea.But still I got kind of stuck :S
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline odeamus

Junior Newbie




Java games rock!


« Reply #3 - Posted 2006-03-16 08:26:03 »

There's a nice simple example game in the book Developing Games in Java (http://www.brackeen.com/javagamebook/).
You can play the game from the site and download all the source code. I think the code for the game is in chapter 5, but not sure.
See if it helps any.

O.
Avenger
Guest
« Reply #4 - Posted 2006-03-16 12:57:50 »

Hey thanks for the link Smiley , I have this book and have read the specific chapter , yes the game example is in chapter 5...but it does not clarify well the part I am asking for.How will I draw the map that is not yet visible to the player ? :pThe part of the map which the player has yet to explore.Will it be stored somewhere?How will I make it appear as the player moves?I have some basic ideas on it  but I am a little confused over the whole topic.

I might be asking too much and all I should do is just sit and try to program it myself through trial and error or something.But as this forum exists I thought I could ask for some help Cheesy
Offline cylab

JGO Knight


Medals: 34



« Reply #5 - Posted 2006-03-16 14:19:39 »

Hmm... I don't really know how to explain this accurately, but I will try to give some hints:

- define the full map (including the areas to be explored) in your textfile
  -> your map will cover a lot more space than the screen size
- calculate an overall position for each tile. since the map is much bigger than the screensize,
  the lower right corner of your map can be 4096, 3072 for example.
- treat your screen as a "viewport" to the map area
 
- virtually assign your screens top-left corner a position inside your map and modify it, when the player moves
- find all tiles in your map, that are at least partly inside the screen-area
  (taking the tiles position, the screen position, the tile-size and the screen-size into account)
- draw the resulting tiles to the screen at the coordinates calculated by substracting the screen-position from the tile-position
  (example: tile position 480,240 - virtual screen-position 300,200 = draw the tile at 180,40 to the screen)

There are several approaches to optimize this approach speed-wise (which may depend on the graphics library you use), but the above is the basic idea.


Mathias - I Know What [you] Did Last Summer!
Avenger
Guest
« Reply #6 - Posted 2006-03-17 21:04:16 »

ok then , thanks Cheesy I will try to make it happen

Another question .. something which I have done not only in problems like these.

Here I readthe map in a class called TileMapMaker :
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
 public  char[][] read()
    {
        try
        {
            String line ;
            while((line = in.readLine()) != null)
            {
                String s = in.readLine();
                for(int i =0;i<127;i++)
                {
                    if(s.charAt(i) == 'G')
                        TileMap[lines][i] = 'G';
                    if(s.charAt(i) == 'B')
                        TileMap[lines][i] = 'B';
                    if(s.charAt(i) == '#')
                        TileMap[lines][i] = '#';
                }
                lines +=1;
            }
        }


then in my main class in the paintWorld method I read the array:  (of course before that I had done map1Array = map1.read(); )
1  
2  
3  
4  
5  
6  
7  
8  
for(int i=0 ;i<44;i++)
            for(int j = 0;j<127;j++)
            {
                if(map1Array[i][j] == 'B')
                    g.drawImage(B , j*16 ,i*16,this  );
                if(map1Array[i][j] == 'G')
                    g.drawImage(G , j*16 ,i*16,this  );
            }


I get errors though ..
java.lang.NullPointerException
        at Version01.TileMapMaker.read(TileMapMaker.java:43)
        at Version01.Legend.initWorld(Legend.java:68)
        at Version01.Legend.gameLoop(Legend.java:87)
        at Version01.Legend.main(Legend.java:163)

and it draw the testmap like I designed it in the .txt but ... it does not cover the whole screen .. even though the resolution is 1024x768
and i max and j max * 16 should cover the whole map it only covers half of the vertical screen.Horizontal it covers it all.Sorry If I did not explain accurately , english is not my 1st language Sad

Any more explanations feel free to ask.




Offline Kova

Senior Member





« Reply #7 - Posted 2006-03-19 02:13:33 »

In my experience, first thing is to cover most simplest and stupid things, so don't be offended with this Smiley :

Is your map inside .txt file big enough for whole vertical coverage of screen? With horizontal there shouldn't be problems since player is supposed to discover the rest anyway, so it's big enough. Try it on a map that is only big enough only for 1024x768 and see if horizontal shrinks also.
Did you tried to track the formula for drawing map on screen and gone through it yourself? It takes ~15 mins but if you're able to it's almost the quickest way to discover bugs.
About null pointer exception, what is in TileMapMaker.java:43 line? It's always the case when you try to calculate or do something with reference that is null.
Avenger
Guest
« Reply #8 - Posted 2006-03-19 12:30:28 »

Hey Kova thx , yesterday I fixed this problem ... while reading the map if the line was null I did not close the stream so that was what it caused it .Now it works ok.Now I have other problems with how to make it scroll when the player moves .. but hmmm trying to figure it out now Cheesy , it is fun trying , failing and trying again Cheesy

EDIT: LOL!I am a complete idiot.I fixed the scrolling too Cheesy An example of my so stupid mistake :

g.drawImage(B , x-offsetX*16 ,y*16,this  );

Last night I was wondering why the hell it did not work
Now with a much more clear head and a cup of coffee I realized it need a parenthesis there
g.drawImage(B , (x-offsetX)*16 ,y*16,this  );   And voila ! Map scrolling works as the player moves Cheesy  Only thing is it goes fas but hey I can fix that Wink
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (12 views)
2014-04-15 18:08:23

BurntPizza (11 views)
2014-04-15 03:46:01

UprightPath (24 views)
2014-04-14 17:39:50

UprightPath (10 views)
2014-04-14 17:35:47

Porlus (27 views)
2014-04-14 15:48:38

tom_mai78101 (49 views)
2014-04-10 04:04:31

BurntPizza (108 views)
2014-04-08 23:06:04

tom_mai78101 (208 views)
2014-04-05 13:34:39

trollwarrior1 (176 views)
2014-04-04 12:06:45

CJLetsGame (182 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!