Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (741)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (823)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [Android] Floor Runner  (Read 3133 times)
0 Members and 1 Guest are viewing this topic.
Offline Ging3rtoby
« Posted 2015-10-29 12:23:11 »

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.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
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;
         }
      }
   }
Offline Kami

Senior Devvie


Medals: 16
Projects: 1


I am not a vampire


« Reply #1 - Posted 2015-10-29 15:37:32 »

Add another boolean to your code
1  
boolean doubleJumped


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

"If I can't be the best I sure as hell can be the worst"
Twitter: https://twitter.com/mushkilann
LinkedIn: https://www.linkedin.com/pub/kami-nasri/108/227/436
Offline Ging3rtoby
« Reply #2 - Posted 2015-10-29 15:43:16 »

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
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Longarmx
« Reply #3 - Posted 2015-10-29 21:48:31 »

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.

1  
2  
3  
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
jumping = true
. If the screen is tapped again before the player hits the ground, and
doubleJumped == false
, then you can set
doubleJumped = true
and call
jump()
. Just remember to reset
doubleJumped
back to
false
when the player hits the ground.

Offline Springrbua
« Reply #4 - Posted 2015-10-30 07:30:00 »

You could also keep an int
1  
jumpCount 
and increase it, whenever jump is pressed. Reset it when the player comes down to the floor again.
You can keep a constant
1  
MAX_JUMPS
and if
1  
jumpCount > MAX_JUMPS
just don't jump.
This way you could also have a tripple jump one time, which would be "something new" Cheesy

EDIT: How do i add In-Line code?!?
Offline ShadedVertex
« Reply #5 - Posted 2015-10-30 07:34:14 »

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.
Offline Ging3rtoby
« Reply #6 - Posted 2015-11-01 16:59:06 »

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.

Offline Longarmx
« Reply #7 - Posted 2015-11-01 19:21:51 »

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

Offline Ging3rtoby
« Reply #8 - Posted 2015-11-13 17:35:21 »

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.

Offline micecd

Junior Devvie


Medals: 8



« Reply #9 - Posted 2015-11-13 18:14:33 »

Use points for the tips of the spikes as collision, not boxes.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Ging3rtoby
« Reply #10 - Posted 2015-11-24 15:23:17 »

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


Offline Ecumene

JGO Kernel


Medals: 195
Projects: 4
Exp: 8 years


I did not hit her! I did not!


« Reply #11 - Posted 2015-11-25 12:45:43 »

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

1  
Rich [icode]Purnell[/icode]

Rich
Purnell


Pages: [1]
  ignore  |  Print  
 
 

 
xxMrPHDxx (21 views)
2017-11-21 16:21:00

xxMrPHDxx (14 views)
2017-11-21 16:14:31

xxMrPHDxx (16 views)
2017-11-21 16:10:57

Ecumene (114 views)
2017-09-30 02:57:34

theagentd (150 views)
2017-09-26 18:23:31

cybrmynd (250 views)
2017-08-02 12:28:51

cybrmynd (249 views)
2017-08-02 12:19:43

cybrmynd (247 views)
2017-08-02 12:18:09

Sralse (260 views)
2017-07-25 17:13:48

Archive (878 views)
2017-04-27 17:45:51
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!