package spells;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import physics.Vector2D;
import serverMessages.ClientEventOut;
import serverMessages.SpellCastEvent;
import units.Unit;
import Client.ClientGameState;
import Global_Package.Entity;
import Global_Package.Enums;
import Server.GameState;
import Server.UdpBroadCast;
import clientMessages.NewSpell;
public class RainbowCannon extends Projectile{
public final static int type=Enums.rainbowCannon;
public final static double mass=0;
public final static double moveForce=50;
public final static double maxMoveSpeed=100;
public final static int castLimit=25;//casts per 30 seconds
public RainbowCannon(int ID, int OwnerID, double theta, Point2D initialLoc) {
super(ID, OwnerID, type, mass, moveForce, maxMoveSpeed, initialLoc,castLimit,40);
// TODO Auto-generated constructor stub
this.theta=theta;
v=new Vector2D(Math.cos(theta),Math.sin(theta));
}
// @Override
// public static BufferedImage getImage() {
// return Enums.ranbowLazer1;
// }
public void networkServerMessageIn(ClientEventOut in,GameState g) {
SpellCastEvent i=(SpellCastEvent)in;
Unit u=g.getUnits().get(i.unitSource);
if(u !=null){
g.getSpells().put(i.ID, new RainbowCannon(i.ID,i.unitSource,i.theta,new Point2D.Double(u.getLoc().getX(),u.getLoc().getY())));
g.udp.newSpell(i.ID, i.unitSource, i.type, u.getLoc().getX(),u.getLoc().getY());
}
}
@Override
public void alterSpell(int prop, int val) {
// TODO Auto-generated method stub
}
@Override
public void render(Graphics2D g, ClientGameState game) {
BufferedImage b=Enums.ranbowLazer2;
int x=(int) loc.getX();
int y=(int) loc.getY();
g.translate(x, y);
g.rotate(game.Player.getTheta());
g.translate(-x, -y);
g.drawImage(b,x-b.getWidth(),(int)y-b.getHeight(),b.getWidth(),b.getHeight(),null);
g.translate(-x, -y);
g.rotate(-game.Player.getTheta());
g.translate(x,y);
// g.translate(x,y);
// if(b==null)
// System.out.print("booooo");
// g.drawImage(b,(int) loc.getX()-b.getWidth(),(int)loc.getY()-b.getHeight(),b.getWidth(),b.getHeight(),null);
//
}
public void networkServerMessageOut(UdpBroadCast udp) {}
@Override
public void onCollide(Entity u, GameState game) {
// TODO Auto-generated method stub
}
@Override
protected void mouseDown(Point2D e, ClientGameState game) {
// TODO Auto-generated method stub
}
@Override
public void keyDown(KeyEvent e, ClientGameState game) {
if (e.getKeyChar() == 'c') {
networkClientMessageOut(game);
}
}
public Spell newSpell(NewSpell s) {
System.out.println("ID creation:"+s.ID);
return new RainbowCannon(s.ID,s.OwnerID,0,new Point2D.Double(s.x,s.y));
}
//server implementation
public Spell newSpell(SpellCastEvent i, Unit u) {
System.out.println("ID creation:"+i.ID);
return new RainbowCannon(i.ID,i.unitSource,i.theta,new Point2D.Double(u.getLoc().getX(),u.getLoc().getY()));
}
}