Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> [GM]Moving up slopes, GameMaker
Monopolyking
post Aug 14 2008, 10:56 AM
Post #1



Group Icon

Group: Member
Posts: 1
Type: None
RM Skill: Undisclosed




I wrote this tutorial about a month ago, it has been helpful for a couple of people. However, im looking for any errors within the script that can be improved because currently im using RMXP (RGSS) but I dont want abandon GM since I think im pretty good at it:

QUOTE
Welcome to an edition of Platformer’s Guide 99. Today we are covering many things which includes:

-Image_scaling

-Slopes

-For Loops

-Movement

-And others

I took the liberty of getting all sprites and objects already created for you; so if you want to follow along exactly, here’s the file:

Link: http://www.megaupload.com/?d=8TT7QGZG

Note: There are many ways to accomplish what I am about to teach you, and I am not saying this way is the best, but it’ll do exactly as I am teaching you

Yes I know the graphics are kind of ugly and poorly done, (but its pretty hard to make good slopes because of the GM sprite editor) but that shouldnt stop us from learning!

The first thing we want to do is go into our Mario’s Create Event… In there add this code:

image_index=0

image_speed=0

Because our Mario sprite is actually an animation (with both our standing and walking sprites), we have to specify that we want him to stand. So we set the image index to 0. And in order for the animation to NOT play and only his standing sprite be shown, we set the image speed to 0.

Now, lets go into Mario’s Right Key event and add this:

if (place_free(x+1,y))
{

image_speed=0.3

image_xscale=1

x+=3

}

Here’s what we did. We first checked to see if the position right of him was free, if it was we set his image_speed to 0.3 so that the animation will play, and we used image_xscale=1 — What is that??? Here’s a little information about image_xscale (skip down if you’re uninterested).

First, when you are creating your sprites, you must have precise collision checking OFF and also you have to certain your origins. Lastly, you have to create a mask (a blank sprite) with about the same sprite properties as your object and “equip” that mask on your object.

So anyway, when we put image_xscale=1 that means our sprite is going to be facing right (since right is the original direction is was created facing), and if we put image_xscale=-1 he would be flipped to face left.

And lastly, we increase his x by 3 to make him move.

Now as you can see, when you stop, his animation still plays! We can easily remedy this by going into his Keyboard Release Right event and putting this:

image_index=0

image_speed=0

Now repeat the process for the Left Key and Left Key Release event, but make sure you check if the place left of him is free and make him face left (image_xscale=-1) and move him to the left (x-=3).

So now lets learn about slopes: The basic idea is to check to see if you’re meeting a slope if you move in that direction. Now as you can see, we have 3 slope objects. One for the right, one for the left, and another one which is going to act as the parent. (I may have forgotten to do so, but make sure in the slopeR and slopeL object properties, slope is set as their parent).

Now lets go back into Mario’s Right Key event and make him move up that slope!

Under the x+=3 part, insert this:

if (place_meeting(x,y-1,obj_slope))

{

for (i=0;i<5,i+=1)
{

y-=i

}
}

Okay! So first we checked to see if he is meeting the slope, then we created a for loop. Here’s some information about for loops (skip down if you’re uninterested).

When you create a for loop, the first statement is initialized; in this case (i=0). Then the second statement is checked (i<5) if it is true (in this case it is, 0 is less than 5) the third statement is executed (i+=1). And it keeps looping until the second statement is false.

Because we SUBTRACT from our y value, that means we are going up; so our for loop keeps Mario moving up as long as he is in the presence of a slope. (Make sure to repeat the for loop for the left key event too)

So here’s what we have in our Right Key Event so far:

if (place_free(x+1,y))
{

image_speed=0.3

image_xscale=1

x+=3

if (place_meeting(x,y-1,obj_slope))
{

for (i=0;i<5,i+=1)
{

y-=i

}
}

}

Now if you havent realized… Because all these statements are under the if statement that checks to see if the place right/left of Mario is free, they’ll only work if that condition is met. So at the end of all of that (after the last }) we’ll add this:

else

{

exit

}

EXIT?!?! I dont want to exit the game!!!! No no no, it’s just saying that if that condition isnt met, exit that script. Make sure to repeat everything for the left key event but make sure it applies to the left.

Now you may realize that Mario moves up the slopes, but not down the slopes… Let’s remedy this situation by going into Mario’s Step Event and adding this code:

if (place_free(x,y+1) && vspeed==0)
{

move_contact_all(270,3)
}

This time in our if statement, we have two conditons that must be met. The first one checks to see if the place under us is free, and the second one checks to see if vspeed is equal to 0 (which it is because we never changed it). Once those conditions are met, we use move_contact_all(270,3).. This means that Mario will move a maximum distance of 3, downward (direction 270) until he hits an object..

Now lets run the game; Mario should be able to move up AND down the slopes.

Last Minute Reminders

-Make sure that the objects (obj_slopeR and obj_slopeL) has obj_slope as their parent in their object properties

-Make sure that Mario has the mask sprite as his mask in his object properties

-Make sure that Mario is in the room

-Make sure that the Left Key Events and Right Key Events are similar but apply to their directions

If you feel as if you went wrong somewhere, here’s the finished product

Link: http://www.megaupload.com/?d=NWAV9LSP
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 25th May 2013 - 11:18 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker