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.

Author
Message
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 26th May 2010 06:11
Ok, i have this code in which Ive been working on. Its a 2d platformer game. Very simple by the moment.

I reached the point in which i have to bring the first enemies to my hero. My hero moves while the background moves to his opposite side, like it should do. Well, the point is that I dont have problems making a moving sequence like the hero and the background, but now that i have enemies, they got to have their own moving sequence, like... left to right, or, idk, up and down, u know, the way an enemy moves. But idk how i can make him have his own sequence WHILE my hero have also his own when u move it... idk, its hard to explain. What i want is an advice about how can i make the enemies in a game to move and not be interrupted by my hero moves, or backwards, about how to collocate that in the code... This may help:

My code (Its the entire code, thats why its so big, i just wanna be sure no detail is being forget, and... It have a lot of images because my hero has several actions and i have several backgrounds on it. The enemies are not putted in the code so u can be free about how should i put it )



Ty guys, Ive done a lot because of all of u (And ty Cloggy too =P)
Uber Ker Noober
17
Years of Service
User Offline
Joined: 13th Jan 2007
Location: Sheffield, UK
Posted: 26th May 2010 15:09
OKay I didn't really look at your code properly as.... its your entire game. What I've done in the past to make 2d platformer bad guys is to give them a very basic "path" normally two points or normally just the x co-ord (as y is handled by gravity)...

so first make a type for the enemy;


Now the path array;


OKay so then i'd set up an example enemy.
Then its path;
So then in the main loop


So just to explain those IF commands;
the first one checks if the enemy has reached the target and changes the target to the next node if it has.
the second checks if the enemy has reached the end of the path and restarts it if it has.
The third and forth one makes the enemy move towards the target depending if it is greater or less then the position.

I didn't test any of the above code I just wrote it out. I sepearted the bits you may not have come accross yet such as type and multi-dimensional arrays so you may need to read tutorials about them. Hope it helps / makes sense.
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 27th May 2010 01:02
Mmmm... I got what ur telling me, but what i need its an advice of how or where i can collocate in my code the enemy code. I know how to make the enemy move and those things, but i dont know how i can put that in my code while my hero those all of his actions in a different part of the code where the enemy code is... like, for example.

This is my main loop:



From that code, i can go to all the actions of my hero, Jump, bite, run, crouch, etc... but, how can i make that... even when im jumping, or biting or whatever action my hero is doing, the enemies keep moving and continuing with their normal routine without the need of having that code in the place im right now. How should i put it in the main loop so it works even if im not in the main loop but in a subroutine, like the actions of my hero?
zeroSlave
15
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 27th May 2010 01:25
You shouldn't stay in a sub routine while your hero is moving.

Set it up like this:


This way, your player is only moving a little bit each loop. Don't make a separate loop for each action (walking left, walking right, jumping, biting, running, etc.) in subroutines or your program will never leave that sub as long as that action is being performed. You will need to make it so that it does a little of the acion each sync. Every Sync update should run through the main DO-LOOP.

I know this doesn't really have any da codez in it, and probably sounds rather goofy, but hopefully it makes some sense.

My green thumb grew the tree my Trojan War horse was crafted from. With roses in our pockets we rally round the tombstones. Ashes to ashes, we all fall down.
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 27th May 2010 02:46
Mmmm... Yes, u know... ive tried that before, and they told me i should do it the way im doing it right now XD

I think there are several ways of making a game, idk, but i see that a lot of ppl use the "Global" thing, and... i have never know what that is or what is it for. Is it like for something that is always gonna happen? Well, i would love something like that... isn't there a code that makes something happens always without having to read that code or be in it?
zeroSlave
15
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 27th May 2010 03:29 Edited at: 27th May 2010 03:30
GLOBAL makes variables usable in functions.



Above will print "This works"
Below, it will not print this.



The reason being that if the variable, VarTest, is not set as "GLOBAL" in the beginning, it will not pass to a function. Inside the function, VarTest will equal 0.

My green thumb grew the tree my Trojan War horse was crafted from. With roses in our pockets we rally round the tombstones. Ashes to ashes, we all fall down.
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 27th May 2010 03:40
Ok, ty. Good to know that.
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 27th May 2010 04:08
So, anyone else got any other idea of how can i do this?
zeroSlave
15
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 27th May 2010 04:09 Edited at: 27th May 2010 04:09
Just got home from work and decided to do a little more to the code above. Sorry that there wasn't too much to it before. Id didn't put any comments in it, but i left it pretty barren to show how you could do it.



Quote: "I think there are several ways of making a game"

You are correct, sir!

My green thumb grew the tree my Trojan War horse was crafted from. With roses in our pockets we rally round the tombstones. Ashes to ashes, we all fall down.

Login to post a reply

Server time is: 2024-11-24 16:01:23
Your offset time is: 2024-11-24 16:01:23