Android Open Source - android-jplay Tank Cannon






From Project

Back to project page android-jplay.

License

The source code is released under:

Copyright (c) Nikolaj Baer All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. ...

If you think the Android project android-jplay 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.nikolajbaer.game.weapons;
//ww w.  j  a va 2 s .  co  m
/* jbox2d */
import org.jbox2d.dynamics.Body; 
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.common.Vec2;

/* local */
import com.nikolajbaer.game.*;
import com.nikolajbaer.game.objects.*;

public class TankCannon extends Weapon {
    private boolean m_shooting;
    private int m_reloadCount;
    private static float m_bulletVelocity = 15.0f;
    private static final int RELOAD_CNTR=20;

    public TankCannon(){
        m_shooting=false;
        m_reloadCount=0;
    }

    public void triggerOn(){
        m_shooting=true;
    }

    public void triggerOff(){
        m_shooting=false;
    }

    public void tick(PlayerObject shooter){
        //System.out.println("ticking");
        if(m_shooting && m_reloadCount%RELOAD_CNTR == 0 ){
            if(shooter.getEnergy() > 10){
                shooter.drawEnergy(20);
                // TODO make it so the shooter can't get hit by their own bullets?
                Body shootb=shooter.getBody();
                Vec2 d=shooter.getDir();
                Body b=Game.game.createCircle(1.0f,0.3f);
                BulletObject bo=new BulletObject(b,10);
                b.setXForm(shootb.getWorldCenter().add(d.mul(4)),shootb.getAngle());
                b.setBullet(true);
                b.setLinearVelocity(d.mul(m_bulletVelocity).add(shootb.getLinearVelocity()));
                // TODO drain energy usage from game object if this is a beam weapon
                shooter.emitGameObject(bo); 
                // TODO set bullet source!
                // CONSIDER maybe use box2d collision filter?
                m_reloadCount=0;
                // Apply kickback
                shootb.applyImpulse(d.mul(-5.0f),shootb.getPosition());
            }else{
                System.out.println("insufficient power, tank stall..");
            }
        }else{ /*System.out.println("reloading"); */ }
        // reload regardless
        m_reloadCount++;
    }

    public int getPortType(){ return 1; }

    public String getName(){ return "Tank Cannon"; }

    public float getVelocity(){ return m_bulletVelocity; }
}




Java Source Code List

com.nikolajbaer.Util.java
com.nikolajbaer.androidrender.AndroidRenderObject.java
com.nikolajbaer.androidrender.DotRenderObject.java
com.nikolajbaer.androidrender.DrawableRenderObject.java
com.nikolajbaer.androidrender.JPlayActivity.java
com.nikolajbaer.androidrender.JPlayThread.java
com.nikolajbaer.androidrender.JPlayView.java
com.nikolajbaer.androidrender.PolygonRenderObject.java
com.nikolajbaer.awtrender.AWTRenderObject.java
com.nikolajbaer.awtrender.JPlay.java
com.nikolajbaer.awtrender.PNGRenderObject.java
com.nikolajbaer.awtrender.PolygonRenderObject.java
com.nikolajbaer.awtrender.RectRenderObject.java
com.nikolajbaer.game.Game.java
com.nikolajbaer.game.objects.BulletObject.java
com.nikolajbaer.game.objects.GameObjectEventListener.java
com.nikolajbaer.game.objects.GameObjectEvent.java
com.nikolajbaer.game.objects.GameObject.java
com.nikolajbaer.game.objects.ObstacleObject.java
com.nikolajbaer.game.objects.PlayerObject.java
com.nikolajbaer.game.objects.PolygonGameObject.java
com.nikolajbaer.game.objects.ShrapnelObject.java
com.nikolajbaer.game.players.GamePlayer.java
com.nikolajbaer.game.players.HunterPlayer.java
com.nikolajbaer.game.players.LambPlayer.java
com.nikolajbaer.game.players.LivePlayer.java
com.nikolajbaer.game.weapons.Blaster.java
com.nikolajbaer.game.weapons.TankCannon.java
com.nikolajbaer.game.weapons.Weapon.java
com.nikolajbaer.render.RenderObject.java
com.nikolajbaer.render.Renderable.java