package MineGod;
import java.io.IOException;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.Animation;
import org.newdawn.slick.Image;
import org.newdawn.slick.SpriteSheet;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;
public class ProjectileEntityDestroy extends ProjectileEntity{
public static Texture projectileTex;
private Animation anim;
private static Image[] ss;
public static final int shotSpacing = 500;
public static int lastShot = shotSpacing + 1;
public static int LAZER_PAUR = 120;
public ProjectileEntityDestroy(double x, double y) {
super(ProjectileType.destroy, x, y);
if (ss == null){
ss = new Image[4];
try {
for (int i = 0; i<4; i++){
ss[i] = new Image(TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/test"+i+".png")));
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
anim = new Animation(false);
for (int i = 0; i<ss.length; i++){
anim.addFrame(ss[i], 80);
}
anim.setLooping(true);
anim.start();
width = 16.0;
height = 16.0;
maskWidth = 6.0;
maskHeight = 6.0;
xSpeed = 0;
ySpeed = 0;
speed = 0.2;
maxAge = 1500;
age = 0;
baseDamage = 10;
mask = new Rectangle((float)(xPos+(width-maskWidth)/2), (float)(yPos+(width-maskHeight)/2), (float)maskWidth, (float)maskHeight);
}
public void handleCollisions(int delta, Chunk prevChunk, Chunk currChunk, Chunk nextChunk){
Rectangle newMask = getNextMask((float)xSpeed*delta, 0f);
CollisionGroup sideBlocks = getSideBlocks(prevChunk, currChunk, nextChunk, newMask);
for (BlockMask blockMask: sideBlocks.orderedArray){
if (blockMask.block != null && blockMask.block.isSolid && Utils.intersects(blockMask.mask, newMask)){
//KABOOM
blowUp(blockMask);
break;
}
}
}
public ProjectileEntityDestroy shoot(int mouseX, int mouseY, double playerX, double playerY, double playerXSpeed, double playerYSpeed){
float a = (float)playerX-(float)mouseX;
float o = (float)playerY-(float)mouseY;
double theta = Math.atan((double)(o/a));
float xs = (float)Math.cos(theta);
if (a < 0){
xs = Math.abs(xs);
}
else{
xs = -Math.abs(xs);
}
float ys = (float)Math.sin(theta);
if (o < 0){
ys = Math.abs(ys);
}
else{
ys = -Math.abs(ys);
}
xSpeed = (xs*speed)+playerXSpeed;
ySpeed = (ys*speed)+playerYSpeed;
lastShot = 0;
return this;
}
@Override
public void doLogic(int delta, Chunk prevChunk, Chunk currChunk, Chunk nextChunk){
anim.update((long)delta);
xPos += xSpeed*delta;
yPos += ySpeed*delta;
if (yPos+height > MineGod.gameHeight){
this.dead = true;
return;
}
age += delta;
mask.setLocation((float)(xPos + (maskWidth-width)/2), (float)(yPos+(maskHeight-height)/2));
handleCollisions(delta, prevChunk, currChunk, nextChunk);
}
@Override
public void render(double worldPos){
if (!dead){
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
projectileTex.bind();
double renderX = xPos - worldPos;
GL11.glColor3d(1.0,1.0,1.0);
GL11.glBegin(GL11.GL_QUADS);
GL11.glNormal3d(0, 0, 1);
GL11.glTexCoord2d(0.0, 0.0);
GL11.glVertex3d(renderX, yPos, zIndex);
GL11.glTexCoord2d(1.0, 0.0);
GL11.glVertex3d(renderX + width, yPos, zIndex);
GL11.glTexCoord2d(1.0, 1.0);
GL11.glVertex3d(renderX + width, yPos + height, zIndex);
GL11.glTexCoord2d(0.0, 1.0);
GL11.glVertex3d(renderX, yPos + height, zIndex);
GL11.glEnd();
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
anim.getCurrentFrame().bind();
GL11.glBegin(GL11.GL_QUADS);
GL11.glNormal3d(0, 0, 1);
GL11.glTexCoord2d(0.0, 0.0);
GL11.glVertex3d(renderX, yPos, zIndex-1);
GL11.glTexCoord2d(1.0, 0.0);
GL11.glVertex3d((renderX+16), yPos, zIndex-1);
GL11.glTexCoord2d(1.0, 1.0);
GL11.glVertex3d((renderX+16), (yPos+16), zIndex-1);
GL11.glTexCoord2d(0.0, 1.0);
GL11.glVertex3d(renderX, (yPos+16), zIndex-1);
GL11.glEnd();
}
}
@Override
public Rectangle getNextMask(float xs, float ys){
return new Rectangle((float)(xPos+(width-maskWidth)/2) + xs, (float)(yPos+(height-maskHeight)/2) + ys, (float)(maskWidth), (float)maskHeight);
}
@Override
public void blowUp(BlockMask b){
//System.out.println("Small blew up");
//Block b = Utils.pointToBlock(xPos, yPos);
b.block.durability -= LAZER_PAUR;
if (b.block.durability<=0.5){
Utils.changeToAirBlock(b.xPos, b.yPos, b.block);
}
for(BlockMask bMask: Utils.getBlockRing(b.xPos, b.yPos, 1)){
if (bMask.block.isSolid){
bMask.block.durability -= LAZER_PAUR/2;
if (bMask.block.durability<=0.5){
Utils.changeToAirBlock(bMask.xPos, bMask.yPos, bMask.block);
}
}
}
for(BlockMask bMask: Utils.getBlockRing(b.xPos, b.yPos, 2)){
if (bMask.block.isSolid){
bMask.block.durability -= LAZER_PAUR*.75;
if (bMask.block.durability<=0.5){
Utils.changeToAirBlock(bMask.xPos, bMask.yPos, bMask.block);
}
}
}
//for(BlockMask bMask: Utils.getBlockRing(b.xPos, b.yPos, 3)){
// if (bMask.block.isSolid){
// bMask.block.durability -= LAZER_PAUR*.5;
// if (bMask.block.durability<=0.5){
// Utils.changeToAirBlock(bMask.xPos, bMask.yPos, bMask.block);
// }
// }
//}
//age = maxAge+1;
}
}