Sunday, July 28, 2013

Source Code of the Universe: My First Game Pt. 2

So, after thinking on it for awhile, I realized that the JLabel, location, and the JTextAreas, view and comm, need to be declared as global variables, as they will be manipulated by other methods. Also, added a line wrap to JTextArea view, as it will contain enough words to require it. I thought I was going to use ActionListener to tell when the user pressed ENTER. Looking into it, I found that using a key binding was a better choice.

My first attempt at using the key binding involved attaching the binding to the component most affected by it: the JTextArea called comm. It's where the user will type the commands. When the user presses the ENTER button on the keyboard, I want the program to take what the user has typed and submit it to a method that will check the text for keywords. However, when the binding code is attached to comm, the program only recognizes the button press when that component is in focus. If the user has clicked elsewhere on the window before pressing ENTER, nothing will happen. I need to attach the code to the entire window instead of just that component, so that the event will trigger whenever the ENTER button is pressed, not just when that one component is in focus. Granted, it will be rare for the user to press ENTER after selecting a different component, but I want to cover those rare instances. Especially if I ever want to add timed events to this project, or future projects that use this same engine. I don't need the user feeling added frustration at failing a timed event because the comm component accidentally lost focus before he or she could press ENTER. As it turns out, all I have to do to accomplish this attach the binding to the view component as well. The code ends up looking like this:


comm.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "inputComm"); comm.getActionMap().put("inputComm", inputComm); view.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "inputComm"); view.getActionMap().put("inputComm", inputComm);

Now, not matter where you click in the window, the program recognizes when you press the ENTER button. Next step is to take whatever the user has typed into the text area, pass it to a method that will check it against available commands, and clear the text area so it is ready to have another command typed into it. Also, I think I am going to add in the functionality of letting the user instantly retype the last command entered by pressing the down button, like DOS used to. Just in case you wanted to do the same thing again, or if you typed something wrong and wanted to try that command again after correcting the error without having to retype the entire thing. This requires another global String variable called lastComm.

Next time, we examine the method that looks at the commands the user give the program!

Tuesday, July 16, 2013

Source Code of the Universe: My First Game Pt. 1

So, I've been reading a blog known as Twenty Sided. It started out as a D&D blog, hence the name, but has become a lot more since. On it, Shamus Young talked about writing a program that procedurally created a night-time cityscape. Reading about his adventures in programming made me start itching really bad to do some programming myself.

I've always loved programming. I'm not great at it, not even good at it, but I do love it. I started with QBasic on Windows 95/98. I tried to make an Interactive Fiction game with it, but never finished it. I didn't know enough to even have a working inventory. After that, I dabbled a little in C++, but my real know-how, if it can actually be called that, is in Java. That's the language I studied in College, and the one I know the most about. I like it because it seemed a lot easier than C++ (though it as been a while since I tried C++), yet was still capable of a lot, and was easily portable to other platforms. As in, no additional programming required because it runs in its own environment.

My idea for my current project isn't as grand as a 3D cityscape, but it's probably the biggest project I've attempted. I'm revisiting my IF roots, and I'm going to try and make a really short, and really crappy Interactive Fiction game, complete with multiple endings and a fully functional inventory system. We'll see what the final project ends up looking like.

The first thing I need to do before I ever even touch a code editor is figure out what I'm doing. I have a story in mind: You are the Hero of the Universe, though no one knows that because you haven't saved shit, yet. You are looking for the mythical Biforce, which has the power to destroy the Great Evil that has descended upon the galaxy. You have tracked it's location to a dinner on the edge of the Galaxy, and, after a thorough search, have come to the conclusion that there is only one place it could possibly be - the women's bathroom. As you are the Hero of the Universe, and not the Heroine Of the Universe, this poses a problem. Especially with the big, burly guard that won't let males into the bathroom. Apparently, they've had issues with that sort of thing.

So, that's my premise. The game takes place entirely within the dinner, and there are only three rooms: the main dining area, the men's room, and the ladies' room. Maybe one or two other areas as the story requires, but that's really it. I have at least one solution in mind, and an idea of how I'm going to set everything up, so I guess I can dive into the fun part for awhile.

The first thing to do, programming wise, is set up the additional Classes I'm going to need for this program. I'm going to use two, one for the rooms/areas, and one for the objects in those rooms/areas. Let's see what we can do.


public class Object { String name = ""; String shortDiscrp = ""; String longDiscrp = ""; boolean inInv = false; Object(String n, String s, String l) { name = n; shortDiscrp = s; longDiscrp = l; } } public class Room { String name = ""; String shortDiscrp = ""; String longDiscrp = ""; String[] objects; Room(String n, String s, String l, String[] o) { name = n; shortDiscrp = s; longDiscrp = l; objects = o; } }

This is a very simple start. I can't, yet, think of everything these classes need (or maybe I have), but I can go back and add more stuff in later if the program requires it. Yes, I realize that this is not the proper way to program. You're supposed to know what it is you code is going to do before you start typing. However, when working for fun, I like to take the approach of coding is like painting; you start off with the basic colors, and add more detail as you go. That, and I'm just too lazy to write out all of that before I get to the fun part.

Now, to set up the Main method and get our opening screen to display.


public static void main(String[] args) { JFrame biforce = new Biforce(); biforce.setVisible(true); } public Biforce() { setTitle("Biforce"); setSize(1000,700); setLocation(300, 100); setLayout(new GridBagLayout()); GridBagConstraints gBC = new GridBagConstraints(); setDefaultCloseOperation(EXIT_ON_CLOSE); getContentPane().setBackground(new Color(100, 100, 100)); gBC.fill = GridBagConstraints.HORIZONTAL; gBC.gridx = 0; gBC.gridy = 0; gBC.weightx = 0.2; gBC.weighty = 0.2; gBC.anchor = GridBagConstraints.FIRST_LINE_START; Label location = new Label("Title Screen"); location.setSize(1000, 10); location.setForeground(new Color(220, 220, 50)); add(location, gBC); gBC.gridx = 0; gBC.gridy = 1; gBC.gridwidth = 3; gBC.weightx = 1; gBC.weighty = 10; gBC.fill = GridBagConstraints.BOTH; JTextArea view = new JTextArea("Welcome to Biforce!!!"); view.setSize(1000, 680); add(view, gBC); view.setEditable(false); gBC.gridx = 0; gBC.gridy = 2; gBC.weightx = 0.00001; gBC.weighty = 0.2; gBC.gridwidth = 1; gBC.fill = GridBagConstraints.NONE; gBC.anchor = GridBagConstraints.LINE_START; Label c = new Label("Type Command, then press ENTER:"); c.setForeground(new Color(220, 220, 50)); c.setSize(300, 10); add(c, gBC); gBC.gridx = 1; gBC.gridy = 2; gBC.weightx = 10; gBC.weighty = 0.2; gBC.gridwidth = 2; gBC.fill = GridBagConstraints.HORIZONTAL; gBC.anchor = GridBagConstraints.LINE_START; JTextArea comm = new JTextArea(); comm.setSize(690, 10); add(comm, gBC); }

This sets everything up and gives us a screen that looks like this:






At the moment, this is exactly what we want. It took a little tweaking to get it this way. I've never used GridBagConstraints, before, but I needed the control it provided over where elements went, and what they looked like. I think it turned out rather nicely, if I do say so myself.

Next time, I'll be creating some Rooms, some Objects to go in those Rooms, and adding the ENTER key functionality that will allow us to travel between those Rooms and manipulate those Objects.

Saturday, July 13, 2013

Toldara: Technology

So, I've missed two Saturdays, now. Damn it. To be fair, the first one we were still adjusting back to real life after our honeymoon, and the second was taken up entirely by my wife's sister's birthday, and then my wife getting really sick. Still, I should have found some time to do this. I am getting better at it, though, and I haven't given up on my goal. This is just a minor setback.

The Toldara campaign setting consists, mostly, of two major continents: The Eastern and the Western. The Western continent has a country completely owned by a faction known as the Techno-Mages. Now, a lot of DMs do not like having technology in their campaigns. If this is the case with you, please note that the Techno-Mages keep to themselves, and do everything they can to keep technology out of the hands of anyone who may use it poorly (AKA, everyone but them). The degree of success they have in their efforts depends entirely on the needs of your campaign. If you don't want any technology, assume a 100% success rate. And the fact that they keep to themselves means that players don't even have to know there is a technology option for this campaign setting.

For those of you who are interested in having some tech in your campaign, here are some notes about how it would work. The Techno-Mages are a group that was founded shortly after the First Fiend War (or, the Fiend War, for anyone who isn't a Karnin). They were initially a group of wizards and gnomish engineers who banded together to contain and control the Western portal used by the Fiends to gain access to the material plane. The Eastern portal was contained by the gods, themselves, when they dropped Mount Karnic on it. The early Techno-Mages were able to harness the massive energy output of the portal while still keeping it closed . . . for the most part.

As it turns out, the containment and usage of the portal by the Techno-Mages creates a kind of inter-dimensional pressure, which builds up and makes things belch forth from the portal. Also, the nature of the tampering the Techno-Mages did to the portal has caused it to no longer link solely to the Abyssal Plane, but to alternate which plane, and even which Universe, it links to in an unpredictable fashion. The Techno-Mages have figured out ways to, at great cost, align the portal to specific places should the need arise.

The "belching" of the portal is actually where the Techno-Mages have gotten a great deal of their technology. Not restricted by time or space, the portal has provided the Techno-Mages which a massive amount of technological and magical artifacts to study and reverse engineer. Even though all of these things come from the Western portal, they didn't always end up at the feet of the Techno-Mages. Often, they would materialize elsewhere on the planet. Also, because the portal now linked to anywhere and everywhere, there was a threat of invasion by more than just the fiends. The Techno-Mages, for these reasons, developed a private army of technologically equipped adventurers to retrieve tech that had appeared elsewhere in the world, and fight off invasions from other worlds. They are known as the Techno-Mage Paramilitary, or TeMP. (Made that up off the top of my head, and is subject to change)

Now, it should be noted here that, while TeMP makes use of adventurers and is perfectly okay for PCs to join, should you want to have your campaign go in that direction, the Techno-Mages themselves are not. They are far too powerful, unless your are running an epic level campaign that is in the high end of epic. If you're familiar with Magic: The Gathering, the Techno-Mages make Planeswalkers look like apprentices. They've been far more places, and seen far more things. If you are running a campaign of sufficient level, and wish to allow your players to join the Techno-Mages, it would count as an epic level Prestige Class, the rules for which I may flesh out at a later date, just for fun. In order to join, a character must be either a spellcaster capable of casting at least 9th level spells (Alchemists count if you're running Pathfinder, as do Psionics *IF* you are running the optional rule that Psionics and Magic are the same), or must be a Tinker, or some other such engineering or tech based class. The character must also go through several months of training to learn how the tech (if he/she's a spellcaster) or the magic (if he/she's a Tinker) works with what the character already knows.

TeMP uses various forms of technology to supplement the skills and abilities of the characters using them. While the Techno-Mages have their own brand of technology that they equip members of TeMP with, most of it come from reverse-engineering and improving on things that have come through the portal. Because of this, any form of technological equipment is possible for a TeMP member to have. Writing rules for every possible item would be painstaking, and, honestly, has probably already been done somewhere else. A good place to start with such rules would the the Dragonstar rulebooks from Fantasy Flight Games. They did an amazing job of making sci-fi rules for a 3rd Ed. D&D fantasy campaign. (I realize that doesn't sound quite right, but give it a read, and you'll understand) The inclusion of such tech requires the addition of new skills, namely the Use Technological Device skill and the Pilot skill. The Pilot skill, like the Craft or Knowledge skills, has several subcategories, each one covering a different type of vehicle. The Use Technological Device is used for activating and using control panels, turning on and correctly using tech devices like communicators and shield generators, and anything else that would reasonably require familiarity with technology to be able to operate. Weapons and armor, however, are covered by the Exotic Weapon Proficiency feat and the Tech Armor Proficiency feat. Other than that, TeMP members operate just like their medieval counterparts.

Even if you don't want your PCs to join TeMP, random portal belches can allow your PCs to find trinkets, weapons, and shields/armor from distant worlds and tech-levels. Keep in mind, though, that the Techno-Mages don't like other people having such technology, as they might not use it wisely. Your PCs may be hounded by TeMP, or even the Techno-Mages themselves, if they acquire such items. The only way to stop such harassment would be to give over the tech, or somehow prove that the PCs were worthy of keeping it. Or destroying the Techno-Mages, but good luck with that. Even if they somehow managed it, who would keep tabs on the portal?

The Techno-Mages have developed their own Star Navy as well. It's small, compared to most such navies, but powerful beyond imagining. The Techno-Mages don't do much interplanetary exploration, however. The Star Navy is mostly for defense from other space-faring navies that may come through the portal. However, every ship is equipped with a FTL drive, and is fully capable of interstellar flight. The crews of these ships are mostly TeMP members, but the higher ranking crew, such as those in command roles, tend to be Techno-Mages. The aforementioned Dragonstar does have rules for starships, but the ones depicted in those rules are not as powerful as the ones the Techno-Mages employ.

I think that about covers it for a general overview of technology in Toldara. Specific rules for it may be coming in the future, but, really, Toldara is mostly a fantasy campaign, and I will be focusing on that. The technology is there if people want to use it, but is mostly just there for flavor. See ya next time!