Android Open Source - ConnectedSpace Laser






From Project

Back to project page ConnectedSpace.

License

The source code is released under:

Copyright (c) 2015, Shreyas Raman <skraman1999@gmail.com>.

If you think the Android project ConnectedSpace 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 me.shreyasr.connected.entities;
/*w  ww  .  ja va 2s.  com*/
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

import me.shreyasr.connected.ConnectedSpace;
import me.shreyasr.connected.util.MathHelper;

public class Laser {

    public enum Outcome {
        DELETE, SEND, KEEP, HIT
    }

    Sprite laser;
    public double x;
    public double y;
    int velocity;

    public Laser(double x, double y, boolean forward) {
        this.x = x;
        this.y = y;
        if (forward)
            laser = new Sprite(ConnectedSpace.OUTWARD_LASER);
        else
            laser = new Sprite(ConnectedSpace.INWARD_LASER);
        laser.setScale(0.5f, 1f);
        laser.flip(false, !forward);
        laser.setOriginCenter();
        velocity = 15 * (forward ? 1 : -1);
    }

    public Outcome render(SpriteBatch batch, double px, double py, double rad) {
        if (y > Gdx.graphics.getHeight())
            return Outcome.SEND;
        else if (y < 0)
            return Outcome.DELETE;
        y += velocity;
        laser.setPosition((float) x - laser.getWidth() / 2, (float) y);
        laser.draw(batch);
        if (velocity < 0) {
            if (MathHelper.intersects(px, py, rad, x, y, x, y + velocity * 4))
                return Outcome.HIT;
        }
        return Outcome.KEEP;
    }
}




Java Source Code List

me.shreyasr.connected.ConnectedSpace.java
me.shreyasr.connected.android.AndroidLauncher.java
me.shreyasr.connected.android.activity.ClientListAdapter.java
me.shreyasr.connected.android.activity.LobbyActivity.java
me.shreyasr.connected.android.networking.BroadcastListenerThread.java
me.shreyasr.connected.android.networking.ConnectionThread.java
me.shreyasr.connected.android.networking.HeartbeatThread.java
me.shreyasr.connected.android.networking.LobbyManager.java
me.shreyasr.connected.android.networking.ServerSocketThread.java
me.shreyasr.connected.android.util.AndroidAddressUtils.java
me.shreyasr.connected.android.util.Client.java
me.shreyasr.connected.desktop.DesktopLauncher.java
me.shreyasr.connected.entities.Laser.java
me.shreyasr.connected.entities.Star.java
me.shreyasr.connected.network.NetworkHandler.java
me.shreyasr.connected.util.MathHelper.java
me.shreyasr.connected.util.SpriteSheet.java