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:
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:
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:
//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:
//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?