Advertisement

Basic level scripting? (for a 2D shmup)

Started by March 17, 2015 02:55 AM
3 comments, last by Shpongle 9 years, 9 months ago

I've managed to mostly figure out the basics of game mechanics in XNA and have a prototype 2D shooter going. But now I want actually build a playable level out of this.

My thought is basing the level on timed events; starting with a class called GameEvent, each instance of that class would represent an event like spawning an enemy, playing a sound, changing music, and so on. In game, it should be a matter of just keeping a list and every time the game time reaches the event time, the event is triggered.

My two questions are:

1) Is this a good approach for something like a shmup-type game?

2) What would be an ideal way to actually script this? Would XML suffice?

Any advice is appreciated. I've tried looking at some scripting tutorials, but I'm feeling a bit lost as there are so many options and opinions out there.


1) Is this a good approach for something like a shmup-type game?

It is a valid approach. Might struggle getting everything in synch (such as level art, etc.) but for the most part it works, assuming the scrolling speed doesn't change.

Frameworks such as Unity and GameMaker would've allowed you to build this visually more easily though (with no synch problems)


2) What would be an ideal way to actually script this? Would XML suffice?

XML would be clean. I personally prefer JSONs as they are easier to parse.


Any advice is appreciated. I've tried looking at some scripting tutorials, but I'm feeling a bit lost as there are so many options and opinions out there.

It depends on what your 'events' can be.

Personally, I'd imagine a structure where you have an event type, and a few parameters such as.


<EventList>
 
<Encounter_1>
<timeIndex>5</timeIndex>
<shipID>3</shipID>
<shipCount>1</shipCount>
</Encounter_1>
 
<Encounter_2>
<timeIndex>10</timeIndex>
<shipID>1</shipID>
<shipCount>5</shipCount>
</Encounter_2>
 
</EventList>

As you load your level, you would parse all of this in memory and rebuild from a timeindex and check against your timer integer. When a value would become equal for the first time, you would fire all of its related details (I've omitted x,y here, assuming your code would be able to assign random coords, though preferably, you would need only a x).

Actual behavior for individual ships could be handled by your game code.

Best of luck.

Advertisement

Personally, I'd imagine a structure where you have an event type, and a few parameters such as.


If you're going to use XML, you might want to do it right. No reason to try and squeeze all data into their own nodes.


<eventlist>
  <encounter time="5" ship="3" count="1" />
  <encounter time="10" ship="1" count="5" />
</eventlist>

P.S. The little finger of my left hand aches just from seeing all those "camels" of yours. When entering data by hand, I don't recommend stressing your Shift-pressing finger any more than you have to.

My 1st real game I made was a Shump, and my levels were scripted just like you mention, based on time. Back then (~1999), I didn't know about XML, and json might not have been around, so I made my own script files. You'll basically want to be able to denote in your level files when, what, where, and some other attributes (speed/direction, extra modifiers) for when objects appear on the screen.

If I were to do it again, I'd use json instead of rolling my own, but I didn't know any better.

You should do the same for all objects i your game, build them with a json script, so you define your enemies, backgrounds, upgrades in json, and, when you create your level script, it just references those tags.

Good luck and have fun, I know I did way back when.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

Thanks for the replies, all. I hadn't heard of JSON before, so I'm investigating that. It seems like a very straightforward way to script things.

This topic is closed to new replies.

Advertisement