10 Posts Tagged 'Gaming' RSS

Making an RPG in Clojure (part one of many?)

What do you get when you combine old-school Final Fantasy-style RPGs with Clojure? Fun times for all. Well, for me at least.

I'm working on a sort of RPG engine in Clojure so I can make my own RPG. Click the thumbnail for a very preliminary video demo (6.5 MB) showing the engine in action.

RPG Demo

All I do in the video is walk around, and eventually start adding random NPCs to the map to test collision detection. Not all that exciting, but I'm proud nonetheless.

To forestall questions, yes I'll eventually post the source code, but no, not yet. It barely works. Just a proof of concept so far.

Right now I can walk around a map while NPCs also randomly walk around the map, not much more. So there isn't much to talk about. But not bad for 4 days and 600 lines of code (one tenth of which is ASCII art... more on that later). Keep in mind that I have no idea what I'm doing.

Collision detection works so people don't walk through walls or each other, and after endless tweaking I got all the animations to be very smooth, even when I add a few dozen NPCs to the map (as I do in the video). The video is a bit jerky but it looks better in person. All of the admittedly poor artwork is also created by myself, thanks to the GIMP and some hastily-read tutorials on pixel art.

It all runs on plain old Swing in Clojure. Here's some of what went right and what went wrong so far.

February 20, 2010 @ 4:27 PM PST
Cateogory: Programming

Spriting and learning

In the mid-1990's I was really into Nintendo games, as was everyone. My favorite was the original NES Final Fantasy. Sometime in my teens I got my first computer, and I decided it would be cool if I had some sprites of that game on my computer.

Before

My first computer ran at 640x480 with 16 colors. I had Windows 3.1 and the most sophisticated image manipulation program around was MS Paint. How could I get sprites into my computer? Well, I had a strategy guide for the game, with blurry photos of all of the enemies, so I just opened up MS Paint, zoomed waaaaaaaay in, and drew all of the sprites pixel-by-pixel. Insane? Maybe, but it's a fun kind of insane.

This took about a year of off-and-on work, but in the end I had something I thought was great. I still have the file:

FF1

September 07, 2009 @ 1:57 PM PDT
Cateogory: Programming

Stylus DIY, hand health

The stylus that comes with a Nintendo DS is a very mild form of hand torture. Not sure whose hands those were designed for, but not mine. In googling for a good replacement, I chanced upon a blog post which suggests finding a nice big ballpoint pen and jamming a DS stylus inside so just the tip sticks out. This works amazingly well. It's not as portable, but I will make that sacrifice to prevent being crippled.

I am in fact always a bit worried about preserving the health of my hands. I have no hard data to support this, but I suspect my generation may have major hand-related problems in the coming decades. What with computer keyboards and tiny cell-phone and PDA keys and lots of other techy things. Many of us use our hands to communicate almost as much as our voices. Until we have Star Trek voice-recognition software, this will be a problem.

I started experiencing a lot of aches and pains in my hands and wrists a decade or so ago, and I attributed it to computer use. Since I started paying more attention, things are better. I maintain a very comfortable typing position for my hands. I have a nice big comfortable mouse. And so on. My hands don't hurt any longer nowadays, which is nice. If I become unable to type someday, I'm completely screwed. How can I work as a programmer if I can't input text into a computer? And I won't be able to draw or do origami or play video games or do many other things I enjoy.

February 01, 2009 @ 2:39 PM PST
Cateogory: Hardware

OpenVPN in Gentoo in 15 minutes

Situation: You have two computers at different locations. One of them is behind a very restrictive firewall that doesn't permit any incoming connections, and may be running Windows (ugh). The other is running Gentoo and is more permissive.

Problem: You want to play a game on these two computers, like ZSNES, which requires both machines to accept a connection on some port. ZSNES ideally uses UDP protocol for this. Or, you want to play some game that requires connections on multiple ports. For these or some other reason, an SSH tunnel isn't practical. So you must defeat the firewall.

Concerns: There are only two computers involved and no chance of more than two ever being involved. You don't care about encryption; if someone wants to snoop your Final Fantasy 6 traffic, so be it. You want to get something up and running in 15 minutes. You want something that is fast and easy to use from that point forward. You need something that works in Windows.

Solution: OpenVPN works really well for this. If you don't care about encryption and such, this "static" HOWTO is very effective at getting something working quickly. Gentoo can also help a lot in this regard, via some nice wiki entries on Gentoo-Wiki.

Anyways, this is how I did it:

  1. Make sure Universal TUN/TAP device driver support is enabled in your kernel for any Linux machines involved. (If you don't already have this included in your kernel, I guess there goes your 15 minutes right there. Oops!)

  2. Have the client install OpenVPN on their computer. (For Windows, download here.)

  3. On the server machine, run:

    emerge openvpn
    cd /etc/openvpn
    openvpn --genkey --secret static.key
    
  4. Edit /etc/openvpn/openvpn.conf and put this in it:

    dev tun
    ifconfig 10.8.0.1 10.8.0.2
    secret static.key
    
  5. Edit client.ovpn and put this in it (filling in your proper server IP address or domain):

    remote SERVER.IP.ADDRESS
    dev tun
    ifconfig 10.8.0.2 10.8.0.1
    secret static.key
    
  6. Send client.ovpn and static.key to the client by whatever means necessary. You should also keep a copy of static.key in /etc/openvpn on the server. You can get rid of client.ovpn on the server machine.

  7. Start up the server:

    /etc/init.d/openvpn start
    

That's it, you should now be able to fire up any program and point to 10.8.0.2 to access the client from the server, or 10.8.0.1 to access the server from the client, any port, TCP or UDP protocol.

If you really care about encryption or security, there are much better ways of doing this using real public/private key sharing. It may be worth taking the extra half hour or so to set up OpenVPN the right way depending on your needs.

September 08, 2007 @ 8:58 AM PDT
Cateogory: Linux

pSX

I found a need to install a Playstation emulator today, and recalling the minor nightmare installing ePSXe always turns out to be, I searched the Gentoo forums. There's a (somewhat) new emulator called pSX which works really amazingly well. No need to hunt down video/audio/CD-ROM plugins, thank God. It just works. The source code appears to be sadly unavailable so it'll be a binary install only. If you need to install it in Gentoo, it depends on dev-cpp/gtkglextmm and x11-libs/gtkglext.

August 25, 2007 @ 4:54 PM PDT
Cateogory: Linux

That's better

This is why I like Gentoo. I installed ZSNES and I got version 1.51 from the Portage tree, but that version doesn't have netplay. The version I want was some funky 1.42n version somebody wrote with netplay built in. It took me all of five minutes to write an ebuild based on the build in the Portage tree and mask the later versions and install what I wanted. In Ubuntu I'd have been back to ./configure && make && sudo make install and it probably would've bombed due to missing libraries.

Lots of chatter on blogs lately about Gentoo management problems. As usual, I guess. Something I've been guilty of in the past myself is ignoring all the good and focusing on the bad. It's somehow easy to install 1000 packages and focus on the one that fails and respond with "Holy crap Gentoo is broken, stupid lazy devs". It's easy to see one offhand comment from a dev on a mailing list that may be very vaguely insulting to someone if read in a certain way and conclude that Gentoo devs as a group hate non-dev users and think they're scum. (How can a one-paragraph email spawn a five-page forums thread?) I'm making a concerted effort to ignore all of this crap as much as possible.

There's so much good here if you open your eyes to it. Sure some things don't work sometimes, but so many things do work so much of the time and it's easy to lose sight of those. This is one reason I think it's important to make some noise when things DO work sometimes, even if it seems redundant. Just to keep perspective.

July 20, 2007 @ 6:05 PM PDT
Cateogory: Linux

PHP design patterns?

As one of my professors used to say, "There's no problem that can't be solved by adding another layer of abstraction". He was joking, but there's a little bit of truth to that.

I've been working on my other website for a while. It's all PHP4, not entirely by my choice but I'm limited what can be installed on my server. PHP4 turned out to be a lot more powerful than I'd initially thought. Namely the OOP options available are mostly adequate and in a few places surprisingly OK. PHP has some nice meta-programming sorts of functions like get_func_args() and call_user_func() which let you play around with doing weird things dynamically at runtime, which were almost essential in putting all this crap together. It lacks the completeness or elegance of Ruby, and PHP's syntax is generally horrific and painful, but it'll do.

I recently read Head First Design Patterns which is quite a good book. I was able to use plenty of what I learned there in designing a sort of templating system for my other website. Basically I have tons and tons of tables of different sorts of data. CSS goes a long way to making the presentation of the tables easy to change given that they are properly marked-up, but actually marking them up properly and consistently was the problem.

So I put together a bunch of classes that generate HTML tables. One of the things from Design Patterns that really makes sense when you hear it is to lean toward composition rather than inheritance. In other words, an object that has another object as an instance variable is often easier to deal with than an object that inherits the same functionality from a parent class; the reason being that you can use polymorphism to your advantage, and have your object contain a member of a GENERIC type, and then you can give your object an object of any subtype of that generic type you want. So your class then does not depend on the type of its instance variable at all, so long as all possible objects that end up in that variable have the same interface. Loose coupling and all that.

I have used this to great advantage in adding flexibility in marking up table cells. A cell will be a different class (actually a different composition of lots of classes) depending on the kind of data it stores. A TextCell holds text, so I know to pad it and format it (differently than an ImageCell, or a cell containing an unordered list). I can composite TextCells with other more specific types; a value that represents a percentile is a PercentileCell; the class handles formatting the numeric value and sticking a % on the end. I could composite it with an ImportantCell which will give it a special background color. It's as simple as $cell = new TextCell( new ImportantCell( new PercentileCell( 56 ))); The nifty thing is that I can composite the cells arbitrarily in any order or combination, because each simply holds a generic "cell" member and calling a method on an object only causes it to call the same method on its child object, all the way down the stack. Also, if I later decide to take the % off the end of all my percentile values, I can do it by changing a single class definition. That's the kind of thing you can't handle well with HTML/CSS alone. Before, it'd take me a month and half to go mucking around in static HTML files fixing it all. (Or an hour worth of Perl regexing, but still, no fun.) Or if I want my HTML to validate as XHTML Strict, I can change the HTML for all my tables at once by screwing with the base Cell class. If I want to turn it into XML or some other markup, I could do that too, in theory.

At this point I'm essentially writing most of my pages entirely in PHP, never needing to write any raw HTML by hand at all, which is a very nice change of pace. I wish they'd have taught more of this sort of thing in college. We learned how to write searching and sorting algorithms until blue in the face. But we never really touched on how to design software at a very high level. I still think I'm not too good at it in many ways, but I'm learning, at least.

January 23, 2007 @ 6:44 PM PST
Cateogory: Programming

PHP makes me sad; programming makes me happy

My other site is about Final Fantasy (the original video game of the series, for the NES). That site is how I learned HTML, a good 7 years ago. It's still my baby and (perhaps sadly) one of what I consider my greatest accomplishments. I wish I had more time to work on it nowadays, but such is life.

Oh how the internet has changed. I started out on that site with plain old static HTML files. It used to take me months to do or change anything. Eventually I learned about server-side includes and I started using those. A few years later I delved into PHP and started using it as a more sophisticated "include" mechanism and templated a good bit of the site.

Fast forward to today, and I'm trying to get most of my data in a mysql database. I learned a lot from work about how to properly design a database. That part I think I did pretty well at, on my FF1 site. The PHP frontend is where I started having problems. PHP is just such an un-fun language to work with. I hear PHP5 is nicer than PHP4, but PHP4 is what I'm stuck with. At first I tried a purely functional solution, and it very quickly become such a tangled mess of spaghetti code that it was nearly impossible to use. Today I rewrote that crap using the extremely weak OOP constructs PHP4 has to offer, and weak though they may be, my code is ten times shorter and probably ten times easier to read.

Sometimes I'll be sitting here banging out code, and it will be not working. The grunt-work of programming is debugging. You write something you think will work, and 10 times out of 10, it will fail the first time. So you find the first bug, fix it, rerun it. Failure. Find the next bug, fix it, run it, failure. Find, fix, run, failure. And you repeat this over and over and over. But eventually you hit that point where you find the very last show-stopper bug, and you fix it, and run your program, and it all of a sudden it WORKS. You almost never expect it to work. Success flies out of nowhere and hits you in the head, and it's really exciting. You get screen after screen of delicious output, all thanks to that last little tweak. That's the moment that makes the slog of computer programming all worth it.

November 24, 2006 @ 8:21 PM PST
Cateogory: Programming

Fullscreen games under TwinView

The only thing bad about having two monitors in Linux is fullscreen apps, from time to time. Mplayer for example is smart, it fullscreens to whatever screen it's on and leaves the other alone. VLC for example bugs out but at least it sticks to one monitor while doing so.

NWN is not so smart, and tries to run at an enormous resolution which either bleeds across both screens or takes up all of one screen and runs off the edge.

One solution is to run in windowed mode. This is less than optimal for all kinds of reasons, especially if you happen to have an auto-raising kicker or something similar.

Found this on the Gentoo forums though; putting a NULL into one of your MetaModes works:

Option "MetaModes" "1280x1024,1680x1050;NULL,1680x1050"

It turns off one monitor and leaves the other on. CTRL-ALT-+ to switch to and from meta-modes, obviously. NWN recognized the smaller resolution and let me run at 1680x1050. Good old Gentoo forums, never let me down.

October 06, 2006 @ 10:13 PM PDT
Cateogory: Linux

I think I can handle this

After I emerged Neverwinter Nights, I got this:

 * The NWN linux client is now installed.
 * Proceed with the following step in order to get it working:
 * Run /opt/nwn/fixinstall as root
>>> Regenerating /etc/ld.so.cache...
>>> games-rpg/nwn-1.67-r1 merged.
>>> Recording games-rpg/nwn in "world" favorites file...

>>> No packages selected for removal by clean.

>>> Auto-cleaning packages...

>>> No outdated packages were found on your system.


 * GNU info directory index is up-to-date.

I hope I didn't run that step out of order. : (

October 06, 2006 @ 8:51 PM PDT
Cateogory: Linux