Flexibility

Lately as i have had time, i have added coins to PhoneDash whereby the coins are added to each platform. Naturally, I have added sounds...or a pinging sound for when the coins are collected. Its changed the Dynamic of the game quite a lot.  

<InsertScreenShotHere>

Once in a while you have an idea of what would work well for something. I work with software in the day, and constantly have the fear that the code you write is not very flexible for your unit testing / Integration testing. It got me thinking of what would make the game flexible whereby it would be relatively easy to add new levels. My first thought was to store levels in a file somewhere, thus adding the flexibility of adding things quite easily. Sadly...the code that i have wrote it pretty much tightly coupled to the gamescene that I have created. I've seperated my skspritenodes into classes so they can be instantiated quite easily but the bulk of the game logic has gone into the update function.

My aim for this week is to make it flexible so that the scene will load up files from a directory and the allow the player to select each level. This will mean that I need to create some xml schema that the game abides by.

Having sat down on the sofa today, and did a little search - I found something called a plist (property list). I believe this to be the file that I can store my level data in. A quick brain dump of what should be in my levels resulted in the following that should translate to some level...how this works, I am not entirely sure. I know it's quite rough...but hopefully I am on the right path :)

<Level>
	<ConfigData>
			<SpaceBetweenPlatforms />
			<Gravity />
			<Speed />
			<CanPickupCoins />
			<CoinToPlatformRatio />
			<MonsterGenerationWeight />
			<Music />
	</ConfigData>
	<MonsterData>
		<Monsters>
			<Monster1/>
			<Monster2/>
			<Monster3/>
		 </Monsters>
	</MonsterData>
	<Backgrounds>
		<BackGrounds1/>
		<Background2/>
		<Background3 />
	</backgrounds>
	<Platforms>
		<Platform />
		<WoodenPlatform/>
		<SmallPlatform>
			<PlatformActions/>
		</SmallPlatform>
	</Platforms>
</Level>

 

 

The aim of this exercise is to make the game configurable so that all the logic is not coded into the scenes and every time a change needs to be done, the scene does not need to be added for a new level. Levels must be quite easy to add. :)

A quick google resulted in the following
https://www.raywenderlich.com/87232/make-game-like-mega-jump-sprite-kit-swift-part-2

 

 

Add comment

Loading