Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Generic Graphic and Drowning  (Read 2861 times)

0 Members and 1 Guest are viewing this topic.
Generic Graphic and Drowning
« on: August 12, 2010, 09:21:17 pm »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
I have been sitting on this for a while now. Don't know why I didn't post this before. I probably have been to busy with life and getting 4Sword's latest stuff in the engine (which is done now). But when working on the engine I actually had two things really bothering me.

The first one was the feature Swimming. Somehow it doesn't seem right to add that to the Stable Engine base. In all 2D Zelda games Link gains the ability to swim after he obtains an item, which can be pretty late in the game. Water actually is a barrier, preventing Link from reaching areas to early in the game. Thus it seemed to me more appropriate to have Swimming as an added feature that anyone can add if they wish for it. Just like weapons, such as the Boomerang. Link's primary reaction to deep water is to drown in it. That is why I implemented drowning.

The below code is from the drown script:
Code: [Select]
var round_i;

switch(argument0){
case STEP:
    if(state == LinkDrown){
        //Check for the end to return to LinkNormal
        if(image_index >= image_number - image_speed){
            maxi_x = MAX_NORM; maxi_y = MAX_NORM;
            x = prev_x - (prev_x mod 16) + 8;
            y = prev_y - (prev_y mod 16) + 8;
            image_index = 0;
            image_speed = 0;
            view_b = 0;
        }
    }else{
        //Link is touching water and not able to swim.
        //He is going to drown.
        x = x - (x mod 16) + 8;
        y = y - (y mod 16) + 9;
        switch(direction){
        case 0: sprite_index = sprLinkDrownR; break;
        case 90: sprite_index = sprLinkDrownU; break;
        case 180: sprite_index = sprLinkDrownL; break;
        default: sprite_index = sprLinkDrownD; break;
        }
        image_index = 0; image_speed = 0.33; counter = 0;
        able_x = 0; able_y = 0; able_d = 0;
        step_x = 0; step_y = 0;
        move_x = 0; move_y = 0;
        state = LinkDrown; substate = 0; weaponInd = -1;
        global.scr_R = 0;
        
        with(instance_create(x,y-3,genGraphic)){
            sprite_index = sprSplashL;
            image_speed = 0.33;
            image_index = 0;
            move_x = -0.5;
            dist_max_x = 100;
        }
        with(instance_create(x,y-3,genGraphic)){
            sprite_index = sprSplashR;
            image_speed = 0.33;
            image_index = 0;
            move_x = 0.5;
            dist_max_x = 100;
        }
    }
    break;
case DRAW:
    // 1. Floor the image_index.
    // 2. draw Link.
    //   a. draw added splash effects if needed.
    // 3. Loop the middle part a couple of times.
    round_i = floor(image_index);
    
    draw_sprite(sprite_index,image_single,x,y);
    
    if(round_i == 5)
        draw_sprite(sprLinkDrownSplash,0,x,y);
    else if(round_i == 6)
        draw_sprite(sprLinkDrownSplash,1,x,y);
        
    if(image_index >= 8 - image_speed && counter < 2){
        counter += 1;
        image_index = 4;
    }
    
    break;
}

If you look at the code than you'll see that there are two "genGraphic" objects created. This brings me to the second thing that was bothering me. The current engine did have a number of things implemented, but none of it was really finished. What I mean with this is that the movement and code was all fine and dandy, but graphically it still lacked a number of things. It lacked the graphics that do not interact with anything but are only there to be more pleasing on the eyes. My idea has always been that the engine has to be accessible to anyone. Even the people who want to build up their game like Lego. Thus the things in the engine had to look finished.

To me it seemed the easiest to do this with a simple temporary graphics object. And that is how I came with "genGraphic". On its own this object does not do much, because it lacks a sprite. After creation you have to assign a sprite and an animation speed to it. With the default setting this will play the animation once on the place of its creation and then destroy the object again. The object has some additional variables that can be set to alter the graphics behavior. You can set the number of times the animation has to run. Default it is set to 1, but a higher number for more loops can be set. Set the loop variable to 0 and it will loop indefinitely. You can also set a number of variables that allow the graphic to move in a straight line in any direction. After the graphic has traveled a maximum distance it will be destroyed. Note that it does not consider collisions. If desired a more complex graphic can be made of this. By assigning a script to the genGraphic object, it will override all the other code standard in the object.

below the code listings of this object:

Create Event:
Code: [Select]
scrGraphic = 0;
loop = 1;
move_x = 0;
move_y = 0;
dist_x = 0;
dist_y = 0;
dist_max_x = 0;
dist_max_y = 0;
Step Event:
Code: [Select]
//Check if it is a complex graphic driven by a script.
if(scrGraphic){
    script_execute(scrGraphic,STEP);
}else{
    if(move_x != 0){
        if(dist_x < dist_max_x){
            x += move_x;
            dist_x += abs(move_x);
        }else{
            instance_destroy();
        }
    }
    if(move_y != 0){
        if(dist_y < dist_max_y){
            y += move_y;
            dist_y += abs(move_y);
        }else{
            instance_destroy();
        }
    }
}
Draw Event:
Code: [Select]
//Is it a complex graphic driven by a script.
if(scrGraphic){
    script_execute(scrGraphic,DRAW);
}else{
    draw_sprite(sprite_index,image_single,x,y);
    if(image_index >= image_number - image_speed){
        loop -= 1;
        if(loop != 0)
            image_index = 0;
        else
            instance_destroy();
    }
}

The genGraphic object has been used with the Drowning state and when you push an pushable object in a hole. Well what do you guys think?
« Last Edit: August 14, 2010, 07:07:30 pm by Niek »
Logged
Re: Generic Graphic and Drowning
« Reply #1 on: August 13, 2010, 12:19:57 am »
  • d(-_-)b
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 36
There is a small error, if you keep pressing the arrow keys the animation never ends.

I like the genGraphic idea, maybe I'll copy it to my engine. But there's one thing that I don't like it, is how the animations happen, the image_speed will always result in bad animations since it will be a constant for each action and even if you try to manipulate it during the animations, there's no garantee that it will result in something good.
Logged
Re: Generic Graphic and Drowning
« Reply #2 on: August 13, 2010, 05:52:40 am »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
There is a small error, if you keep pressing the arrow keys the animation never ends.
Hmm, you're right I'll take a look at it.

I like the genGraphic idea, maybe I'll copy it to my engine. But there's one thing that I don't like it, is how the animations happen, the image_speed will always result in bad animations since it will be a constant for each action and even if you try to manipulate it during the animations, there's no garantee that it will result in something good.
With this I don't follow you. What is wrong with a constant image_speed. How come it will not result in something good? If you want something more complex like for every frame a different speed then you can always use a script for it.
Logged
Re: Generic Graphic and Drowning
« Reply #3 on: August 13, 2010, 03:21:09 pm »
  • d(-_-)b
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 36
The image_speed works for animations like walking or rolling but not to the drink animation, for example:

Image   Number of frames
#0   4 frames
#1   10 frames
#2   2 frames
#3   2 frames
#4   4 frames
#5   8 frames
#6   20 frames
#7   8 frames
#8   4 frames
#9   4 frames
#10   4 frames
#11   6 frames
#12   8 frames
#13   4 frames

As you can see, there's no way to use a constant image speed and have a good animation.
Logged
Re: Generic Graphic and Drowning
« Reply #4 on: August 13, 2010, 04:01:20 pm »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
Uhm, you are talking now about animations for Link, which is already implemented in the respective scripts, but that is not what the genGraphic object is meant for. The purpose of the generic graphic is to show some nice animation that does not interact with any of the objects in the room. Think about the crumbling shards of a broken pot, the falling leaves of a cut plant, the splash of something falling in the water, the puff clouds from walking on dust, or the afterimage of something that falls in a pit.

For example a monster falls in the pit. This means that the monster is destroyed and cannot hurt Link. If you only change the sprite_index into an after image the object remains the same and is thus still treated the same as a monster. By destroying the monster object and put in a graphic instead, it still looks as if the monster is falling in the pit but it gets ignored by the Link object.
Logged
Re: Generic Graphic and Drowning
« Reply #5 on: August 13, 2010, 11:28:01 pm »
  • d(-_-)b
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 36
I understand the purpose of the generic graphic and it is a great idea, in fact most generic graphics will have a constant image speed but there are exceptions like a pot shattering, you can see the difference between variable and constant:



Starting a little bit faster and slowing down the speed the variable speed gives a smooth effect to the animation.

Edit:
There's also another error, after you jump in a ledge and fall in a pit you can walk over the water.
« Last Edit: August 13, 2010, 11:54:31 pm by Freki »
Logged
Re: Generic Graphic and Drowning
« Reply #6 on: August 14, 2010, 07:06:11 pm »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
Okay, I fixed the errors. The first one was an error in the LinkDrowning state, the second one was an error in the engine itself. But it already had been fixed in the new version that will be released later.

Are there some more comments.
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.22 seconds with 51 queries.