Recent posts by EndlessSporadic on Kongregate

Flag Post

Topic: Game Programming / Procedural Generation

If you had a 20×20 world and you wanted element[6,15], you would have the following:

index = 15 * 20 + 6;

which gets you element 306. element[6,15] = element[ 306 ];

This assumes your 2d array stores elements in [x,y] fashion. Switch x and y in the formula if you store your data [y,x].

Elements[] elements = new Elements[20 * 20]; //400
Elements[,] elements2d = new Elements[20,20];

elements[26] = elements2d[26 % 20, 26 / 20] = elements2d[6,1];

elements2d[6,1] = elements[1 * 20 + 6] = elements[26];

EDIT: Had to edit this post multiple times because I confused myself. It should be correct now.

 
Flag Post

Topic: Game Programming / Procedural Generation

//index = desired 1d index
//y = desired y index
//x = desired x index
//W = width

//2d to 1d
index = y * W + x;

//1d to 2d
y = index / W;
x = index % W;
 
Flag Post

Topic: Game Programming / Procedural Generation

More on Gluten’s point, I will give a general idea of what Minecraft does.

Minecraft is made of near unlimited regions. Each region is 32×32 chunks. Each chunk is 16×256×16 [x,y,z].

Consider this. You are in a local chunk (0,0). You load 2 chunks in every direction. When you move to chunk (1,0), you unload chunk (-2,0) and load chunk (3,0). You can think of it in another way. If a single block of a chunk is within a certain radius of a player, load that chunk.

When you load your game, you load the chunks nearest to the player first and then load the surrounding ones. They don’t need to load instantly, but it is generally a good idea to have them start to load just outside of the player’s vision range.

 
Flag Post

Topic: Game Programming / Problems with resetting

I’m not familiar enough with ActionScript’s usage to be of assistance when it comes to best practices.

 
Flag Post

Topic: Game Programming / Procedural Generation

Perlin/Simplex noise functions are REALLY slow. The only way to load it faster with noticeable impact is to coroutine or thread your map generation.

 
Flag Post

Topic: Game Programming / Problems with resetting

Out of curiosity, why are you making it go to another frame instead of destroying it outright? If you want to do an animation, sure, but if it makes it invisible you should just destroy it,

 
Flag Post

Topic: Game Programming / Procedural Generation

He means something along the lines of the following. I use simplex here, but that is preference. Perlin works just as well – since the perlin/simplex function accepts between 1-infinity floats as parameters, just change “Simplex.Noise” to “Perlin.Noise”.

float valueX, valueY;
valueX = Simplex.Noise(tile.x);
valueY = Simplex.Noise(tile.y);
tile.Type = Math.Floor(Simplex.Noise(valueX, valueY, tile.z));

This means you will need some good weighting if you want to make terrain with it.

 
Flag Post

Topic: Off-topic / My mom broke her foot this morning

My foot broke your mom.

 
Flag Post

Topic: Game Programming / Procedural Generation

Originally posted by PanisRahl:

Hmmmmmm, i need to look into Simplex then…. could you do me a favor and look at my code im using and tell me if i did it… efficiently…. or not, and if it would be easy to convert a Simplex version of it?

this is the version of the game that the code i pasted is running
http://www.fastswf.com/E5ugHP0

This is the code to the version of the game posted above this line
http://pastebin.com/dB2k3UXF

What you have is fine. I really can’t see your weighting at all, but the map it generated looked good enough.

 
Flag Post

Topic: Game Programming / Procedural Generation

using the perlin noise way.

Perlin and Simplex noise have the same function parameters. The only difference is the internals of the function.

The only real advantages of simplex over perlin are that simplex is slightly faster, has a better gradient, and can be expanded in multiple dimensions more cheaply than perlin noise. With that said the speed is only significant if you are remaking minecraft, the gradient is better for clean hills (once again, minecraft), and the dimensions don’t really matter in terms of speed past 4 dimensions. It does not matter which one you use, especially for a flash game.

 
Flag Post

Topic: Game Programming / Procedural Generation

Perlin noise is a method of pseudo-randomizing using math. Quite frankly, simplex noise creates better terrain than perlin noise does. Take a look at the following. It is in C#, but the concept still stands. Assume you have your tiles. They have a Vector3 position (x,y,z). You would call Simplex.Noise(tile.x, tile.y, tile.z) and it would return a float. The floats between Simplex.Noise(tile.x, tile.y, tile.z) and Simplex.Noise(tile.x + 1, tile.y, tile.z) would be extremely close, but not the same. Anyway, you now have this returned float. What do you do with it? You weight it. If tile.y is less than a certain value, multiply the returned float by X. If it is greater, multiply it by Y. You take this new value and compare it to a chart. If this new value is between X1 and X2 the tile is a type of stone. If it is between X2 and X3 it is air. If it is between X3 and X4 it is a cloud.

http://pastebin.com/GvMKEnQb

As for doing it faster than 1 tile per frame, look into coroutines. I’m not sure ActionScript has them, but the concept is what you need to look up.

 
Flag Post

Topic: Game Programming / Are there any errors in this C# Script?

Two noticeable things.

First:

CharacterController cc = GetComponent(); //Incorrect
CharacterController cc = GetComponent<CharacterController>(); //Correct

Second, the above code should go in Start().

 
Flag Post

Topic: Off-topic / Anime Addicts Anonymous (AAA)

I have high hopes for Mekaku.

 
Flag Post

Topic: Game Programming / Kong Username displayed above Unity3D character

Attach this to your camera or an empty gameobject that does not get destroyed between scenes.

using UnityEngine;

    /// <summary>
    /// Provides quick access to Kongregate's API system, allowing the submission of stats. It is best to handle setup of this class
    /// as soon as possible in your application.
    /// </summary>
    public class KongregateAPI : MonoBehaviour
    {
        /// <summary>
        /// Are we connected to Kongregate's API?
        /// </summary>
        public static bool Connected { get; private set; }
        /// <summary>
        /// The user's UserID.
        /// </summary>
        public static int UserId { get; private set; }
        /// <summary>
        /// The user's username.
        /// </summary>
        public static string Username { get; private set; }
        /// <summary>
        /// The game's authentication token.
        /// </summary>
        public static string GameAuthToken { get; private set; }

        void Start()
        {
            Connect();
        }

        /// <summary>
        /// Connect to Kongregate's API service.
        /// </summary>
        public void Connect()
        {
            if (!Connected)
            {
                Application.ExternalEval(
                    "if(typeof(kongregateUnitySupport) != 'undefined') {" +
                        "kongregateUnitySupport.initAPI('" + gameObject.name + "', 'OnKongregateAPILoaded');" +
                    "}"
                );
            }
            else
                Debug.LogWarning("You are attempting to connect to Kongregate's API multiple times. You only need to connect once.");
        }

        /// <summary>
        /// Submit a value to the server.
        /// </summary>
        /// <param name="statisticName">The name of the statistic. This is the name provided in the "Statistic name" section when you fill in the API when uploading your game.</param>
        /// <param name="value">The value to submit (score, kills, deaths, etc...).</param>
        public static void Submit(string statisticName, int value)
        {
            if (Connected)
                Application.ExternalCall("kongregate.stats.submit", statisticName, value);
            else
                Debug.LogWarning("You are attempting to submit a statistic without being connected to Kongregate's API. Connect first, then submit.");
        }

        private void OnKongregateAPILoaded(string userInfoString)
        {
            Connected = true;
            string[] parameters = userInfoString.Split('|');
            UserId = System.Convert.ToInt32(parameters[0]);
            Username = parameters[1];
            GameAuthToken = parameters[2];
        }
    }

And in your character class…

//Text is either a GUIText or 3DText
Text.text = KongregateAPI.Username;
 
Flag Post

Topic: Game Programming / As3: Adding all movieclips on stage to an array

I assume you want the following:

for (i = 0; i < mc.numChildren; ++i)
     array.push(mc.getChildAt(i));

//hittestfunction

You may need to do “int i = 0” instead. I don’t know AS3 syntax.

 
Flag Post

Topic: Off-topic / Go to speedtest.net

 
Flag Post

Topic: Game Programming / any means to increase size limits?

If your final size is 20-30mb, you can contact the staff and have them remove the limit. You will need to upload a temporary file first.

 
Flag Post

Topic: Off-topic / What have/are YOU doing to improve OT as a whole???!!! (aguspal thread)

In a way, not posting here is the best thing everyone can do for OT.

 
Flag Post

Topic: Game Programming / Unity C# API Tutorials?

KongregateAPI.Submit("hs", score.myscore);
 
Flag Post

Topic: Off-topic / I think my parents are having sex right now while I am writing this title...(Hardcore thread)

Originally posted by Haruhion:

So your parents only lasted 45 minutes? they should keep practicing, maybe do some cardio.

Non-porn sex generally only lasts an average of 1 minute 48 seconds.

 
Flag Post

Topic: Off-topic / What is the worst human in history?

Originally posted by DrOctaganapus2:

I’d say Stalin; Hitler killed more people faster, but Stalin’s overall bodycount goes over 60mil I believe.

His definite body count is around 10 million. As for Hitler, he did nothing wrong.

 
Flag Post

Topic: Game Programming / [Unity C# - Sight Cones] - Uzzbuzz's Questions

Get the atan2 between the two game objects and add 10, then add that to your position. That should work.

I haven’t played around with AI in Unity, so I don’t know the best way to go about this.

 
Flag Post

Topic: Game Programming / Is self-promotion of games acceptable in this forum?

Originally posted by dragon_of_celts:

Exactly. Which is why “how do you like my game?” is a game design question (if anything). It is not asking for programming advice/tips, but for opinions on the game’s design. Thanks for coming over to the dark purple with blue paisley side.

This is about as blunt as you can make it. Anything really disregarding this is just fighting back because they don’t want to admit that they were incorrect in this fact. “How is my game” is NEVER a programming question. NEVER. It is fundamentally, by nature, a design question.

 
Flag Post

Topic: Game Programming / Unity C# API Tutorials?

Attach the following to an empty gameobject. Make sure the object is not destroyed between scenes.

using UnityEngine;

namespace MyNamespace
{
    /// <summary>
    /// Provides quick access to Kongregate's API system, allowing the submission of stats. It is best to handle setup of this class
    /// as soon as possible in your application.
    /// </summary>
    public class KongregateAPI : MonoBehaviour
    {
        /// <summary>
        /// Are we connected to Kongregate's API?
        /// </summary>
        public static bool Connected { get; private set; }
        /// <summary>
        /// The user's UserID.
        /// </summary>
        public static int UserId { get; private set; }
        /// <summary>
        /// The user's username.
        /// </summary>
        public static string Username { get; private set; }
        /// <summary>
        /// The game's authentication token.
        /// </summary>
        public static string GameAuthToken { get; private set; }

        void Start()
        {
            Connect();
        }

        /// <summary>
        /// Connect to Kongregate's API service.
        /// </summary>
        public void Connect()
        {
            if (!Connected)
            {
                Application.ExternalEval(
                    "if(typeof(kongregateUnitySupport) != 'undefined') {" +
                        "kongregateUnitySupport.initAPI('" + gameObject.name + "', 'OnKongregateAPILoaded');" +
                    "}"
                );
            }
            else
                Debug.LogWarning("You are attempting to connect to Kongregate's API multiple times. You only need to connect once.");
        }

        /// <summary>
        /// Submit a value to the server.
        /// </summary>
        /// <param name="statisticName">The name of the statistic. This is the name provided in the "Statistic name" section when you fill in the API when uploading your game.</param>
        /// <param name="value">The value to submit (score, kills, deaths, etc...).</param>
        public static void Submit(string statisticName, int value)
        {
            if (Connected)
                Application.ExternalCall("kongregate.stats.submit", statisticName, value);
            else
                Debug.LogWarning("You are attempting to submit a statistic without being connected to Kongregate's API. Connect first, then submit.");
        }

        private void OnKongregateAPILoaded(string userInfoString)
        {
            Connected = true;
            string[] parameters = userInfoString.Split('|');
            UserId = System.Convert.ToInt32(parameters[0]);
            Username = parameters[1];
            GameAuthToken = parameters[2];
        }
    }
}
 
Flag Post

Topic: Game Programming / Is self-promotion of games acceptable in this forum?

Originally posted by saybox:
Originally posted by dragon_of_celts:

So why is there a Game Design forum (for games they have programmed or intend to program or are considering programming)? Or any other forum that can be, with some stretching, connected to programming?

Don’t ask me – my original suggestion was to move GiTD to the Game Design board. I just don’t think it makes any sense to say “GiTD is about programming and nothing to do with Game Design” or “Some feedback threads are okay here but others aren’t”. It should be all or nothing.

No feedback threads should be accepted here. Only “I have a problem. Here is my code and here is my program. Help.”