package scorpioengine.main;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.util.*;
import javax.swing.*;
//These import lines assure that all needed Java files are imported into the game.
//The "*"s tell the game to import the entire package of files.
import scorpioengine.main.intro.IntroJpanel;
public class MainJPanel extends JPanel implements ActionListener, Runnable{
public static GroundTileATop GroundATop;
public static int objectsSpawned=0;
private int OW;
private int character=1;
private int characters=2;
private int cutscene;
private int forcedcharacter;
private boolean downpressed=false;
public boolean running=true;
private int keyDown=KeyEvent.VK_DOWN;
private int keyLeft=KeyEvent.VK_LEFT;
private int keyRight=KeyEvent.VK_RIGHT;
private boolean uppressed=false;
private int keyUp=KeyEvent.VK_UP;
public boolean selectpressed=false;
public int keySelect=KeyEvent.VK_Z;
private int objectId;
private int spx;
private int spy;
private Image A,B,C,D,E,F,G,H,I,K,L,M,N,O,P,Q,R,S,T,U,V,Y,Point,ChompTilesBG,PointerL,PointerR,ChompPortrait,chomppointer,eggplantpointer;
public int menuoption=1;
public int optionsoption=1;
public int quikplay=0;
public int gamestate=1;
public String GroundTileATop = "GroundTileATop";
private Map m;
private MapPointer mp;
private Level l;
private Collection<Tile> elements = new ArrayList<Tile>();
private Scanner s;
private String currenttile;
public Thread game;
public MainJPanel(){
//game controls
l = new Level();
m = new Map();
mp = new MapPointer();
File();
game = new Thread(this);
game.start();
addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e){
int keycode=e.getKeyCode();
if(keycode==keyDown){
if(gamestate==1){
if (menuoption<4){
downpressed=true;
menuoption+=1;
}
else{
menuoption=1;
downpressed=true;
}
}
if(gamestate==7){
if(m.getMap(mp.getTileX(),mp.getTileY()+1).equals("1")){
mp.movement(0, 1);
}
}
}
if(keycode==keyUp){
if(gamestate==1){
if (menuoption>1){
uppressed=true;
menuoption-=1;
}
else{
menuoption=4;
uppressed=true;
}
}
if(gamestate==7){
if(m.getMap(mp.getTileX(),mp.getTileY()-1).equals("1")){
mp.movement(0, -1);
}
}
}
if(keycode==keyLeft){
if(gamestate==2){
if (character>=1){
character-=1;
}
if (character<1){
character=characters;
}
}
if(gamestate==7){
if(m.getMap(mp.getTileX()-1,mp.getTileY()).equals("1")){
mp.movement(-1, 0);
}
}
}
if(keycode==keyRight){
if(gamestate==2){
if (character<=characters){
character+=1;
}
if (character>characters){
character=1;
}
}
if(gamestate==7){
if(m.getMap(mp.getTileX()+1,mp.getTileY()).equals("1") || m.getMap(mp.getTileX()+1,mp.getTileY()).equals("2")){
mp.movement(1, 0);
}
}
}
if(keycode==keySelect && !selectpressed){
if(gamestate==1){
if(menuoption==1){
selectpressed=true;
gamestate=2;
}
if(menuoption==2){
selectpressed=true;
gamestate=3;
}
if(menuoption==3){
selectpressed=true;
gamestate=4;
}
if(menuoption==4){
selectpressed=true;
gamestate=5;
}
}
if(gamestate==2 && !selectpressed){
selectpressed=true;
cutscene=0;
gamestate=6;
}
if(gamestate==6 && !selectpressed){
gamestate=7;
selectpressed=true;
}
if(gamestate==7 && !selectpressed){
if(m.getMap(mp.getTileX(),mp.getTileY()).equals("1")){ //this controls which tiles act as stage tiles so the game will switch to level mode
gamestate=8;
selectpressed=true;
}
}
}
}
public void keyReleased(KeyEvent e){
if(e.getKeyCode()==keyDown){
downpressed=false;
}
if(e.getKeyCode()==keyUp){
uppressed=false;
}
if(e.getKeyCode()==keySelect){
selectpressed=false;
}
}
public void keyTyped(KeyEvent e){
int keycode=e.getKeyCode();
}
});
setFocusable(true);
ImageIcon img = new ImageIcon("C://CWWGFX//8x8ALarge.PNG"); //Filepath to the "A" of the main font
A=img.getImage();
img = new ImageIcon("C://CWWGFX//8x8BLarge.PNG"); //Filepath to the "B" of the main font
B=img.getImage();
img=new ImageIcon("C://CWWGFX//8x8CLarge.PNG"); //Filepath to the "C" of the main font
C=img.getImage();
img=new ImageIcon("C://CWWGFX//8x8DLarge.PNG"); //Filepath to the "D" of the main font
D=img.getImage();
img=new ImageIcon("C://CWWGFX//8x8ELarge.PNG"); //Filepath to the "E" of the main font
E=img.getImage();
img=new ImageIcon("C://CWWGFX//8x8FLarge.PNG"); //Filepath to the "F" of the main font
F=img.getImage();
img=new ImageIcon("C://CWWGFX//8x8GLarge.PNG"); //Filepath to the "F" of the main font
G=img.getImage();
img=new ImageIcon("C://CWWGFX//8x8HLarge.PNG"); //Filepath to the "H" of the main font
H=img.getImage();
img=new ImageIcon("C://CWWGFX//8x8ILarge.PNG"); //Filepath to the "I" of the main font
I=img.getImage();
img=new ImageIcon("C://CWWGFX//8x8KLarge.PNG"); //Filepath to the "K" of the main font
K=img.getImage();
img=new ImageIcon("C://CWWGFX//8x8LLarge.PNG"); //Filepath to the "L" of the main font
L=img.getImage();
img=new ImageIcon("C://CWWGFX//8x8MLarge.PNG"); //Filepath to the "M" of the main font
M=img.getImage();
img=new ImageIcon("C://CWWGFX//8x8NLarge.PNG"); //Filepath to the "N" of the main font
N=img.getImage();
img=new ImageIcon("C://CWWGFX//8x8OLarge.PNG"); //Filepath to the "O" of the main font
O=img.getImage();
img=new ImageIcon("C://CWWGFX//8x8PLarge.PNG"); //Filepath to the "P" of the main font
P=img.getImage();
img=new ImageIcon("C://CWWGFX//8x8QLarge.PNG"); //Filepath to the "Q" of the main font
Q=img.getImage();
img=new ImageIcon("C://CWWGFX//8x8RLarge.PNG"); //Filepath to the "R" of the main font
R=img.getImage();
img = new ImageIcon("C://CWWGFX//8x8SLarge.PNG"); //Filepath to the "S" of the main font
S=img.getImage();
img=new ImageIcon("C://CWWGFX//8x8TLarge.PNG"); //Filepath to the "T" of the main font
T=img.getImage();
img=new ImageIcon("C://CWWGFX//8x8ULarge.PNG"); //Filepath to the "U" of the main font
U=img.getImage();
img=new ImageIcon("C://CWWGFX//8x8VLarge.PNG"); //Filepath to the "V" of the main font
V=img.getImage();
img=new ImageIcon("C://CWWGFX//8x8YLarge.PNG"); //Filepath to the "Y" of the main font
Y=img.getImage();
img=new ImageIcon("C://CWWGFX//OptionTriangleLarge.PNG"); //Filepath to the option triangle of the main menu
Point=img.getImage();
img=new ImageIcon("C://CWWGFX//ChompTilesBG.PNG"); //Filepath to the Chomp portrait of the character select
ChompTilesBG=img.getImage();
img=new ImageIcon("C://CWWGFX//Pointertriangleleft.PNG"); //Filepath to the left arrow of the character select
PointerL=img.getImage();
img=new ImageIcon("C://CWWGFX//Pointertriangleright.PNG"); //Filepath to the right arrow of the character select
PointerR=img.getImage();
img=new ImageIcon("C://CWWGFX//ChompPortraitLarge.PNG"); //Filepath to the Chomp portrait of the character select
ChompPortrait=img.getImage();
img = new ImageIcon("C://CWWGFX//ChompPointerLarge.png");
chomppointer=img.getImage();
img = new ImageIcon("C://CWWGFX//EggplantPointerLarge.png");
eggplantpointer=img.getImage();
}
public void actionPerformed(ActionEvent e) {
repaint();
}
public void paint(Graphics g){ //this is the graphics subroutine
super.paint(g);
if(gamestate==1){
if(menuoption==1){
g.drawImage(Point,14,32,null);
}
if(menuoption==2){
g.drawImage(Point,14,64,null);
}
if(menuoption==3){
g.drawImage(Point,14,96,null);
}
if(menuoption==4){
g.drawImage(Point,14,128,null);
}
g.drawImage(S,32,32,null);
g.drawImage(T,48,32,null);
g.drawImage(A,64,32,null);
g.drawImage(R,80,32,null);
g.drawImage(T,96,32,null);
g.drawImage(L,32,64,null);
g.drawImage(O,48,64,null);
g.drawImage(A,64,64,null);
g.drawImage(D,80,64,null);
g.drawImage(O,32,96,null);
g.drawImage(P,48,96,null);
g.drawImage(T,64,96,null);
g.drawImage(I,80,96,null);
g.drawImage(O,96,96,null);
g.drawImage(N,112,96,null);
g.drawImage(S,128,96,null);
g.drawImage(E,32,128,null);
g.drawImage(D,48,128,null);
g.drawImage(I,64,128,null);
g.drawImage(T,80,128,null);
g.drawImage(O,96,128,null);
g.drawImage(R,112,128,null);
}
if (gamestate==2){
g.drawImage(PointerL,132,224,null);
g.drawImage(PointerR,398,224,null);
if(character==1){
g.drawImage(ChompPortrait,220,150,null);
g.drawImage(C,246,280,null);
g.drawImage(H,262,280,null);
g.drawImage(O,278,280,null);
g.drawImage(M,294,280,null);
g.drawImage(P,310,280,null);
}
if(character==2){
g.drawImage(M,220,150,null);
g.drawImage(N,246,280,null);
g.drawImage(O,262,280,null);
g.drawImage(L,278,280,null);
g.drawImage(L,294,280,null);
g.drawImage(L,310,280,null);
}
}
if (gamestate==4){
g.drawImage(ChompTilesBG,0,0,null);
if (optionsoption==1){
g.drawImage(Point,14,32,null);
}
g.drawImage(Q,32,32,null);
g.drawImage(U,48,32,null);
g.drawImage(I,64,32,null);
g.drawImage(K,80,32,null);
g.drawImage(P,112,32,null);
g.drawImage(L,128,32,null);
g.drawImage(A,144,32,null);
g.drawImage(Y,160,32,null);
if (quikplay==0){
g.drawImage(O,192,32,null);
g.drawImage(F,208,32,null);
g.drawImage(F,224,32,null);
}
if (quikplay==1){
g.drawImage(O,192,32,null);
g.drawImage(N,208,32,null);
}
g.drawImage(K,32,64,null);
g.drawImage(E,48,64,null);
g.drawImage(Y,64,64,null);
g.drawImage(C,96,64,null);
g.drawImage(O,112,64,null);
g.drawImage(N,128,64,null);
g.drawImage(F,144,64,null);
g.drawImage(I,160,64,null);
g.drawImage(G,176,64,null);
g.drawImage(L,32,96,null);
g.drawImage(I,48,96,null);
g.drawImage(V,64,96,null);
g.drawImage(E,80,96,null);
g.drawImage(S,96,96,null);
g.drawImage(B,32,128,null);
g.drawImage(O,48,128,null);
g.drawImage(S,64,128,null);
g.drawImage(S,80,128,null);
g.drawImage(I,112,128,null);
g.drawImage(N,128,128,null);
g.drawImage(T,144,128,null);
g.drawImage(R,160,128,null);
g.drawImage(O,176,128,null);
}
if (gamestate==6){
g.drawImage(L,310,280,null);
}
if (gamestate==7){
for(int y = 0; y < (m.getmapsizey()); y++){
for(int x = 0; x < m.getmapsizex(); x++){
if(m.getMap(x,y).equals("g")){
g.drawImage(m.getGrassEK(),x*32,y*32,null);
}
if(m.getMap(x,y).equals("t")){
g.drawImage(m.getGrassEKTop(),x*32,y*32,null);
}
if(m.getMap(x,y).equals("w")){
g.drawImage(m.getWaterEK(),x*32,y*32,null);
}
}
}
for(int y = (m.getmapsizey()+1); y < (m.getmapsizey()*2); y++){
for(int x = 0; x < m.getmapsizex(); x++){
if(m.getMap(x,y).equals("1")){
g.drawImage(m.getPath1(),x*32,(y-14)*32,null);
}
if(m.getMap(x,y).equals("2")){
g.drawImage(m.getPath2(),x*32,(y-14)*32,null);
}
}
}
if (character==1){
g.drawImage(chomppointer,mp.getTileX()*32,(mp.getTileY()-15)*32,null);
}
if (character==2){
g.drawImage(eggplantpointer,mp.getTileX()*32,(mp.getTileY()-15)*32,null);
}
}
if (gamestate==8){
add(new GroundTileATop(spx,spy));
}
}
public void File(){
try{
s = new Scanner(new File("C://CWWLEVELS//world1stage1.txt"));
while(s.hasNextLine()){
addElements(s.nextLine());
}
s.close();
}catch(Exception e){
System.out.println("error loading map2");
}
}
public void fpsSetter() {
try{game.sleep(16);
} catch(Exception e){
e.printStackTrace();
}
}
public void run() {
while (running){
fpsSetter();
repaint();
}
}
public void addElements(String line) {
Scanner scanner = new Scanner(line);
objectId = scanner.nextInt();
spx = scanner.nextInt();
spy = scanner.nextInt();
System.out.println("Object: " + objectId + " At: " + spx + "," + spy);
}
}