Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (534)
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  
  help with scrolling terrain  (Read 1114 times)
0 Members and 1 Guest are viewing this topic.
Offline mizzy

Junior Newbie





« Posted 2010-03-22 05:48:03 »

i have this class that runs the game in a vertical scrolling
i need help, what do i need to change in the codes below to make it a side-scroller(horizontal scrolling)?
and if you can tell me the exact code that needed to replace the codes below
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248  
249  
250  
251  
252  
253  
254  
255  
256  
257  
258  
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
 
public class GameMap {
 
// Terrain 1
private static final int[][] map1 = {
{10,10,10,10,10,10,10,10},
{10,10,10,10,10,10,10,10},
{10,10,10,10,10,10,10,10},
{10,10,10,10,10,10,10,10},
{10,10,12,10,1,2,3,4},
{10,10,10,10,4,5,6,7},
{3,10,10,10,7,8,9,10},
{6,10,10,10,10,10,10,10},
{9,10,1,2,3,10,10,10},
{10,10,4,5,6,12,12,12},
{10,10,7,8,9,10,11,12},
{10,10,10,10,10,10,10,10},
{10,10,10,10,10,10,10,10},
{10,10,10,12,10,10,10,10},
{10,10,10,10,10,1,2,3},
{10,10,10,10,10,4,5,6},
{10,10,10,10,10,4,5,6},
{10,10,10,10,10,4,5,6},
{10,10,10,10,10,4,5,6},
{10,11,10,10,10,7,8,9},
{10,10,10,10,10,10,10,10},
{10,10,10,12,10,10,10,10},
{10,12,10,10,10,10,10,10},
{10,10,10,10,10,10,10,10},
{10,10,10,10,10,10,10,10},
{10,10,10,10,10,10,10,10},
{3,10,10,10,10,10,10,10},
{6,10,10,10,10,10,10,10},
{6,10,11,10,1,2,3,4},
{6,12,10,10,4,5,6,7},
{6,10,10,10,7,8,9,10},
{6,10,10,10,10,10,10,10},
{9,10,1,2,3,10,10,10},
{10,10,4,5,6,10,10,10},
{10,10,7,8,9,10,10,10},
{10,10,10,10,10,10,10,10},
{12,10,10,10,12,10,10,10},
{10,10,10,10,10,10,10,10},
{2,3,10,11,10,10,10,10},
{5,6,10,10,10,10,10,10},
{5,6,11,10,1,2,3,4},
{5,6,10,10,4,5,6,7},
{5,6,10,10,7,8,9,10},
{5,6,10,10,10,10,10,10},
{8,9,10,10,10,10,10,10},
{10,10,10,12,10,10,12,12},
{10,10,10,10,10,10,10,10},
{11,10,10,10,10,10,10,10},
{10,10,10,10,10,10,10,10}
};
 
// Terrain 2
private static final int[][] map2 = {
{10,10,10,10,10,10,10,10},
{10,10,10,10,10,10,10,10},
{10,10,12,12,10,10,10,10},
{10,10,12,12,10,10,10,10},
{10,10,10,10,10,10,10,10},
{10,10,10,10,10,10,10,10},
{10,10,10,10,10,10,10,10},
{10,10,10,10,10,10,10,10},
{10,10,10,10,10,10,10,10},
{10,10,10,10,10,10,10,10},
{10,10,10,10,10,10,10,10},
{10,10,10,10,10,10,10,10},
{10,10,10,10,10,10,10,10},
{10,10,10,10,10,10,10,10},
{10,10,10,10,10,10,10,10},
{ 3,10,10,10,10,10,10,10},
{ 6,10,10,10,10,10,10,10},
{ 6,10,12,10, 1, 2,3,4},
{ 6,10,10,10, 4, 5,6,7},
{ 6,10,10,10, 7, 8,9,10},
{ 6,10,10,10,10,10,10,10},
{ 9,10, 1, 2, 3,10,10,10},
{10,10, 4, 5, 6,12,12,12},
{10,10, 7, 8, 9,10,10,10},
{10,10,10,10,10,10,10,10},
{10,10,10,10,10,10,10,10},
{10,12,10,10,10,10,10,10},
{ 2, 3,10,10,10,10,10,10},
{ 5, 6,10,10,10,10,10,10},
{ 5, 6,11,10, 1, 2,3,4},
{ 5, 6,10,10, 4, 5,6,7},
{ 8, 9,10,10, 7, 8,9,10},
{10,10,10,10,10,10,10,10},
{10,10, 1, 2, 3,10,10,10},
{10,10, 4, 5, 6,10,10,10},
{10,10, 7, 8, 9,10,10,10},
{10,10,10,10,10,10,10,10},
{12,10,10,10,12,10,10,10},
{10,10,10,10,10,10,10,10},
{ 2, 3,10,11,10,10,10,10},
{ 5, 6,10,10,10,10,10,10},
{ 5, 6,11,10, 1, 2,3,4},
{ 5, 6,10,10, 4, 5,6,7},
{ 5, 6,10,10, 7, 8,9,10},
{ 5, 6,10,10,10,10,10,10},
{ 5, 6,10,10,10,10,10,10},
{ 5, 6,10,11,10,10,10,10},
{ 5, 6,10,10,10,10,10,10},
{ 5, 6,10,10,10,10,10,10},
{ 8, 9,10,10,10,10,10,10},
{10,10,10,12,10,10,10,10}
};
 
private static final int[][] map3 = {
{10,10,10,10,10,10},
{10,10,10,10,10,10},
{ 3,10,10,10,10, 1},
{ 6,10,10,10,10, 4},
{ 6,10,10,10,10, 4},
{ 6,10,10,10,10, 4},
{ 6,10,10,10,10, 4},
{ 6,10,10,10,10, 4},
{ 6,10,10,10,10, 4},
{ 6,10,10,10,10, 4},
{ 6,10,10,10,10, 4},
{ 9,10,10,10,10, 7},
{10,10,10,10,10,10},
{10,10,10,10,10,10},
{10,10,10,10,10,10},
{10,10,10, 1, 2, 3},
{10,10,10, 4, 5, 5},
{10,10,10, 4, 5, 5},
{10,10,10, 4, 5, 5},
{10,10,10, 7, 8, 8},
{10,10,10,10,10,10},
{10,10,10,10,11,10},
{10,10,10,10,10,10},
{10,12,10,10,10,10},
{10,10,10,10,10,10},
{ 2, 2, 3,10,10,10},
{ 5, 5, 6,10,11,10},
{ 5, 5, 6,10,10,10},
{ 5, 5, 6,10,10,10},
{ 5, 5, 6,10,10,10},
{ 5, 5, 6,10,10,10},
{ 5, 5, 6,10,10,10},
{ 5, 5, 6,10,10,12},
{ 5, 5, 6,10,10,10},
{ 8, 8, 9,10,10,10},
{10,10,10,10,10,10}
};
 
// Set Constant values, the values are direct
// relation to the actually tile sizes
// defined for the terrain graphics
static final int TILE_WIDTH = 32;
static final int TILE_HEIGHT = 32;
static final int TILE_NUM_COL = 8;
int TILE_NUM_ROW;
 
static final int MAP_MOVEMENT = 2; // the rate which the map scrolls, 2 pixels per cycle

// To hold the current map
private int[][] currentMap;
 
// To hold the current terrain
private TiledLayer terrain;
 
// To hold the current background/floor color
private int groundColor;
 
// To hold the current screen, value neeeded for scrolling calculation
private int screenHeight;
 
// To hold Y position for scrolling
private int terrainScroll;
 
public GameMap(int screenHeight) throws Exception {
this.screenHeight = screenHeight;
setMap(1); // default to set to terrain 1
}
 
private int[][] mergeMaps(int[][] map1, int[][] map2) {
int[][] xMap = new int[map1.length+map2.length][8];
System.arraycopy(map1,0,xMap,0,map1.length);
System.arraycopy(map2,0,xMap,map1.length - 1, map2.length);
return xMap;
}
 
// Set Appropriate Terrain and Map
public void setMap(int level) throws Exception {
Image tileImages = null;
 
switch (level) {
case 1: tileImages = Image.createImage("/pic/terrain1.png");
currentMap = mergeMaps(map1,map2);
break;
 
case 2: tileImages = Image.createImage("/pic/terrain2.png");
currentMap = mergeMaps(map2,map3);
groundColor = 0x00DECE6B;
 
break;
 
case 3: tileImages = Image.createImage("/pic/terrain3.png");
currentMap = mergeMaps(map3,map1);
groundColor = 0x0024B400;
break;
 
case 4: tileImages = Image.createImage("/pic/terrain4.png");
currentMap = mergeMaps(map2,map1);
groundColor = 0x0024B400;
break;
}
TILE_NUM_ROW = currentMap.length;
terrain = new TiledLayer(TILE_NUM_COL,TILE_NUM_ROW,tileImages,TILE_WIDTH,TILE_HEIGHT);
 
// Map Terrain Map with actual graphic from terrain.png
for (int row=0; row<TILE_NUM_ROW; row++) {
for (int col=0; col<TILE_NUM_COL; col++) {
terrain.setCell(col,row,currentMap[row][col]);
}
}
 
terrainScroll = 1 - (terrain.getCellHeight() * terrain.getRows()) + screenHeight;
terrain.setPosition(0,terrainScroll);
}
 
public int getMapLength() {
return this.currentMap.length;
}
 
public int getMapType(int x, int y) {
return this.currentMap[x][y];
}
 
public void scrollTerrain() {
if (terrainScroll < 0) {
terrainScroll += MAP_MOVEMENT;
terrain.setPosition(0,terrainScroll);
}
}
 
// Terrain Getter
public TiledLayer getTerrain() {
return terrain;
}
 
// Ground/Floor color Getter
public int getGroundColor() {
return groundColor;
}
 
// Map Movement Getter
public int getMapScrollAmount() {
return MAP_MOVEMENT;
}
}
Offline delt0r

JGO Knight


Medals: 26
Exp: 18 years


Computers can do that?


« Reply #1 - Posted 2010-03-22 10:41:42 »

So you want someone else to write the code for you....

I have no special talents. I am only passionately curious.--Albert Einstein
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #2 - Posted 2010-03-22 10:43:33 »

This smells like homework assignment...

If you have successfully written the program to be vertically scrolling then it should be a relatively trivial matter to make it horizontally scrolling.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline mizzy

Junior Newbie





« Reply #3 - Posted 2010-03-22 11:48:18 »

This smells like homework assignment...

If you have successfully written the program to be vertically scrolling then it should be a relatively trivial matter to make it horizontally scrolling.

well this is actually a project and we just study programming by our selves
we don't have a formal lecture about this kind of stuff.
our school only teaches the very basic programming that's why i'm asking for help
Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #4 - Posted 2010-03-22 12:01:58 »

Where is the drawing code ?  Huh
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #5 - Posted 2010-03-22 21:17:34 »

did you author this code? if so then a simple hint may be sufficient for you to progress...

since vertical scrollers scroll along the Y direction, it is logical to assume that horizontal scrollers scroll along the X direction and as a starting point a simple substitution of y to x in your scrolling logic should allow a crude starting point for horizontal scrolling.
Offline ChouChou

Senior Newbie





« Reply #6 - Posted 2010-03-23 03:59:43 »

I assume vertical  scrolling is working correctly already, all you have to do is change the scrolling Y to scrolling X and there's your horizontal scrolling. You probably also want to change your maps to fit horizontal scrolling.

Your current map:
________
|              |
|              |
|              |
|              |
|              |
|              |
|_______|


Change to:

__________________
|                                  |
|                                  |
|                                  |
|_________________|


Hope that helps, if you still don't get it try this site, its written in flash, but the concept is the same.
http://www.tonypa.pri.ee/tbw/start.html
Offline mizzy

Junior Newbie





« Reply #7 - Posted 2010-03-26 01:10:24 »

I assume vertical  scrolling is working correctly already, all you have to do is change the scrolling Y to scrolling X and there's your horizontal scrolling. You probably also want to change your maps to fit horizontal scrolling.

Your current map:
________
|              |
|              |
|              |
|              |
|              |
|              |
|_______|


Change to:

__________________
|                                  |
|                                  |
|                                  |
|_________________|


Hope that helps, if you still don't get it try this site, its written in flash, but the concept is the same.
http://www.tonypa.pri.ee/tbw/start.html
thank you very much i'll try this
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.

pw (35 views)
2014-07-24 01:59:36

Riven (33 views)
2014-07-23 21:16:32

Riven (21 views)
2014-07-23 21:07:15

Riven (24 views)
2014-07-23 20:56:16

ctomni231 (55 views)
2014-07-18 06:55:21

Zero Volt (47 views)
2014-07-17 23:47:54

danieldean (38 views)
2014-07-17 23:41:23

MustardPeter (43 views)
2014-07-16 23:30:00

Cero (59 views)
2014-07-16 00:42:17

Riven (56 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!