i am new on game development so can any one guide me or help to make the jump in the game more realistic like monster inc run,mega run have in which user can jump or also make the long jump if it pressed long on screen. i tried the box2d code for making simple jump i am using this code
b2Vec2 impulse = b2Vec2([self body]->GetMass()*vert, [self body]->GetMass()*horz);
b2Vec2 impulsePoint = [self body]->GetWorldCenter();//GetWorldPoint(b2Vec2(5.0/100.0, -15.0/100.0));
[self body]->ApplyLinearImpulse(impulse, impulsePoint);
but it's not giving me the correct result i want the exact logic or technique which all the games have. Can any one suggest me the book,tutorial,or sample code so i can make my game more attractive with game play and also tell me how i can make the longer jump thing. i searched a lot but i didn't find any good tutorial or thing on the web so i decided to asked it here and sorry for my english i am not good with it.
I do not know Cocos2D, but I can suggest you how I've seen it done:
When the user starts pressing the button, you start applying a vertical force to the character, this force continues applying for a certain ammount of time (having the character achieve more height) or until the user stops pressing the button.
That way if its just a tap then the force applied is little, but if the button is pressed for longer the character jumps higher
Related
I am currently working on a new RPG game using Pygame (my aim here is really to learn how to use object oriented programming). I started a few days ago and developed a movement system where the player clicks a location and the character sprite goes to that location and stops when it get's there by checking if the sprite 'collides' with the mouse position.
I quickly found however that this greatly limited the world size (to the app window size).
I started having a look into making a movement system where the background would move with respect to the player, hence providing the illusion of movement.
I managed to achieve this by creating a variable keeping track of my background map position. The map is much bigger than the app window. And each time I want my player to move I offset the background by the speed of the player in the opposite direction.
My next problem now is that I can't get my character to stop moving... because the character sprite never actually reaches the last position clicked by the mouse, since it is the background that is moving, not the character sprite.
I was thinking of spending some time coding in a variable that would keep track of how many displacements it would take the character sprite to reach the mouse clicked position if it was to move. Since the background moves at the character sprite's speed it would take as many displacement of the background in the x and y directions to center the clicked position on the background to the character sprite at the center of the screen.
It would be something like that:
If MOUSEBUTTON clicked:
NM = set number of moves needed to reach the clicked position based on character sprite distance to click and character sprite speed.
If NM != 0:
Move background image
Else:
pass
This would mean that when my background has moved enough for the character sprite to now be just over the area of the background that was originally clicked by the player, the movement would stop since NM == 0.
I guess that my question is: Does that sound like a good idea or will it be a nightmare to handle the movement of other sprites and collisions ? And are there better tools in Pygame to achieve this movement system ?
I could also maybe use a clock and work out how many seconds the movements would take.
I guess that ultimately the whole challenge is dealing with a fixed reference point and make everything move around it, both with respect to this fixed reference, but also to their own. e.g. If two other sprites move toward one another, and the character of the player also "moves" then the movement of the other two sprites will have to depend both on the position of the other sprite and also on the offset of the background caused by the movement of the player's character.
An interesting topic which has been frying my brain for a few nights !
Thank you for your suggestions !
You actually asking for an opinion on game design. The way I look at it, nothing is impossible so go ahead and try your coding. Also it would be wise to look around at similar projects scattered around the net. You may be able to pick up a lot of tips without re inventing the wheel. Here is a good place to start.
scrolling mini map
Cocos2d offers two ways to let the player jump up, but by using jumpto() and jumpby(), people could not change the position of the sprite any more when it is jumping up.
How to write a method so that the sprite can jump like the "Super Mario"?
Some time ago I contributed some cocos2d code which made CCMove and CCJump actions stackable. See here. Starting from cocos2d 2.1, you can apply a CCJump actions concurrently with other movements.
However, if you want to deeply fine tune how the controls of your game feel, I'd avoid using CCActions altogether and I'd manage the sprite.position directly by processing player input.
you have to check for two condition for making your player to jump, same as in Super Mario.
Condition 1)
Only jump button is pressed at that time in CCJumpTo action you have to give the next position as the current position , height and no. jumps as one.
id jump = [CCJumpTo actionWithDuration:1 position:ccp(player.position.x, player.position.y)) height:20 jumps:1];
Condition 2)
When jump and forward button is pressed at that time in CCJumpTo action you have to give the next position as the current position.x + the distance you want to cover by jump,this will be static all the time , height and no. jumps as one.
id jump = [CCJumpTo actionWithDuration:1 position:ccp(player.position.x+20, player.position.y)) height:20 jumps:1];
And at the end you have to run jump action on player, hope you found this as solution for your question...!!
I am trying to create a simple game that mainly consists of a ball rolling down an incline. The player's only control is to cause the ball to jump. My question is, what is the best way to make it appear to roll while generally keeping the ball at the same place on the screen? I have considered CCCamera, but it seems like it's not the best option since I want a repeating background image. Scrolling the background manually is also giving me trouble because it's not clear how to get the ball to stay in one place while letting Box2D handle the physics. I'd appreciate any help as I've been stuck on this for quite a while.
Use CCFollow on the layer where you draw the game stuff, and let it follow the ball sprite:
[gameLayer runAction:[CCFollow actionWithTarget:ball]];
I am struggling with my first semi basic game for iPhone. The game operates well but I want a button to display saying restart and then when clicked it restarts the scene. This button should only appear when my sprite (called sprite) falls below the bottom of the iphone screen. I am using both cocos 2d and box 2d if that makes a difference.
Thank you for the help in advanced, it is greatly appreciated!
Quick answer for having the button appear once the sprite falls below a certain point: When you create the button, set its state to not visible. resetButton.isVisible = NO; Then write an if statement about your sprite's position and enable the button once that happens.
if (sprite.position.y >= 0)
{
resetButton.isVisible = YES;
}
This should get you started on that aspect. I'm not at my Mac right now, but if memory serves, a non-visible button is not enabled, so clicking on its location won't matter. If that's incorrect, just add in resetButton.isEnabled = NO; and YES appropriately.
As for resetting the scene, this can get a little tricky depending on what exactly you want to accomplish. You need to essentially replace the scene with itself, but this can cause undesirable flashes. A quick google search found a bunch of forum posts on this. If you can elaborate on what you've already tried and where you're getting caught up, I can try and get more specific.
I'm new to development and I have played around with a few tutorials. I wonder what the best way to set up a menu for a game with cocos2d?
I want a MainMenu with a Startbutton, SettingsButton, HighScoresButton and a little info/creditsButton in the corner.
How should I set this up?
Should I have the MainMenu as a Scene and the others as layers or just make all of them as separate Scenes?
The buttons that I add, should they be a plain button and then I add the textLabel on top or should I make them complete with textLabel?
I would like the buttons to "wiggle" like it is made of jello when i tap them, how do I do that?
As I said, I am new to this but I wanna learn as much as I can before school starts. I'm currently taking a summer class in iphone development so I get a head start for the next semester. I would like to see experienced game developers to help me out with this since i want to work with that when I get older, if they could also show me how to structure a game and the design.
Thank you so much.
David H
You've got several questions buried in there, so I'll address them in order...
First, to save on memory, you should break sections of your game, including menus, into separate scenes and switch between them using:
[[CCDirector sharedDirector] replaceScene: yourScene];
Alternatively you can use pushScene: and popScene, but these hold pushed scenes in memory and can be very costly depending on what you've got in the scene.
As for how to design your buttons, that's completely up to you and what fits best with the game. Some games look fine with text buttons. Others need a more stylized button that is best created with images. Remember, a CCMenuItem (button) is just a CCNode, so you can layer images and text in almost any way you wish.
Animating buttons is going to be a manual thing. I suggest subclassing the CCMenuItem, or CCMenuItemImage and overriding the selected and unselected methods to animate the underlying images.
We used cocos2d for our game The Selfish Birdbreeder. You can find the game and source here and dig around. I'm pretty certain we have a main menu.
http://pyweek.org/e/BirdBreeder/