Alice Community

Alice Community (http://www.alice.org/community/index.php)
-   How do I...? (http://www.alice.org/community/forumdisplay.php?f=16)
-   -   Stuck making a platform game! Please help! (http://www.alice.org/community/showthread.php?t=6245)

mcb0193 04-03-2011 06:39 PM

Stuck making a platform game! Please help!
 
1 Attachment(s)
I am making a side-scrolling platformer, and would like to make it so that the character turns in the direction that she moves (ex: if she is facing right, and the user tells her to move left, she turns around before moving). I also want to make it so that the turn method won't be called if she is already facing in the direction of the movement. I figured I'd need to use an if/else statement for this, but I can't find a function for it.

I've uploaded the file below for reference. I will greatly appreciate any help.

nickster654 04-05-2011 07:23 PM

[QUOTE=mcb0193;33435]I am making a side-scrolling platformer, and would like to make it so that the character turns in the direction that she moves (ex: if she is facing right, and the user tells her to move left, she turns around before moving). I also want to make it so that the turn method won't be called if she is already facing in the direction of the movement. I figured I'd need to use an if/else statement for this, but I can't find a function for it.

I've uploaded the file below for reference. I will greatly appreciate any help.[/QUOTE]

im kinda stumped on this one, try using some boleon variables though

Lordelwood 04-05-2011 08:16 PM

i was thinking a variable as well, ill take a look at it and see what i can do...

Lordelwood 04-05-2011 09:02 PM

here is a good game that i think has what your looking to do, take a look at it get some ideas about the code and such

[URL="http://www.alice.org/community/showthread.php?t=5564&highlight=dark"]http://www.alice.org/community/showthread.php?t=5564&highlight=dark[/URL]

Matchewawa 04-05-2011 09:22 PM

Put some if's or while's in the method that you're attaching to the pressed keys (lets say left and right arrow keys). Make a variable, and make it so that while the left arrow key is pressed, 'move left' method is triggered. In this method, you make a couple of if's in a do together. Make one say, "if 'variable' == 1", which is the default variable value. Make this if turn you to face left and set the variables value to, say, 2, rather than the default 1. So now you only turn and go left that first time that you press the left arrow key. Now, in the other if, put "if 'variable' == 2" and make this if cause you just to move left and not change a variable while your at it. (This will work as long as you start facing right.) It will make you turn left and then just move left without turning. Now, basically, this means that when you are facing left, the variable is 2, and when you are facing right the variable is 1. Because of this, when you copy this code into a seperate method for the right arrow key, not only change it so that you move right rather than left, but also reverse what you are setting the variable to in the method (don't change the starting value of the variable). Otherwise, you will turn when you move right, while you are already facing right.

I'm not much of a teacher. I don't explain things very well, but I hope this will help.

Matchewawa 04-05-2011 10:32 PM

Here it is
 
1 Attachment(s)
Here you go. This actually only took me like two minutes, but I've been learning a lot about Alice (self-teaching since my teacher "only knows the basics") at a very fast pace so that's probably it. I think I deleted a couple methods. The jumping and sprinting, I think, but that shouldn't be too much trouble to add back in.

P.S.
I used the same method that I explained in my previous comment to do this.

P.P.S.
Health is finally working for the player and enemies in my RPG, WOOT WOOT! Was trying to get it working for like three hours straight today!

mcb0193 04-07-2011 07:22 AM

Thanks!
 
Thank you so much for helping me! I never really knew how to use variables, and you helped me understand them better.

However, there's only one complaint; it's that she only turns partially around if you release the key too early. This was easy to solve, though: I simply cut and pasted one of the "if" statements into a new method (turnLeft; turnRight) and put those methods into "begin" on the event. That way, she always turns fully around before moving.


All times are GMT -5. The time now is 08:10 PM.

Copyright ©2018, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.