Trouble with adding field types and Gravity
Blitz3D Forums/Blitz3D Beginners Area/Trouble with adding field types and Gravity
| ||
First of all I'm trying to add types like this: Player1\y = Player1\y + Player1\Gravity But it doesnt seem to register the "Player1\Gravity" part but if I replace it with a number it works fine. And my type player is defined like this: Type player ; main player Field Frame Field Status = 0 Field x, y Field TempX, TempY Field Health, Lives, Score, Gold Field DropFlag = 0 Field Gravity = 1 End Type Last, is there a better way to add gravity to my player other than this? Player1\y = Player1\y + Player1\Gravity If ImagesCollide(Player1Anim, Player1\x, Player1\y, 0, WhatLevel, GraphicsWidth()/2, GraphicsHeight()/2, 0) Player1\y = Player1\y - 1 EndIf |
| ||
I didn't think that you could attach numbers and things to the fields like that "Field Gravity = 1" Instead, try Player1\Gravity = 1 |
| ||
yeah,Field Gravity = 1 Won't do anything. I'm assuming it compiles though, or it would be throwing up an error. Field Status = 0 Field x, y Does that even complie? |
| ||
It shouldnt compile it. it should say something like: Type declared incorrectly |
| ||
Nope it compiled fine...I fixed that now. But does anyone know how to fix my gravity problem. By the way this is a 2d game, When my player walks off a hill my player doesnt keep "attached" to the level. Its like if you would to drive off a hill really fast you would be in the air for a bit. How can I keep my player "attached"? |
| ||
do this:Type player ; main player Field Frame Field Status Field x, y Field TempX, TempY Field Health, Lives, Score, Gold Field DropFlag Field Gravity End Type global p.player = new player p\gravity = 1 ;set all the other stuff too ;also If gravity = 1 p\y = p\y - 5;whatever value you need else endif |
| ||
OK, I have another question and I'm going to post it here instead of making a new thread. Now I have a level like this: +----------------+ |.........._..........| |.........| |.........| |-------| |-------| the periods represent nothing, air if you will. |......................| the --- and | represent walls +----------------+ And I need the player to stop when he hits the wall. My code looks like this: If Player1\Gravity = 1 Then Player1\y = Player1\y + 5 ; initial gravity If ImagesCollide(Player1Anim, Player1\x, Player1\y, 0, WhatLevel, GraphicsWidth()/2, GraphicsHeight()/2, 0) Then While ImagesCollide(Player1Anim, Player1\x, Player1\y, 0, WhatLevel, GraphicsWidth()/2, GraphicsHeight()/2, 0) Player1\y = Player1\y - 1 Wend endif endif But if I do this and the player collides with that wall, he will just "jump" to the top of the wall because of my While loop, any help please? |
| ||
If anyone can help that would be great. |
| ||
If Player1\Gravity = 1 Then Player1\y = Player1\y + 5 ; initial gravity If ImagesCollide(Player1Anim, Player1\x, Player1\y, 0, WhatLevel, GraphicsWidth()/2, GraphicsHeight()/2, 0) Then If ImagesCollide(Player1Anim, Player1\x, Player1\y, 0, WhatLevel, GraphicsWidth()/2, GraphicsHeight()/2, 0) Player1\y = Player1\y - 1 Wend endif endif You shouldnt use this: While ImagesCollide(Player1Anim, Player1\x, Player1\y, 0, WhatLevel, GraphicsWidth()/2, GraphicsHeight()/2, 0) cause it will freeze Use "If" It will update every frame so dont use while It usually is 30 or more fps, so updating shold be no problem. *DEPENDING ON THE GRAPHICS CARD* |