AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Delphi-PRAXiS - Lounge Delphi-News aus aller Welt Tutorial 3.4: Adding extra info to our maps
Thema durchsuchen
Ansicht
Themen-Optionen

Tutorial 3.4: Adding extra info to our maps

Ein Thema von DP News-Robot · begonnen am 29. Apr 2020
Antwort Antwort
Benutzerbild von DP News-Robot
DP News-Robot

Registriert seit: 4. Jun 2010
15.403 Beiträge
 
#1

Tutorial 3.4: Adding extra info to our maps

  Alt 29. Apr 2020, 21:10
Before I dive too deep into making maps and drawing many different tiles, let’s see IF and HOW we can import this map into our game. And more importantly, if it contains all the features we need. I’m confident graphics wise (since I wasn’t planning spectacular features anyway), but we also need to make sure our physics and A.I. routines can deal with the map. I think so, but better be sure than sorry. As said, generic solutions often have restrictions. One way or another, there always seems to be a catch somewhere. Prince Charming with white socks. Princess Thai that happens to be a boy.




First we need to fill in some of the empty Java classes that were proposed in 3.2. And probably we can get rid of a few things as well. But let’s start with “MapInfo.java”.

public class MapInfo {
String mapName;
String mapFileName; // TMX file

// Initial state
int time; // Seconds to survive
Vector2 orbStartPos; // Initial plaement of orb
float orbStartSize; // Radius meters

// Music
// ...

// Enemy waves
// ...

} // MapInfo




A few properties I can imagine right now, but sure there is more to come. Just like images and animations, Maps are yet another type of Resource. Owned by a “MapSystem”, filled by our Game Resource file. Same old story:

public class MapSystem {

HashMap maps; // Collection

public MapSystem()
{
this.maps = new HashMap();
} // create



public void addMap( String mapFilePath )
{
// Use fileName as idName
int start = mapFilePath.lastIndexOf( '/' )+1;
int end = mapFilePath.lastIndexOf( '.' );

String idName = mapFilePath.substring( start, end );

// Make image and add to the list
MapInfo map = new MapInfo( mapFilePath );
this.maps.put( idName, map );
} // addImage


public MapInfo get( String idName )
{
return this.maps.get( idName );
} // idName


} // MapLibrary



private void loadInitial_LevelPack()
{
engine.getMapLibrary().addMap( "Maps/TestMap01.map" );
} // loadInitial_LevelPack

TestMap01.map hu? Smells fishy. I just made up a file that doesn’t exist yet. We DO have a TMX file that we just generated with the Tiled editor. But we need more than just a map. As the mostly empty MapInfo class already reveals, we have extra options. Such as the background music, or start position of the Orb.


You can in fact add such custom properties to your map in Tiled. Those are limited to primitive types though, such as strings, Booleans or numbers. Which is actually sufficient for the properties we got there, so far. But there is one more advanced type of data: "Enemy Waves".


Not all enemies appear at once while playing a map. They come in waves, and/or partially random. For example, spawn 10 weak sissies in the first minute. Then 4 heavies in the second minute. This type of information doesn’t fit in a few simple map attributes, it needs a more delicate structure.


Buuutt… We may as well solve this by creating “spawners” in Tiled. Below I created a rectangle (object). Not for drawing, but to hold spawning information. The properties suggest that after 1,5 seconds playing, enemy “Dumbass01” appears. At 9 seconds, there is a 75% chance that another Dumbass appears. Note it could be any entity. “Health crate” or something. It’s still a somewhat crude way of defining your enemy waves, but at least it beats the crap out of Notepad.



So you know what? We’ll just refer to the TMX file instead, and see how far we get with that.


private void loadInitial_LevelPack()
{
engine.getMapLibrary().addMap( "Maps/TestMap01.tmx" );
} // loadInitial_LevelPack


Weiterlesen...
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:02 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz