Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Making a Path to Sprites Follow

Author
Message
vitinho444
14
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 17th Dec 2011 23:56
Hey community!

So i got a struct for a enemy (struct Enemy1)

And now before the game starts i got:



This creates 3 enemy's with the struct of the Enemy1 (The easiest) and spawn's them on the screen in their positions.

Ok now what i want to do is to move them in a certain path.


I already got the Move Function:



So i can make easily:



Ok so i already tryed a system:


It didn't work at all...

If you have a working system that can make the sprite goes through a path in the determinated time and stuff please help me


If you helped me give me the name to put in the credits. No matter what you helped as long as you gived something, you are in the credits page

C++ Medium 3.5/5
VB6 Advanced: 4/5
VB.NET Advanced: 4/5
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 18th Dec 2011 07:52
for a proper system you will either use a vector () or have some mess with pointers (which could produce the same effect as the vector), so the best thing is to use a vector, here's some pseudo code:


so for the loop, we're doing this:
do we have more than 0 way points?
YES: point the sprite towards it and move, have we reached it?
YES: remove this target point from the vector(our array), we know it's the 0th (very first) element of the vector so we will erase the beginning of the vector
so then, next waypoint on the vector will be the 0th because the 0th was erased, thus this will keep going untill the size reaches 0 which indicates no more points to go
note that checking if a point is reached won't be a "==", you will check if it's in range, for example:
if ( abs ( x1 - x2 ) < speed / 2 && abs ( y1 - y2 ) < speed / 2 )
//reached
i used speed/2 to be the epsilon because, it will be the best to fit to cause no flickering, i think that's the best you can check for
also, i gave you the d bPointSprite function a couple of weeks ago so i think you'll be fine

vitinho444
14
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 18th Dec 2011 12:52
wow...

Hassan i dont know why but you keep suprising me (obvious i dont know why because you are just the best =D)

Well, and suprisingly i understood all you said.

I got the struct ready and inside the main function i got:



I dont know if its the right place ..

now the problem is that it doesnt recognise path1V (vector)

And another thing:

How can i make the Move function (for general, for all enemies) inside the Update one? so it can recognize that it needs to move a determined enemy .. or i can just use the point and dbmove


Thanks

C++ Medium 3.5/5
VB6 Advanced: 4/5
VB.NET Advanced: 4/5
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: &lt;script&gt; alert(1); &lt;/script&gt;
Posted: 18th Dec 2011 13:31
you don't need a move function because all it does is dbMoveSprite, just put dbMoveSprite inside the update function, vector<Path1> path1V; must be a part of the Enemy1 struct and

should be inside the Init function, though, i already mentioned this in the previous post so if you are lost just read it again

vitinho444
14
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 18th Dec 2011 14:38
I still got the problem of indentifying the vector.
it cant indentefy the path1V

C++ Medium 3.5/5
VB6 Advanced: 4/5
VB.NET Advanced: 4/5
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: &lt;script&gt; alert(1); &lt;/script&gt;
Posted: 18th Dec 2011 16:48
how about some code? it should be like this:

and


vitinho444
14
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 18th Dec 2011 18:43


I got error on:









Quote: "1>.\Main.cpp(69) : error C2059: syntax error : '{'
1>.\Main.cpp(69) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>.\Main.cpp(79) : error C2059: syntax error : 'for'
1>.\Main.cpp(79) : error C2143: syntax error : missing ')' before ';'
1>.\Main.cpp(79) : error C2238: unexpected token(s) preceding ';'
1>.\Main.cpp(79) : error C2143: syntax error : missing ';' before '<'
1>.\Main.cpp(79) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\Main.cpp(79) : error C2238: unexpected token(s) preceding ';'
1>.\Main.cpp(79) : error C2143: syntax error : missing ';' before '++'
1>.\Main.cpp(79) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\Main.cpp(79) : error C2059: syntax error : ')'
1>.\Main.cpp(80) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>.\Main.cpp(237) : error C2065: 'path1v' : undeclared identifier
1>.\Main.cpp(237) : error C2228: left of '.begin' must have class/struct/union"


:S sorry for the interruption

C++ Medium 3.5/5
VB6 Advanced: 4/5
VB.NET Advanced: 4/5
3d point in space
15
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 18th Dec 2011 19:42
i don't think you can have a for loop in a struct like what you have.

Go through yourself at a wall.
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: &lt;script&gt; alert(1); &lt;/script&gt;
Posted: 18th Dec 2011 20:04
i said this is in the Init function (Load function..) don't you read what i post

vitinho444
14
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 18th Dec 2011 20:09
I just fixed all errors

Now ITS MOVING !!!!!

I JUST LOVE YOU HASSAN AND you 3d point in space for telling me that error, i didnt see it xDD

Omg its moving!!!!

OMFG I CANT BELIEVE IT!!!



HASSAN HOW DID YOU DO THAT!!!!!!!!!??

I LOVE THE WORLD!!

C++ Medium 3.5/5
VB6 Advanced: 4/5
VB.NET Advanced: 4/5
vitinho444
14
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 18th Dec 2011 22:41
hey hassan, can you give me that website of DirectX 9 or 10 i dunno again?

C++ Medium 3.5/5
VB6 Advanced: 4/5
VB.NET Advanced: 4/5
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: &lt;script&gt; alert(1); &lt;/script&gt;
Posted: 19th Dec 2011 08:36
what website, this?

vitinho444
14
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 19th Dec 2011 16:31
yes its that i will learn DX 11 =D

Do you recommend?

I just fall in love with the water effect tutorial


You rock hassan =D

C++ Medium 3.5/5
VB6 Advanced: 4/5
VB.NET Advanced: 4/5
vitinho444
14
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 20th Dec 2011 16:19
Ok, i made a map and i have all the coordinates of the path

here it is:


But i still got a problem..

When it reaches the final destination i told him that he can spawn again (start over) :




But .. he "doesn't listen" and just shutdown the game...

Any thing i can do so he can start all over again?

C++ Medium 3.5/5
VB6 Advanced: 4/5
VB.NET Advanced: 4/5
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: &lt;script&gt; alert(1); &lt;/script&gt;
Posted: 20th Dec 2011 19:23


there, don't put anything other than re-filling the vector (the push_back part) (unless you want to do something upon finishing the path)

vitinho444
14
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 20th Dec 2011 23:17
Well... When it finishes that path i want to do a certain procedure.

Like:
He reached the end, so the player couldn't kill him, so lose 1 life.
Then delete the sprite so it can free up the ID but wait don't get rid of the "struct copy" so it can be used again.

Then i want to add a respawn time like 10 seconds and then:
If 10 seconds passed {
//push back the vector, not sure how to do that help me out hassan
cSpawn = true; //enemy can spawn =D
}


Not a complex system but full of unknow things i dont know in C++...

getting a book in my country about c++ its impossible.. so i only learn on the internet and not for gaming...

C++ Medium 3.5/5
VB6 Advanced: 4/5
VB.NET Advanced: 4/5
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: &lt;script&gt; alert(1); &lt;/script&gt;
Posted: 21st Dec 2011 13:03
how about this:
don't check for empty vector in your Enemy1::Update (the else {} part), and make a new simple function in Enemy1 like this:


and in your game loop, do this:


you shouldn't have any loading functions in Initialize, except for static stuff which is ok (if done properly)

vitinho444
14
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 21st Dec 2011 15:41
So.. in struct:



Then in LoadEnemy (Initialize)



Then in the update checking for if the vector is empty:




Then in the Loop, or just in Update of the Enemy it can be:


Is it right?

C++ Medium 3.5/5
VB6 Advanced: 4/5
VB.NET Advanced: 4/5
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: &lt;script&gt; alert(1); &lt;/script&gt;
Posted: 21st Dec 2011 16:05 Edited at: 21st Dec 2011 16:06
nnoo..
i strongly recommend you to start here, before any attempt at DirectX.

you cannot assign this function a value, all it's doing is telling whether the path is finished or not, why did you add all that pointless code there?
i thought i explained it pretty well: this is ALL you need

and in your game loop (this is not anywhere inside the struct), this:


though, you need to read on those concepts (structs/vectors/classes/a couple more basics) before you go on this way

vitinho444
14
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 21st Dec 2011 16:39
Ok hassan now i get it =D

Sorry :S

I saw another problem here.

If i change the speed of the enemy... it kinda get stuck in some place..

the perfect speed is -1 (1), with this it doesnt get stuck anywhere,

but per example, with -3 (3), it get stuck at the second point.

with -2 (2), it get stuck at third point..

C++ Medium 3.5/5
VB6 Advanced: 4/5
VB.NET Advanced: 4/5
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: &lt;script&gt; alert(1); &lt;/script&gt;
Posted: 21st Dec 2011 17:10
i did explain why this happens, previous topic maybe? dunno, it's your point reach check, between sprite position and path point, don't check if they are EXACTLY equal, check if the distance between them is less than <speed>

vitinho444
14
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 21st Dec 2011 17:54
i did this:



Its funny because its working but only when the dbSpriteY is less than Map1V[0].y or same for X so it cheats sometimes xD

How to fix it ? xDDD

C++ Medium 3.5/5
VB6 Advanced: 4/5
VB.NET Advanced: 4/5
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: &lt;script&gt; alert(1); &lt;/script&gt;
Posted: 21st Dec 2011 19:04 Edited at: 21st Dec 2011 19:05


vitinho444
14
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 21st Dec 2011 20:32
and you are right.. again =D

Thanks a lot hassan.

Do you know where i can learn how to use timers?
I want to make a respawn time =D

C++ Medium 3.5/5
www.oryzhon.com <-- My company's website (W.I.P)

Login to post a reply

Server time is: 2024-11-19 05:17:22
Your offset time is: 2024-11-19 05:17:22