| Author |
Message |
amari77

Joined: 19 Jun 2007
Posts: 140
Location: At the comp
400
0
|
Posted:
Sun Aug 19, 2007 8:00 pm |
  |
Ok. I think I would need to make it where when the player hittest the platform the gravity = 0 and then the players _y turns back to normal and the jump = false and onfloor = true. But i dont know how to make the _y turn back to normal. But thats only if the above idea is correct. |
|
|
 |
 |
Racoon

Joined: 14 Dec 2006
Posts: 3279
11068
0
|
Posted:
Sun Aug 19, 2007 8:09 pm |
  |
Ehehe, I love my students....student.
You are on a good path, but I got to know...
When you jump...what happens to your gravity?
And also...what happens when gravity is ++? |
|
|
 |
 |
amari77

Joined: 19 Jun 2007
Posts: 140
Location: At the comp
400
0
|
Posted:
Sun Aug 19, 2007 8:25 pm |
  |
Well when the player jumps , with the code i have now, the gravity = -12 so when i land i set it back to 0. And the gravity++ makes it continue to go up by 1. Oh so maybe i dont need to set the gravity = 0 becuz the gravity ++ will do that for me. Am i correct? |
|
|
 |
 |
Racoon

Joined: 14 Dec 2006
Posts: 3279
11068
0
|
Posted:
Wed Aug 22, 2007 8:56 am |
  |
hmm, interesting...
So your gravity will always increase by one correct?
So if your gravity always increases by one how could the platform stop it from
going past zero?
How could it be canceled out by a platform? |
|
|
 |
 |
amari77

Joined: 19 Jun 2007
Posts: 140
Location: At the comp
400
0
|
Posted:
Wed Aug 22, 2007 9:40 pm |
  |
I think i could make the platform so that when it is hitTest by the player gravity = 0.  |
|
|
 |
 |
Racoon

Joined: 14 Dec 2006
Posts: 3279
11068
0
|
Posted:
Wed Aug 22, 2007 9:54 pm |
  |
Well what would happen if we put a code where
++ meets -- ? |
|
|
 |
 |
amari77

Joined: 19 Jun 2007
Posts: 140
Location: At the comp
400
0
|
Posted:
Wed Aug 22, 2007 9:56 pm |
  |
Oh that would make them cancel out. I forgot about the (--) sugn, Well didnt really even know about it. LOL. I understand what you sayin tho. |
|
|
 |
 |
Racoon

Joined: 14 Dec 2006
Posts: 3279
11068
0
|
Posted:
Wed Aug 22, 2007 10:40 pm |
  |
| x2i wrote: |
| Code: |
onClipEvent (load) {
//Sets the initial speed and downwards pull
gravity = 5;
speed = 5;
isJump = true;
}
onClipEvent (enterFrame) {
//Moves the player up or down
gravity++;
_y += gravity;
//Keys to move left and right
if (Key.isDown(Key.LEFT)) {
_x -= speed;
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
}
//Check whether the character is already jumping
//If not then jump
if (Key.isDown(Key.UP) && isJump == false) {
isJump = true;
_y -= 5;
gravity = -13;
}
}
//////platforms code/////
onEnterFrame = function () {
// Check whether platform has been landed on
while (hitTest(_root.player._x, _root.player._y, true)) {
// Stop player and allow him to jump again
_root.player.isJump = false;
_root.player.gravity = 0;
_root.player._y--;
}
}; |
|
In truth we are basically modeling our code after x2i's
Now with the instruction thus far you should really see how this particular code works.
However my method takes this formula and changes it a bit.
First break done this code, we'll get into making a simple game in a moment. |
|
|
 |
 |
amari77

Joined: 19 Jun 2007
Posts: 140
Location: At the comp
400
0
|
Posted:
Wed Aug 22, 2007 10:45 pm |
  |
I understand the code fully but i dont understand what u were asking me to do in your last post. Srry i was sleepin in class. |
|
|
 |
 |
Racoon

Joined: 14 Dec 2006
Posts: 3279
11068
0
|
Posted:
Wed Aug 22, 2007 10:53 pm |
  |
explain it in detail.
It'll help with whats next. |
|
|
 |
 |
amari77

Joined: 19 Jun 2007
Posts: 140
Location: At the comp
400
0
|
Posted:
Thu Aug 23, 2007 12:00 am |
  |
Ok. Here I go:
| Code: |
onClipEvent (load) {
//Sets the initial speed and downwards pull
gravity = 5;
speed = 5;
isJump = true;
}
|
^ These are the variables that control the MC's speed, gravity, and also checks if it can jump or not.
| Code: |
onClipEvent (enterFrame) {
//Moves the player up or down
gravity++;
_y += gravity;
//Keys to move left and right
if (Key.isDown(Key.LEFT)) {
_x -= speed;
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
}
|
^ This code enables the MC to be able to move left and right when the arrow keys ( Left and Right ) are down. Also the gravity++ makes the gravity increase by 1.
| Code: |
if (Key.isDown(Key.UP) && isJump == false) {
isJump = true;
_y -= 5;
gravity = -13;
}
}
|
^ This code makes the MC jump when the arrow Key. Up is down only if the MC is not already jumping. To make the jump effect the gravity is lowered so the MC will float up off of the platform.
| Code: |
//////platforms code/////
onEnterFrame = function () {
// Check whether platform has been landed on
while (hitTest(_root.player._x, _root.player._y, true)) {
// Stop player and allow him to jump again
_root.player.isJump = false;
_root.player.gravity = 0;
_root.player._y--;
}
}; |
^This code goes on the platform. This code makes the MC stop moving when he lands on the platform. It also makes it where the MC can jump again.
Theres my explanation teach. What do u think? |
|
|
 |
 |
chif ii

Joined: 16 Feb 2007
Posts: 2320
Location: maybe later
5163
0
|
Posted:
Sun Aug 26, 2007 5:48 pm |
  |
I take it you guys aren't on particle behavior yet, huh? |
|
|
  ![[ Hidden ] [ Hidden ]](templates/fisubgrey/images/lang_english/icon_email.gif)  |
 |
amari77

Joined: 19 Jun 2007
Posts: 140
Location: At the comp
400
0
|
Posted:
Sun Aug 26, 2007 8:51 pm |
  |
| chif ii wrote: |
| I take it you guys aren't on particle behavior yet, huh? |
What is that? And no i dont think so. |
|
|
 |
 |
chif ii

Joined: 16 Feb 2007
Posts: 2320
Location: maybe later
5163
0
|
Posted:
Sun Aug 26, 2007 10:31 pm |
  |
That's the movement of free-moving items, with and without the influence of outside forces, that are independent of one another but interact like a whole. Here, take this as an example. |
|
|
  ![[ Hidden ] [ Hidden ]](templates/fisubgrey/images/lang_english/icon_email.gif)  |
 |
amari77

Joined: 19 Jun 2007
Posts: 140
Location: At the comp
400
0
|
Posted:
Mon Aug 27, 2007 1:22 am |
  |
nope havent learned that yet but its nice.  |
|
|
 |
 |
|
|