00:00
00:00
Newgrounds Background Image Theme

Breakfast-Crow just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

pairs in as3 2015-02-28 10:45:53


So here's the deal I have 2 arrays like so:

private static const level7EnemyTypesArray:Array =	 new Array(11, 11, 10, 9, 9, 10, 10, 10, 12, 12, 10, 9, 10, 10, 9, 10, 11, 9, 10,10, 9, 10, 11, 9, 10, 9, 10, 10, 9, 10, 10, 9, 10, 9, 11, 9, 9, 10, 9, 10, 10, 9, 10, 9, 11, 9, 9, 10, 9, 9, 10, 11, 10, 9, 10, 9, 10, 9, 10, 11, 10, 9, 10, 9, 9, 10, 10, 10, 9, 9, 11, 9, 10, 9, 10, 9, 9, 10, 11, 9, 12, 10, 10, 9, 10, 9, 9, 10, 11, 9, 10, 9, 9, 10, 9, 10, 9, 
11, 9, 9, 10, 9, 10, 10, 9, 9, 11, 9, 10, 9, 9, 10, 9, 10, 9, 11, 9, 10, 9, 9, 10, 9, 10, 9, 10, 9, 9, 11, 9, 10, 11, 11, 11, 99);

private static const level7EnemyPositionArray:Array = new Array (0, 0, 1, 1, 5, 5, 2, 0, 4, 2, 0, 1, 0, 5, 5, 2, 0, 4, 0, 
		0, 1, 1, 0, 5, 2, 3, 4, 0, 0, 1, 0, 5, 5, 2, 0, 4, 0, 0, 1, 0, 5, 5, 2, 3, 0, 0, 0, 0, 1, 5, 5, 0, 3, 4, 0, 0, 1, 1, 
		0, 3, 4, 0, 1, 5, 2, 3, 0, 4, 5, 0, 0, 1, 2, 3, 0, 4, 1, 5, 0, 2, 3, 4, 1, 0, 0, 5, 2, 4, 0, 3, 1, 0, 0, 5, 3, 0, 2,
		0, 0, 1, 5, 5, 2, 0, 3, 4, 0, 1, 1, 5, 4, 0, 0, 1, 5, 0, 3, 2, 4, 1, 5, 0, 0, 1, 5, 3, 2, 0, 4, 1, 0, 0, 0, 99);

Each enemy type in array 1 corresponds to a position in array 2 at the same location. so enemy 11 spawns at position 0 and so on.

But maintaining this is a nightmare.
Now I've done a fair bit of coding c++ and in the situation I would create a vector of pairs. However
I've looked and AS3 doesn't seem to support this. Is there another way to do this?

Response to pairs in as3 2015-02-28 11:12:14


At 2/28/15 10:45 AM, Splyth wrote: But maintaining this is a nightmare.
Now I've done a fair bit of coding c++ and in the situation I would create a vector of pairs. However
I've looked and AS3 doesn't seem to support this. Is there another way to do this?

Why not create a pair class or even better an enemy class?

Response to pairs in as3 2015-02-28 11:17:13


Enemies are generated elsewhere
the numbers in this case are simply used to tell my
EnemyManager class which enemy to spawn and what position
to spawn him in.

I have created a tiny class to store these numbers and I'm currently going through
and updating the array to see if this will work for me.

Response to pairs in as3 2015-02-28 11:39:22


AS3 has the Point type which is essentially a pair of Number types: left is x and right is y. If you need something more specific then it's as simple as building your own.

Response to pairs in as3 2015-02-28 11:45:27


alright then.

Thanks for the help.

Response to pairs in as3 2015-03-01 12:34:45 (edited 2015-03-01 12:36:30)


At 2/28/15 10:45 AM, Splyth wrote: I've looked and AS3 doesn't seem to support this. Is there another way to do this?

the command pattern

Basically speaking, it's a delayed function call.

Instead of calling the function that does the spawning directly:

//definition
spawnEnemyAt(EnemyClass:Class, spawnPosition:Point):void

//used like this:
spawnEnemyAt(Monster, new Point(12, 34));

You wrap this function call into a class.
The objects of that class hold all the information on how the function should be called, but doesn't call the function right away. e.g.

//definition
class SpawnCommand 

// local variables

function SpawnCommand(EnemyClass:Class, spawnPosition:Point)
{
    //store parameter values in variables here
}

function execute()
{
    spawnEnemyAt(/*use values of local variables here*/)
}

//used like this:
var monsterSpawn:SpawnCommand = new SpawnCommand(Monster, new Point(12, 34));

// later:
monsterSpawn.execute();

Think of it as buying a cookbook with a recipe for a certain meal instead of ordering the food itself.

All of the above is pseudocode, but you get the idea.

Response to pairs in as3 2015-03-07 09:04:31


Interesting.

In my case this just shifts where the long list of numbers are.
which doesn't really help much. But I didn't know about this pattern
before, Thanks for the info.

Response to pairs in as3 2015-03-07 15:00:58


At 3/7/15 09:04 AM, Splyth wrote: Interesting.

In my case this just shifts where the long list of numbers are.
which doesn't really help much. But I didn't know about this pattern
before, Thanks for the info.

that's assuming that these properties will always be the only 2 things you use. every time you add another it will get more confusing. plus what happens when you wan to completely change one, you have to find it's array position twice, with def pairs you automtically know which 2 values to change. if your design is concrete, no need to change it, if you think it will grow/change, reconsider

Response to pairs in as3 2015-03-09 16:13:49 (edited 2015-03-09 16:15:07)


At 3/7/15 09:04 AM, Splyth wrote: Interesting.

In my case this just shifts where the long list of numbers are.
which doesn't really help much. But I didn't know about this pattern
before, Thanks for the info.

Except it is the thing you were asking for: a vector of pairs
Initially you were asking for a better data structure. I provided a way to do this (with the additional functionality to use that information in a desirable way, as opposed to plain pairs)

If you are complaining about long lists of numbers now, you are getting off topic.
Even in C++ (or any other language) you have to fill the data structure with data somehow... and this is what makes the long lists of numbers so long: you hard code the values.

It seems to me that your actual problem is not finding the right data structure but to fill it in a convenient way. This is a content management problem.
The usual way would be to create something like a level editor, that allows you to create levels (aka the long lists of numbers) and that writes them in some kind of file or files.
It is up to you to decide what format you choose. Sure enough you can let it generate the source code that you later compile into a game or you could serialize the data into files loaded at runtime by your game, allowing you to provide additional levels over time or user generated content.

After all, you are the programmer. And if you think, "Oh boy, writing all these long lists of numbers sure is a tedious task prone to error", I have to ask why you are not creating a program to help you do this? Editing numbers in source code to modify levels is a maintenance nightmare, just like you said. A level editor solves that problem. But it can provide any other helpful tool. Creating a list of monsters to be spawned is one thing, but knowing the overall monster HP spawned in a level is another. Comparing different levels in order to provide a smooth, yet challenging experience for players sounds like a convenient thing to have as a game dev. Creating alternative waves depending on the player's behaviour goes down the (bottomless) AI rabbit hole.

I think that having long lists of numbers in different places in different ways can actually help much.
The command pattern can help you automate the task of writing them.

If I still do not understand you right, please elaborate on what you goal is.

Response to pairs in as3 2015-03-10 21:47:45


Ok, well then let me change the topic then.

This an ancient copy of what I'm currently working on:

I'm curious, how should I approach making a level editor for this?
Should I have the list of non spawned enemies on the side. So I can see what's
coming next?

I can code it, I just don't know what would make a good level editor for this?

Response to pairs in as3 2015-03-12 14:06:17


At 3/10/15 09:47 PM, Splyth wrote: I'm curious, how should I approach making a level editor for this?

Ask yourself:
What was the most time consuming and tedious task when creating the levels?
Is it worth creating a tool to help me do this?

Should I have the list of non spawned enemies on the side. So I can see what's
coming next?

What the level editor does is dictated by what the levels should look like.
I have no idea what you want to do in your levels or what the underlying rules are that define your levels. This is your game design.

I guess what holds true in general is that using the game itself to create levels makes it easier to create them.
Imagine your game with something like a scrollbar to scroll through time (aka advance through the level).
Have a list of enemies similar to a toolbox to drag and drop them into the level.

-> Maybe your enemies have adjustable properties that you want to modify.
Make dropped enemies selectable to modify them.

-> Maybe you don't want to randomly spawn your enemies, but have them spawn in a position relative to the player.
If you have a dummy player in your editor, you could use it to build relationships like "spawn this enemy at the position of the player so it is on a collision course"

-> Maybe you want to have patterns of enemies.
Have another tool box with patterns that can be filled with an enemy (and the pattern automatically fills itself)
You could create a maze to fly through like "create a wall of enemies with only one passage for the player that is 120° from the player" or "create 5 of this enemy, each one delayed and 20° shifted to the right"

-> Maybe you want to have intermediate goals.
Kill the little boss before the level advances.

Again, these are all game design ideas that are common for the kind of game you presented.
If being able to drag & drop these ideas into your levels directly is useful for you is up to you.
Keep in mind that creating this level editor takes time too.

Response to pairs in as3 2015-03-15 21:21:20


ok. I think I know what I want to do.

For now I'll ignore the level editor. The game is fairly balanced
as is. And given the games' current state the time it would take to build
a level editor vs the the time to modify it by hand doesn't work out in favor
of making a level editor.

It is something I will keep in mind on future projects.

Thanks for your help.