import java.util.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import javax.swing.*;
import javax.imageio.*;
import java.lang.Math;
import java.io.*;
import java.util.concurrent.*;
import java.util.concurrent.TimeUnit.*;
public class CellAttack extends JPanel
{
public static Rectangle screen, bounds;
public static JFrame frame;
public static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
public static RedBloodCell[] redCellArray = new RedBloodCell[40];
public static interactiveParticle[] IPArray = new interactiveParticle[2];
public static Random RG = new Random();
public BufferedImage background = null;
public static CellAttack panel;
public CellAttack()
{
super();
screen = new Rectangle(0, 0, 800, 600);
bounds = new Rectangle(0, 0, 800, 600);
for(int i = 0; i < redCellArray.length; i++)
{
redCellArray[i] = new RedBloodCell(RG.nextInt(bounds.width+1),RG.nextInt(bounds.height-130)+50,(RG.nextInt(5)+1),bounds.width,bounds.height-130);
}
for(int m = 0; m < IPArray.length; m++)
{
IPArray[m] = new interactiveParticle(RG.nextInt(bounds.width+1),RG.nextInt(bounds.height-130)+50,(RG.nextInt(5)+1),bounds.width,bounds.height-130,RG.nextInt(3)+1,panel);
}
frame = new JFrame("Cell Attack");
try
{
background = ImageIO.read(new File("background.png"));
}
catch(IOException e){}
}
public void paintComponent(Graphics g)
{
bounds = g.getClipBounds();
g.clearRect(screen.x, screen.y, screen.width, screen.height);
g.drawImage(background,0,0,this);
for(int k = 0; k < redCellArray.length; k++)
{
g.drawImage(redCellArray[k].img, redCellArray[k].x, redCellArray[k].y, this);
}
for(int n = 0; n < IPArray.length; n++)
{
g.drawImage(IPArray[n].img, IPArray[n].x, IPArray[n].y, this);
}
}
public void increaseIPArray()
{
interactiveParticle[] tempIPArray = new interactiveParticle[IPArray.length+1];
for(int q = 0; q < IPArray.length; q++)
{
tempIPArray[q] = IPArray[q];
}
tempIPArray[IPArray.length] = new interactiveParticle(bounds.width,RG.nextInt(bounds.height-130)+50,(RG.nextInt(5)+1),bounds.width,bounds.height-130,RG.nextInt(3)+1,panel);
IPArray = tempIPArray;
}
public static void main(String arg[])
{
panel = new CellAttack();
Runnable mover = new Runnable()
{
public void run()
{
for(int j = 0; j < redCellArray.length; j++)
{
redCellArray[j].move();
}
for(int p = 0; p < IPArray.length; p++)
{
IPArray[p].move();
}
frame.repaint();
}
};
scheduler.scheduleAtFixedRate(mover, 0, 20, TimeUnit.MILLISECONDS);
panel.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel.frame.setSize(panel.screen.width, panel.screen.height+22);
panel.frame.setContentPane(panel);
panel.frame.setVisible(true);
}
}