Quick screen grab from my first big project, more details coming soon!
Follow the learning and progress of a waiter who wants to make games. Java, Android and Game Development. Includes code snippets, book reviews and recommendations, game analysis and concept sketches!
Showing posts with label Game Development. Show all posts
Showing posts with label Game Development. Show all posts
Tuesday, 12 January 2016
Monday, 7 September 2015
MediaPlayer experiments
When working with the media player there are some little things I have found that you need to keep an eye out for. The first is that the MediaPlayer object is quite happy to continue playing your media track after you have closed the app itself. This is an example of how important it is to release all resources and to monitor which ones persist in the memory of the device! While bumming around on the android developer website, I started looking into the billing API and found another example in the Google Payments "Binding" when an in-app purchase is attempted. When an app closes, if that binding is not released, it can use up system resources and degrade performance.
My experiments with the media player began with finding a question on the learnandroid subreddit, which asked about pausing media with a touchevent. From my reading I could see that the poster had not prepared the media track after stopping it, something which is unique to that circumstance but not the pause method. The poster also had a bit of confusion about the touch event itself and where to trigger the media playing. After posting a quick suggestion I decided that I should try to implement a music player in a test app too to get to grips with the little things that might be confusing for a beginner.
Following on from my blank screen SurfaceView test, I used VLC to convert a ripped mp3 into the OGGVorbis format with reduced sound quality (to save on memory) and added that into a new assets folder. From my previous experiemnts with Soundpool (An app with pikachu on it that says pikachu when you touch the screen, and plays a computer booting up sfx from pokemon firered on launch), I knew that sound files can be retrieved using the AssetManager in android. I made the first mistake in not putting the new directory in the right place in the file structure, but that didn't become apparent until it was fully set up.
My first set up was to have all of the media player implemented in the SurfaceView class itself, which is a Runnable in a class called Screen. The implementation included instantiating an asset manager, trying to get the file i wanted an AssetFileDescriptor which I could pass into a new instance of MediaPlayer. The process itself was all set up and the data source set and media started, but the app itself didn't work. After adding some Log notes and an exception message for the try-catch block I found that the asset manager wasn't retrieving the files in the folder, and looked back to my original pikachu app to find the structure difference.
Once the file was able to load and play I ran the app and lo and behold, the music played, (Nine Inchnails- Satellites for those who need to know!). I was elated, then I closed the app and hmm.. still music.
I knew this had something to do with releasing the resources and the activity life cycle so I started to look there for ways to control my music. I started with onStop, onPause and onResume methods inside my SurfaceView which were called from the main activity, and implemented checks for if the media player was valid and playing etc, and stopped the music and restarted it as I expected. This did not work. The app was happy enough to stop the music but not to restart it when the app was loaded up again. I understood that the app was saved in temporary memory when the app was minimized or obscured, so the app was going through the onPause method, but I didn't realize the onStop method was being called also!
Going back I was able to debug my app and place appropriate boolean flags to control the music playing. In the onPause method, the music is (if it is not already) paused, and on resume the music is (if not null such as on initial bootup of the app) started again. The call to onStop was moved into an if block which checked that the app was not being closed fully (isFinishing()) and if so, stopped playback and also released the media player.
With my experiment finally performing the way I wanted it to, I was finally able to begin abstracting the audio into a seperate class. I created an Audio class that could handle music using static methods, which would mean it is accessible throughout my app. Instead of using a default constructor to set up the Audio environment, I opted instead to use static methods that only initialize variables if they are going to be used. I currently have a method that is needed to pass in a context for use in attaining the assets, but later on I will access this statically from a core class that handles the game.
The Audio class also has onPause, onResume and onStop methods which can be called to ensure that any active media, be it sound FX from the soundPool or music from MediaPlayer are paused and resumed correctly, and destroyed on closing the app.
I am really quite happy with the progress I am making in understanding these (albeit simple) aspects of app development. I want to be able to say not only that I understand the theory, but that I can put code on paper to describe the processes and show that I understand the way these systems work together on a more holistic level.
The code for my Audio and Screen app are linked below for viewing.
MainActivity Class
Audio Class
SurfaceView Class
My experiments with the media player began with finding a question on the learnandroid subreddit, which asked about pausing media with a touchevent. From my reading I could see that the poster had not prepared the media track after stopping it, something which is unique to that circumstance but not the pause method. The poster also had a bit of confusion about the touch event itself and where to trigger the media playing. After posting a quick suggestion I decided that I should try to implement a music player in a test app too to get to grips with the little things that might be confusing for a beginner.
Following on from my blank screen SurfaceView test, I used VLC to convert a ripped mp3 into the OGGVorbis format with reduced sound quality (to save on memory) and added that into a new assets folder. From my previous experiemnts with Soundpool (An app with pikachu on it that says pikachu when you touch the screen, and plays a computer booting up sfx from pokemon firered on launch), I knew that sound files can be retrieved using the AssetManager in android. I made the first mistake in not putting the new directory in the right place in the file structure, but that didn't become apparent until it was fully set up.
My first set up was to have all of the media player implemented in the SurfaceView class itself, which is a Runnable in a class called Screen. The implementation included instantiating an asset manager, trying to get the file i wanted an AssetFileDescriptor which I could pass into a new instance of MediaPlayer. The process itself was all set up and the data source set and media started, but the app itself didn't work. After adding some Log notes and an exception message for the try-catch block I found that the asset manager wasn't retrieving the files in the folder, and looked back to my original pikachu app to find the structure difference.
Once the file was able to load and play I ran the app and lo and behold, the music played, (Nine Inchnails- Satellites for those who need to know!). I was elated, then I closed the app and hmm.. still music.
I knew this had something to do with releasing the resources and the activity life cycle so I started to look there for ways to control my music. I started with onStop, onPause and onResume methods inside my SurfaceView which were called from the main activity, and implemented checks for if the media player was valid and playing etc, and stopped the music and restarted it as I expected. This did not work. The app was happy enough to stop the music but not to restart it when the app was loaded up again. I understood that the app was saved in temporary memory when the app was minimized or obscured, so the app was going through the onPause method, but I didn't realize the onStop method was being called also!
Going back I was able to debug my app and place appropriate boolean flags to control the music playing. In the onPause method, the music is (if it is not already) paused, and on resume the music is (if not null such as on initial bootup of the app) started again. The call to onStop was moved into an if block which checked that the app was not being closed fully (isFinishing()) and if so, stopped playback and also released the media player.
With my experiment finally performing the way I wanted it to, I was finally able to begin abstracting the audio into a seperate class. I created an Audio class that could handle music using static methods, which would mean it is accessible throughout my app. Instead of using a default constructor to set up the Audio environment, I opted instead to use static methods that only initialize variables if they are going to be used. I currently have a method that is needed to pass in a context for use in attaining the assets, but later on I will access this statically from a core class that handles the game.
The Audio class also has onPause, onResume and onStop methods which can be called to ensure that any active media, be it sound FX from the soundPool or music from MediaPlayer are paused and resumed correctly, and destroyed on closing the app.
I am really quite happy with the progress I am making in understanding these (albeit simple) aspects of app development. I want to be able to say not only that I understand the theory, but that I can put code on paper to describe the processes and show that I understand the way these systems work together on a more holistic level.
The code for my Audio and Screen app are linked below for viewing.
MainActivity Class
Audio Class
SurfaceView Class
Thursday, 27 August 2015
Return to Game Development
Recently I have moved away from the Udacity course and tried to get back on track with the game development that I have wanted to do all along. I have returned my studies to Beginning Android Games, an Apress book I got a while back. When I first started trying to learn from this book I found the information to be far too heavy, I was not experienced enough with the Android OS to get it. Now that I have a better understanding, the pieces are coming together much easier.
While working through the examples, I have been playing around with the code and finding out the OTHER methods that some of the classes do. While I had made a game on Android following a "For Dummies" book in the past, this time I actually understand the process, the effect that the Activity Life Cycle has, and can see where the ideas I have fit into the code.
To help me keep notes and have an "in my own words" reference, I have been typing up notes into Google Keep, an app I have had on my phone for a long time and rarely used. Being able to type quickly has always prevented me from note-taking on my phone. I am a terrible touch screen typist! Using the in-browser version of Google Keep has been a lifesaver- actual keyboard typing, and sync to my phone for on the go note revision. I have found myself memorizing key concepts quicker with these notes, and can now comfortably say that an extremely basic framework in a regular View can flow pretty quickly from my fingers. I do enjoy making notes and even updating them to make them more precise, but I can't always be at my laptop- for this reason I have contemplated buying a bluetooth for a while. (I have planned to buy a tablet for myself for quite a while now and really wanted a keyboard for it- so I have been watching Amazon and Bestbuy for a deal daily!) I finally ordered myself a keyboard last night, and hopefully that gives me more opportunities to be productive- either in writing up ideas, taking notes or coding when I am not limited by the amount of time I can comfortably sit at the computer.
As an example of the notes I have been keeping, here is my first entry!
Soundpool is a RAM based storage for small soundFX files, ideally in .ogg format and shorter than about 5 seconds. Setting up a SoundPool requires the parameters indicating how many sounds can play simultaneously (20 is a good default), which sound stream is being used (AudioManager.STREAM_MUSIC for media of any type), and a final unused parameter, default 0.
SoundPool sp = new SoundPool(20, AudioManager.STREAM_MUSIC, 0);
The SoundPool default constructor has been deprecated with the release of Lollipop, and now utilises a Builder for instantiating a SoundPool object.
SoundPool sp = SoundPool.Builder()
.setUsage(audioAttributes)
.setStream()
.build();
To load a soundFX file to the Pool, you have to get an AssetFileDescriptor from the Asset file.
AssetManager assetManager = context.getAssets();
AssetFileDescriptor asset1 = assetManager.openFD("dir/filename.extension");
When adding the descriptor to the soundpool, it will return an integer which identifies the sound loaded, which can be used as a parameter later. It is vital therefore that any files loaded be done so in an integer expression. the load method itself will take in the AssetFileDescriptor and a sound priority int as parameters. The sound priority is currently unused as is default as 1 (similar I guess to the weight attribute in xml layouts, having them all at 1 gives uniform importance).
int asset1IdNum = sp.load(asset1, 1);
This asset can later be played using the SoundPool instance, by referencing the identifier for the resource, as well as some other parameters.
sp.play(identifierInt, float leftChannelVolume, float rightChannelVolume, int priority, int looping, float playbackSpeed)
The channelVolume parameters allow a sound to be set on one ear or the other. The priority again is unused and is defaulted to 0. Looping is often not a good idea for a sound effect and is thus set to 0, and playback speed will be 1 by default, less for slow play and more for fast playback.
When all use of the SoundPool is done, it is best practice to release the resources directly by using either specific calls to soundPool.unload(identifierInt) or to all resources using soundPool.release();
I have made notes on MusicStream, working with the View and onDraw() method (invalidating as a method of continuous graphics rendering), setting the application to keep the screen on, go fullscreen and hide the notification bar and working in SurfaceView and Threads.
I'm hoping that my notes will not only enable me to retain information better, but also that they may help me to guide others if they ask me for advice on starting on a similar path!
There are notes I have to include after todays coding to describe how to set a listener for loading files, as I wanted to have a specific sound effect play as my testing app opens (computer booting up sound effect from a monster catching game you may have heard of!)
While working through the examples, I have been playing around with the code and finding out the OTHER methods that some of the classes do. While I had made a game on Android following a "For Dummies" book in the past, this time I actually understand the process, the effect that the Activity Life Cycle has, and can see where the ideas I have fit into the code.
To help me keep notes and have an "in my own words" reference, I have been typing up notes into Google Keep, an app I have had on my phone for a long time and rarely used. Being able to type quickly has always prevented me from note-taking on my phone. I am a terrible touch screen typist! Using the in-browser version of Google Keep has been a lifesaver- actual keyboard typing, and sync to my phone for on the go note revision. I have found myself memorizing key concepts quicker with these notes, and can now comfortably say that an extremely basic framework in a regular View can flow pretty quickly from my fingers. I do enjoy making notes and even updating them to make them more precise, but I can't always be at my laptop- for this reason I have contemplated buying a bluetooth for a while. (I have planned to buy a tablet for myself for quite a while now and really wanted a keyboard for it- so I have been watching Amazon and Bestbuy for a deal daily!) I finally ordered myself a keyboard last night, and hopefully that gives me more opportunities to be productive- either in writing up ideas, taking notes or coding when I am not limited by the amount of time I can comfortably sit at the computer.
As an example of the notes I have been keeping, here is my first entry!
Soundpool is a RAM based storage for small soundFX files, ideally in .ogg format and shorter than about 5 seconds. Setting up a SoundPool requires the parameters indicating how many sounds can play simultaneously (20 is a good default), which sound stream is being used (AudioManager.STREAM_MUSIC for media of any type), and a final unused parameter, default 0.
SoundPool sp = new SoundPool(20, AudioManager.STREAM_MUSIC, 0);
The SoundPool default constructor has been deprecated with the release of Lollipop, and now utilises a Builder for instantiating a SoundPool object.
SoundPool sp = SoundPool.Builder()
.setUsage(audioAttributes)
.setStream()
.build();
To load a soundFX file to the Pool, you have to get an AssetFileDescriptor from the Asset file.
AssetManager assetManager = context.getAssets();
AssetFileDescriptor asset1 = assetManager.openFD("dir/filename.extension");
When adding the descriptor to the soundpool, it will return an integer which identifies the sound loaded, which can be used as a parameter later. It is vital therefore that any files loaded be done so in an integer expression. the load method itself will take in the AssetFileDescriptor and a sound priority int as parameters. The sound priority is currently unused as is default as 1 (similar I guess to the weight attribute in xml layouts, having them all at 1 gives uniform importance).
int asset1IdNum = sp.load(asset1, 1);
This asset can later be played using the SoundPool instance, by referencing the identifier for the resource, as well as some other parameters.
sp.play(identifierInt, float leftChannelVolume, float rightChannelVolume, int priority, int looping, float playbackSpeed)
The channelVolume parameters allow a sound to be set on one ear or the other. The priority again is unused and is defaulted to 0. Looping is often not a good idea for a sound effect and is thus set to 0, and playback speed will be 1 by default, less for slow play and more for fast playback.
When all use of the SoundPool is done, it is best practice to release the resources directly by using either specific calls to soundPool.unload(identifierInt) or to all resources using soundPool.release();
I have made notes on MusicStream, working with the View and onDraw() method (invalidating as a method of continuous graphics rendering), setting the application to keep the screen on, go fullscreen and hide the notification bar and working in SurfaceView and Threads.
I'm hoping that my notes will not only enable me to retain information better, but also that they may help me to guide others if they ask me for advice on starting on a similar path!
There are notes I have to include after todays coding to describe how to set a listener for loading files, as I wanted to have a specific sound effect play as my testing app opens (computer booting up sound effect from a monster catching game you may have heard of!)
Sunday, 28 June 2015
3 Way Battle Simulation
So in my previous post I made reference to a simulation of battles between Mages, Rangers and Warriors. Just thought I'd post it here for anyone to look through and play with! The Barracks.java class is the runnable, and will output a .rep file (simple text document, open with Notepad) with the breakdown of the battle. It wouldn't be too hard to add more info to the report. you can tweak the attack power and defense or any of the other stats for each of the classes.
Mob Class (Parent for the three rpg-classes)
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 | package saving; import java.io.Serializable; @SuppressWarnings("serial") public class Mob implements Serializable{ int maxHealth; int health; String name; int attack; double defence; double accuracy; double dodge; String type; private String battleReport = null; private String attackReport = null; private boolean isAlive; public Mob(){ isAlive = true; } public void takeDamage(int damage){ int absorb = (int) (damage * defence); if(damage - absorb >= 1){ health -= (damage - absorb); } battleReport = name + " absorbs " + absorb + " damage.\n" + name + " takes " + (damage - absorb) + " damage\nHealth remaining: " + health + "\n"; if(health <= 0) { health = 0; isAlive = false; } } public void attack(Mob enemy){ attackReport = null; battleReport = null; enemy.attackReport = null; enemy.battleReport = null; attackReport = (name + " is attacking " + enemy.name); if(Math.random() > accuracy){ // Missed attackReport += "\nAttack missed. End of attack."; enemy.battleReport = enemy.name + " is unharmed\n"; return; } if(Math.random() < enemy.dodge){ // Dodged attackReport += "\n" + enemy.name + " dodged the attack. End of attack.\n"; enemy.battleReport = enemy.name + " is unharmed\n"; return; } int attackDamage = attack; if ((type.equals("Orc") && enemy.type.equals("Elf")) || (type.equals("Human") && enemy.type.equals("Orc")) || (type.equals("Elf") && enemy.type.equals("Human"))){ attackDamage *= 1.2; attackDamage -= Math.random() * attackDamage; } else if((type.equals("Orc") && enemy.type.equals("Human")) || (type.equals("Human") && enemy.type.equals("Elf")) || (type.equals("Elf") && enemy.type.equals("Orc"))){ attackDamage *= 0.8; attackDamage -= Math.random() * attackDamage + 1; } enemy.takeDamage(attackDamage); } public void heal(int hpUp){ health += hpUp; if(health > maxHealth) health = maxHealth; } public String toString(){ return "MOB: " + this.hashCode() + "\nHealth: " + health +"\nAlive: " + isAlive; } public boolean isAlive(){ return isAlive; } public String getBattleReport(){ return battleReport; } public String getAttackReport(){ return attackReport; } }
|
Main Class - Barracks.java
Edit the COMBATANTS constant to change how many mobs are in each army, note, it will take a lot longer to run if you go too high!
1000 combatants (3,000 total) took approx 0.5 seconds
10,000 combatants (30,000 total) took approx 5 seconds
100,000 combatants (300,000 total) took approx 62 seconds
1,000,000 Could not run, Out of Memory.
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 | package saving; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; public class Barracks { private final int COMBATANTS = 500; // exceed 100,000 at your own risk. private int skirmishes; @SuppressWarnings("rawtypes") private ArrayList<ArrayList> mobs; public static void main(String[] args) { Barracks b = new Barracks(); b.go(); } public void go(){ long startTime = System.currentTimeMillis(); System.out.println("Starting simulation: Number of Combatants per army = " + COMBATANTS); // Armies of Mobs ArrayList<Orc> orcs = new ArrayList<Orc>(); ArrayList<Elf> elves = new ArrayList<Elf>(); ArrayList<Human> humans = new ArrayList<Human>(); // Populate armies for(int i = 0; i < COMBATANTS; i++){ orcs.add(new Orc("Warrior" + i)); elves.add(new Elf("Ranger" + i)); humans.add(new Human("Mage" + i)); } // Armies added to array list mobs = new ArrayList<>(); mobs.add(orcs); mobs.add(elves); mobs.add(humans); try { // Create text report FileWriter fw = new FileWriter("BattleReport.rep"); BufferedWriter bw = new BufferedWriter(fw); // Report title bw.write("Battle between " + COMBATANTS + " orcs, elves and Humans:"); // Main simulation loop while(!orcs.isEmpty() && !elves.isEmpty() && !humans.isEmpty()){ // While all armies have combatants, select to opposite faction mobs int class1 = (int) (Math.random() * 3); int mobNum = (int) (Math.random() * mobs.get(class1).size()); Mob fighter1 = (Mob) mobs.get(class1).get(mobNum); // Prevent same faction skirmish int class2 = (int) (Math.random() * 3); while(class2 == class1){ class2 = (int) (Math.random() * 3); } int mob2Num = (int)(Math.random() * mobs.get(class2).size()); Mob fighter2 = (Mob) mobs.get(class2).get(mob2Num); // Actual skirmish fighter1.attack(fighter2); // Get report on actions taken bw.write("\n" + fighter1.getAttackReport()); // Get report on hits taken and damage mitigation bw.write("\n" + fighter2.getBattleReport()); // If damage is taken, increment skirmishes counter if(fighter2.getBattleReport().contains("takes")){ skirmishes++; } if(!((Mob) mobs.get(class1).get(mobNum)).isAlive()){ mobs.get(class1).remove(mobNum); } else if(!((Mob) mobs.get(class2).get(mob2Num)).isAlive()){ mobs.get(class2).remove(mob2Num); } } long delta = System.currentTimeMillis() - startTime; double elapsedTime = delta / 1000.0; System.out.println("Ending simulation: Number of Skirmishes = " + skirmishes + "\nTime taken: " + elapsedTime + "sec"); // Write out summary of battles bw.write(battleReport()); bw.close(); }catch (IOException e){ } } public String battleReport(){ String report = null; // Find defeated army and display remaining enemies and total skirmishes if(mobs.get(0).isEmpty()){ report = "\nOrcs are defeated" + "\n" + mobs.get(1).size() + " Elves remain" + "\n" + mobs.get(2).size() + " Humans remain"; } else if (mobs.get(1).isEmpty()){ report = "\nElves are defeated" + "\n" + mobs.get(0).size() + " Orcs remain" + "\n" + mobs.get(2).size() + " Humans remain"; }else if (mobs.get(2).isEmpty()){ report = "\nHumans are defeated" + "\n" + mobs.get(0).size() + " Orcs remain" + "\n" + mobs.get(1).size() + " Elves remain"; } return (report + "\n" + skirmishes + " total Skirmishes"); } } |
Elf.java - The Ranger class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | package saving; @SuppressWarnings("serial") public class Elf extends Mob{ public Elf(String name){ super(); this.name = name; maxHealth = 180; health = maxHealth; type = "Elf"; attack = 16; defence = 0.15; accuracy = 0.95; dodge = 0.06; } } |
Orc.java - The Warrior class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | package saving; @SuppressWarnings("serial") public class Orc extends Mob{ public Orc(String name){ super(); this.name = name; maxHealth = 150; health = maxHealth; type = "Orc"; attack = 20; defence = 0.30; accuracy = 0.85; dodge = 0.1; } } |
Mage.java - The Mage class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | package saving; @SuppressWarnings("serial") public class Human extends Mob{ public Human(String name){ super(); this.name = name; maxHealth = 140; health = maxHealth; type = "Human"; attack = 30; defence = 0.12; accuracy = 0.90; dodge = 0.05; } } |
A bit of background
Self learning ain't easy
Being a self taught programmer and game designer is definitely not going to be easy, I am already finding the task of finding good material to learn from to be a problem. Often when I am finished with one resource, the next either assumes a greater level of knowledge or falls back to basics.
My main resources for learning Java have so far been:
- Codecademy: My first look at coding was the Javascript track which I began playing with just from curiosity. While this is not the best track to learn programming, at the time this was the only one available. Ruby and Python came later with redesigned tracks to support the programming route as a whole.
- CS106A Stanford Programming Methodology: Lectures by Professor Mehran Sahami
This series of lectures is available on Youtube and has assignment material available via the Stanford website. This course first introduced me to Java with Karel, the little robot. - Java - An introduction to Problem Solving and Programming: Walter Savitch (5th Edition)
This textbook was donated to me by a work colleague who had taken the course as part of her university education but had no interest in pursuing it further. The book helped me to move away from the safe environment of Stanford's custom Java work space and onto making my own applications within Eclipse. I am currently using Eclipse Luna version 4.4.1 - TheCherno: Youtube Game Programming series
This series was a love/hate one, I enjoyed the coding and following along with a project and being able to tinker was very fun, but I think while the aim was for newer programmers to use this series as an introduction to game programming, it sometimes left me wondering what the heck I was doing. I stopped following this series after about 60 episodes but it definitely contributed to inspiring my continuation of studies. - After a period of stagnation and loss of direction, I finally found Head First Java, which took a couple of attempts for me to work with. At first I found the quirky sense of humor to be annoying and tired of it. It took another couple of months before I gave it another try (following some reddit advice) and got through my brick wall.
The game I am working on designing and coding is an economic simulation in a food service setting. My ideas have been littered around my apartment in different forms without any direction, but the book is helping me to organize my approach. It's still important to write down or doodle my ideas, but I am now trying to keep the wild "this feature would be amazing!" type ideas from taking up too much time. Once I have a working prototype and my core mechanics working properly, then the features will be tested and discarded or developed as necessary.
I have also been looking into keeping an offline private wiki as a means to keep all ideas and documents I write accessible from one place. For this I have started learning to use a program called Wikidpad. With such little organization so far, there's not much to put into a wiki but as I bring my design ideas together and throw away the garbage, I intend to post snippets of wiki pages for people to read here too.
Simulations
My main interest is in simulations, and as I have gained new skills I have done my best to create small scenarios in code that behave in ways typical of simulations. For instance, once I learned about ArrayList and the QueueBlocking Arrays, I put together a background service in the mini restaurant testing program I have to create parties of guests at random intervals, assigning them to different Queues based on the size of the party, and limiting the combined total number of queueing parties. When a "table" became available, the service (nicknamed the Hostess) would assign an appropriate sized party to the empty table and free up a space in the queue.
More recently, while learning about serialization techniques, I created a mini simulation based on the classic fantasy triangle of damage. Warrior > Ranger > Magic User > Warrior. This is a common strengths/weakness model, most notably for me found in Runescape. The simulation pitted armies of each type into a war where each of the three types is randomly paired into a skirmish with a member of one of the other armies. Their fight gave an outcome and eventually all members of an army died and the results were saved out to a text file.
An example of the output is shown to the right, of a battle between 50 "mobs" per army. It was very fun to tweak some of the stats I had given each class to see how the outcome was affected. Getting the numbers to become pretty fair was surprisingly sensitive, as even a slight increase or decrease to a stat sometimes swung the outcome a completely different direction.
This type of simulation taught me a lot about how to work with arrays and random number generation. Having to check the arrays for "dead" mobs and delete them, creating damage and damage absorption that is calculated on the fly in each skirmish and even adding in a dodge and accuracy stat really mixed up the outcomes.
Starting simulation: Number of Combatants per army = 500
Ending simulation: Number of Skirmishes = 2806
Time taken: 0.279sec
Starting simulation: Number of Combatants per army = 500
Ending simulation: Number of Skirmishes = 2806
Time taken: 0.279sec
Moving forward
My intention with this blog is to create a place for new programmers to look to see my trials and tribulations. If anyone can gather any knowledge, resources or inspiration from me then this blog will have served a purpose. For my own needs, I want to use this as a place to summarize my studies, hold myself accountable, and also to see where I was at a particular stage of my journey. Please feel free to get in touch if you have any questions or comments. Thanks for reading!
Subscribe to:
Posts (Atom)
