Technique of making enemies.

This forum is currently in read-only mode.
From the Asset Store
Make your own platformer for both the web and mobile easy with this Santas Platformer Template, FULLY DOCUMENTED
  • Hey guys, what's up?

    I'm glad I found this forum a month ago or so, I have a lot of updates on my Mega Man X engine. I've made just 2 enemies (1 of them is buggie though). But I want to know if there is better techniques.

    I've followed the Deadeye's tutorial, I make my enemies doing the Spawn object thing, and for each Spawn Box, create a enemyBox, and I program the enemy.

    I use this kind of animations:

    <img src="http://sprites-inc.co.uk/files/X/X1/Enemy/new%20versions/mmx1-e-cannonlift.gif">

    Then I make a timer (for timers I use 2 events, 1 for set a value, and then another to check if the value is not 0, substract 1). The timer is for actions, so if the timer is "X", that means an animation is playing, so if "Y" animation is playing, create a Ball Object (a bullet).

    It's complicated when I'm trying this enemies:

    <img src="http://sprites-inc.co.uk/files/X/X2/Enemy/mmm-mmx2scorpin.gif">

    But also there is this kind of sprites:

    <img src="http://sprites-inc.co.uk/files/X/X3/Enemy/rmx3_blady.gif">

    But I don't know how should I program that seems pretty complicated.

    So, what do you recommend me? Please tell me your techniques to make enemies.

    Thank you!,

    Carlos.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • you can check if animations are playing, which one and in which frame using sprite conditions.

    Also, I'm pretty sure that scorpion looking thing was animated with separate objects. It may look weird or use too much VRAM the way you're doing it now. I recommend trying animating it with bones, only not too much because it's rather difficult to animate that way.

  • I don't think you would need bones, and I don't think that sprite is going to have too much effect on VRAM.

    What is confusing is what it's doing. I have no idea how that thing is supposed to move or attack.

    What you should do, if you know how it should move, is separate the frames into their own animations. That's the first step.

    Second, create a timer to control when it switches from moving to attacking. Or for when it switches from attack 1 to attack 2, etc.

    Third, when the enemy is activated (like, when it's on the screen) start the timer. When the timer counts down, switch modes.

    When one mode is active (you can use a "mode" variable for this) then perform only the actions that it should be performing.

    Something like so:

    + Scorpion is On Screen (or whatever)
    + Trigger Once
        -> Scorpion: Value('active') to 1
        -> Scorpion: Set Value(myTimer') to 2
    
    + For Each Scorpion
    + Scorpion.Value('active') = 1
        + Scorpion.Value('myTimer') > 0
            -> Subtract 60*timedelta from Scorpion.Value('myTimer')
    
            + Scorpion.Value('myTimer') <= 0
                -> Scorpion: Set Value ('mode') to random(3)
                -> Scorpion: Set Value ('myTimer') to 2
    
        + Scorpion.Value('mode') = 0
            -> Do movement actions
    
        + Scorpion.Value('mode') = 1
            -> Do attack 1 actions
    
        + Scorpion.Value('mode') = 2
            -> Do attack 2 actions
    [/code:12mit8ay]
    
    Obviously this is just the theory part of it, you will need to fill in the blanks.  But something like this will make it so that every 2 seconds the scorpion will pick a random "mode" and then you can use that mode variable to control what it's doing, whether it's moving, shooting a bullet, playing the proper animation, or whatever.
    
    This single "mode" setting is what's known as a state machine.  You basically boil down everything that the enemy can do into separate chunks, and pick one state, or "mode," at a time to control which chunks are being processed at that moment.  This is a very simple version of a state machine, they can get rather complex, but they do make things a lot easier when doing things like AI and controls and animation.
    
    Also, you don't necessarily have to use a timer, like I showed.  You can set the state based on whatever you like, such as an animation finishing.
  • Well at least I was not too lost

    I was wondering how to make sprites with "bones", I think it's pretty complicated and I can't see the adventages.

    Other question, what is "timerDelta" for? I haven't use it and maybe it would help me.

    And also I've discovered the Random function by Deadeye's post, so thank you

    And thank you for answering,

    Carlos.

  • timedelta is the measured difference in time between the current frame and the previous one. It is most used when dealing with movement.

    bones are very complex, but the advantage is using a single sprite for each part of animations made out of moving parts. I believe right now the benefits do not outweigh the difficulty in making them, but they should =/ perhaps later they will.

  • Timedelta is the number of seconds between ticks. It's a very low number. The number changes slightly from tick to tick because processing speed may vary.

    Anyway, if your fps is 60 and you say "subtract 60*timedelta" to something, it will average out to subtracting 1 every second. So in that timer example I posted, you set the timer to 2, and subtract 60*timedelta, that means the timer will run out in two seconds.

    If instead you told Construct to "Always -> subtract 1 from timer" then on very fast computers the timer would be shorter than two seconds, and on very slow computers it could be longer than two seconds. Timedelta makes sure it's the same on all computers.

    But yes, mostly it's used for moving things around to make sure stuff runs at the same speed on all computers. All the built-in behaviors use timedelta automatically.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)