Idris Kadri
Front & Back End Developer & Animator

2D Platformer

Github

Languages & Tools: Android Development, Game Development, Java, LibGDX

2D Android Mobile Platformer, also runs on PC. Created with the LibGDX engine using Java.


Sample Code



	

void gun2Levitate(){
if (levitate2){
levitate2Amount = levitate2Amount + 0.7f;

if(levitate2Amount >=30)
levitate2 = false;
}

if (!levitate){
levitate2Amount = levitate2Amount - 0.7f;
levitate2 = false;

if(levitate2Amount <=5)
levitate2 = true;
}

}

void shoot(Batch batch){
shootSpeed = 15;

if(body.getLinearVelocity().x != 0){
shootSpeed = shootSpeed + walkspeed;
}

if( Gdx.input.isKeyPressed(Input.Keys.SPACE) || frame % 24 == 0){
bullet.go(gun.getX(),gun.getY(), faceLeft, shootSpeed);
}

if( Gdx.input.isKeyPressed(Input.Keys.SPACE) || frame % 24 == 12){
bullet2.go(gun2.getX(),gun2.getY(), faceLeft, shootSpeed);
}


bullet.draw(batch);
bullet2.draw(batch);
}

public boolean getStanding(){

if(body.getLinearVelocity().x == 0 && body.getLinearVelocity().y == 0) {
isStanding = true;
isWalking = false;
}else {
isStanding = false;
}
return isStanding;
}

void getAnimation(){

timePassed += Gdx.graphics.getDeltaTime();

anim = idleAnim;

if(isStanding) {
anim = idleAnim;
}
if(isWalking) {
anim = walkAnim;

}

if(isJumping && !bounce) {
if(timePassed > 17){
timePassed = 17;
}
anim = jumpAnim;
}


if (bounce) {
anim = bounceAnim;
}

if(isFalling()) {
anim = jumpAnim;
timePassed = 17;
}

tex = (TextureRegion) anim.getKeyFrame(timePassed, true);

}

void getFacing(){
//TURNING LEFT AND RIGHT
if(faceLeft) {
if(!tex.isFlipX())
tex.flip(true, false);
//gun2.setPosition(gun2.getX() - BoxOut.scale(100),gun2.getY());
}else {
if(tex.isFlipX())
tex.flip(true, false);
//gun2.setPosition(gun2.getX() + BoxOut.scale(100),gun2.getY());
}
}

void jumpGravity(){
if(Controller.isJumpButtonPressed() || Gdx.input.isKeyPressed(Input.Keys.UP)){
gravity = 1f;
body.applyLinearImpulse(0,gravity,0,0,true);
Gdx.app.log("gravity", String.valueOf(gravity));

}


}

void getJump(){

if(Gdx.input.isKeyPressed(Input.Keys.UP) && !isInAir() && !bounce || Controller.isJumpButtonPressed() && !isInAir() && !bounce){

if(jump) {
jump = false;
body.applyLinearImpulse(0, jumpHeight, 0, 0, true);

isJumping = true;
isStanding = false;
isWalking = false;

timePassed = 0;

touchWall = false;
}
}

if(!Gdx.input.isKeyPressed(Input.Keys.UP) && !Controller.isJumpButtonPressed()){
jump = true;
JUMP_STATE = true;
}


}

void bounceMove(){
if(getVelocityY() == 0)
BOUNCE_STATE = false;

if(Gdx.input.isKeyPressed(Input.Keys.DOWN) && isInAir() && !Gdx.input.isKeyPressed(Input.Keys.UP) && !bounce
|| Controller.jumpButtonCount == 2 && !bounce && isInAir()) { //|| Controller.jumpButtonCount == 2 Controller.isJumpButtonPressed() && isInAir() && !bounce &&
//Gdx.app.log("BOUNCE", String.valueOf(Controller.jumpButtonCount));
body.applyLinearImpulse(0, -50, 0, 0, true);
bounce = true;
BOUNCE_STATE = true;

}

if(!isInAir() && bounce) {
body.applyLinearImpulse(0, 40, 0, 0, true); // keyboard
}

}


public boolean isInAir(){
if(body.getLinearVelocity().y != 0) {
return true;
}else {
return false;
}
}

Back