For all of your programming needs and wants.


    Agalag - Behind the scenes.

    Share
    avatar
    SoulRed12
    Moderator
    Moderator

    Posts : 129
    Join date : 2009-05-08
    Age : 27
    Location : West-coast USA

    Agalag - Behind the scenes.

    Post by SoulRed12 on 11/2/2009, 10:12 pm

    Well since I don't write games anymore, I don't have any big secrets to keep about my programming so I figure it's okay to explain a little about how it was written.

    First of all, here's a link to the game.

    Okay, down to business. Feel free to reply with a question, if you want. No guarantees that I'll answer, but I'll definitely try, and really, you never know.

    (I probably won't be adding any actual code, only because I don't have access to the original file without starting up my windows computer which I'm almost never on. But I'll try and describe what the code does to the best of my ability.)

    Contents:
    Section 1: The enemies
    Section 2: The player
    Section 3: Menus
    Section 4: Saving

    ~~~Section 1: The enemies~~~
    The most basic thing to say about the enemies (which you control) is that they are arranged in a ds_grid. The grid's cells contain the id numbers of each individual enemy object, which have a Boolean variable which tells them whether they should stay with the fleet. They also have x and y variables containing their position in the ds grid, so they can get the correct location (when they're expanding and shrinking, and moving up and down). When you click on one of the enemy ships, since the enemy will never go back to the grid, the boolean variable in the enemy ship is set to false and the enemy is "allowed" to do whatever it was meant to do.

    The diamonds in the corner, which tell you how many ships you can control at once, simply poll all the enemies to find the number of ones with the boolean set to false, and turns that many diamonds red. If there are too many active (the limit is 3 in the main game), then a condition returns false in the enemy object and the click does nothing.

    Creating new ships was also rather simple. All I had to do is keep the currently selected ship in a variable. But I also needed to keep track of the current stock, since it is different in every playthrough. To do that, I created an array with 10 indexes to hold each of the user's 10 ships in their stock. Then, I simply used numbers from 1 up to the number of ships to insert into the stock array which ship was in each place. In the master drawing object, when drawing the HUD, it simply used the numbers in the array to select a subimage of a single sprite containing all the "planks" with the pictures of the enemies. That is also, by the way, how the enemies functioned; the enemies were all a single object, but they changed subimages depending on their "enemy type" variable which was created and set upon right clicking on an empty grid spot.

    When the user actually right-clicks on one of the empty slots in order to create a new ship of the selected type, all that happens is a new enemy object is created and given the correct values that correspond to the grid cell the player clicked on. Then of course, the new id is taken and placed in the actual cell of the ds grid.

    And that's the basis of the enemies system. Be sure to write me questions if you have any, though I can't guarantee I'll be able to get to them.

    ~~~Section 2: The Player~~~
    Of course, by "player" I mean the "player" ship, not the actual person playing the game. I feel I should clarify that off the bat. Similarly, "enemies" are the ships you control.

    Anyways, the player is mostly just a big heap of A.I. Seriously, like a buttload. That was by far the most difficult part of the game for me, because at first the player would be too skilled, or become too skilled too quickly, etc. I tried to emulate a "practice effect" by having the player get better after he keeps dying. Of course that meant I had to implement lives, etc. and because lives have to run out, I also implemented the whole quarter system.

    Alright, now I'm going to try to describe the decisions made by the computer without sounding too convoluted. Basically, the player has to choose an action. This is determined in part by the vicinity to an enemy. If the enemy is too close, the player will move away to avoid getting hit. However if the enemy is above the player, the player will usually move to kill the enemy since the player shoots upwards.

    When no enemy is active, the player searches for the closest enemy in your fleet and attacks it. If there is an enemy active, however, it will detect it, and either move to shoot it, or move to escape it. It does something similar for bullets. If the player gets trapped in a corner it will move in one of the two remaining available directions, whichever would give a better chance at survival. However, if the player is programmed to be able to get caught in a corner; it all depends on the player's skill level at that point (essentially, how many times you've killed the player).

    The player stores the closest enemy's id number in a variable and then decides what to do based on things like distance, direction, position, etc. However, the player also stores the second closest enemy in order to be able to retain a secondary objective. If shooting the closest enemy won't work, because it's moving right at him, for example, the player will *try* to target the second-closest enemy as long as it can avoid being killed by the closest. It also lets the player determine when two enemies are coming from opposite sides so it can move in another direction (i.e., two enemies on left and right, player moves up or down, depending on vertical position of enemies).

    Of course, computer A.I. has to be fallible, and that's why I made the skill system. As I mentioned already, the player keeps track of how many times it has been destroyed, and gets "better" by having faster reaction times, shooting more, and being more likely to escape from corners, approaching enemies, etc. Every time the player is killed, his skill goes up.

    That's about it for the player. Trust me, it was MUCH more complicated when actually having to figure out and program this all from scratch. XD

    Let me know if I left anything out.


    Last edited by SoulRed12 on 11/3/2009, 10:50 pm; edited 1 time in total
    avatar
    SoulRed12
    Moderator
    Moderator

    Posts : 129
    Join date : 2009-05-08
    Age : 27
    Location : West-coast USA

    Re: Agalag - Behind the scenes.

    Post by SoulRed12 on 11/2/2009, 10:12 pm

    [reserved for more of the guide]

    Sorry for the double post, but I'll be updating the guide periodically, and I'm reserving this spot in case I need extra room if the board has a character limit turned on or something.
    avatar
    John
    Admin
    Admin

    Posts : 265
    Join date : 2009-04-20
    Location : U.S.A.

    Re: Agalag - Behind the scenes.

    Post by John on 11/28/2009, 1:31 am

    Our board have no character limits. I find those annoying Razz


    _____________________
    Any questions or concerns? PM me.

    Sponsored content

    Re: Agalag - Behind the scenes.

    Post by Sponsored content


      Current date/time is 11/19/2017, 4:24 am