Asteroids

Flash, Games, Programming, ade's stuff No Comments

Lazy reader’s link to the current version of the game

I went to a short flash-based videogame course a few weeks back. The exam is in form of a homework assignment where you select one of three games to implement. I chose to make a asteroids-style game clone. The platform is Flash CS3 and Actionscript 3.

I started out with the ship, drawing it as a movieclip with 4 frames, for idling, turning left and right, and moving forward. Then i made a SpaceShip-class that handled as much as possible of the ship and its movement. First, I made it turn, with some basic turning-speed acceleration and deceleration, using the three different frames to animate it. Click to try, use left and right arrows to turn.

Then there was some coding involved with making the ship move. The ship uses a vector for movement and modifying its course uses vector addition, which creates a pretty cool skidding effect. When the ship moves toward the edge of the game area, it needs to warp the opposide side of the screen, and there should be visual evidence before the transfer is complete that the spaceship is going to show up on the other end. So, there needed to be a “clone” involved that acts as a copy of the spaceship until the original ship is outside the screen, at which point the clone will take over. I ended up using a border of movieclips and using hit-testing to see if the ship was getting close to the edge. Try version two. Use left, right and up arrows.
When the ship movement was complete, i started working on the “asteroids”. So I put some rocks from my plant in my scanner and put them as a single movieclip in flash. Then i made the Rock class, to handle the rocks movement across the screen. They use a similar edge-detection and clone method, as well as movement. They start with a random position, speed and apperance. Click here to see.

Then of course, I needed to make a end-game screen when the ship hit an asteroid. So i had this vision in my head, how i would call rockMovieClip.hitTest(shipMovieClip) and just find out at once if the ship was hitting the rock. But a quick test revals that flash uses boxes for hit detection and a not-so-fast googling of the situation revealed that there was not really a practical way to do this. I tried to make the pixel-level hitdetection that was described in the BitmapData class but it just wasn’t a very clean solution, so i just made the objects check for their distance instead, since the rocks are kinda round and the ship too. Try here.

Finally, the ship obviously needs to shoot something. I made a green little round particle thingy and copied the movement code from the other classes and wired everything together in the flash file (first frame). Tanja decided my green projectiles were unsatisfactory and suggested I made them pink instead which turned out quite fabulous. Use spacebar to shoot. You may notice that the shots are aware of the ship’s movement.

There’s a slight bug still, where asteroids can “leak” outside the playing area. Need to check my edge-handling code a bit. The “A:” counter shows how many rock instances you are currently dealing with. Get it to 0 and you win (but I haven’t made the win-screen yet.)

Update: The final version is complete.

GTA 4

Games No Comments

Just one more day.

Official siteGTA4.NET

cakepawn

Games, Programming, ade's stuff No Comments

cake

i’ve made a script editor for the sa-mp scripting platform, for the pawn language. kalle made the cool pic for it :D

it’s my first larger open-source project, and it’s released under gpl3. it’s a multiple document interface editor with syntax highlighting of course, integrated compiler messages parsing and viewing, and has some nice bonus stuff like reading the includes for method insight (the little tooltip that tells you the arguments expected when you type the name of the function) and a color picker with transparency support. still working on it and have many great ideas to complete yet, and alot of ugly code (not mine originally) to refactor. the textarea itself is another opensource project, made by digitalrune, who extended the editor control from the sharpdevelop project.

screenshots:

if you happen to be a sa-mp pawn script maker or want to download the app for some other reason it’s available at http://ade.se/projects/cakepawn

San Andreas: Multiplayer

Games, Internet, Programming, ade's stuff 3 Comments

when the community-made multiplayer mod for original GTA 3 came out years ago, I checked it out and soon realized it wasn’t all that much fun. there was one made for the sequel vice city too, and it had alot more features, and was actually quite fun for a while, but in the end you’d get sick of all the client crashes and lag problems. then a few years passed and I kinda forgot about the whole thing. since then there has been yet another GTA release (for PC), san andreas. so now I checked out the multiplayer mod for that, and wow, I was really impressed. the stability is so much better, and if you avoid certain weapons you can actually have a pretty fair gunfight on the streets without feeling that you’ve unloaded 4 magazines of tec9 in someones head and nothing happened. remember, this is done by hacking the internals of a single-player only game… it’s pretty much not been done before on such a scale.

the most interesting feature with the “SA-MP” mod is that you can run scripts server side to make unique rules for your server. the server’s behavior will be completely different from server to server things like weapons allowed, spawn points, text/UI on your screen, classes, objectives and special scriptable functions like banks, shops, houses…. there’s a good amount of API functions to use. from some of these servers, whole communities take shape.

I played around on servers a bit (but only for like 4-5 hours total) and soon realized that I could be writing my very own gta-mini-mmorpg variant. so I wanted too take a look at how the scripting worked. It’s done in a language called Pawn (formerly SmallC), familiar from things like the amxmod in the half-life engine (specifically, counter-strike 1.6 and below) servers. the general syntax is familiar from C or Java and it’s pretty easy to get into. then I found the MySQL plugin for the script engine, and pretty much just started coding and coding…. ;)

I never really looked into the existing scripts that were available in the community. most of them were just variants of one original huge script some guy made anyway, and I thought it would be more interesting to make everything from scratch with my own ideas. as it turned out, there was alot of work involved with this, doing basic stuff like registering, loggin in, setting spawn points, making car spawn locations, etc, especially since I wanted everything to be dynamic and stored in the mysql database :) after about two weekends of work, I have a pretty nice foundation (~4000 lines of code), including user account system, a persistent player housing system with a couple of interesting features, dynamic administration of the server with adding/removing cars, spawnpoints, houses, etc. I also made a inventory system and raw-material gathering from various places around the map, with things like harvesting on field with a combine harvester, fishing, and more. one of the goals is to avoid making this rich 3d environment into a zork-style text adventure seen on some servers, where you have to type commands in text every time you want to do something. Instead, the script provides for on-screen menus and visualization, and events triggered upon things you do in the game environment such as entering a certain type of car in a certain area. my friend is helping me with some content adding stuff like making player houses, placing cars and spawnpoints etc.

an interesting side-effect of the mysql architecture is that you can really easily dump information out into webpages, and even allow for some web-based playing if you don’t have access to the real server. more info on the project later :)