[프로젝트, 3학년] Elancia VolleyBall

류명운

·

2016. 1. 13. 16:29

반응형

 

프로젝트명  ElanciaVolleyBall
개 발 언 어  Java Database  
개 발 도 구  Eclipse Luna 라이브러리  java.awt, javax.swing

프로젝트 기간  2016.01.03 ~ 2016.01.05 프로젝트 종류  스터디 개인 프로젝트
개 발 종 류  스윙으로 작성한 배우게임 프로그램

담 당  메인 프로그래밍
프로그램 요약  
 <개발 목적>
 - 게임 제작을 통한 알고리즘 개발능력을 향상시키고 싶었습니다.


 <프로그램 설명>
 - 자바의 스윙 클래스를 이용하여 GUI로 작성한 일랜시아 배구게임 입니다.
 - 메인 스레드에서는 전체적인 게임 진행, 점수관리, 키입력 관리, 서브 스레드 생성 및 관리를 하며, 각 서브 스레드(Ball, Player1, Player2)에서는 볼, 플레이어1, 플레이어2 객체를 생성해 게임을 진행할 수 있게 한다.
 - 게임이 진행되는 메인 프레임의 컨텐트팬 레이아웃을 'null'로 설정하여 각 객체들(볼, 플레이어 1, 2)의 좌표를 절대 값으로 관리하여 움직이며 게임을 진행하도록 구현하였다. 


 <특이 사항>
 * 중/고등학교 시절을 함께한 넥슨의 일랜시아 게임을 컨셉으로 잡아 본인 게임 캐릭터 이미지를 사용하였습니다.

프로
시연 영상





 

주요소스 - 공이 움직이는 알고리즘

	// 바닥 반사
if (background.mg.ball_y > 610) {
	if (background.mg.ball_x < 435) {
		background.mg.getScore(2);
	} else {
		background.mg.getScore(1);
	}
	background.mg.speed_x = 0;
	background.mg.speed_y = 5;
	background.mg.speed_y = -background.mg.speed_y;
	draw();
}
	// Player1 진영에 공이 닿았을 경우
else if (background.mg.p1_x - 30 < background.mg.ball_x
		&& background.mg.ball_x < background.mg.p1_x + 70
		&& background.mg.p1_y < background.mg.ball_y
		&& background.mg.ball_y < background.mg.p1_y + 137) {
	System.out.println(background.mg.p1_jump);
	if (background.mg.p1_jump == true && background.mg.p1_event == 1) {
		background.mg.ball_y = background.mg.p1_y;
		background.mg.ball_x = background.mg.p1_x + 80;
		background.mg.speed_x = 9;
		background.mg.speed_y = 2;
		background.mg.p1_event = 0;
		background.mg.p1_jump = false;
	} else if (background.mg.p1_jump == true
			&& background.mg.p1_event == 2) {
		background.mg.speed_x = 5;
		background.mg.speed_y = -10;
		background.mg.p1_event = 0;
		background.mg.p1_jump = false;
	} else {
		background.mg.ball_y = background.mg.p1_y;
		background.mg.speed_y = -Math.abs(background.mg.speed_y);
		draw();
		if (background.mg.ball_touch == false) {
			if (background.p1_left == true) {
				background.mg.speed_x = Math.abs(background.mg.speed_x) - 3;
			} else if (background.p1_right == true) {
				background.mg.speed_x = Math.abs(background.mg.speed_x) + 3;
			}
		}
		background.mg.ball_touch = true;
	}

} else if (background.mg.ball_y <= 0) { // 천장 반사
	background.mg.ball_y = 0;

	background.mg.speed_y = -background.mg.speed_y;
	draw();
} else if (background.mg.ball_x <= 0) { // 왼쪽 벽 반사
	background.mg.ball_x = 0;
	background.mg.speed_x = -background.mg.speed_x;
	draw();
} else if (background.mg.ball_x > 870) { // 오른쪽 벽 반사
	background.mg.ball_x = 870;
	background.mg.speed_x = -background.mg.speed_x;
	draw();
} else if (390 < background.mg.ball_x && background.mg.ball_x < 478
		&& 315 < background.mg.ball_y && background.mg.ball_y < 321) { // 기둥 위 반사
	background.mg.speed_y = -background.mg.speed_y;
	draw();
} else if (390 < background.mg.ball_x && background.mg.ball_x < 478
		&& 317 < background.mg.ball_y) {//// 기둥 옆 반사
	if (background.mg.speed_x > 0) {
		background.mg.ball_x = 390;
	} else if (background.mg.speed_x < 0) {
		background.mg.ball_x = 478;
	}
	background.mg.speed_x = -background.mg.speed_x * 2;
	draw();
	background.mg.speed_x = background.mg.speed_x / 2;
} else {
	background.mg.ball_touch = false;
	draw();
}
background.mg.repaint();

 

반응형