Organizing code

Hello Guys. After a long time I’m starting a new project using openFL. It is a collection of mini games. Now I remember I read a while ago that I can organize the code in a way that I can create some “base units” (shared by all games) and then code the implementation of each game separatedly. But I can’t find any related post on how to do it. If anyone can point me where to start reading about that. I would really appreciate.

With regards
Luis

1 Like

That might not be the help you need, but I’d say just do it. Do a first game, then another, and then you’ll have a good feeling of what you can reuse and where.

By planning too far ahead you risk not actually making the games.

2 Likes

Thanks a lot for your advice, I really appreciate them and I agree 100% with you. However this is a project to recode an old set of games already developed in Macromedia Director ( Shockwave, the predecessor of flash!). For that I am 100 % sure on what I need to reuse and where.

Thanks again.
Luis

1 Like

If you have set of mini games, then you can develop them separately, an then call it from main file as string:

var game1:Dynamic=Type.createInstance(Type.resolveClass("com.yourpackage.Game1"));
addChild(game1);

In this case you ca have a lobby with buttons references to your mini games and run them from one place.

When there are many mini-games, I tend to organise everything using a base-project-xml and a separate mini-game-project-xml and then a separate common-asset-project-xml. Something like this:

Main XML

<?xml version="1.0" encoding="utf-8"?>
<project>
	
	<meta title="" package="myapp.something.something" version="1.0.0" company="" />
	<app main="myapp.Main" path="Export" file="Main" preloader="myapp.Preloader" />
 	 <assets path="assets/common/fonts" rename="fonts" include="*.ttf" /> 
 	<template path="assets/index.html" rename="index.html" />
 	<window width="960" height="640" if="flash" />
	<window width="960" height="640" if="html5" />
 	<source path="src" />
 	<haxelib name="openfl" />
	<haxelib name="actuate" />
 	<haxelib name="swf" />
	
 		 <include path="penalty-shootout-assets.xml" />  
		 <!-- <include path="hoopshoot-assets.xml" />   -->
		<!-- <include path="beatthebomb-assets.xml" /> -->
	 
		<include path="common-assets.xml" />  
		<icon path="assets/openfl.svg" />
		<haxelib name="swf" />
		<haxedef name ='canvas'/>

 </project>

Mini Game XML:

<?xml version="1.0" encoding="utf-8"?>
<project>
 
	<meta title="Penalty Shootout" package="myapp.something.something" version="1.0.0" company="" />
<assets path="assets" rename="assets" exclude="*.svg" />

 	<assets path="assets/penaltyshootout/fonts" rename="fonts" include="*.ttf" embed="true" />	 
	<haxelib name="swf" />
	
	<assets path="assets/penaltyshootout/audio" rename="audio" if="web">
 		<sound path="background-music-1.mp3" id="background-music-1" />
 		<sound path="boo.mp3" id="boo" />
  
     </assets>
 		
 	<assets path="assets/penaltyshootout/audio" rename="audio" if="html5" />

	<library   path="assets/penaltyshootout/assets.swf"  preload="true" />
 	
	<haxedef name="penaltyShootout" /> 
	
</project>

Common Assets XML

<?xml version="1.0" encoding="utf-8"?>
<project>
 		 
 		<assets path="assets/common/audio" rename="audio" unless="web">
 		<sound path="correct.mp3" id="correct" />
 		<sound path="wrong.ogg" id="wrong" />	
 		<sound path="explosion.ogg" id="wrong" />	
 		</assets>
	
	
		<assets path="assets/common/audio" rename="audio" if="web">
 		<sound path="correct.mp3" id="correct" />
		<sound path="wrong.mp3" id="wrong" />	
		<sound path="explosion.mp3" id="explosion" />	
 		</assets>

</project>
1 Like