[Android] Floor Runner

Hi,

I am currently working on a little android game called floor runner. The idea is your a stick man and you just have to keep away from objects trying to kill you. Very simple. Currently I have some base code in place and very bad graphics. I am looking for someone to create some minimlistic but good looking art, if they want. I will start to post screen shots when im making good progress. This is just the start of the post.

I have a question on how to add double jumping into the game, below is the code I use for jumping.

public void update(float delta) {
		if(jumping) {
			velocity.y = -100;
			jumping = false;
		}
		
		if(position.y > originalY){
			position.y = originalY;
			canJump = true;
		}else{
			canJump = false;
			velocity.add(gravity.cpy().scl(delta));
		}
		
		position.add(velocity.cpy().scl(delta));

		collisionBox.x = position.x + 3;
		collisionBox.y = position.y + 1;
	}

	public void onClick(){
		if(isAlive){
			if(!jumping && canJump == true){
				jumping = true;
				canJump = false;
			}
		}
	}

Add another boolean to your code

boolean doubleJumped

and with that determine if the player can jump again even after jumping once. I guess you get the idea right?

I did have that idea but the part I struggled with is where do I add that boolean and how do I modify the loops

Instead of using a conditional statement in your update loop, perhaps it would be better to call a method to set the player’s velocity.


private void jump() {
     velocity.y = -100;
}

Then, when the screen is tapped and the player is still on the ground (the first jump), this method is called instead of setting [icode]jumping = true[/icode]. If the screen is tapped again before the player hits the ground, and [icode]doubleJumped == false[/icode], then you can set [icode]doubleJumped = true[/icode] and call [icode]jump()[/icode]. Just remember to reset [icode]doubleJumped[/icode] back to [icode]false[/icode] when the player hits the ground.

You could also keep an int

jumpCount 

and increase it, whenever jump is pressed. Reset it when the player comes down to the floor again.
You can keep a constant

MAX_JUMPS

and if

jumpCount > MAX_JUMPS

just don’t jump.
This way you could also have a tripple jump one time, which would be “something new” :smiley:

EDIT: How do i add In-Line code?!?

It all comes down to the usage of booleans to determine if it’s the second time the player is jumping. And it’s up to the boolean to prevent the player from triple-jumping.

So looking at the post I now have double jumping in the game which will allow me to start adding some game features. The screen shot below shows the current state of the game. I have added some rectangles for collision detection which I will be adding next.

Hopefully those collision bounds get reduced because there are not many things more infuriating than a misrepresented visual :point:

UPDATE:

So here is a little post showing what I have added into the game.

  • A player (needs new graphic and now has double jump)
  • A floor and roof which scroll
  • Blocks to jump over that are randomly generated and inifinite
  • Simple collision detection with the block and player
  • Projectiles that fire off at random directions and random angles
  • A bat entity that needs some very basic AI

Here is a little screenshot off the progress.


http://j27.imgup.net/pic186e1.png

Use points for the tips of the spikes as collision, not boxes.

Another new update to bring:

  • A bat now has a simple AI that fires projectiles to the player
  • The player now has a new texture
  • Some AI for generating the terrain was tweaked


http://s15.postimg.org/n7iblj18r/pic2.png

Rich [icode]Purnell[/icode]

Rich [icode]Purnell[/icode]