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: FAQ. Frequently Asked Questions  (Read 5082 times)

0 Members and 1 Guest are viewing this topic.
FAQ. Frequently Asked Questions
« on: April 26, 2006, 11:41:53 am »
  • =/
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2284
Copied and pasted directly from IF ZFGC.

anyways....


hookshot:



Provided by Crystallizer


In the Hook Object, have a collision check with the Wall Object. Make the hook stop and set a variable

eg. global.hooked='true';

In the step event of the Hookshot Link or Link Object, check to see if the hook hit the wall.

if global.hooked='true' {
move_towards_point(obj_hook.x,obj_hook.y,5)} // move Link to the hook object. 5 is the speed of link when he moves to the hook object.
else //If the hook has not hit the wall
{
}

Finally, in Link's collision event with the hook, check to see if the hook is in the wall, destory the hook object, and set the hooked variable back to false.

if global.hooked='true' {
with (obj_hook) { instance_destroy } //destroys the hook object
global.hooked='false'; //sets the hooked variable back to false
}
else
{
}


huds:



Provided by Crystallizer


You can do that easily by using views.

If you haven't enabled views yet. Select the room that the HUDs going to be in. Go to the Views Tab and check "Enable the use of Views" and "Visible when room starts". Mess around with the W and H and choose the object (Link) to follow.

To get the HUD appear in the top right corner, you need to put:

view_left[ + 10, view_top[ + 225 //Change 10 and 225 to suit your needs


Walking (left, but work from there ^_^):



provided by Scrappersa


if place_free(x-6, y) {
x -= 6;
image_single = -1;
global.facing = "left";
sprite_index = walking left;
}


Boomerang


Provided by Scrappersa



//come back


move_towards_point(link.x, link.y)

//move, name this script boomerang move

if global.linkdirect = left
{
hspeed = arguement0
}

if global.linkdirect = right
{
hspeed = arguement1
}

if global.linkdirect = up
{
vspeed = arguement3
}

if global.linkdirect = down
{
vspeed = arguement4
}

//Now use this in the button event of link pressing a button
//4 and -4 are good just to test with, anything can be used
boomerangmove(-4, 4, -4, -4)


I made an prioritised movement! Very easy, but may not work. It worked for me!
Step Event:
if (keyboard_check(vk_left)=true) then
{
sprite_index=playerwalkleft;
playerDirection="Left";
if (place_free(link.x-playerSpeed,y))then
{
x-=playerSpeed;
}
}

if (keyboard_check(vk_right)=true) then
{
sprite_index=playerwalkright;
playerDirection="Right";
if (place_free(link.x+playerSpeed,y))then
{
x+=playerSpeed;
}
}

if (keyboard_check(vk_up)=true) then
{
playerDirection="Up";
sprite_index=playerwalkup;
if (place_free(link.x,y-playerSpeed))then
{
y-=playerSpeed;
}
}

if (keyboard_check(vk_down)=true) then
{
playerDirection="Down";
sprite_index=playerwalkdown;
if (place_free(link.x,y+playerSpeed))then
{
y+=playerSpeed;;
}

Then add another code.

if (keyboard_check(vk_left)=false) and
(keyboard_check(vk_up)=false) and
(keyboard_check(vk_right)=false) and
(keyboard_check(vk_down)=false) then
{
sound_stop(walk3);

if (playerDirection="Left") then
{
image_index=1;
sprite_index=playerstand;
}

if (playerDirection="Down") then
{
image_index=0;
sprite_index=playerstand;
}

if (playerDirection="Up") then
{
image_index=2;
sprite_index=playerstand;
}

if (playerDirection="Right") then
{
image_index=3;
sprite_index=playerstand;
}

}


//Negative is left and up
//Positive is right and down

Ok, i??ve discoveres myself, if anyone wants it, here there is:

Saving:

Save files
QUOTE 
file_open_write("your filename")
file_write_real(global.rupeescount);file_writeln() //example of a real global variable
file_write_real(global.chest0001);file_writeln()
file_write_real(link.lives);file_writeln //:<_< //Not sure, example of a local variable
file_write_string(string(global.dir));file_writeln() // If you want to save a string
file_close()



Loading(RENEMBER, IN THE SAME ORDER YOU SAVED THEM)

QUOTE 
file_open_read("your filename")
global.rupeescount=file_read_real();file_readln()
global.chest0001=file_read_real();file_readln()
link.lives=file_read_real();file_readln() //In this case, the instance link must exist in the screen
global.dir=file_read_string();file_readln()
file_close()

Advanced movement
By cloudsquall:

Ok, it might be useful for someone out there.
No credit needed

You might have noticed a problem with handling Link's movement with the conventional method
(you know, the
if place_free(x-something,y) {x-=something}
thingy)

If for example something=2 and there is a solid object 3 pixels to the left of Link,Link will stop 1 pixel away from it.Most of the time this isn't
noticable,but when Link can just pass between two objects, a problem might occur.
So here's a workaround  for this:

Set two variables first:
CODE
global.xspeed=3; //or any other number
global.yspeed=3; //same here

Then in the step event:
CODE
if keyboard_check(vk_left)
{
     for (i=1; i<=global.xspeed; i+=1)
     {
           if place_free(x-1,y)  {x-=1}
     }
}

if keyboard_check(vk_right)
{
     for (i=1; i<=global.xspeed; i+=1)
     {
           if place_free(x+1,y)  {x+=1}
     }
}

if keyboard_check(vk_up)
{
     for (i=1; i<=global.yspeed; i+=1)
     {
           if place_free(x,y-1)  {y-=1}
     }
}

if keyboard_check(vk_down)
{
     for (i=1; i<=global.yspeed; i+=1)
     {
           if place_free(x,y+1)  {y+=1}
     }
}

That way Link will move by one pixel three times(or however many you want) each step
instead of moving by three pixels each step and the place_free check will occur for every pixel,letting Link move as close to a solid
object as possible.

Note: Add any other FAQ to this topic.
NO SPAM
« Last Edit: May 07, 2006, 12:15:22 pm by piers »
Logged

Limey

Re: FAQ. Frequently Asked Questions *Potential S...
« Reply #1 on: April 26, 2006, 08:19:33 pm »
I'm stickying, but you should probably bold/underline the titles of each tutorial, as to make looking through it easier.
Logged

Lunar

Re: FAQ. Frequently Asked Questions *Potential S...
« Reply #2 on: April 26, 2006, 08:29:48 pm »
Nice going, dumbass limey. <_< you locked it instead of stickying.
Logged

Limey

Re: FAQ. Frequently Asked Questions *Potential S...
« Reply #3 on: April 26, 2006, 08:32:05 pm »
>.< Oops
Logged
Re: FAQ. Frequently Asked Questions *Potential S...
« Reply #4 on: April 26, 2006, 09:10:50 pm »
  • =/
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2284
Lol, that was good.
Logged
Re: FAQ. Frequently Asked Questions
« Reply #5 on: May 22, 2006, 04:22:47 pm »
  • odens knop
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1608
I know a good guide for people getting started with GML!

Linkzorz!
Logged
|LEUS HERTAN MINAT|
Re: FAQ. Frequently Asked Questions
« Reply #6 on: May 01, 2009, 04:52:09 pm »
  • *
  • Reputation: +16/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1627
That save file bit is pretty useful. When I get around to adding a save function I'll definitely use it as a starting point.

Might as well make a usefull post while I'm at it. Here's a bit of code for advanced advanced movement. This will give you pixel perfect movement and it will also move you along sloped walls. I did leave out a lot of code to keep it somewhat simple. Just contact me if I left out too much. This code should be used at every step, with your speed being reset, and your speed and direction variables being calculated, beforehand.

--------------------------

// With (obj_Character_Control_Tile)

// Set VARIABLES
Test_Variable = 0;
Distance_Counter = 0;
New_X_Position = x;
New_Y_Position = y;
Total_X_Distance = 0;
Total_Y_Distance = 0;
Partial_Distance = 0;

// MOVEMENT routine
if (Walking_Direction mod 90 = 0) {Partial_Distance=1} else {Partial_Distance=sqrt(2)};

if (Walking_Speed <> 0)
{
    repeat (ceil(Walking_Speed))
    {
        if (Test_Variable = 0 and Distance_Counter < Walking_Speed)
        {
            // Check collision straight ahead
            Distance_Counter += Partial_Distance;
            if (Walking_Direction mod 90 = 0) {Partial_Distance=1} else {Partial_Distance=sqrt(2)};
            if (Distance_Counter = ceil(Walking_Speed)){Partial_Distance = Walking_Speed-Distance_Counter+1};
            script_execute(30,Walking_Direction, Partial_Distance);

            if (place_meeting(round(New_X_Position+Final_xspeed),round(New_Y_Position+Final_yspeed),obj_Solid)=false)
            {
                New_X_Position += Final_xspeed;
                New_Y_Position += Final_yspeed;
                Total_X_Distance += Final_xspeed;
                Total_Y_Distance += Final_yspeed;
            }
            else
            {

                // Check collision first angle
                if (((Walking_Direction+45)mod 360) mod 90 = 0) {Partial_Distance=1} else {Partial_Distance=sqrt(2)};
                script_execute(30, (Walking_Direction + 45)mod 360, Partial_Distance);

                if (place_meeting(round(New_X_Position+Final_xspeed),round(New_Y_Position+Final_yspeed),obj_Solid)=false)
                {
                    New_X_Position += Final_xspeed;
                    New_Y_Position += Final_yspeed;
                    Total_X_Distance += Final_xspeed;
                    Total_Y_Distance += Final_yspeed;
                }
                else
                {
                    // Check collision with second angle
                    if (((Walking_Direction-45)mod 360) mod 90 = 0) {Partial_Distance=1} else {Partial_Distance=sqrt(2)};
                    script_execute(30, (Walking_Direction - 45)mod 360, Partial_Distance);

                    if (place_meeting(round(New_X_Position+Final_xspeed),round(New_Y_Position+Final_yspeed),obj_Solid)=false)
                    {
                        New_X_Position += Final_xspeed;
                        New_Y_Position += Final_yspeed;
                        Total_X_Distance += Final_xspeed;
                        Total_Y_Distance += Final_yspeed;
                    }
                    else
                    {
                        // STOP MOVEMENT
                        Final_xspeed = round(New_X_Position)-New_X_Position;
                        Final_yspeed = round(New_Y_Position)-New_Y_Position;
                        Total_X_Distance += Final_xspeed;
                        Total_Y_Distance += Final_yspeed;
                        Test_Variable = 1;
                    };
                };
            };
        };
    };
};

// Create actual movement
parent_Character.hspeed = Total_X_Distance;
parent_Character.vspeed = Total_Y_Distance;

--------------------------------
// Script 30
// Input:
// argument[0] = Walking_Direction
// argument[1] = Partial_Distance

if (Sprite_Index_Counter = 0) {Final_xspeed = 0; Final_yspeed = 0}
else {if (argument[0] = 360) {Final_xspeed = argument[1]; Final_yspeed = 0}
else {if (argument[0] = 270) {Final_xspeed = 0; Final_yspeed = argument[1]}
else {if (argument[0] = 180) {Final_xspeed = -1*argument[1]; Final_yspeed = 0}
else {if (argument[0] = 90) {Final_xspeed = 0; Final_yspeed = -1*argument[1]}
   
else {if (argument[0] < 90)
{Final_xspeed=argument[1]*cos(degtorad(argument[0]));
Final_yspeed=-1*argument[1]*cos(degtorad(90-argument[0]))}

else {if (argument[0] < 180)
{Final_xspeed=-1*argument[1]*cos(degtorad(argument[0]-90));
Final_yspeed=-1*argument[1]*cos(degtorad(180-argument[0]))}

else {if (argument[0] < 270)
{Final_xspeed=-1*argument[1]*cos(degtorad(argument[0]-180));
Final_yspeed=argument[1]*cos(degtorad(270-argument[0]))}

else {Final_xspeed=argument[1]*cos(degtorad(argument[0]-270));
Final_yspeed=argument[1]*cos(degtorad(360-argument[0]))}

;};};};};};};};
Logged
Pages: [1]   Go Up

 


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



Page created in 0.513 seconds with 48 queries.

anything