Android Open Source - killingspree Client Player






From Project

Back to project page killingspree.

License

The source code is released under:

MIT License

If you think the Android project killingspree listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.sillygames.killingSpree.clientEntities;
//w  w  w.ja  v  a  2  s.c  om
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.MathUtils;
import com.sillygames.killingSpree.managers.WorldRenderer;
import com.sillygames.killingSpree.pool.AssetLoader;
import com.sillygames.killingSpree.serverEntities.ServerPlayer;

public class ClientPlayer extends ClientEntity{

    private Sprite sprite;
    private Sprite gunSprite;
    private boolean markForDispose;
    private Animation walk;
    private float walkDuration;
    private boolean previousXFlip;
    
    public ClientPlayer(short id, float x, float y, WorldRenderer renderer) {
        super(id, x, y, renderer);
        markForDispose = false;
        Texture texture = AssetLoader.instance.getTexture("sprites/player.png");
        sprite = new Sprite(texture);
        gunSprite = new Sprite(AssetLoader.instance.getTexture("sprites/arrow.png"));
        gunSprite.setOrigin(gunSprite.getWidth()/2, gunSprite.getHeight()/2);
        walk = new Animation(0.05f, TextureRegion.split(texture,
                texture.getWidth()/10, texture.getHeight())[0]);
        walk.setPlayMode(Animation.PlayMode.LOOP);
        walkDuration = 0;
        gunSprite.setSize(40, 6);
        gunSprite.setOrigin(gunSprite.getWidth()/2, gunSprite.getHeight()/2);
        gunSprite.setAlpha(0.7f);
    }
    
    @Override
    public void render(float delta, SpriteBatch batch) {
        walkDuration += delta;
        if (markForDispose) {
            dispose();
            return;
        }
        renderPlayer(batch);
        
    }
    private void renderPlayer(SpriteBatch batch) {
        angle *= MathUtils.radiansToDegrees;
        
        if (vY !=0) {
            walkDuration = 0.49f;
        }
        if (Math.abs(vX)> 0.4f) {
            sprite.setRegion(walk.getKeyFrame(walkDuration));
        }
        else {
            sprite.setRegion(walk.getKeyFrame(0.49f));
        }
        if ((extra & 0x1) == 0) {
            sprite.setAlpha(0.5f);
        } else {
            sprite.setAlpha(1);
        }
        
        if (angle < -90.1f || angle > 90.1f ) {
            previousXFlip = true;
//            Gdx.app.log("true", Float.toString(angle));
        } else if (angle > -89.9f && angle < 89.9f ){
//            Gdx.app.log("false", Float.toString(angle));
            previousXFlip = false;
        }
//        Gdx.app.log("angle", Float.toString(angle));
        sprite.flip(previousXFlip, false);
        
        sprite.setSize(ServerPlayer.WIDTH + 6f, 
                ServerPlayer.HEIGHT + 1f);
        sprite.setOrigin(sprite.getWidth()/2, sprite.getHeight()/2);
        
        float x = position.x - sprite.getWidth() / 2;
        float y = position.y - sprite.getHeight() / 2 + ServerPlayer.YOFFSET;
       
        drawAll(sprite, batch, x, y);
        
        renderer.hudRenderer.render(batch, x, y, extra, renderer.stateProcessor.
                playerNames.players.get(id));
        
        x = position.x - gunSprite.getWidth() / 2;
        y = position.y - gunSprite.getHeight() / 2 + ServerPlayer.YOFFSET;
        gunSprite.setRotation(angle);
        drawAll(gunSprite, batch, x, y);
    }

//    @Override
//    public void processState(EntityState nextState, float alpha) {
//        super.processState(nextState, alpha);
//    }
    
    @Override
    public void dispose() {
    }

    
}




Java Source Code List

com.sillygames.killingSpree.AndroidLauncher.java
com.sillygames.killingSpree.KillingSpree.java
com.sillygames.killingSpree.PlatformServices.java
com.sillygames.killingSpree.categories.EnemyCategory.java
com.sillygames.killingSpree.categories.ExplodingWeaponCategory.java
com.sillygames.killingSpree.categories.LivingCategory.java
com.sillygames.killingSpree.categories.NonExplodingWeaponCategory.java
com.sillygames.killingSpree.clientEntities.ClientArrow.java
com.sillygames.killingSpree.clientEntities.ClientBlob.java
com.sillygames.killingSpree.clientEntities.ClientBomb.java
com.sillygames.killingSpree.clientEntities.ClientBullet.java
com.sillygames.killingSpree.clientEntities.ClientEntity.java
com.sillygames.killingSpree.clientEntities.ClientFly.java
com.sillygames.killingSpree.clientEntities.ClientFrog.java
com.sillygames.killingSpree.clientEntities.ClientPlayer.java
com.sillygames.killingSpree.clientEntities.ClientTestPlayer.java
com.sillygames.killingSpree.controls.InputController.java
com.sillygames.killingSpree.controls.onScreenControls.java
com.sillygames.killingSpree.desktop.DesktopLauncher.java
com.sillygames.killingSpree.desktop.DesktopServices.java
com.sillygames.killingSpree.helpers.EntityUtils.java
com.sillygames.killingSpree.helpers.Event.java
com.sillygames.killingSpree.helpers.MyButton.java
com.sillygames.killingSpree.helpers.MyConnection.java
com.sillygames.killingSpree.helpers.Utils.java
com.sillygames.killingSpree.managers.LevelLoader.java
com.sillygames.killingSpree.managers.WorldBodyUtils.java
com.sillygames.killingSpree.managers.WorldManager.java
com.sillygames.killingSpree.managers.WorldRenderer.java
com.sillygames.killingSpree.managers.physics.Body.java
com.sillygames.killingSpree.managers.physics.CollisionProcessor.java
com.sillygames.killingSpree.managers.physics.Ray.java
com.sillygames.killingSpree.managers.physics.WorldDebugRenderer.java
com.sillygames.killingSpree.managers.physics.World.java
com.sillygames.killingSpree.networking.ControlsSender.java
com.sillygames.killingSpree.networking.NetworkRegisterer.java
com.sillygames.killingSpree.networking.StateProcessor.java
com.sillygames.killingSpree.networking.messages.AudioMessage.java
com.sillygames.killingSpree.networking.messages.ClientDetailsMessage.java
com.sillygames.killingSpree.networking.messages.ConnectMessage.java
com.sillygames.killingSpree.networking.messages.ControlsMessage.java
com.sillygames.killingSpree.networking.messages.EntityState.java
com.sillygames.killingSpree.networking.messages.GameStateMessage.java
com.sillygames.killingSpree.networking.messages.PlayerNamesMessage.java
com.sillygames.killingSpree.networking.messages.ServerStatusMessage.java
com.sillygames.killingSpree.pool.AssetLoader.java
com.sillygames.killingSpree.pool.EntityPool.java
com.sillygames.killingSpree.pool.MessageObjectPool.java
com.sillygames.killingSpree.pool.Pool.java
com.sillygames.killingSpree.pool.Poolable.java
com.sillygames.killingSpree.renderers.HUDRenderer.java
com.sillygames.killingSpree.screens.AbstractScreen.java
com.sillygames.killingSpree.screens.ClientDiscoveryScreen.java
com.sillygames.killingSpree.screens.GameScreen.java
com.sillygames.killingSpree.screens.LobbyScreen.java
com.sillygames.killingSpree.screens.MainMenuScreen.java
com.sillygames.killingSpree.screens.OptionsScreen.java
com.sillygames.killingSpree.screens.SplashScreen.java
com.sillygames.killingSpree.screens.settings.Constants.java
com.sillygames.killingSpree.serverEntities.ServerArrow.java
com.sillygames.killingSpree.serverEntities.ServerBlob.java
com.sillygames.killingSpree.serverEntities.ServerBomb.java
com.sillygames.killingSpree.serverEntities.ServerBullet.java
com.sillygames.killingSpree.serverEntities.ServerEntity.java
com.sillygames.killingSpree.serverEntities.ServerFly.java
com.sillygames.killingSpree.serverEntities.ServerFrog.java
com.sillygames.killingSpree.serverEntities.ServerPlayer.java
com.sillygames.killingSpree.sound.SFXPlayer.java