리그캣의 개발놀이터

JAVA 텀 프로젝트 - PUSHPUSH 게임 오버워치 (4) 본문

팀 활동/프로젝트

JAVA 텀 프로젝트 - PUSHPUSH 게임 오버워치 (4)

리그캣 2018. 1. 28. 13:10

8. 소스 구성 방식


ProjectMain.java

 

package Main;

 

import org.newdawn.slick.AppGameContainer;

import org.newdawn.slick.GameContainer;

import org.newdawn.slick.Music;

import org.newdawn.slick.SlickException;

import org.newdawn.slick.state.StateBasedGame;

 

import ExeScenes.ExeCh0_Scene;

import ExeScenes.ExeCh1_Scene;

import ExeScenes.ExeCh2_Scene;

import ExeScenes.Ranking;

import Scenes.MenuScene;

import Scenes.PlayScene;

import Scenes.PlayScene0;

import Scenes.PlayScene1;

 

 

public class ProjectMain extends StateBasedGame {

public static String _name;

public static int score = 1000000; // 총 점수

public static final int _width = 1300;//화면넓이

public static final int _height = 800;//화면높

public static boolean _full = false;

//Scene 이동하기 위한 상수 설정.

public static final int _Menu = 0;//메뉴 상수6

public static final int _Exe0 = 1; //설명 0

 

 

public static final int _Play0 = 2;//게임플레이0 상수

public static final int _Exe = 3;//설명

public static final int _Play = 4;//게임플레이 상수

public static final int _Exe1 = 5; //설명1

public static final int _Play1 = 6;//게임플레이1

public static final int _Ranking = 7;

//배경음악 설정

public static Music bg_music ;//메인 화면 음향

public static Music bg_ex;//게임설명화면 음향

public static Music play_bg;//게임플레이시 음향.

 

public ProjectMain(String name) {

super(name);

// TODO Auto-generated constructor stub

}

@Override

public void initStatesList(GameContainer arg0) throws SlickException {

// TODO Auto-generated method stub

//배경음설정.

bg_music = new Music("sounds/Menu_bg.wav");

bg_ex = new Music("sounds/Anubis_bg.wav");

play_bg = new Music("sounds/play_bg.wav"); //게임플레이시 배경음향.

addState(new MenuScene(_Menu));//메뉴 추가

addState(new ExeCh0_Scene(_Exe0));//플레이 추가

addState(new PlayScene0(_Play0));//플레이 추가

addState(new ExeCh1_Scene(_Exe));//플레이 추가

addState(new PlayScene(_Play));//플레이 추가

addState(new ExeCh2_Scene(_Exe1));//플레이 추가

addState(new PlayScene1(_Play1));//플레이 추가

addState(new Ranking(_Ranking));//플레이 추가

}

 

 

public static String getName() {

// TODO Auto-generated method stub

return ProjectMain._name;

}

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

 

try{

AppGameContainer appgc;

appgc = new AppGameContainer(new ProjectMain("Push Push Game-SH"));//창이름.

appgc.setDisplayMode(_width, _height,_full);//width,high,창모드할건지 출력

appgc.setTargetFrameRate(100);

appgc.start();

}catch(SlickException e){

e.printStackTrace();//예외 발생시 익셉션 처리.

}

}

 

}

 

MenuScene.java

 

package Scenes;

 

import org.newdawn.slick.Color;

import org.newdawn.slick.GameContainer;

import org.newdawn.slick.Graphics;

import org.newdawn.slick.Image;

import org.newdawn.slick.Input;

import org.newdawn.slick.SlickException;

import org.newdawn.slick.Sound;

import org.newdawn.slick.gui.TextField;

import org.newdawn.slick.state.BasicGameState;

import org.newdawn.slick.state.StateBasedGame;

 

import Basic.Model;

 

import org.lwjgl.input.Mouse;

 

import Main.ProjectMain;

 

public class MenuScene extends BasicGameState {

 

StateBasedGame game;

GameContainer gc;

 

protected int ID;

Model model = new Model();

TextField playerName;

boolean name = false;

private Image BackGround;//배경화면

private Image PushLogo;//손바닥로고

private Image PushLogo1;//손바닥로고 반대

//음향설정.

//public static Sound bg_ex; //게임 진입 배경음악

public static Sound effect; //효과

private int logo_x;//마우스 갖다되면 크기조정하기위해 설정.

private int logo_y;//마우스 갖다되면 크기조정하기위해 설정.

public MenuScene() {

// TODO Auto-generated constructor stub

}

 

public MenuScene(int id) {

// TODO Auto-generated constructor stub

this.ID = id;

}

@Override

public void init(GameContainer arg0, StateBasedGame arg1)

throws SlickException {

// TODO Auto-generated method stub

 

 

 

game = arg1;

gc = arg0;

ProjectMain.bg_music.loop();

effect = new Sound("sounds/digitimpact.ogg");

BackGround = new Image("rsc/Background.png");//이미지 지정

PushLogo = new Image("rsc/PushLogo.png");

PushLogo1 = new Image("rsc/PushLogo1.png");

playerName = new TextField(gc, gc.getDefaultFont(), 580, 520, 140, 20);

playerName.setMaxLength(15); // Sets the max name length to 15

}

 

@Override

public void render(GameContainer gc, StateBasedGame sbg, Graphics g)

throws SlickException {

// TODO Auto-generated method stub

logo_x=233;//손바닥 로고 초기값.

logo_y=282;//손바닥 로고 초기값.

model.set_pos_x_y(Mouse.getX(), Mouse.getY());//마우스 위치 지정

BackGround.draw(0,0,1300,800);//메뉴 배경화면 뿌려줌.

PushLogo.draw(240, 180,logo_x,logo_y);//푸시로고 출력

PushLogo1.draw(800, 180,logo_x,logo_y);//푸시로고 좌우바뀐사진 출력

g.setColor(Color.white);

g.drawString("Copyright of this wallpaper is in Blizzard.", 800, 700);//저작권 글자 출력

g.drawString("x "+model.getPos_x()+"y"+model.getPos_y(), 820, 750);//마우스 좌표띄우기.

playerName.setBackgroundColor(Color.white);

playerName.setBorderColor(Color.orange);

playerName.setTextColor(Color.black);

playerName.setCursorVisible(true);

playerName.render(gc, g);

if((model.getPos_x()>248&&model.getPos_x()<481)&&(model.getPos_y()>330&&model.getPos_y()<612)){

PushLogo.drawFlash(240, 180,logo_x+50,logo_y+50);//마우스 갖다댔을때 효과

}

if((model.getPos_x()>800&&model.getPos_x()<1033)&&(model.getPos_y()>330&&model.getPos_y()<612)){

PushLogo1.drawFlash(760, 180,logo_x+50,logo_y+50);//로그 오른쪽 손 마우스 갔다댔을때 flash효과와 커짐.

}

Input input = gc.getInput();

if((model.getPos_x()>597&&model.getPos_x()<700)&&(model.getPos_y()>338&&model.getPos_y()<456)){

if(input.isMouseButtonDown(0)){//0은 마우스 왼쪽 클릭의미

}

 

 

}

}

 

@Override

public void update(GameContainer gc, StateBasedGame sbg, int delta)

throws SlickException {

// TODO Auto-generated method stub

Input input = gc.getInput();//마우스 클릭받기위한 Input

if((model.getPos_x()>248&&model.getPos_x()<481)&&(model.getPos_y()>330&&model.getPos_y()<612)){

//logo_x+=50;

//logo_y+=50;

//PushLogo.

if(input.isMouseButtonDown(0)){//0은 마우스 왼쪽 클릭의미

ProjectMain._name = playerName.getText();

effect.play();//눌렀을때 소리

ProjectMain.bg_music.stop(); //노래 종료

ProjectMain.bg_ex.play(); //다음 노래 재생

game.enterState(ProjectMain._Exe0);

}

} //왼쪽 로고 눌렀을시 게임화면 이동

if((model.getPos_x()>800&&model.getPos_x()<1033)&&(model.getPos_y()>330&&model.getPos_y()<612)){

if(input.isMouseButtonDown(0)){//0은 마우스 왼쪽 클릭의미

effect.play();

ProjectMain.bg_music.stop(); //노래 종료

ProjectMain.bg_ex.play(); //다음 노래 재생

game.enterState(ProjectMain._Play0);

}

} //오른쪽 로고 눌렀을시 게임화면 이동

 

}

 

@Override

public int getID() {

// TODO Auto-generated method stub

return ID;

}

 

@Override

public void keyReleased(int key, char c) {

switch(key){

case Input.KEY_1:

game.enterState(ProjectMain._Play);

break;

}

}

 

}

 

Model.java

 

package Basic;

 

public class Model {

private static int heroLife=3; //초기 영웅 에너지.

boolean feelkey=false;//궁극기 사용위한 boolean

int start_x;//start로고 x

int start_y;//start로고 y

int Hero_x; //초기 영웅 x

int Hero_y;//초기 영웅 Y

int Hero_v = 1; //1만큼 움직이게끔

 

int Car_x; //초기 화물 x

int Car_y;//초기 화물 Y

int Car_v = 1; //1만큼 움직이게끔

 

int Car_Des_x ; //화물 목적지 위치

int Car_Des_y ; // 화물 목적지 위치

int Enemy_x;//초기 적 x

int Enemy_y;//초기 적 y

int Enemy_v = 1; // 움직이게끔.

int xpos;//마우스 x좌표

int ypos;//마우스 y좌표

int menu_x;//메뉴x좌표

int menu_y;//메뉴y좌표

public int getHeroLife() {

return heroLife;

}

public boolean getFeel() {

return feelkey;

}

 

public void setHeroLife(int heroLife) {

Model.heroLife = heroLife;

}

public int minusHeroLife(){

return heroLife--;

}

public void setHero_x_y(int x,int y){

Hero_x=x;

Hero_y=y;

}

public void plusHero_x(){

Hero_x+=Hero_v;

}

public void plusHero_y(){

Hero_y+=Hero_v;

}

 

 

 

public void minusHero_x(){

Hero_x-=Hero_v;

}

public void minusHero_y(){

Hero_y-=Hero_v;

}

public void setHero_v(int x){

Hero_v=x;

}

public void setCar_x_y(int x,int y){

Car_x=x;

Car_y=y;

}

public void setCar_Des_x_y(int x,int y){

Car_Des_x=x;

Car_Des_y=y;

}

public void setEnemy_x_y(int x,int y){

Enemy_x=x;

Enemy_y=y;

}

public void set_pos_x_y(int x,int y){

xpos=x;

ypos=y;

}

public void setStart_x_y(int x,int y){

start_x=x;

start_y=y;

}

public void setMenu_x_y(int x,int y){

menu_x=x;

menu_y=y;

}

public void trueFeel(){

feelkey=true;

}

public void falseFeel(){

feelkey=false;

}

public void plusCar_x(){

Car_x+=Car_v;

}

public void plusCar_y(){

Car_y+=Car_v;

}

public void minusCar_x(){

Car_x-=Car_v;

}

public void minusCar_y(){

Car_y-=Car_v;

}

public void setCar_v(int x){

Car_v=x;

}

public void plusEnemy_x(){

Enemy_x+=Enemy_v;

}

public void plusEnemy_y(){

Enemy_y+=Enemy_v;

}

 

 

public void minusEnemy_x(){

Enemy_x-=Enemy_v;

}

public void minusEnemy_y(){

Enemy_y-=Enemy_v;

}

public void setEnemy_v(int x){

Enemy_v=x;

}

public int getHero_x() {

return Hero_x;

}

public int getHero_y() {

return Hero_y;

}

public int getHero_v(){

return Hero_v;

}

public int getCar_x() {

return Car_x;

}

public int getCar_y() {

return Car_y;

}

public int getCar_v(){

return Car_v;

}

public int getCar_Des_x() {

return Car_Des_x;

}

public int getCar_Des_y() {

return Car_Des_y;

}

public int getEnemy_x() {

return Enemy_x;

}

public int getEnemy_y() {

return Enemy_y;

}

public int getPos_x() {

return xpos;

}

public int getPos_y() {

return ypos;

}

public int getStart_x() {

return start_x;

}

public int getStart_y() {

return start_y;

}

public int getMenu_x() {

return menu_x;

}

public int getMenu_y() {

return menu_y;

}

public int Target(int x1,int y1,int x2,int y2){

return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);

 

 

}

public float Target(int x1,int y1,float x2,float y2){

return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);

}

public int Target_Max(int x1,int y1){

return (x1+y1)*(x1+y1);

}

}

 

Control.java

 

package Basic;

 

import org.newdawn.slick.Input;

 

 

public class Control {

public void controller (Input input,Model model){

if((model.getHeroLife()>0)){

if(input.isKeyDown(Input.KEY_UP)){model.minusHero_y();if(model.getHero_y()<1){model.plusHero_y();}}

if(input.isKeyDown(Input.KEY_DOWN)){model.plusHero_y();if(model.getHero_y()>553){model.minusHero_y();}}

if(input.isKeyDown(Input.KEY_LEFT)){model.minusHero_x();if(model.getHero_x()<1){model.plusHero_x();}}

if(input.isKeyDown(Input.KEY_RIGHT)){model.plusHero_x();if(model.getHero_x()>1007){model.minusHero_x();}}

}// 케릭터 컨트롤

}

public void controller_car (Input input,Model model,float Min, float Max){

if(Min<Max&&model.getHero_x()>model.getCar_x()){model.minusCar_x();if(model.getCar_x()<1){model.plusCar_x();}}

if(Min<Max&&model.getHero_x()<model.getCar_x()){model.plusCar_x();if(model.getCar_x()>1007){model.minusCar_x();}}

if(Min<Max&&model.getHero_y()>model.getCar_y()){model.minusCar_y();if(model.getCar_y()<1){model.plusCar_y();}}

if(Min<Max&&model.getHero_y()<model.getCar_y()){model.plusCar_y();if(model.getCar_y()>553){model.minusCar_y();}}

}// 화물 컨트롤

public void controllerPush (Input input,Model model){

if((model.getHeroLife()>0)){

if((model.getHero_x()>728&&model.getHero_x()<795)&&(model.getHero_y()>252&&model.getHero_y()<425)){

if(input.isKeyDown(Input.KEY_UP)){model.minusHero_y();if(model.getHero_y()<253){model.plusHero_y();}}

 

 

if(input.isKeyDown(Input.KEY_DOWN)){model.plusHero_y();if(model.getHero_y()>424){model.minusHero_y();}}

if(input.isKeyDown(Input.KEY_LEFT)){model.minusHero_x();if(model.getHero_x()<729){model.plusHero_x();}}

if(input.isKeyDown(Input.KEY_RIGHT)){model.plusHero_x();if(model.getHero_x()>794){model.minusHero_x();}}

}// 케릭터 컨트롤 처음 시작부분 4*2 이동

if(((model.getHero_x()<795)&&(model.getHero_x()>360))&&(model.getHero_y()>304&&model.getHero_y()<317)){

if(input.isKeyDown(Input.KEY_UP)){model.minusHero_y();if(model.getHero_y()<305){model.plusHero_y();}}

if(input.isKeyDown(Input.KEY_DOWN)){model.plusHero_y();if(model.getHero_y()>316){model.minusHero_y();}}

if(input.isKeyDown(Input.KEY_LEFT)){model.minusHero_x();if(model.getHero_x()<361){model.plusHero_x();}}

if(input.isKeyDown(Input.KEY_RIGHT)){model.plusHero_x();if(model.getHero_x()>794){model.minusHero_x();}}

}// 케릭터 컨트롤 중간통로 이동

if(((model.getHero_x()<430)&&(model.getHero_x()>423))&&(model.getHero_y()>141&&model.getHero_y()<317)){

if(input.isKeyDown(Input.KEY_UP)){model.minusHero_y();if(model.getHero_y()<142){model.plusHero_y();}}

if(input.isKeyDown(Input.KEY_DOWN)){model.plusHero_y();if(model.getHero_y()>316){model.minusHero_y();}}

if(input.isKeyDown(Input.KEY_LEFT)){model.minusHero_x();if(model.getHero_x()<424){model.plusHero_x();}}

if(input.isKeyDown(Input.KEY_RIGHT)){model.plusHero_x();if(model.getHero_x()>429){model.minusHero_x();}}

}// 케릭터 컨트롤 통로 들어간다음 위쪽 이동

if(((model.getHero_x()<425)&&(model.getHero_x()>303))&&(model.getHero_y()>141&&model.getHero_y()<151)){

if(input.isKeyDown(Input.KEY_UP)){model.minusHero_y();if(model.getHero_y()<142){model.plusHero_y();}}

if(input.isKeyDown(Input.KEY_DOWN)){model.plusHero_y();if(model.getHero_y()>150){model.minusHero_y();}}

if(input.isKeyDown(Input.KEY_LEFT)){model.minusHero_x();if(model.getHero_x()<304){model.plusHero_x();}}

if(input.isKeyDown(Input.KEY_RIGHT)){model.plusHero_x();if(model.getHero_x()>424){model.minusHero_x();}}

}// 케릭터 컨트롤 왼쪽으로 세칸이동

if(((model.getHero_x()<309)&&(model.getHero_x()>303))&&((model.getHero_y()>141)&&(model.getHero_y()<258))){

 

 

if(input.isKeyDown(Input.KEY_UP)){model.minusHero_y();if(model.getHero_y()<142){model.plusHero_y();}}

if(input.isKeyDown(Input.KEY_DOWN)){model.plusHero_y();if(model.getHero_y()>257){model.minusHero_y();}}

if(input.isKeyDown(Input.KEY_LEFT)){model.minusHero_x();if(model.getHero_x()<304){model.plusHero_x();}}

if(input.isKeyDown(Input.KEY_RIGHT)){model.plusHero_x();if(model.getHero_x()>308){model.minusHero_x();}}

}// 케릭터 컨트롤 아래로 세칸이동

if(((model.getHero_x()<309)&&(model.getHero_x()>238))&&(model.getHero_y()>248&&model.getHero_y()<258)){

if(input.isKeyDown(Input.KEY_UP)){model.minusHero_y();if(model.getHero_y()<249){model.plusHero_y();}}

if(input.isKeyDown(Input.KEY_DOWN)){model.plusHero_y();if(model.getHero_y()>257){model.minusHero_y();}}

if(input.isKeyDown(Input.KEY_LEFT)){model.minusHero_x();if(model.getHero_x()<239){model.plusHero_x();}}

if(input.isKeyDown(Input.KEY_RIGHT)){model.plusHero_x();if(model.getHero_x()>308){model.minusHero_x();}}

}// 케릭터 컨트롤 왼쪽으로 두칸이동

if(((model.getHero_x()<250)&&(model.getHero_x()>238))&&(model.getHero_y()>256&&model.getHero_y()<371)){

if(input.isKeyDown(Input.KEY_UP)){model.minusHero_y();if(model.getHero_y()<257){model.plusHero_y();}}

if(input.isKeyDown(Input.KEY_DOWN)){model.plusHero_y();if(model.getHero_y()>370){model.minusHero_y();}}

if(input.isKeyDown(Input.KEY_LEFT)){model.minusHero_x();if(model.getHero_x()<239){model.plusHero_x();}}

if(input.isKeyDown(Input.KEY_RIGHT)){model.plusHero_x();if(model.getHero_x()>249){model.minusHero_x();}}

}// 케릭터 컨트롤 아래로 세칸이동

if(((model.getHero_x()<368)&&(model.getHero_x()>238))&&(model.getHero_y()>362&&model.getHero_y()<371)){

if(input.isKeyDown(Input.KEY_UP)){model.minusHero_y();if(model.getHero_y()<363){model.plusHero_y();}}

if(input.isKeyDown(Input.KEY_DOWN)){model.plusHero_y();if(model.getHero_y()>370){model.minusHero_y();}}

if(input.isKeyDown(Input.KEY_LEFT)){model.minusHero_x();if(model.getHero_x()<239){model.plusHero_x();}}

if(input.isKeyDown(Input.KEY_RIGHT)){model.plusHero_x();if(model.getHero_x()>367){model.minusHero_x();}}

}// 케릭터 컨트롤 오른쪽로 세칸이동

 

 

if(((model.getHero_x()<369)&&(model.getHero_x()>360))&&(model.getHero_y()>241&&model.getHero_y()<371)){

if(input.isKeyDown(Input.KEY_UP)){model.minusHero_y();if(model.getHero_y()<242){model.plusHero_y();}}

if(input.isKeyDown(Input.KEY_DOWN)){model.plusHero_y();if(model.getHero_y()>370){model.minusHero_y();}}

if(input.isKeyDown(Input.KEY_LEFT)){model.minusHero_x();if(model.getHero_x()<361){model.plusHero_x();}}

if(input.isKeyDown(Input.KEY_RIGHT)){model.plusHero_x();if(model.getHero_x()>368){model.minusHero_x();}}

}// 케릭터 컨트롤 위로 세칸이동

if(((model.getHero_x()<430)&&(model.getHero_x()>238))&&(model.getHero_y()>247&&model.getHero_y()<259)){

if(input.isKeyDown(Input.KEY_UP)){model.minusHero_y();if(model.getHero_y()<248){model.plusHero_y();}}

if(input.isKeyDown(Input.KEY_DOWN)){model.plusHero_y();if(model.getHero_y()>258){model.minusHero_y();}}

if(input.isKeyDown(Input.KEY_LEFT)){model.minusHero_x();if(model.getHero_x()<239){model.plusHero_x();}}

if(input.isKeyDown(Input.KEY_RIGHT)){model.plusHero_x();if(model.getHero_x()>429){model.minusHero_x();}}

}// 작은 중간통로 이동

if(((model.getHero_x()<430)&&(model.getHero_x()>361))&&(model.getHero_y()>240&&model.getHero_y()<317)){

if(input.isKeyDown(Input.KEY_UP)){model.minusHero_y();if(model.getHero_y()<241){model.plusHero_y();}}

if(input.isKeyDown(Input.KEY_DOWN)){model.plusHero_y();if(model.getHero_y()>316){model.minusHero_y();}}

if(input.isKeyDown(Input.KEY_LEFT)){model.minusHero_x();if(model.getHero_x()<362){model.plusHero_x();}}

if(input.isKeyDown(Input.KEY_RIGHT)){model.plusHero_x();if(model.getHero_x()>429){model.minusHero_x();}}

}// 작은 중간통로 이동

}

}

public void controller_car_Push (Input input,Model model,float Min, float Max){

if((model.getCar_x()>728&&model.getCar_x()<795)&&(model.getCar_y()>252&&model.getCar_y()<425)){

if(Min<Max&&model.getHero_y()>model.getCar_y()){model.minusCar_y();if(model.getCar_y()<253){model.plusCar_y();}}

if(Min<Max&&model.getHero_y()<model.getCar_y()){model.plusCar_y();if(model.getCar

 

 

_y()>424){model.minusCar_y();}}

if(Min<Max&&model.getHero_x()>model.getCar_x()){model.minusCar_x();if(model.getCar_x()<729){model.plusCar_x();}}

if(Min<Max&&model.getHero_x()+8<model.getCar_x()){model.plusCar_x();if(model.getCar_x()>794){model.minusCar_x();}}

}

if((model.getCar_x()<795&&model.getCar_x()>360)&&(model.getCar_y()>304&&model.getCar_y()<=320)){

if(Min<Max&&model.getHero_y()>model.getCar_y()){model.minusCar_y();if(model.getCar_y()<305){model.plusCar_y();}}

if(Min<Max&&model.getHero_y()<model.getCar_y()){model.plusCar_y();if(model.getCar_y()>319){model.minusCar_y();}}

if(Min<Max&&model.getHero_x()>model.getCar_x()){model.minusCar_x();if(model.getCar_x()<361){model.plusCar_x();}}

if(Min<Max&&model.getHero_x()+5<model.getCar_x()){model.plusCar_x();if(model.getCar_x()>794){model.minusCar_x();}}

}

if((model.getCar_x()<430&&model.getCar_x()>423)&&(model.getCar_y()>141&&model.getCar_y()<=315)){

if(Min<Max&&model.getHero_y()>model.getCar_y()){model.minusCar_y();if(model.getCar_y()<142){model.plusCar_y();}}

if(Min<Max&&model.getHero_y()<model.getCar_y()){model.plusCar_y();if(model.getCar_y()>314){model.minusCar_y();}}

if(Min<Max&&model.getHero_x()>model.getCar_x()){model.minusCar_x();if(model.getCar_x()<424){model.plusCar_x();}}

if(Min<Max&&model.getHero_x()+5<model.getCar_x()){model.plusCar_x();if(model.getCar_x()>429){model.minusCar_x();}}

}

if((model.getCar_x()<425&&model.getCar_x()>303)&&(model.getCar_y()>141&&model.getCar_y()<151)){

if(Min<Max&&model.getHero_y()>model.getCar_y()){model.minusCar_y();if(model.getCar_y()<142){model.plusCar_y();}}

if(Min<Max&&model.getHero_y()<model.getCar_y()){model.plusCar_y();if(model.getCar_y()>150){model.minusCar_y();}}

if(Min<Max&&model.getHero_x()>model.getCar_x()){model.minusCar_x();if(model.getCar_x()<304){model.plusCar_x();}}

if(Min<Max&&model.getHero_x()+5<model.getCar_x()){model.plusCar_x();if(model.getCar_x()>424){model.minusCar_x();}}

}

if((model.getCar_x()<309&&model.getCar_x()>303)&&(model.getCar_y()>141&&model.getCar_y()<258)){

if(Min<Max&&model.getHero_y()>model.getCar_y()){model.minusCar_y();if(model.getC

 

 

ar_y()<142){model.plusCar_y();}}

if(Min<Max&&model.getHero_y()<model.getCar_y()){model.plusCar_y();if(model.getCar_y()>257){model.minusCar_y();}}

if(Min<Max&&model.getHero_x()>model.getCar_x()){model.minusCar_x();if(model.getCar_x()<304){model.plusCar_x();}}

if(Min<Max&&model.getHero_x()+5<model.getCar_x()){model.plusCar_x();if(model.getCar_x()>308){model.minusCar_x();}}

}

if((model.getCar_x()<309&&model.getCar_x()>238)&&(model.getCar_y()>248&&model.getCar_y()<258)){

if(Min<Max&&model.getHero_y()>model.getCar_y()){model.minusCar_y();if(model.getCar_y()<249){model.plusCar_y();}}

if(Min<Max&&model.getHero_y()<model.getCar_y()){model.plusCar_y();if(model.getCar_y()>257){model.minusCar_y();}}

if(Min<Max&&model.getHero_x()>model.getCar_x()){model.minusCar_x();if(model.getCar_x()<239){model.plusCar_x();}}

if(Min<Max&&model.getHero_x()+5<model.getCar_x()){model.plusCar_x();if(model.getCar_x()>308){model.minusCar_x();}}

}

if((model.getCar_x()<250&&model.getCar_x()>238)&&(model.getCar_y()>256&&model.getCar_y()<371)){

if(Min<Max&&model.getHero_y()>model.getCar_y()){model.minusCar_y();if(model.getCar_y()<257){model.plusCar_y();}}

if(Min<Max&&model.getHero_y()<model.getCar_y()){model.plusCar_y();if(model.getCar_y()>370){model.minusCar_y();}}

if(Min<Max&&model.getHero_x()>model.getCar_x()){model.minusCar_x();if(model.getCar_x()<239){model.plusCar_x();}}

if(Min<Max&&model.getHero_x()+5<model.getCar_x()){model.plusCar_x();if(model.getCar_x()>249){model.minusCar_x();}}

}

if((model.getCar_x()<368&&model.getCar_x()>238)&&(model.getCar_y()>362&&model.getCar_y()<371)){

if(Min<Max&&model.getHero_y()>model.getCar_y()){model.minusCar_y();if(model.getCar_y()<363){model.plusCar_y();}}

if(Min<Max&&model.getHero_y()<model.getCar_y()){model.plusCar_y();if(model.getCar_y()>370){model.minusCar_y();}}

if(Min<Max&&model.getHero_x()>model.getCar_x()){model.minusCar_x();if(model.getCar_x()<239){model.plusCar_x();}}

if(Min<Max&&model.getHero_x()+5<model.getCar_x()){model.plusCar_x();if(model.getCar_x()>367){model.minusCar_x();}}

}

if((model.getCar_x()<369&&model.getCar_x()>360)&&(model.getCar_y()>241&&model.

 

 

getCar_y()<371)){

if(Min<Max&&model.getHero_y()>model.getCar_y()){model.minusCar_y();if(model.getCar_y()<252){model.plusCar_y();}}

if(Min<Max&&model.getHero_y()<model.getCar_y()){model.plusCar_y();if(model.getCar_y()>370){model.minusCar_y();}}

if(Min<Max&&model.getHero_x()>model.getCar_x()){model.minusCar_x();if(model.getCar_x()<361){model.plusCar_x();}}

if(Min<Max&&model.getHero_x()+5<model.getCar_x()){model.plusCar_x();if(model.getCar_x()>368){model.minusCar_x();}}

}

if((model.getCar_x()<430&&model.getCar_x()>238)&&(model.getCar_y()>247&&model.getCar_y()<259)){

if(Min<Max&&model.getHero_y()>model.getCar_y()){model.minusCar_y();if(model.getCar_y()<248){model.plusCar_y();}}

if(Min<Max&&model.getHero_y()<model.getCar_y()){model.plusCar_y();if(model.getCar_y()>258){model.minusCar_y();}}

if(Min<Max&&model.getHero_x()>model.getCar_x()){model.minusCar_x();if(model.getCar_x()<239){model.plusCar_x();}}

if(Min<Max&&model.getHero_x()+8<model.getCar_x()){model.plusCar_x();if(model.getCar_x()>429){model.minusCar_x();}}

}

if((model.getCar_x()<433&&model.getCar_x()>361)&&(model.getCar_y()>242&&model.getCar_y()<320)){

if(Min<Max&&model.getHero_y()>model.getCar_y()){model.minusCar_y();if(model.getCar_y()<243){model.plusCar_y();}}

if(Min<Max&&model.getHero_y()<model.getCar_y()){model.plusCar_y();if(model.getCar_y()>319){model.minusCar_y();}}

if(Min<Max&&model.getHero_x()>model.getCar_x()){model.minusCar_x();if(model.getCar_x()<362){model.plusCar_x();}}

if(Min<Max&&model.getHero_x()+5<model.getCar_x()){model.plusCar_x();if(model.getCar_x()>432){model.minusCar_x();}}

}

}// 화물 컨트롤

public void controllerEnemy_Push (Model model){

if(model.getFeel()!=true){

if(model.getEnemy_x()>303&&model.getEnemy_x()<309){

if(model.getEnemy_y()<=258){model.plusEnemy_y();}

}//아래로이동

if(model.getEnemy_y()<=259&&model.getEnemy_y()>252&&model.getEnemy_x()<330){

if(model.getEnemy_x()>=241){model.minusEnemy_x();}

}//왼쪽으로이동

if(model.getEnemy_x()>=240&&model.getEnemy_x()<244){

if(model.getEnemy_y()<=370){model.plusEnemy_y();}

}//아래로이동

 

 

if(model.getEnemy_y()<=371&&model.getEnemy_y()>368){

if(model.getEnemy_x()<=368){model.plusEnemy_x();}

}//오른쪽으로 이동

if(model.getEnemy_x()<=369&&model.getEnemy_x()>367){

if(model.getEnemy_y()>=248){model.minusEnemy_y();}

}//위이동

if(model.getEnemy_y()>=247&&model.getEnemy_y()<250&&model.getEnemy_x()>334){

if(model.getEnemy_x()<=433){model.plusEnemy_x();}

}//오른쪽으로이동

if(model.getEnemy_x()<=434&&model.getEnemy_x()>430){

if(model.getEnemy_y()>=144){model.minusEnemy_y();}

}//위이동

if(model.getEnemy_y()>=143&&model.getEnemy_y()<146){

if(model.getEnemy_x()>=304){model.minusEnemy_x();}

}//왼쪽으로이동

}

}

}

 

ExeCh0_Scene.java

 

package ExeScenes;

 

import org.newdawn.slick.GameContainer;

import org.newdawn.slick.Graphics;

import org.newdawn.slick.Image;

import org.newdawn.slick.Input;

import org.newdawn.slick.SlickException;

import org.newdawn.slick.Sound;

import org.newdawn.slick.state.BasicGameState;

import org.newdawn.slick.state.StateBasedGame;

 

import Basic.Model;

 

import org.lwjgl.input.Mouse;

import Main.ProjectMain;

 

public class ExeCh0_Scene extends BasicGameState{

StateBasedGame game;

GameContainer gc;

protected int ID;

Model model = new Model();

private Image BackGround;

private Image Start;

public static Sound Target; //타겟으로 접근 음향

public ExeCh0_Scene(){

}

 

 

 

 

public ExeCh0_Scene(int id){

this.ID = id;

}

 

@Override

public void init(GameContainer arg0, StateBasedGame arg1) throws SlickException {

// TODO Auto-generated method stub

game = arg1;

gc = arg0;

model.setStart_x_y(550, 530);

Target = new Sound("sounds/EnterTarget.wav"); //들어갈때 음량 설정

BackGround = new Image("rsc/Ch00_ex.png");

Start = new Image("rsc/Start.png");

}

 

@Override

public void render(GameContainer arg0, StateBasedGame arg1, Graphics g) throws SlickException {

// TODO Auto-generated method stub

BackGround.draw(0,0,ProjectMain._width,ProjectMain._height);

Start.draw(model.getStart_x(),model.getStart_y(),200,200);

model.set_pos_x_y(Mouse.getX(), Mouse.getY());

g.drawString("x "+model.getPos_x()+"y"+model.getPos_y(), 900, 750);//마우스 좌표 출력 why?(이미지 뿌리기 위해 좌표찾기)

if((model.getPos_x()>552&&model.getPos_x()<742)&&(model.getPos_y()>74&&model.getPos_y()<266)){

Start.drawFlash(model.getStart_x(), model.getStart_y(),200,200);//마우스 갖다댔을때 효과

}

}

 

@Override

public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {

// TODO Auto-generated method stub

Input input = gc.getInput();

if((model.getPos_x()>552&&model.getPos_x()<742)&&(model.getPos_y()>74&&model.getPos_y()<266)){

if(input.isMouseButtonDown(0)){//0은 마우스 왼쪽 클릭의미

Target.play();//타겟에 진입하시오 알림음.

ProjectMain.bg_ex.stop();//종료

ProjectMain.play_bg.loop();//플레이음향

game.enterState(ProjectMain._Play0);//게임 플레이

} //눌렀을때 play 화면 진입

}

}

 

 

 

 

 

@Override

public int getID() {

// TODO Auto-generated method stub

return ID;

}

public void keyReleased(int key, char c){

switch(key){

case Input.KEY_1:

game.enterState(ProjectMain._Play0);

break;

}

}

 

}

 

PlayScene0.java

 

package Scenes;

 

import org.lwjgl.input.Mouse;

import org.newdawn.slick.Color;

import org.newdawn.slick.GameContainer;

import org.newdawn.slick.Graphics;

import org.newdawn.slick.SlickException;

import org.newdawn.slick.Sound;

import org.newdawn.slick.state.BasicGameState;

import org.newdawn.slick.state.StateBasedGame;

 

import Basic.Control;

import Basic.Model;

import Main.ProjectMain;

 

import org.newdawn.slick.Input;

import org.newdawn.slick.Image;

 

//먼저 PLAYSCENE을 만들고 추후에 BASICSCENE을 만들어 필요한부분만 상속받아 간단하게고칠 예정.WHY?STAGE나누기 위해서.

public class PlayScene0 extends BasicGameState {

StateBasedGame game;

GameContainer gc;

protected int ID; // BasicGameState로 들어오기 위한 ID

private Control control=new Control();

private Model model=new Model(); ;

private Image BackSpace;//게임 기본배경

private Image Hero; // 게임 메인 케릭터

private Image Car; // 화물

private Image Enemy;

private Image Car_Destination; // 화물 목적지

private Image Continue; // herolife0이되면 출력

private Image mei_Enerzy_0;//에너지 다 떨어졌을때.

private Image mei_Enerzy_3;//에너지 최대치 (추후에 애니메이션으로 바꿀예정.)

private Image Feel;

 

 

private Sound mei_feel;//메이 궁 사운드

long starttime = System.currentTimeMillis();//게임 시작시간

long endtime; //끝나는시간

 

long starttime1;//궁극기 시작시간

long endtime1; //궁극기끝나는시간

int TimePassed;

public PlayScene0(){

}

public PlayScene0(int id){

this.ID = id;//ID지정

}

public void init(GameContainer arg0, StateBasedGame arg1) throws SlickException {

game = arg1;

gc = arg0;

//초기 좌표값지정

model.setHero_x_y(790,424);

model.setEnemy_x_y(305,200);

model.setCar_x_y(730,372);

model.setCar_Des_x_y(790,372);

model.setMenu_x_y(1100,50);

//소리지정

mei_feel = new Sound("sounds/mei_feel.wav");

//이미지 지정

Hero = new Image("rsc/mei.png");

Enemy = new Image("rsc/Liffer1.png");

BackSpace = new Image("rsc/BackPlay1.png"); //배경화면

Car = new Image("rsc/Logo.png");

Car_Destination = new Image("rsc/Logo_Destination.png");

Continue = new Image("rsc/Continue.png");

Feel = new Image("rsc/mei_feel.png");

 

mei_Enerzy_0 = new Image("rsc/mei_energy_0.png");

mei_Enerzy_3 = new Image("rsc/mei_energy_3.png");

//이미지 정의 종료

TimePassed=0;

}

 

@Override

public void render(GameContainer arg0, StateBasedGame arg1, Graphics g) throws SlickException {

// TODO Auto-generated method stub

//이미지 관리

BackSpace.draw(0,0,ProjectMain._width,ProjectMain._height);//기본 배경출력

Car.draw(model.getCar_x(),model.getCar_y(),60,60);//화물 이미지 출력

Car_Destination.draw(model.getCar_Des_x(),model.getCar_Des_y(),60,60);//화물 도착지 출력

Hero.draw(model.getHero_x(),model.getHero_y(),60,60);//영웅 이미지 출력

 

 

 

 

Enemy.draw(model.getEnemy_x(),model.getEnemy_y(),60,60);//적군 이미지 출력

//이미지 끝

//메뉴화면 구성넘어가는 부분

g.setColor(Color.white);//글자 색상 흰색 지정W

g.drawString("STAGE 1", model.getMenu_x(), model.getMenu_y());

g.drawString("Your ID : "+ProjectMain._name, model.getMenu_x(), model.getMenu_y()+40);

g.drawString("TIME : "+endtime, model.getMenu_x(), model.getMenu_y()+80);

g.drawString("SCORE : "+(ProjectMain.score/100), model.getMenu_x(), model.getMenu_y()+120);

g.drawString("Life : "+model.getHeroLife(), model.getMenu_x(), model.getMenu_y()+160);

if(model.getHeroLife()>=3){mei_Enerzy_3.draw(model.getMenu_x()-15,model.getMenu_y()+220,200,200);}//영웅 체력 3이면 해당 체력이미지 출력

if(model.getHeroLife()<=0){mei_Enerzy_0.draw(model.getMenu_x()-15,model.getMenu_y()+220,200,200);}//영웅 체력 1이면 해당 체력이미지 출력

//메뉴화면 구성 끝

model.set_pos_x_y(Mouse.getX(), Mouse.getY());//마우스 X,Y좌표

g.drawString("x "+model.getPos_x()+"y"+model.getPos_y(), model.getMenu_x(), 710);//마우스 좌표 출력 why?(이미지 뿌리기 위해 좌표찾기)

g.drawString("Hero_x "+model.getHero_x()+"Hero_y"+model.getHero_y(), model.getMenu_x(), 750);

g.drawString("Car_x "+model.getCar_x()+"Car_y"+model.getCar_y(), model.getMenu_x(), 790);

if(model.getHeroLife()<=0){

Continue.draw(250,200,700,250); //계속하시겠습니까 출력

Input input = arg0.getInput(); //키입력받기 Y면 라이프3으로 세팅후 실해 N이면 메뉴화면 되돌아감.

if(input.isKeyDown(Input.KEY_Y)){model.setHeroLife(3);}

if(input.isKeyDown(Input.KEY_N)){game.enterState(ProjectMain._Menu);}

}

//궁극기 시전 (적이 얼어 붙음)

Input input = arg0.getInput();

if(input.isKeyDown(Input.KEY_SPACE)){//space누르면 궁극기 발동

mei_feel.play();//메이 궁극기 노래 플레이

starttime1=System.currentTimeMillis();

model.trueFeel();}//궁극기온

if(model.getFeel()){

if((endtime1-starttime1)/10<500)//5초동안 적얼림

Feel.draw(0,0,ProjectMain._width,ProjectMain._height);//궁극기 그림 출력

if((endtime1-starttime1)/10>550){//5.5초뒤에 궁극기 소모

model.falseFeel();//궁극기 종료

}

} //궁극기 한번만 쓸수있게 하려했으나 프로젝트 보고할때 편의를 위해 제한을 안둠.

}

@Override

 

 

 

 

 

 

public void update(GameContainer arg0, StateBasedGame arg1, int arg2) throws SlickException {

// TODO Auto-generated method stub

//메인화면 꾸며주기 위한 update

//걸린시간 체크

if((model.getHeroLife()>0)){

endtime = System.currentTimeMillis();//게임시간

endtime1 = System.currentTimeMillis();//궁극기 시간

endtime = (endtime-starttime)/1000;

ProjectMain.score-=endtime/5;}

// 메인 케릭터 입력값.

// 메인 꾸며주기 끝.

// 키입력받기 시작

Input input = arg0.getInput();

control.controllerPush(input,model);

//피타고라스의 정리 이용하여 부딪히면공이 없어지거나 화물이동할수있도록 설정함.

float Hero_Car = model.Target(model.getHero_x(),model.getHero_y(), model.getCar_x(),model.getCar_y());//영웅과 화물의 현재거리

float Hero_Car_Max = model.Target_Max(25,25);//영웅과 화물의 최대거리

//화물운송 완료

float Car_Des_Car = model.Target(model.getCar_Des_x(),model.getCar_Des_y(),model.getCar_x(),model.getCar_y());//화물과 도착지의 현재거리

float Car_Des_Car_Max = model.Target_Max(25,25);//화물과 도착지간의 최대거리

//적군 컨트롤

control.controller_car_Push(input, model, Hero_Car, Hero_Car_Max);//화물 컨트롤

TimePassed += arg2;

if(TimePassed > 2){

TimePassed = 0;

control.controllerEnemy_Push(model);

}//적 컨트롤 종료

float Hero_Enemy = model.Target(model.getHero_x(), model.getHero_y(), model.getEnemy_x(), model.getEnemy_y());//영웅과 적의 거리

float Hero_Enemy_Max =model.Target_Max(15, 15);//영웅과 적의 최대 거리

if(Hero_Enemy<Hero_Enemy_Max){//만약 영웅과 적이 만나면

ProjectMain.score-=500;//점수 제거

model.setHeroLife(0);

}

if(Car_Des_Car<Car_Des_Car_Max){//만약 CARCAR_목적지 닿게되면 CAR가 그자리 대신하게끔 만듬.

model.setCar_x_y(model.getCar_Des_x(),model.getCar_Des_y());//목적지에 화물이 들어감.

Car_Destination.getGraphics();//원래잇던 목적지 덮어씌우기

ProjectMain.play_bg.stop();//플레이음악 중지

ProjectMain.bg_ex.loop();//설명음악 시작

game.enterState(ProjectMain._Exe);//다음게임으로 넘어감.

}

//마우스 클릭효과 설정.

//비행기 클릭시 초기 위치로 이동

 

 

if((model.getPos_x()>440&&model.getPos_x()<530)&&(model.getPos_y()>37&&model.getPos_y()<69)){

if(input.isMouseButtonDown(0)){//0은 마우스 왼쪽 클릭의미

model.setHero_x_y(790,424);

model.setCar_x_y(730,372);

}

}

//오른쪽 화살표 클릭시 다음게임 진행

if((model.getPos_x()>344&&model.getPos_x()<410)&&(model.getPos_y()>16&&model.getPos_y()<77)){

if(input.isMouseButtonDown(0)){//0은 마우스 왼쪽 클릭의미

game.enterState(ProjectMain._Play);//다음게임넘어감.

}

}

//?메뉴 클릭시 게임안내판으로 넘어감.

if((model.getPos_x()>564&&model.getPos_x()<620)&&(model.getPos_y()>16&&model.getPos_y()<86)){

if(input.isMouseButtonDown(0)){//0은 마우스 왼쪽 클릭의미

ProjectMain.play_bg.stop();//플레이음악 중지

ProjectMain.bg_ex.loop();//설명음악 시작

game.enterState(ProjectMain._Exe0);//게임안내판으로 넘어감.

}

}

//맨우측 메뉴클릭시 메인화면으로 이동함.

if((model.getPos_x()>667&&model.getPos_x()<744)&&(model.getPos_y()>10&&model.getPos_y()<80)){

if(input.isMouseButtonDown(0)){//0은 마우스 왼쪽 클릭의미

ProjectMain.play_bg.stop();//플레이음악 중지

ProjectMain.bg_music.loop();//메인노래 진입.

game.enterState(ProjectMain._Menu);//메뉴화면으로 넘어감.

}

}

 

}

 

public int getID() {

// TODO Auto-generated method stub

return ID;

}

//F1키 누르면 바로메인화면 빠져나오게 만들어봄. 추후 변경할 예정.

public void keyReleased(int key, char c){

switch(key){

case Input.KEY_F1:

game.enterState(ProjectMain._Menu);

break;

}

}

}

ExeCh1_Scene.java

 

package ExeScenes;

 

import org.newdawn.slick.GameContainer;

import org.newdawn.slick.Graphics;

import org.newdawn.slick.Image;

import org.newdawn.slick.Input;

import org.newdawn.slick.SlickException;

import org.newdawn.slick.Sound;

import org.newdawn.slick.state.BasicGameState;

import org.newdawn.slick.state.StateBasedGame;

 

import Basic.Model;

 

import org.lwjgl.input.Mouse;

import Main.ProjectMain;

 

public class ExeCh1_Scene extends BasicGameState{

StateBasedGame game;

GameContainer gc;

protected int ID;

Model model = new Model();

private Image BackGround;

private Image Start;

public static Sound Target; //타겟으로 접근 음향

public ExeCh1_Scene(){

}

public ExeCh1_Scene(int id){

this.ID = id;

}

 

@Override

public void init(GameContainer arg0, StateBasedGame arg1) throws SlickException {

// TODO Auto-generated method stub

game = arg1;

gc = arg0;

model.setStart_x_y(550, 530);

Target = new Sound("sounds/EnterTarget.wav"); //들어갈때 음량 설정

BackGround = new Image("rsc/Ch01_ex.png");

Start = new Image("rsc/Start.png");

}

 

@Override

 

 

 

 

 

public void render(GameContainer arg0, StateBasedGame arg1, Graphics g) throws SlickException {

// TODO Auto-generated method stub

BackGround.draw(0,0,ProjectMain._width,ProjectMain._height);

Start.draw(model.getStart_x(),model.getStart_y(),200,200);

model.set_pos_x_y(Mouse.getX(), Mouse.getY());

g.drawString("x "+model.getPos_x()+"y"+model.getPos_y(), 900, 750);//마우스 좌표 출력 why?(이미지 뿌리기 위해 좌표찾기)

if((model.getPos_x()>552&&model.getPos_x()<742)&&(model.getPos_y()>74&&model.getPos_y()<266)){

Start.drawFlash(model.getStart_x(), model.getStart_y(),200,200);//마우스 갖다댔을때 효과

}

}

 

@Override

public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {

// TODO Auto-generated method stub

Input input = gc.getInput();

if((model.getPos_x()>552&&model.getPos_x()<742)&&(model.getPos_y()>74&&model.getPos_y()<266)){

if(input.isMouseButtonDown(0)){//0은 마우스 왼쪽 클릭의미

Target.play();//타겟에 진입하시오 알림음.

ProjectMain.bg_ex.stop();//종료

ProjectMain.play_bg.loop();//플레이음향

game.enterState(ProjectMain._Play);//게임 플레이

} //눌렀을때 play 화면 진입

}

}

 

@Override

public int getID() {

// TODO Auto-generated method stub

return ID;

}

public void keyReleased(int key, char c){

switch(key){

case Input.KEY_1:

game.enterState(ProjectMain._Play);

break;

}

}

 

}

PlayScene.java

 

package Scenes;

 

import java.util.ArrayList;

import java.util.Random;

 

import org.lwjgl.input.Mouse;

import org.newdawn.slick.Color;

import org.newdawn.slick.GameContainer;

import org.newdawn.slick.Graphics;

import org.newdawn.slick.SlickException;

import org.newdawn.slick.Sound;

import org.newdawn.slick.geom.Circle;

import org.newdawn.slick.state.BasicGameState;

import org.newdawn.slick.state.StateBasedGame;

 

import Basic.Control;

import Basic.Model;

import Main.ProjectMain;

 

import org.newdawn.slick.Input;

import org.newdawn.slick.Image;

 

//먼저 PLAYSCENE을 만들고 추후에 BASICSCENE을 만들어 필요한부분만 상속받아 간단하게고칠 예정.WHY?STAGE나누기 위해서.

public class PlayScene extends BasicGameState {

StateBasedGame game;

GameContainer gc;

protected int ID; // BasicGameState로 들어오기 위한 ID

private Control control=new Control();

private Model model=new Model(); ;

private Sound kenzi_feel;

private Sound Excellent;

 

private ArrayList<Circle> balls; // 위에서 떨어지는 공들

private ArrayList<Circle> balls_2; // 아래서 올라가는 공들

private Image BackSpace;//게임 기본배경

private Image PushLogo;// 지구행성 추가

private Image PushLogo1; // 달 추가

private Image Hero; // 게임 메인 케릭터

private Image Car; // 화물

private Image Car_Destination; // 화물 목적지

private Image Continue; // herolife0이되면 출력

private Image Feel;//궁극기 이미지 띄우기

private Image Feel2;//궁극기 이미지 띄우기

private Image Kenzy_Enerzy_0;//에너지 다 떨어졌을때.

private Image Kenzy_Enerzy_1;

private Image Kenzy_Enerzy_2;

private Image Kenzy_Enerzy_3;//에너지 최대치 (추후에 애니메이션으로 바꿀예정.)

 

 

 

 

 

private Random random;//balls 소환하기 위한 random함수.

private int TimePassed; // 시간 지정

long starttime = System.currentTimeMillis();//게임 시작시간

long endtime; //끝나는시간

 

long starttime1;//궁극기 시작시간

long endtime1; //궁극기끝나는시간

public PlayScene(){

}

public PlayScene(int id){

this.ID = id;//ID지정

}

public void init(GameContainer arg0, StateBasedGame arg1) throws SlickException {

game = arg1;

gc = arg0;

//초기 좌표값지정

model.setHero_x_y(950,200);

model.setCar_x_y(900,200);

model.setCar_Des_x_y(30,450);

model.setMenu_x_y(1100,50);

//소리지정

kenzi_feel = new Sound("sounds/kenzi_feel.wav");

Excellent = new Sound("sounds/excellent.wav");

//이미지 지정

Hero = new Image("rsc/kenzi.png");

BackSpace = new Image("rsc/BackPlay.png"); //배경화면

PushLogo = new Image("rsc/PushLogo.png");

PushLogo1 = new Image("rsc/PushLogo1.png");

Car = new Image("rsc/Logo.png");

Car_Destination = new Image("rsc/Logo_Destination.png");

Continue = new Image("rsc/Continue.png");

Feel = new Image("rsc/kenzi_feel.png");

Feel2 = new Image("rsc/kenzi_feel2.png");

Kenzy_Enerzy_0 = new Image("rsc/kenzi_energy_0.png");

Kenzy_Enerzy_1 = new Image("rsc/kenzi_energy_1.png");

Kenzy_Enerzy_2 = new Image("rsc/kenzi_energy_2.png");

Kenzy_Enerzy_3 = new Image("rsc/kenzi_energy_3.png");

//이미지 정의 종료

balls = new ArrayList<Circle>(); //위에서 내려오는 balls

balls_2 = new ArrayList<Circle>(); //아래서 올라가는 balls

TimePassed = 0;

random = new Random(); //랜덤으로 볼 소환하기위하여

}

 

@Override

public void render(GameContainer arg0, StateBasedGame arg1, Graphics g) throws SlickException {

// TODO Auto-generated method stub

//이미지 관리

BackSpace.draw(0,0,ProjectMain._width,ProjectMain._height);//기본 배경출력

PushLogo.draw(870,170,180,180);//Car 출발 손바닥

PushLogo1.draw(10,420,120,120);//Car 목적지 손바닥

Car.draw(model.getCar_x(),model.getCar_y(),60,60);

Hero.draw(model.getHero_x(),model.getHero_y(),80,60);

 

 

Car_Destination.draw(model.getCar_Des_x(),model.getCar_Des_y(),60,60);

//이미지 끝

//메뉴화면 구성넘어가는 부분

g.setColor(Color.white);//글자 색상 흰색 지정

g.drawString("STAGE 2", model.getMenu_x(), model.getMenu_y());

g.drawString("Your ID : "+ProjectMain._name, model.getMenu_x(), model.getMenu_y()+40);

g.drawString("TIME : "+endtime, model.getMenu_x(), model.getMenu_y()+80);

g.drawString("SCORE : "+(ProjectMain.score/100), model.getMenu_x(), model.getMenu_y()+120);

g.drawString("Life : "+model.getHeroLife(), model.getMenu_x(), model.getMenu_y()+160);

if(model.getHeroLife()>=3){Kenzy_Enerzy_3.draw(model.getMenu_x()-15,model.getMenu_y()+220,200,200);}

if(model.getHeroLife()==2){Kenzy_Enerzy_2.draw(model.getMenu_x()-15,model.getMenu_y()+220,200,200);}

if(model.getHeroLife()==1){Kenzy_Enerzy_1.draw(model.getMenu_x()-15,model.getMenu_y()+220,200,200);}

if(model.getHeroLife()<=0){Kenzy_Enerzy_0.draw(model.getMenu_x()-15,model.getMenu_y()+220,200,200);}

//추후에 애니매이션으로 만들까 구상중.

//메뉴화면 구성 끝

model.set_pos_x_y(Mouse.getX(), Mouse.getY());//마우스 X,Y좌표

g.drawString("x "+model.getPos_x()+"y"+model.getPos_y(), model.getMenu_x(), 710);//마우스 좌표 출력 why?(이미지 뿌리기 위해 좌표찾기)

g.drawString("Hero_x "+model.getHero_x()+"Hero_y"+model.getHero_y(), model.getMenu_x(), 750);

for(Circle c : balls){

g.fill(c);

}

for(Circle c2 : balls_2){

g.fill(c2);

}

if(model.getHeroLife()<=0){

Continue.draw(250,200,700,250); //계속하시겠습니까 출력

Input input = arg0.getInput(); //키입력받기 Y면 라이프3으로 세팅후 실해 N이면 메뉴화면 되돌아감.

if(input.isKeyDown(Input.KEY_Y)){model.setHeroLife(3);}

if(input.isKeyDown(Input.KEY_N)){game.enterState(ProjectMain._Menu);}

}

//heroLife 1일때 궁극기 사용가능

if(model.getHeroLife()==1){

Input input = arg0.getInput();

if(input.isKeyDown(Input.KEY_SPACE)){//space누르면 궁극기 발동

starttime1=System.currentTimeMillis();

kenzi_feel.play();

model.trueFeel();model.setHero_v(2);model.setCar_v(2);}//궁극기시 속도도 빨라짐

if(model.getFeel()){

if((endtime1-starttime1)/10<50)

Feel.draw(model.getHero_x()-20, model.getHero_y()-40,100,100);//궁극기 그림 출력

if((endtime1-starttime1)/10>200)

 

 

Feel2.draw(model.getHero_x()-10, model.getHero_y()-10,110,80);//궁극기 그림 출력

if((endtime1-starttime1)/10>800){//8초뒤에 궁극기 소모

model.falseFeel();

model.setHero_v(1);model.setCar_v(1);//원래 속도로 돌아옴.

}

}

}

}

@Override

public void update(GameContainer arg0, StateBasedGame arg1, int arg2) throws SlickException {

// TODO Auto-generated method stub

//메인화면 꾸며주기 위한 update

//걸린시간 체크

if((model.getHeroLife()>0)){

endtime = System.currentTimeMillis();//게임시간

endtime1 = System.currentTimeMillis();//궁극기 시간

endtime = (endtime-starttime)/1000;

ProjectMain.score-=endtime/5;}

// 메인 케릭터 입력값.

// 메인 꾸며주기 끝.

// 키입력받기 시작

Input input = arg0.getInput();

control.controller(input,model);

//피타고라스의 정리 이용하여 부딪히면공이 없어지거나 화물이동할수있도록 설정함.

float Hero_Car = model.Target(model.getHero_x(),model.getHero_y(), model.getCar_x(),model.getCar_y());//영웅과 화물의 현재거리

float Hero_Car_Max = model.Target_Max(25,25);//영웅과 화물의 최대거리

control.controller_car(input, model, Hero_Car, Hero_Car_Max);//화물 컨트롤

//화물운송 완료

float Car_Des_Car = model.Target(model.getCar_Des_x(),model.getCar_Des_y(),model.getCar_x(),model.getCar_y());//화물과 도착지의 현재거리

float Car_Des_Car_Max = model.Target_Max(25,25);//화물과 도착지간의 최대거리

float Ball_Max = model.Target_Max(15,15);//공과 케릭터간의 최대거리

TimePassed += arg2;

if(TimePassed > 500){

TimePassed = 0;

balls.add(new Circle(20+random.nextInt(880),0,10)); //X의 값 200부터 700사이. 렌덤하게 BALL출력

balls_2.add(new Circle(20+random.nextInt(880),630,10));

}

//Y값이 증가하는 공

for(Circle c: balls){

c.setCenterY(c.getCenterY()+(arg2/5));

}

//Y값이 떨어지는 공.

for(Circle c2: balls_2){

c2.setCenterY(c2.getCenterY()-(arg2/5));

}

 

 

for(int i=balls.size()-1;i>= 0; i--){

Circle c = balls.get(i);

float e = model.Target(model.getHero_x(),model.getHero_y(),c.getX(), c.getY());//공과 영웅간의 거리

//Y값 특정이상이면 제거

if(c.getCenterY()>610){

balls.remove(i);

}else if(e<Ball_Max){//메인케릭터와 부딪히면 BALL소멸

balls.remove(i);

if(model.getFeel()!=true)//궁극기 상태가 아니면

model.minusHeroLife();

ProjectMain.score-=10000; //heroLife깍이면 점수 100점 감점.

}

}

for(int i=balls_2.size()-1;i>= 0; i--){

Circle c2 = balls_2.get(i);

float f1 = model.Target(model.getHero_x(),model.getHero_y(),c2.getX(), c2.getY());//공과 영웅간의 거리

if(c2.getCenterY()<10){

balls_2.remove(i);

}else if(f1<Ball_Max){

balls_2.remove(i);

if(model.getFeel()!=true)//궁극기 상태가 아니면

model.minusHeroLife();

}

}

if(Car_Des_Car<Car_Des_Car_Max){//만약 CARCAR_목적지 닿게되면 CAR가 그자리 대신하게끔 만듬.

model.setCar_x_y(model.getCar_Des_x(),model.getCar_Des_y());//목적지에 화물이 들어감.

Car_Destination.getGraphics();//원래잇던 목적지 덮어씌우기

Excellent.play();

ProjectMain.play_bg.stop();//플레이음악 중지

ProjectMain.bg_ex.loop();//설명음악 시작

game.enterState(ProjectMain._Exe1);//다음게임으로 넘어감.

}

//마우스 클릭효과 설정.

//비행기 클릭시 초기 위치로 이동

if((model.getPos_x()>440&&model.getPos_x()<530)&&(model.getPos_y()>37&&model.getPos_y()<69)){

if(input.isMouseButtonDown(0)){//0은 마우스 왼쪽 클릭의미

model.setHero_x_y(950,200);

model.setCar_x_y(900,200);

}

}

//오른쪽 화살표 클릭시 다음게임 진행

if((model.getPos_x()>344&&model.getPos_x()<410)&&(model.getPos_y()>16&&model.getPos_y()<77)){

if(input.isMouseButtonDown(0)){//0은 마우스 왼쪽 클릭의미

 

 

game.enterState(ProjectMain._Play1);//다음게임넘어감.

}

}

//?메뉴 클릭시 게임안내판으로 넘어감.

if((model.getPos_x()>564&&model.getPos_x()<620)&&(model.getPos_y()>16&&model.getPos_y()<86)){

if(input.isMouseButtonDown(0)){//0은 마우스 왼쪽 클릭의미

ProjectMain.play_bg.stop();//플레이음악 중지

ProjectMain.bg_ex.loop();//설명음악 시작

game.enterState(ProjectMain._Exe);//게임안내판으로 넘어감.

}

}

//맨우측 메뉴클릭시 메인화면으로 이동함.

if((model.getPos_x()>667&&model.getPos_x()<744)&&(model.getPos_y()>10&&model.getPos_y()<80)){

if(input.isMouseButtonDown(0)){//0은 마우스 왼쪽 클릭의미

ProjectMain.play_bg.stop();//플레이음악 중지

ProjectMain.bg_music.loop();//메인노래 진입.

game.enterState(ProjectMain._Menu);//메뉴화면으로 넘어감.

}

}

 

}

 

public int getID() {

// TODO Auto-generated method stub

return ID;

}

//F1키 누르면 바로메인화면 빠져나오게 만들어봄. 추후 변경할 예정.

public void keyReleased(int key, char c){

switch(key){

case Input.KEY_F1:

game.enterState(ProjectMain._Menu);

break;

}

}

}

 

ExeCh2_Scene.java

 

package ExeScenes;

 

import org.newdawn.slick.GameContainer;

import org.newdawn.slick.Graphics;

import org.newdawn.slick.Image;

import org.newdawn.slick.Input;

import org.newdawn.slick.SlickException;

import org.newdawn.slick.Sound;

import org.newdawn.slick.state.BasicGameState;

import org.newdawn.slick.state.StateBasedGame;

 

import Basic.Model;

 

 

import org.lwjgl.input.Mouse;

import Main.ProjectMain;

 

public class ExeCh2_Scene extends BasicGameState{

StateBasedGame game;

GameContainer gc;

protected int ID;

Model model = new Model();

private Image BackGround;

private Image Start;

public static Sound Target; //타겟으로 접근 음향

public ExeCh2_Scene(){

}

public ExeCh2_Scene(int id){

this.ID = id;

}

 

@Override

public void init(GameContainer arg0, StateBasedGame arg1) throws SlickException {

// TODO Auto-generated method stub

game = arg1;

gc = arg0;

model.setStart_x_y(550, 530);

Target = new Sound("sounds/EnterTarget.wav"); //들어갈때 음량 설정

BackGround = new Image("rsc/Ch02_ex.png");

Start = new Image("rsc/Start.png");

}

 

@Override

public void render(GameContainer arg0, StateBasedGame arg1, Graphics g) throws SlickException {

// TODO Auto-generated method stub

BackGround.draw(0,0,ProjectMain._width,ProjectMain._height);

Start.draw(model.getStart_x(),model.getStart_y(),200,200);

model.set_pos_x_y(Mouse.getX(), Mouse.getY());

g.drawString("x "+model.getPos_x()+"y"+model.getPos_y(), 900, 750);//마우스 좌표 출력 why?(이미지 뿌리기 위해 좌표찾기)

if((model.getPos_x()>552&&model.getPos_x()<742)&&(model.getPos_y()>74&&model.getPos_y()<266)){

Start.drawFlash(model.getStart_x(), model.getStart_y(),200,200);//마우스 갖다댔을때 효과

}

}

 

@Override

public void update(GameContainer gc, StateBasedGame sbg, int delta) throws

 

 

SlickException {

// TODO Auto-generated method stub

Input input = gc.getInput();

if((model.getPos_x()>552&&model.getPos_x()<742)&&(model.getPos_y()>74&&model.getPos_y()<266)){

if(input.isMouseButtonDown(0)){//0은 마우스 왼쪽 클릭의미

Target.play();//타겟에 진입하시오 알림음.

ProjectMain.bg_ex.stop();//종료

ProjectMain.play_bg.loop();//플레이음향

game.enterState(ProjectMain._Play1);//게임 플레이

} //눌렀을때 play 화면 진입

}

}

 

@Override

public int getID() {

// TODO Auto-generated method stub

return ID;

}

public void keyReleased(int key, char c){

switch(key){

case Input.KEY_1:

game.enterState(ProjectMain._Play1);

break;

}

}

 

}

 

PlayScene1.java

 

package Scenes;

 

import java.util.Random;

 

import org.lwjgl.input.Mouse;

import org.newdawn.slick.GameContainer;

import org.newdawn.slick.Graphics;

import org.newdawn.slick.SlickException;

import org.newdawn.slick.Sound;

import org.newdawn.slick.state.BasicGameState;

import org.newdawn.slick.state.StateBasedGame;

import Main.ProjectMain;

 

import org.newdawn.slick.Input;

import org.newdawn.slick.Image;

 

public class PlayScene1 extends BasicGameState {

StateBasedGame game;

GameContainer gc;

protected int ID;

private Random random;

 

 

 

private int xpos;// 마우스 x좌표

private int ypos;// 마우스 y좌표

private Sound Hero_Bullet_Sound;

private Sound Rusiu_Skill;

private Image Rusiu_Skill_Effect;

private Image BackSpace;

private Image LeftHero;

private Image RightHero;

private Image Car;

private Image Car2;

private Image Car_Destination;

private Image Car2_Destination;

private Image Continue;

private Image Enemy;

private Image Enemy_Bullet;

private Image Hero_Bullet_Left;

private Image Hero_Bullet_Right;

private Image Rusiu_Image_Left;

private Image Rusiu_Image_Right;

private Image Enemy_Skilled;

 

long ClearTime;

long ClearTime2;

long SkillTime = 10;

long SkillTime2;

long StartTime = System.currentTimeMillis();

int Hero_Jump = 0;

int heroLife = 1;

int Hero_Direction = 0;

int Hero_x = 1170;

int Hero_y = 90;

int Hero_v = 1;

 

int Rusiu_x[] = { 1030, 780 };

int Rusiu_y[] = { 376, 532 };

int Rusiu_Life[] = { 1, 1 };

int Rusiu_Direction[] = { 0, 0 };

int Rusiu_Speed = 2;

int Rusiu_Jump[] = { 0, 0 };

int Rusiu_Skill_Count[] = { 0, 0 };

int Rusiu_Skill_X_Y[] = { 0, 0 };

int Rusiu_SKill_Range = 0;

int Car_Destination_Count = 0;

int Car2_Destination_Count = 0;

 

int Car_Count = 0;

int Car2_Count = 0;

 

int Car_v = 1;

 

int Car_x = 1050;

int Car_y = 90;

 

int Car2_x = 800;

int Car2_y = 552;

 

int Car_Des_x = 66;

int Car_Des_y = 690;

 

int Car2_Des_x = 1100;

 

 

 

int Car2_Des_y = 690;

int Enemy_Life[] = { 3, 3, 3, 3, 3 };

int Enemy_x[] = { 78, 300, 150, 530, 150 };

int Enemy_y[] = { 376, 228, 376, 376, 670 };

int Enemy_Bullet_x[] = { 128, 350, 200, 550, 200 };

int Enemy_Bullet_y[] = { 406, 258, 406, 406, 700 };

int Enemy_Bullet_Speed[] = { 2, 3, 3, 4, 4 };

 

int Hero_Bullet_Speed = 4;

int Hero_Bullet_x[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

int Hero_Bullet_y[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

int Hero_Bullet_Fire[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

0 };

int Hero_Bullet_Count = 0;

int Hero_Bullet_Direction[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

0, 0 };

 

public PlayScene1(int id) {

this.ID = id;

}

 

public void init(GameContainer arg0, StateBasedGame arg1) throws SlickException {

game = arg1;

gc = arg0;

Rusiu_Image_Left = new Image("rsc/Rusiu_Image_Left.png");

Rusiu_Image_Right = new Image("rsc/Rusiu_Image_Right.png");

Hero_Bullet_Sound = new Sound("sounds/Hero_Bullet_Sound.wav");

Rusiu_Skill = new Sound("sounds/Rusiu_Skill.wav");

BackSpace = new Image("rsc/Stage1BackGround.png");

LeftHero = new Image("rsc/Ch_01.png");

RightHero = new Image("rsc/Ch_02.png");

Car = new Image("rsc/Logo.png");

Car_Destination = new Image("rsc/Logo_Destination.png");

Car2 = new Image("rsc/Logo.png");

Car2_Destination = new Image("rsc/Logo_Destination.png");

Continue = new Image("rsc/Continue.png");

Enemy = new Image("rsc/Enemy_Image.png");

Enemy_Bullet = new Image("rsc/Enemy_Bullet_Right.png");

Hero_Bullet_Left = new Image("rsc/Hero_Bullet_Left.png");

Hero_Bullet_Right = new Image("rsc/Hero_Bullet_Right.png");

Rusiu_Skill_Effect = new Image("rsc/Rusiu_Skill_Effect.png");

Enemy_Skilled = new Image("rsc/Enemy_Skilled_Image.png");

random = new Random();

}

 

@Override

public void render(GameContainer arg0, StateBasedGame arg1, Graphics g) throws SlickException {

// TODO Auto-generated method stub

BackSpace.draw(0, 0, ProjectMain._width, ProjectMain._height);

 

for (int i = 0; i < 2; ++i) {

if (Rusiu_Life[i] > 0) {

if (Rusiu_Direction[i] == 0) {

Rusiu_Image_Left.draw(Rusiu_x[i], Rusiu_y[i], 100, 100);

 

 

 

} else if (Rusiu_Direction[i] == 1) {

Rusiu_Image_Right.draw(Rusiu_x[i], Rusiu_y[i], 100, 100);

}

}

 

if (Rusiu_Life[0] > 0 && Rusiu_Direction[0] == 0)

Car.draw(Rusiu_x[0], Rusiu_y[0] + 40, 30, 30);

if (Rusiu_Life[1] > 0 && Rusiu_Direction[1] == 0)

Car2.draw(Rusiu_x[1], Rusiu_y[1] + 40, 30, 30);

if (Rusiu_Life[0] > 0 && Rusiu_Direction[0] == 1)

Car.draw(Rusiu_x[0] + 75, Rusiu_y[0] + 40, 30, 30);

if (Rusiu_Life[1] > 0 && Rusiu_Direction[1] == 1)

Car2.draw(Rusiu_x[1] + 75, Rusiu_y[1] + 40, 30, 30);

if (Rusiu_Life[0] == 0)

Car.draw(Car_x, Car_y, 60, 60);

if (Rusiu_Life[1] == 0)

Car2.draw(Car2_x, Car2_y, 60, 60);

}

for (int i = 0; i < 5; ++i) {

if (Enemy_Life[i] > 0) {

Enemy.draw(Enemy_x[i], Enemy_y[i], 100, 100);

Enemy_Bullet.draw(Enemy_Bullet_x[i], Enemy_Bullet_y[i], 60, 30);

}

}

 

if (Hero_Direction == 0) {

LeftHero.draw(Hero_x, Hero_y, 60, 60);

} else if (Hero_Direction == 1) {

RightHero.draw(Hero_x, Hero_y, 60, 60);

}

 

if (Car_Des_x == Car_x && Car_Des_y == Car_y) {

Car_Count = 1;

Car_Destination_Count = 1;

}

if (Car2_Des_x == Car_x && Car2_Des_y == Car_y) {

Car_Count = 1;

Car2_Destination_Count = 1;

}

if (Car_Des_x == Car2_x && Car_Des_y == Car2_y) {

Car2_Count = 1;

Car_Destination_Count = 1;

}

if (Car2_Des_x == Car2_x && Car2_Des_y == Car2_y) {

Car2_Count = 1;

Car2_Destination_Count = 1;

}

if (Car_Destination_Count == 0) {

Car_Destination.draw(Car_Des_x, Car_Des_y, 60, 60);

}

 

if (Car2_Destination_Count == 0) {

Car2_Destination.draw(Car2_Des_x, Car2_Des_y, 60, 60);

}

 

g.drawString("State 1", 50, 50);

xpos = Mouse.getX();// 마우스 x좌표

ypos = Mouse.getY();// 마우스 y좌표

 

 

g.drawString("x " + xpos + "y" + ypos, 900, 750);// 마우스 좌표 출력 why?(이미지

// 뿌리기 위해 좌표찾기)

for (int i = 0; i < 30; ++i) {

if (Hero_Bullet_Fire[i] == 1) {

if (Hero_Bullet_Direction[i] == 1) {

Hero_Bullet_Left.draw(Hero_Bullet_x[i], Hero_Bullet_y[i], 30, 15);

} else if (Hero_Bullet_Direction[i] == 2) {

Hero_Bullet_Right.draw(Hero_Bullet_x[i], Hero_Bullet_y[i], 30, 15);

}

}

}

if (heroLife <= 0) {

Continue.draw(300, 250, 700, 250);

Input input = arg0.getInput();

if (input.isKeyDown(Input.KEY_Y)) {

heroLife = 1;

}

if (input.isKeyDown(Input.KEY_N)) {

game.enterState(ProjectMain._Menu);

}

}

if (Rusiu_Skill_Count[0] == 1 || Rusiu_Skill_Count[1] == 1) {

if ((ClearTime - SkillTime) > 10) {

Rusiu_Skill_Effect.draw(Rusiu_Skill_X_Y[0] - (Rusiu_SKill_Range / 2),

Rusiu_Skill_X_Y[1] - (Rusiu_SKill_Range / 2), 100 + Rusiu_SKill_Range,

100 + (((float) 0.8) * Rusiu_SKill_Range));

SkillTime = ClearTime;

Rusiu_SKill_Range += 20;

}

}

if((ClearTime-SkillTime2)<10000)

{

for (int i = 0; i < 5; ++i) {

if (Enemy_Life[i] > 0) {

Enemy_Skilled.draw(Enemy_x[i], Enemy_y[i], 100, 100);

Enemy_Bullet.draw(Enemy_Bullet_x[i], Enemy_Bullet_y[i], 60, 30);

Enemy_Life[i]=3;

}

}

}

else

{

for (int i = 0; i < 5; ++i) {

if (Enemy_Life[i] > 0) {

Enemy.draw(Enemy_x[i], Enemy_y[i], 100, 100);

Enemy_Bullet.draw(Enemy_Bullet_x[i], Enemy_Bullet_y[i], 60, 30);

}

}

}

g.drawString(String.valueOf(ProjectMain.score), 100, 10);

}

 

 

 

@Override

public void update(GameContainer arg0, StateBasedGame arg1, int arg2) throws SlickException {

// TODO Auto-generated method stub

if (Rusiu_Life[0] == 0 && Rusiu_Life[1] == 1 && Rusiu_Skill_Count[1] == 0) {

Rusiu_Skill_X_Y[0] = Rusiu_x[1];

Rusiu_Skill_X_Y[1] = Rusiu_y[1];

Rusiu_Skill_Count[1] = 1;

Rusiu_Skill.play();

SkillTime = System.currentTimeMillis();

SkillTime2 = System.currentTimeMillis();

}

if (Rusiu_Life[0] == 1 && Rusiu_Life[1] == 0 && Rusiu_Skill_Count[0] == 0) {

Rusiu_Skill_X_Y[0] = Rusiu_x[0];

Rusiu_Skill_X_Y[1] = Rusiu_y[0];

Rusiu_Skill_Count[0] = 1;

Rusiu_Skill.play();

SkillTime = System.currentTimeMillis();

SkillTime2 = System.currentTimeMillis();

}

if (Car_x < 66 || Car_x > 1174)

Car_x = 600;

if (Car2_x < 66 || Car2_x > 1174)

Car2_x = 600;

 

if (Car2_Destination_Count == 1 && Car_Destination_Count == 1) {

game.enterState(ProjectMain._Ranking);

}

for (int i = 0; i < 2; ++i) {

if (Rusiu_Life[i] > 0) {

if (Rusiu_Direction[i] == 0) {

Rusiu_x[i] -= Rusiu_Speed;

} else if (Rusiu_Direction[i] == 1) {

Rusiu_x[i] += Rusiu_Speed;

}

if (Rusiu_x[i] < 200) {

Rusiu_Direction[i] = 1;

} else if (Rusiu_x[i] > 1100) {

Rusiu_Direction[i] = 0;

}

 

}

if (Rusiu_y[i] == 70 && Rusiu_x[i] > 752) {

} else if (Rusiu_y[i] == 70 && Rusiu_x[i] < 502) {

} else if (Rusiu_y[i] == 670) {

} else if (Rusiu_y[i] == 228 && Rusiu_x[i] < 994 && Rusiu_x[i] > 260) {

} else if (Rusiu_y[i] == 376 && Rusiu_x[i] < 390) {

} else if (Rusiu_y[i] == 376 && Rusiu_x[i] < 748 && Rusiu_x[i] > 495) {

} else if (Rusiu_y[i] == 376 && Rusiu_x[i] > 864) {

} else if (Rusiu_y[i] == 532 && Rusiu_x[i] < 922 && Rusiu_x[i] > 675) {

} else if (Rusiu_y[i] == 532 && Rusiu_x[i] < 574 && Rusiu_x[i] > 327) {

} else if (Rusiu_Jump[i] == 0) {

Rusiu_y[i] += 2;

}

if (Rusiu_Jump[i] > 0) {

 

 

Rusiu_y[i] -= 4;

Rusiu_Jump[i]++;

if (Rusiu_Jump[i] == 50)

Rusiu_Jump[i] = 0;

}

if (random.nextInt(300) > 297

&& (Rusiu_y[i] == 376 || Rusiu_y[i] == 228 || Rusiu_y[i] == 670 || Rusiu_y[i] == 532)) {

Rusiu_Jump[i] = 1;

}

 

}

 

if (Rusiu_Life[0] > 0) {

Car_x = Rusiu_x[0];

Car_y = Rusiu_y[0];

}

if (Rusiu_Life[1] > 0) {

Car2_x = Rusiu_x[1];

Car2_y = Rusiu_y[1];

}

for (int i = 0; i < 30; ++i) {

if (Hero_Bullet_Fire[i] == 1) {

if (Hero_Bullet_x[i] < 66 || Hero_Bullet_x[i] > 1214) {

Hero_Bullet_Fire[i] = 0;

}

if (Hero_Bullet_Direction[i] == 1) {

for (int j = 0; j < 5; ++j) {

if ((Hero_Bullet_x[i] > Enemy_x[j]) && (Hero_Bullet_x[i] < Enemy_x[j] + 80)

&& (Hero_Bullet_y[i] > Enemy_y[j] + 15) && (Hero_Bullet_y[i] < Enemy_y[j] + 70)) {

if (Enemy_Life[j] > 0) {

Enemy_Life[j]--;

Hero_Bullet_Fire[i] = 0;

}

Hero_Bullet_x[i] -= Hero_Bullet_Speed;

} else {

Hero_Bullet_x[i] -= Hero_Bullet_Speed;

}

}

for (int j = 0; j < 2; ++j) {

if ((Hero_Bullet_x[i] > Rusiu_x[j]) && (Hero_Bullet_x[i] < Rusiu_x[j] + 80)

&& (Hero_Bullet_y[i] > Rusiu_y[j] + 15) && (Hero_Bullet_y[i] < Rusiu_y[j] + 70)) {

if (Rusiu_Life[j] > 0) {

Rusiu_Life[j]--;

Hero_Bullet_Fire[i] = 0;

}

Hero_Bullet_x[i] -= Hero_Bullet_Speed;

} else {

Hero_Bullet_x[i] -= Hero_Bullet_Speed;

}

}

} else if (Hero_Bullet_Direction[i] == 2) {

for (int j = 0; j < 5; ++j) {

 

 

if (Hero_Bullet_x[i] < Enemy_x[j] && Hero_Bullet_y[i] > Enemy_y[j] + 10

&& Hero_Bullet_y[i] < Enemy_y[j] + 65) {

if (Enemy_Life[j] > 0) {

Enemy_Life[j]--;

Hero_Bullet_Fire[i] = 0;

}

Hero_Bullet_x[i] += Hero_Bullet_Speed;

} else {

Hero_Bullet_x[i] += Hero_Bullet_Speed;

}

}

}

}

}

for (int i = 0; i < 5; ++i) {

 

if (Enemy_Life[i] > 0) {

if (Enemy_Bullet_y[i] > Hero_y && Enemy_Bullet_y[i] < Hero_y + 20 && Enemy_Bullet_x[i] > Hero_x - 60

&& Enemy_Bullet_x[i] < Hero_x) {

Enemy_Bullet_x[i] = Enemy_x[i] + 50;

heroLife--;

ProjectMain.score -= 100;

} else if (Enemy_Bullet_y[i] > Car_y && Enemy_Bullet_y[i] < Car_y + 40 && Enemy_Bullet_x[i] > Car_x - 60

&& Rusiu_Life[0] == 0) {

Enemy_Bullet_x[i] = Enemy_x[i] + 50;

} else if (Enemy_Bullet_y[i] > Car2_y && Enemy_Bullet_y[i] < Car2_y + 40

&& Enemy_Bullet_x[i] > Car2_x - 60 && Rusiu_Life[1] == 0) {

Enemy_Bullet_x[i] = Enemy_x[i] + 50;

} else if (Enemy_Bullet_x[i] > 1174) {

Enemy_Bullet_x[i] = Enemy_x[i] + 50;

} else {

Enemy_Bullet_x[i] += Enemy_Bullet_Speed[i];

}

}

}

if (Hero_y == 90 && Hero_x > 752) {

} else if (Hero_y == 90 && Hero_x < 502) {

} else if (Hero_y == 690) {

} else if (Hero_y == 248 && Hero_x < 994 && Hero_x > 260) {

} else if (Hero_y == 396 && Hero_x < 390) {

} else if (Hero_y == 396 && Hero_x < 748 && Hero_x > 495) {

} else if (Hero_y == 396 && Hero_x > 864) {

} else if (Hero_y == 552 && Hero_x < 922 && Hero_x > 675) {

} else if (Hero_y == 552 && Hero_x < 574 && Hero_x > 327) {

} else if (Hero_Jump == 0) {

Hero_y += 2;

}

if (Hero_Jump > 0) {

if (Hero_y < 30)

Hero_Jump = 49;

Hero_y -= 4;

Hero_Jump++;

if (Hero_Jump == 50)

 

 

Hero_Jump = 0;

}

if (Car_y == 90 && Car_x > 752) {

} else if (Car_y == 90 && Car_x < 502) {

} else if (Car_y == 690) {

} else if (Car_y == 248 && Car_x < 994 && Car_x > 260) {

} else if (Car_y == 396 && Car_x < 390) {

} else if (Car_y == 396 && Car_x < 748 && Car_x > 495) {

} else if (Car_y == 396 && Car_x > 864) {

} else if (Car_y == 552 && Car_x < 922 && Car_x > 675) {

} else if (Car_y == 552 && Car_x < 574 && Car_x > 327) {

} else {

Car_y += 2;

}

if (Car2_y == 90 && Car2_x > 752) {

} else if (Car2_y == 90 && Car2_x < 502) {

} else if (Car2_y == 690) {

} else if (Car2_y == 248 && Car2_x < 994 && Car2_x > 260) {

} else if (Car2_y == 396 && Car2_x < 390) {

} else if (Car2_y == 396 && Car2_x < 748 && Car2_x > 495) {

} else if (Car2_y == 396 && Car2_x > 864) {

} else if (Car2_y == 552 && Car2_x < 922 && Car2_x > 675) {

} else if (Car2_y == 552 && Car2_x < 574 && Car2_x > 327) {

} else {

Car2_y += 2;

}

if (Car2_y == Car_y && Car2_x < Car_x + 50 && Car2_x > Car_x - 50) {

if (Car2_x > Car_x) {

Car2_x += Car_v;

} else if (Car2_x < Car_x) {

Car2_x -= Car_v;

}

}

Input input = arg0.getInput();

if ((heroLife > 0)) {

ClearTime=System.currentTimeMillis();

ClearTime2=System.currentTimeMillis();

ClearTime2 = (ClearTime2-StartTime)/1000;

ProjectMain.score-=ClearTime2/5;

if (input.isKeyDown(Input.KEY_LEFT) && Hero_x > 66) {

Hero_x -= Hero_v;

Hero_Direction = 0;

}

if (input.isKeyDown(Input.KEY_RIGHT) && Hero_x < 1176) {

Hero_x += Hero_v;

Hero_Direction = 1;

}

if (input.isKeyPressed(Input.KEY_SPACE)

&& (Hero_y == 248 || Hero_y == 396 || Hero_y == 552 || Hero_y == 690 || Hero_y == 90)) {

Hero_Jump = 1;

}

if (input.isKeyPressed(Input.KEY_LCONTROL)) {

Hero_Bullet_Sound.play();

Hero_Bullet_y[Hero_Bullet_Count] = Hero_y + 15;

Hero_Bullet_Fire[Hero_Bullet_Count] = 1;

if (Hero_Direction == 0) {

Hero_Bullet_x[Hero_Bullet_Count] = Hero_x - 30;

Hero_Bullet_Direction[Hero_Bullet_Count] = 1;

} else if (Hero_Direction == 1) {

 

 

Hero_Bullet_x[Hero_Bullet_Count] = Hero_x + 60;

Hero_Bullet_Direction[Hero_Bullet_Count] = 2;

}

Hero_Bullet_Count += 1;

if (Hero_Bullet_Count == 30) {

Hero_Bullet_Count = 0;

}

}

 

if (Hero_y == Car_y && Car_Count == 0 && Rusiu_Life[0] == 0) {

if (Hero_x > Car_x && (Hero_x < Car_x + 56)) {

Car_x -= Car_v;

} else if (Hero_x < Car_x && (Hero_x > Car_x - 56)) {

Car_x += Car_v;

}

 

}

if (Hero_y == Car2_y && Car2_Count == 0 && Rusiu_Life[1] == 0) {

if (Hero_x > Car2_x && (Hero_x < Car2_x + 56)) {

Car2_x -= Car_v;

} else if (Hero_x < Car2_x && (Hero_x > Car2_x - 56)) {

Car2_x += Car_v;

}

}

}

 

}

 

public int getID() {

// TODO Auto-generated method stub

return ID;

}

 

public void keyReleased(int key, char c) {

switch (key) {

case Input.KEY_F1:

game.enterState(ProjectMain._Menu);

break;

}

}

}

Ranking.java

 

package ExeScenes;

 

import org.newdawn.slick.GameContainer;

import org.newdawn.slick.Graphics;

import org.newdawn.slick.Image;

import org.newdawn.slick.Input;

import org.newdawn.slick.SlickException;

import org.newdawn.slick.state.BasicGameState;

import org.newdawn.slick.state.StateBasedGame;

 

import java.io.*;

import java.util.ArrayList;

 

 

import Main.ProjectMain;

 

public class Ranking extends BasicGameState {

StateBasedGame game;

GameContainer gc;

protected int ID;

private boolean _Switch = true;

ArrayList<String> lineList = new ArrayList<String>();

private Image BackGround;

 

public Ranking() {

}

 

public Ranking(int id) {

this.ID = id;

}

 

@Override

public void init(GameContainer arg0, StateBasedGame arg1) throws SlickException {

// TODO Auto-generated method stub

game = arg1;

gc = arg0;

}

 

@Override

public void render(GameContainer arg0, StateBasedGame arg1, Graphics g) throws SlickException {

// TODO Auto-generated method stub

BackGround.draw(0, 0, ProjectMain._width, ProjectMain._height);

for (int i = 0; i < 20; i++) {

if (i % 2 == 0) {

g.drawString(lineList.get(i), 882, 265 + (43 * (i / 2)));

} else {

g.drawString(lineList.get(i), 630, 265 + (43 * (i / 2)));

}

}

}

 

@Override

public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {

// TODO Auto-generated method stub

if (_Switch == true) {

String StringChanged = String.valueOf((ProjectMain.score/100));

BackGround = new Image("rsc/Ranking.png");

File oFile = new File("rsc/Rank.txt");

// File Reader를 위한 객체 생성

FileReader frd = null;

BufferedReader brd = null;

// 내용 저장을 위한 ArrayList 정의

// 라인 단위 저장 및 카운트를 위한 변수 정의

String rLine = null;

int lineNum = 0;

boolean hasMore = true;

try {

frd = new FileReader(oFile);

brd = new BufferedReader(frd);

while (hasMore) {

if ((rLine = brd.readLine()) != null) {

// ArrayList에 읽은 라인 추가

 

 

lineList.add(rLine);

hasMore = true;

} else

hasMore = false;

}

frd.close();

brd.close();

} catch (IOException e) {

e.printStackTrace();

}

// 라인단위 출력(for loop)

lineNum = lineList.size();

int i = 18;

while (i > 0&&(ProjectMain.score/100) > Integer.parseInt(lineList.get(i)))

{

i -= 2;

}

i+=2;

if((ProjectMain.score/100)>Integer.parseInt(lineList.get(0)))

i=0;

lineList.add(i, StringChanged); // 점수를 Stirng으로 변환한 값을 i번째에 넣어줌.

lineList.add(i + 1, ProjectMain.getName()); // 이름을 i+1번째에 넣어줌.

lineList.remove(20);

lineList.remove(20);

for (i = 0; i < lineNum; i++) {

System.out.println(lineList.get(i));

}

try {

FileWriter fw = new FileWriter("rsc/Rank.txt"); // 절대주소 경로 가능

BufferedWriter bw = new BufferedWriter(fw);

for (i = 0; i < lineNum; i++) {

String str = lineList.get(i);

bw.write(str);

bw.newLine(); // 줄바꿈

}

bw.close();

} catch (IOException e) {

System.err.println(e); // 에러가 있다면 메시지 출력

System.exit(1);

}

 

}

 

_Switch = false;

 

}

 

@Override

public int getID() {

// TODO Auto-generated method stub

return ID;

}

 

public void keyReleased(int key, char c) {

switch (key) {

case Input.KEY_1:

game.enterState(ProjectMain._Play1)

 

 

break;

}

}

 

}

Comments