Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.xerpi.weaponlib;
- import java.util.LinkedList;
- import java.util.ListIterator;
- import android.graphics.Bitmap;
- import android.graphics.Canvas;
- import android.graphics.Paint;
- public class WeaponLib{
- Bitmap img;
- float time,w,h,c_time;
- String status = "stop";
- LinkedList <Bullet> bullets = new LinkedList<Bullet>();
- public WeaponLib(Bitmap img, float time){
- this.img = img;
- this.w = img.getWidth();
- this.h = img.getHeight();
- this.time = time;
- }
- public boolean outOfScreen(Bullet bullet){
- if (bullet.x > 854 || bullet.x < 0 || bullet.y > 480 || bullet.y < 0){
- return true;
- }
- return false;
- }
- public void blit(Canvas canvas, Paint paint){
- for( ListIterator<Bullet> a = bullets.listIterator(); a.hasNext(); ) {
- Bullet i = (Bullet) a.next();
- canvas.save();
- canvas.rotate((float) Math.toDegrees(i.ang),i.x,i.y);
- canvas.drawBitmap(this.img,i.x,i.y,paint);
- canvas.restore();
- }
- }
- public void move(){
- this.c_time++;
- for( ListIterator<Bullet> a = bullets.listIterator(); a.hasNext(); ) {
- Bullet i = (Bullet) a.next();
- if (outOfScreen(i) ){
- a.remove();
- // continue;
- }
- i.y += i.inc_y * i.vel;
- i.x += i.inc_x * i.vel;
- }
- }
- public void insertBullet(float vel, float x, float y, float ang){
- this.bullets.add(new Bullet(vel, x, y, ang));
- }
- public void shoot(float vel, float x, float y, float ang){
- if (this.c_time >= this.time){
- this.bullets.add(new Bullet(vel, x, y, ang));
- this.c_time = 0;
- }
- }
- public class Bullet{
- float vel,x,y,ang,inc_x,inc_y;
- public Bullet(float vel, float x, float y, float ang){
- this.vel = vel; this.x = x; this.y = y; this.ang = ang;
- this.inc_x = (float) Math.cos(ang);
- this.inc_y = (float) Math.sin(ang);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement