Be a Supporter!
Response to: Tell me what you think Posted March 11th, 2014 in Game Development

So you hold space, all enemies run to the upper left corner, release space, they die and it starts lagging?
The graphics are okay, but your code seems to be a wreck to be honest...
You should try to fix/improve/structure/remake (whatever) your current code before trying to make more content.

Response to: Points on a line between objs AS3 Posted March 4th, 2014 in Game Development

At 3/4/14 09:16 PM, Barzona wrote: If you know of a good formula to achieve this or a math resource with this information, I'd appreciate it. I'm guessing it wont be as simple as the little midpoint formula I have. Thanks in advance!

Calculate the distance-vector from mouse to player and divide it by (1 + ballAmount).
You can now position your balls by adding multiples of this vector, let's call it v.
If you now offset your 1st ball by 1 * v, your 2nd ball by 2 * v etc. you will get the desired effect.

Response to: Smoot moving along border AS3 Posted March 3rd, 2014 in Game Development

At 3/3/14 08:36 PM, Etherblood wrote: To make this more accurate

Sry, shouln't have used the word "accurate" here, as this isn't even trying to approximate the orginal solution.
It will look better, but I don't know if it will look good. There are still ways to improve it though.

Response to: Smoot moving along border AS3 Posted March 3rd, 2014 in Game Development

At 3/3/14 06:18 PM, Barzona wrote: I've tried a few things like saving the last two positions in an array and relocating him to the former position, but that caused the same result. I figured it would make it so he's never really on the edge and could still move, but it didn't quite work that way..

What you need is pretty much a projection of the movement vector onto the edge.
The problem here is that you don't know where exactly the edge is.

An easy workaround would be to step in x and y direction seperately and check if the current position is valid.
If it is invalid, just undo the last x/y step.
To make this more accurate you may initially divide the movement vector by z and repeat this process z times.

I'm pretty sure there are a lot better "solutions" to this, but I think it should work. (never tested it)

Response to: How to make Minecraft type games? Posted February 25th, 2014 in Programming

At 2/25/14 09:42 AM, dburford11 wrote: Learn C if you want to make games, it's the best.

...
I don't even know how to respond to this.
Other languages (e.g. java) are more than capable at making games, no need to switch to C.

Response to: Newgrounds Api: Saving And Loading Posted February 25th, 2014 in Game Development

And post the test code I had afterwards:
(scene contains a TextField named label and a Button named btn)

import com.newgrounds.*;

stop();
var saveFile:SaveFile;

API.addEventListener(APIEvent.API_CONNECTED, executeQuery);
API.connect(this, "moep:moep", "MoepMoepMoepMoep");

btn.addEventListener(MouseEvent.CLICK, save);

function save(e:MouseEvent = null)
{
	if(saveFile)
	{
		saveFile.save();
	}
}

function executeQuery(e:APIEvent = null):void
{
	var query:SaveQuery = API.createSaveQuery("saveGroup");
	query.addCondition(SaveQuery.AUTHOR_ID, SaveQuery.OPERATOR_EQUAL, API.userId);
	query.addEventListener(APIEvent.QUERY_COMPLETE, queryComplete);
	query.execute();
}

function queryComplete(event:APIEvent):void
{
	if (event.data.files.length == 0)
	{
		saveFile = API.createSaveFile("saveGroup");
		saveFile.name = "saveFile";
		saveFile.data = "";
	}
	else
	{
		saveFile = event.data.files[0];
		saveFile.load();
	}
	
	saveFile.addEventListener(APIEvent.FILE_SAVED, onSaved);
	saveFile.addEventListener(APIEvent.FILE_LOADED, onLoaded);
}

function onSaved(e:APIEvent):void
{
	if(e.success)
	{
		label.text = e.data.data;
	}
	else trace(e.error);
}

function onLoaded(e:APIEvent):void
{
	if(e.success)
	{
		saveFile.data += "1";
	}
	else trace(e.error);
}
Response to: Newgrounds Api: Saving And Loading Posted February 25th, 2014 in Game Development

At 2/25/14 03:08 AM, VanDennGames wrote: Hi!

So I'm just about finished with my game but I'm having trouble understanding how Newgrounds save and load works. If someone could help me understand the API or give me a pseudo-code on what to do, that would really help me a lot! :)

Cheers!

Sry, I don't have time for a long answer, so I'll just link you here:
http://www.newgrounds.com/bbs/topic/1358516/2#bbspost24944731_post_text

Response to: Submitting Swf's On Ng & Classes Posted February 23rd, 2014 in Game Development

At 2/23/14 07:19 PM, Tired-Maniac wrote: Thing is, you can't upload .as class files onto NG, just the .swf's so how do people who have created .as class files upload there shit without it screwing up? I know the question might be silly for some, but i'm really new to this stuff, thanks.

The .swf file contains 'copies' of all your classes after compiling, the .as files are only used by the editor-program.
Try dragging/copying you .swf out of your project-folder and running it, it should work without all the .as files.

Response to: As3 score won't stop going up Posted February 16th, 2014 in Game Development

At 2/16/14 10:06 PM, Etherblood wrote: will run 24 times per frame until

meant 24 times per second

Response to: As3 score won't stop going up Posted February 16th, 2014 in Game Development

At 2/16/14 09:56 PM, bitcubes wrote: this.addEventListener(Event.ENTER_FRAME, enterf);
function enterf(e:Event)
{
score +=1;
score_txt.text = String(score);
}

after it reaches the frame that this code is in, it keeps going up and never stops, I just want it to go up once how do I do this?

The EnterFrame-Event is triggered once every frame, so if your game runs at 24 fps the function enterf will run 24 times per frame until you remove the eventListener.

if you just want to increase the score by once by 1 when entering a keyframe, the code

score +=1;
score_txt.text = String(score);

should suffice.

Response to: As3 Hittest? Posted February 16th, 2014 in Game Development

At 2/16/14 08:53 PM, bitcubes wrote:

If all the objects you want to hittest against are childrean of trash, and it has no other childs, you could just do:

for(var i:int = 0; i < trash.numChildren; i++)
{
    player.hitTestObject(trash.getChildAt(i));
}

You don't need instanceNames to make hitTests.
I recommend the array approach, please DON'T EVER use 55 identical if's in succession, use loops.

Response to: How do I add medals to a game? Posted February 15th, 2014 in Programming

At 2/15/14 07:06 PM, Denisowator wrote: I wanted to add achievements to my game (when I make one) so I searched how to and found that you have to create a project and then make achievements on one of the project pages, and use the unlock_medal and get_medal commands.

I assume that you already created your project on newgrounds and enabled api tools?
If yes you can create new medals on the api tools->medals page.
If you got this done you need to connect your game to newgrounds, which looks like this in AS3 (look up your equivalent):

API.connect(root, apiId, encryptionKey);//look up the id & key at the api tools page of your project
API.addEventListener(APIEvent.API_CONNECTED, onConnected);
function onConnected(event:APIEvent):void
{
    trace("connected");
}

After connecting you can unlock your medals like this (again in as3):

API.unlockMedal("Test Medal");
Response to: How to make Minecraft type games? Posted February 15th, 2014 in Programming

At 2/14/14 04:53 PM, Mantum wrote: I was wondering if anyone of u know how to make a minecraft type game (give me links to the web)! And giv me a link to a tutorial because I"m don't get it myself!

Are you looking for something like this:
cubes ?
It's a plugin for jmonkey (3d java engine) that does the block-render stuff for you.

Response to: 3D Game Tutorial Request Posted February 14th, 2014 in Programming

At 2/14/14 06:04 AM, Oh-Sama wrote: Looks good so far, any release yet??

It was a project for university and we stole the models, so no release, sry.

If you don't mind how much time did it take and how did you organize team roles??

It took about 13 weeks to make. We met once a week, discussing what to do next and assigning who does what for the next week. Each person spent ~10-20h per week on the game.

Any tutorials/troubles you had during the making of the game??

The 3D stuff took about half of our time as we had no prior experience in 3D.
http://www.riemers.net/index.php was pretty useful to start out, but we pretty much used everything we could find with google.

The biggest problem was, that the build-in XNA model rendering was to slow for our game,
so we had to rewrite the whole rendering stuff (own shaders etc.), which was a pain in the ass.
(The game needed to be able to have 1000+ units working at the same time, logic and rendering)

Response to: 3D Game Tutorial Request Posted February 14th, 2014 in Programming

At 2/14/14 02:42 AM, Oh-Sama wrote: Anyone knows a good/complete tutorial on creating low polygons 3D games that also run on lower resources?? I want to make a small 3D world with few characters just to experiment with 3D and to learn what 3D is all about.
My current configuration is 2,2GHZ Dual Core CPU, 3 GB RAM and 1GB Integrated Graphic Card. I have tried modeling with Blender before but my PC couldn't handle the rendering and I can't get any upgrades for the moment. So instead I wanted to go from scratch but I have absolutely no idea on where to star from :/
I have searched on the internet but I'm kinda lost. Which languages are the best deal for my case? I have basic knowledge of C, Java (Visual Basic is a forgotten knowledge) also I have some basic OOP. So I understand in some ways what coding is about. Here some references so you know which tutorial I'm seeking...
Thanks for your time guys :)

You might want to check out http://jmonkeyengine.org/, a 3D engine for java.
I never used it, only saw and played a few jMonkey games, but it should work. (It can import blender models I think)

I personally only have experience with XNA Game Studio 4.0, it sucks (don't use it if you don't have to), but does it's job if you tweak it a lot.
This is a xna game I made with 6 other people which also should run on your computer:
screen

Response to: Cannot get preloaders to work (AS3) Posted February 13th, 2014 in Game Development

At 2/12/14 09:28 PM, Aprime wrote: Could you explain why this works and why this works and why it hadn't previously?

http://stackoverflow.com/questions/18450704/actionscript-3-what-does-export-in-frame-1-in-the-symbol-properties-mean/18451361#18451361

Everything exported in frame 1 will be loaded before frame 1 is played, same for frame 2 and so on.
If you export everything in frame 1 and your preloader is in frame 1, everything will be loaded before the preloader is shown.
If you export in frame 2 and your preloader is in frame 1, the preloader will be downloaded, do it's work, and then frame 2 will be shown. (no download for frame 2, because the preloader already got all the data)

Response to: Hard Time Making a preloader Posted February 11th, 2014 in Game Development

At 2/11/14 01:43 PM, SpaceCommandZero wrote: Can anyone tell me how to go on with this?

I answered in your other post,
http://www.newgrounds.com/bbs/topic/1360663
but lets keep the discussion here.

Response to: Hard time making a preloader Posted February 11th, 2014 in Programming

function progress(e:Event):void

should be:

function progress(e:ProgressEvent):void
Response to: Hard time making a preloader Posted February 11th, 2014 in Programming

At 2/11/14 12:38 PM, SpaceCommandZero wrote: Can anyone tell me how to go on with this?

You need to use events for stuff like this.

loaderInfo.addEventListener(Event.COMPLETE, completed);

function completed(e:Event):void
{
    trace("loading complete"); //do stuff after loading here
}
loaderInfo.addEventListener(ProgressEvent.PROGRESS, progress);

function progress(e:Event):void
{
    var percentage:int = 100 * e.bytesLoaded / e.bytesTotal;
    trace(percentage + "% loaded"); //update loading progress here
}

Also, you should post flash related stuff in the flash forum.

Response to: Cannot get preloaders to work (AS3) Posted February 11th, 2014 in Game Development

At 2/10/14 05:52 PM, PianoGamer wrote: I've tried 3 of the preloaders from the downloads section, but all have the same result: The window stays white untill my game is loaded. The instructions doesn't seem to imply anything can go wrong, they just say "put the preloader movie clip in the first frame of your fla", which I do.

Did you try to set your as3 publish settings to export classes in frame 2?
If not, file->publish settings->tool symbol next to actionscript 3, upper right->export classes in frame 2.

Response to: AS3 Hit testing different mcs Posted February 10th, 2014 in Game Development

At 2/10/14 01:53 PM, Liran wrote: Hi

I am building a game and want to check for hit testing of the player mc with other mcs on stage. All mcs are placed on the frame in the timeline.
I have different types of mcs (walls, doors, etc..). for each type of object the player hits i want to perform a different action.

I have an enter frame function on my main timeline.
In it I use this code to list all mcs on stage:

for(var i:int = 0; i<numChildren; i++)
{
var e:DisplayObject = getChildAt(i);
if(e is MovieClip)
{

}
}

So for each object "e" I want to hittest and based on the type of object (wall, door) i want to use a different action.
How can I distinguish different objects?

I tried to put a variable in each mc like this:

var mctype="wall"

and then use this code to check which type of mc it is:

for(var i:int = 0; i<numChildren; i++)
{
var e:DisplayObject = getChildAt(i);
if(e is MovieClip)
{
if (e.mctype=="wall") {trace("wall");}
}
}

but it gives me an error for "a possibly undefined property mctype.

Thanks

The easiest "fix" to this concrete problem would be to change your code to sth. like this:

for(var i:int = 0; i<numChildren; i++)
{
    var e:DisplayObject = getChildAt(i);
    if(e is MovieClip && "mctype" in e) // checks if e is a MovieClip and if it contains a var or function named "mctype"
    {
        if (e["mctype"]=="wall") // checks if e's var or function named "mctype" == "wall"
            {trace("wall");}
    }
}

I strongly advise against this method though.

You should use different classes for different objects, so your code could look more like this:

for(var i:int = 0; i<numChildren; i++)
{
    var e:DisplayObject = getChildAt(i);
    if(e is Wall)
    {
        trace("wall");
    }
    else if(e is Door)
    {
        trace("door");
    } // etc
}

There's still a lot potential for improvement in regards to coding practices, but I'll leave it at that in this answer.

Response to: Single event listener vs multiple Posted February 9th, 2014 in Game Development

At 2/9/14 07:46 AM, Mandaley wrote: I'm making a Side Scroller Shooter game using AS3. Would there be that much of a difference in performance if I were to make each object such as bullets, player and enemies have their own OnEnterFrame event listener? Or, is it better to have them all under a single main OnEnterFrame listener, and have it loop through calling each object's action function? The game won't be a bullet hell so there won't be that many objects on the screen; nearly much like RaidenX for example.

I didn't make a as3 game with many objects on stage yet, so my answer might be inaccurate.

I'm pretty sure that if you encounter performance problems, it won't be because each object has it's own enter-frame-listener. (I still recommend to have an action function for each object and call it instead)
It's more likely to be because you have a lot movieclips on stage, and movieclips are (relatively) slow, but I think it shouldn't be a problem in your example.

The easiest way to find out if it'll work is to test it.
You might want to consider Blitting if you encounter performance problems, just ask if you do.

Response to: Check range within math.random? Posted February 4th, 2014 in Game Development

my randomElement's return value should be Object, not int

public static function randomElement(table:Array):<strong>Object</strong>
Response to: Check range within math.random? Posted February 4th, 2014 in Game Development

At 2/4/14 09:50 AM, kkots wrote: randomNumber will never be equal to 0, nor to sum. You can assume that it has a very low value, but not 0. Therefore my code is correct.

Math.random() "Returns a pseudo-random number n, where 0 <= n < 1."
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Math.html#random()
randomNumber can become equal to 0, but not to sum

Why <= ? randomNumber is a floating point number, it will never be exactly equal to anything.

Floating point numbers can be equal, it's just rare in most cases.
And for why < was wrong:
randomIndex([0, 1]) could return 0 (if randomNum was 0), but the result should always be 1

Nice. Hope the original poster will find this useful. If he is not dead from our programmer talk already.

Maybe if I added comments to my code...

Response to: Check range within math.random? Posted February 4th, 2014 in Game Development

At 2/4/14 08:45 AM, kkots wrote: Sorry, mistake in this code.
for(i=0;i<table.length;i++){
if(randomNumber>sum+table[i].range)return table[i].func;else
sum+=table[i].range;
}
}

Replacing > with < should fix it I think

It should be

for(i=table.length-1;i>=0;i--){
if(randomNumber>totalRange-sum-table[i].range)return table[i].func;else
sum+=table[i].range;
}
}

This is wrong, try with randomNumber = 0, the loop will finish without returning assuming range is always positive


At 2/4/14 07:53 AM, Etherblood wrote: for (i = 0; limits[i] < randomNum; i++)
{
}

return i;
}
Your code has errors too

Yup, it should be <= instead of <

It should be

for(i=limits.length-1; limits[i]<randomNum; i--){}
return i;

lolol

Nope, this is wrong again, try the randomNum = 0 example it will return the last index when 0 should be returned

You forgot the return at the end for the compiler.
Didn't notice that the limit array creation in my code was unnecessary, thx.
I like to make my helper functions as general as possible to be able to recycle it, so I'd change the return type and the value types in the array to Object. This way it'd be easier to use this function for other stuff.

Changed my code:

public static function randomIndex(probabilities:Array):int
{
	var sum:Number = 0;
	for (var i:int = 0; i < probabilities.length; i++)
	{
		sum += probabilities[i];
	}
	var randomNum:Number = Math.random() * sum;
	
	sum = 0;
	for (i = 0; (sum += probabilities[i]) <= randomNum; i++){}
	
	return i;
}

And added a table version like yours:
(table = {range:x, element:y})

public static function randomElement(table:Array):int
{
	var sum:Number = 0;
	for (var i:int = 0; i < table.length; i++)
	{
		sum += table[i].range;
	}
	var randomNum:Number = Math.random() * sum;
	
	sum = 0;
	for (i = 0; (sum += table[i].range) <= randomNum; i++){}
	
	return table[i].element;
}
Response to: Check range within math.random? Posted February 4th, 2014 in Game Development

At 2/4/14 07:17 AM, milchreis wrote: a probability is always tied to a certain function

But what takes less memory and works faster - objects or synchronized arrays?
idk, it doesn't really matter in this case and I doubt it ever will

I agree that it's easier to mess up with synced arrays, but think that both approaches are valid.
I imagined my helper function to look like this:

public static function randomIndex(probabilities:Array):int
{
	var limits:Array = [];
	var sum:Number = 0;
	for (var i:int = 0; i < probabilities.length; i++)
	{
		sum += probabilities[i];
		limits.push(sum);
	}
	var randomNum:Number = Math.random() * sum;
	
	for (i = 0; limits[i] < randomNum; i++)
	{
	}
	
	return i;
}

which is much easier to use with seperate arrays.
It's usage in our example could look like this:

[aiAttack, aiMagic, aiHeal][randomIndex([0.7, 0.2, 0.1])](); //short and dirty...
Response to: Check range within math.random? Posted February 3rd, 2014 in Game Development

At 2/3/14 06:51 PM, Hero101 wrote:
Now I'm not sure why anyone would need to do a ton of else/if statements, but I was wondering if in theory if this would work?

As stated before, it would work, but I would avoid it if possible.

You can do it like milchreis said and just put aiAttack 7 times into the array and aiMagic 2 times to get the probabilities from your example, or you could use the analog switch case:

switch(aiNumber)
{
	case 8:
	case 9:
		aiMagic();
		break;
	case 10:
		aiHeal();
		break;
	default:
		aiAttack();
		break;
}

I personally would use a loop if I had to scale up your example, which would look something like this:
(with less hardcoding and as an own function)

var functions:Array = [aiAttack, aiMagic, aiHeal];
var limits:Array = [7, 9, 10];

var randomNum:Number = Math.ceil(Math.random() * limits[limits.length - 1]);

for (var i:int = 0; limits[i] < randomNum; i++) 
{
}

functions[i]();

I prefer the loop because it could handle floating point limits with little change and i like probabilities to sum up to 1 and it's easier to make a function out of it (limits as input, i as output).

Response to: Check range within math.random? Posted February 2nd, 2014 in Game Development

At 2/2/14 01:41 AM, Hero101 wrote:
The else that it seems like you didn't type is what restricts the 2nd conditional to the numbers 8 and 9. If it's less than 8, the first conditional takes care of it and the 2nd one never runs.
Ooooh damn I didn't see the "else" in the "else if" of the second condition.... Forgive me I'm not all there tonight...

Thank you guys...

Ok, forget my previous post, I was slow posting it and MSGhero's answer is better anyways.
Glad it works now.

Response to: Check range within math.random? Posted February 2nd, 2014 in Game Development

At 2/2/14 01:31 AM, Hero101 wrote:

No I understand them completely. I tried your code and traced what the number would be every time it aiMagic was called and I got numbers below 9 all the way down to 1. Think about it.... <= 9 .... so the number can be less than 9 but it never stops at 8....


So I fixed it by doing this:

if (aiNumber == 8 || aiNumber == 9)
{
aiMagic();
}

If you copied my code correctly it is impossible to reach the line which calls aiMagic with other numbers than 8 and 9.

if the number is 1-7:

if (aiNumber <= 7) // true
{
	aiAttack(); //<---executed
}
else if (...) // this will not be executed, because previous if was true

if the number is 8-9:

if (aiNumber <= 7) // false, else statement will be executed
{
		aiAttack();
}
else if (aiNumber <= 9) //true
{
	aiMagic();//<---executed
}
else ... // this will not be executed, because previous if was true

if the number is 10:

if (aiNumber <= 7) // false, else statement will be executed
{
	aiAttack();
}
else if (aiNumber <= 9) // false, else statement will be executed
{
	aiMagic();
}
else
{
	aiHeal();//<---executed
}

this code is more or less the same as:

if (aiNumber <= 7)
{
	aiAttack();
}
if (7 < aiNumber && aiNumber <= 9) // or "if (aiNumber == 8 || aiNumber == 9)" like you did it
{
	aiMagic();
}
if (9 < aiNumber)
{
	aiHeal();
}
Response to: Check range within math.random? Posted February 2nd, 2014 in Game Development

At 2/2/14 01:00 AM, Hero101 wrote:
Unfortunately that didn't work for the aiMagic because it would still cast magic if it was <= 9 but attack is <= 7. It works for attack and heal but I need magic to be 8 or 9 only. If it is <= 9 then odds are it will also be <= 7 which is what attack is.

Either I don't understand your question or I need to explain else-statements.
You want to call aiAttack if aiNumber is 1-7, aiMagic if it is 8-9 and aiHeal if it is 10?
Because this is what the code I posted does, if you want I can try to explain else-statements or you can just google it.