Press 'd' or 'j' to move left or right
for Hit a something in your game
THAT's AUTOMATIC
THAT's AUTOMATIC
FONTS = NOT WORKING IN BROWSERS
IF YOU CAN RUN IN SOFTWARE [PROCESSING 2.0]
PLEASE.....RUN IT ^^ FOR Beautiful animation
Designed :
Name of function
- keypressed ไม่มี Parameter ไม่มี return value ใช้สำหรับ รับค่าของ User (interface)
- DrawBackground ไม่มี Parameter ไม่มี return value ใช้สำหรับ วาดภาพพื้นหลังของเกม
- DrawCharacter ไม่มี Parameter ไม่มี return value ใช้สำหรับ วาดตัวละครในตัวเกม
- update1 ไม่มี Parameter ไม่มี return value ใช้สำหรับสุ่มค่าจุดเริ่มต้นตำแหน่งและช่องของ ลูกบอล 1
- update2 ไม่มี Parameter ไม่มี return value ใช้สำหรับสุ่มค่าจุดเริ่มต้นตำแหน่งและช่องของ ลูกบอล 2
- DrawMonster ไม่มี Parameter ไม่มี return value ใช้สำหรับวาดจุดเริ่มต้นตำแหน่งและช่องของ ลูกบอล 1 และ 2
- DrawHit ไม่มี Parameter ไม่มี return value ใช้สำหรับวาดค้อนที่ใช้ทุบ (ตำแหน่งที่ทุบ) เมื่อมีการกดปุ่ม j หรือ k
- CountPoint ไม่มี Parameter มี return value คือ ค่า Point (คะแนนที่ได้) ใช้สำหรับนับค่าคะแนนเมื่อค้อนกระทบกับลูกบอล ในระยะที่ถูกต้อง
- TextShow ไม่มี Parameter ไม่มี return value ใช้สำหรับแสดงผลค่าคะแนน แล้วก็ชื่อเกม รวมไปถึง หน้าต่าง GAME OVER เมื่อเกมจบ
Responsible Man
- Kananard Sathienthai 5601012630019 = DrawBackground(), TextShow(),update1(),update2()- Chinnawat Chimdee 5601012630060 = All Function (Main Developer)
- Tanath Poonnachit 5601012630124 = DrawCharacter(),CountPoint(),ClearGame()
CODE in Game :
boolean cis = true;
int Width=600;
int Height=400;
int count=0;
int xMove=0;
int i=0;
int Speed=20; //////////// CAN CHANGE
int frame=0;
int[] index = {
0, 0
};
int[] Slot = {
0, 110, 220
};
int[] indexMons = new int[2];
int[] PosMons = { //X axis
80, 190, 300, 410, 520
};
int[] xPosMons = {
0, 0
};
int[][] yPosMons= {
{
300, 280, 250, 210, 180, 150
}
,
{
320, 290, 260, 230, 180, 150
}
};
boolean[] Hit= {
false, false
};
boolean[] CheckHIT= {
false, false
};
void setup()
{
frameRate(10);
size(Width, Height);
update1();
update2();
}
void draw()
{
DrawBackground();
DrawCharacter();
DrawMonster();
TextShow();
frame++;
}
void keyPressed() //kEYPRESSED USER BUTTON FOR PLAY
{
if (key=='j' || key=='J')
{
if (xMove<220)
{
i++;
}
}
if (key=='f' || key=='F')
{
if (xMove>0)
{
i--;
}
}
xMove=Slot[i];
if (key=='r' || key=='R')
{
ClearGame();
}
}
void ClearGame()
{
i=0;
frame=0;
index[0]=0;
index[1]=0;
cis = true;
xMove=0;
Speed=20;
yPosMons[0][0]=300;
yPosMons[1][0]=320;
count=0;
update1();
update2();
DrawBackground();
DrawCharacter();
DrawMonster();
TextShow();
}
void update1() //update ball 1
{
indexMons[0]=int(random(0, 5)); //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
xPosMons[0]=PosMons[indexMons[0]];
}
void update2() //update ball 2
{
indexMons[1]=int(random(0, 5)); //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
xPosMons[1]=PosMons[indexMons[1]];
}
void DrawBackground() //BG - Moowhan
{
background(100, 100, 255);
int HeightHalf=Height/2;
int xStart_Line=0;
int xEnd_Line=50;
strokeWeight(0.25);
line(0, 175, width, 175);
strokeWeight(4);
fill(0);
for (xStart_Line=0 ; xStart_Line<Width ; xStart_Line+=110) {
xEnd_Line=xStart_Line+50;
line(xStart_Line, HeightHalf, xEnd_Line, HeightHalf);
}
}
void DrawCharacter() //Interface Character - Sinn
{
ellipse(188+xMove, 70, 50, 50); //Head
ellipse(188+xMove, 130, 30, 60); //Body
strokeWeight(4);
line(160+xMove, 175, 175+xMove, 160); //LeftLeg
line(200+xMove, 160, 215+xMove, 175); //RightLeg
fill(255);
strokeWeight(1);
ellipse(180+xMove, 70, 10, 10); //LeftEye
ellipse(200+xMove, 70, 10, 10); //RightEye
ellipse(190+xMove, 85, 30, 5); //Mouth
DrawHit();
}
int CountPoint() //CountPoint sinn+wat
{
for (int j=0;j<2;j++)
{
if (index[j]<=5) {
switch (indexMons[j]) {
case 0 :
if (xMove==Slot[0] && yPosMons[j][index[j]] == 180 && CheckHIT[j]==false)
{
count++;
CheckHIT[j]=true;
}
break;
case 1 :
if (xMove==Slot[1] && yPosMons[j][index[j]] == 180 && CheckHIT[j]==false)
{
count++;
CheckHIT[j]=true;
}
break;
case 2 :
if ((xMove==Slot[0] || xMove==Slot[2]) && yPosMons[j][index[j]] == 180 && CheckHIT[j]==false)
{
count++;
CheckHIT[j]=true;
}
break;
case 3 :
if (xMove==Slot[1] && yPosMons[j][index[j]] == 180 && CheckHIT[j]==false)
{
count++;
CheckHIT[j]=true;
}
break;
case 4 :
if (xMove==Slot[2] && yPosMons[j][index[j]] == 180 && CheckHIT[j]==false)
{
count++;
CheckHIT[j]=true;
}
break;
}
}
}
AutoHit();
return count;
}
void AutoHit()
{
for (int q=0;q<2;q++) {
if (yPosMons[q][index[q]] == 180) {
if (xMove==Slot[0])
{
if (indexMons[q]==0)
{
Hit[0]=true;
}
if (indexMons[q]==2)
{
Hit[1]=true;
}
}
if (xMove==Slot[1])
{
if (indexMons[q]==1)
{
Hit[0]=true;
}
if (indexMons[q]==3)
{
Hit[1]=true;
}
}
if (xMove==Slot[2])
{
if (indexMons[q]==2)
{
Hit[0]=true;
}
if (indexMons[q]==4)
{
Hit[1]=true;
}
}
}
}
}
void DrawHit() //draw hammer that hit - wat
{
fill(0);
if (Hit[0]==false)
{
quad(80+xMove, 20, 50+xMove, 50, 80+xMove, 80, 110+xMove, 50);
strokeWeight(3);
line(95+xMove, 67, 125+xMove, 100); //LeftHammerHandle
strokeWeight(8);
line(125+xMove, 100, 140+xMove, 117);//LeftHand
strokeWeight(4);
line(143+xMove, 120, 160+xMove, 125);//LeftArm
}//LeftNoHit
if (Hit[1]==false)
{
quad(295+xMove, 20, 265+xMove, 50, 295+xMove, 80, 325+xMove, 50);
strokeWeight(3);
line(250+xMove, 100, 280+xMove, 67);//RightHammerHandle
strokeWeight(8);
line(235+xMove, 117, 250+xMove, 100);//RightHand
strokeWeight(4);
line(213+xMove, 125, 233+xMove, 120);//RightArm
}//RightNoHit
if (Hit[0]==true) //ball check and slot check => draw********************************
{
quad(60+xMove, 130, 105+xMove, 130, 105+xMove, 175, 60+xMove, 175);//LeftHammer
strokeWeight(3);
line(100+xMove, 155, 125+xMove, 150);//LeftHammerHandle
strokeWeight(8);
line(125+xMove, 150, 140+xMove, 143);//LeftHand
strokeWeight(4);
line(143+xMove, 140, 160+xMove, 130);//LeftArm
Hit[0]=false;
}//LeftHit
if (Hit[1]==true)
{
quad(280+xMove, 130, 325+xMove, 130, 325+xMove, 175, 280+xMove, 175);//RightHammer
strokeWeight(3);
line(250+xMove, 150, 280+xMove, 155);//RightHammerHandle
strokeWeight(8);
line(235+xMove, 142, 250+xMove, 150);//RightHand
strokeWeight(4);
line(213+xMove, 130, 233+xMove, 140);//RightArm
Hit[1]=false;
}//RightHit
}
void TextShow() //OUTPUT POINT METHOD Moowhan
{
fill(0);
//del /* xxxxxxx */ if you run in Processing program
/*
textSize(40);
text("VERMIN", 300, 350);
text(CountPoint(), 500, 350);
if (yPosMons[0]<=150 || yPosMons[1] <=150)
{
background(0);
fill(255);
text("GAME OVER", 185, height/2-50);
text("Press R to Restart", 130, height/2);
text("Score : "+CountPoint(), 220, height/2+50);
}
*/
text("VERMIN", 300, 350);
text(CountPoint(), 500, 350);
if (index[0]>5 || index[1]>5)
{
background(0);
fill(255);
text("GAME OVER", 250, height/2-50);
text("Press R to Restart", 230, height/2);
text("Score : "+CountPoint(), 255, height/2+50);
}
}
void DrawMonster() //draw monster - wat
{
int r=20;
int j;
fill(0);
for (j=0;j<2;j++)
{
if (CheckHIT[j] == false)
{
if (j==0 && frame%Speed==0)
{
index[0]++;
}
if (j==1 && frame%Speed-2==0)
{
index[1]++;
}
if (j==0 && index[0]<=5)
{
ellipse(xPosMons[j], yPosMons[j][index[0]], r, r);
}
if (j==1 && index[1]<=5)
{
ellipse(xPosMons[j], yPosMons[j][index[1]], r, r);
}
if (CountPoint() % 10 == 0 && CountPoint() != 0 && cis == true && Speed >=16) {
Speed -= 2;
cis=false;
}
else if (CountPoint()%10 >= 1 && CountPoint() != 1)
{
cis=true;
}
}
if (CheckHIT[j] == true)
{
if (j==0)
{
update1();
index[0]=0;
}
if (j==1)
{
update2();
index[1]=0;
}
CheckHIT[j]=false;
}
}
}
int Width=600;
int Height=400;
int count=0;
int xMove=0;
int i=0;
int Speed=20; //////////// CAN CHANGE
int frame=0;
int[] index = {
0, 0
};
int[] Slot = {
0, 110, 220
};
int[] indexMons = new int[2];
int[] PosMons = { //X axis
80, 190, 300, 410, 520
};
int[] xPosMons = {
0, 0
};
int[][] yPosMons= {
{
300, 280, 250, 210, 180, 150
}
,
{
320, 290, 260, 230, 180, 150
}
};
boolean[] Hit= {
false, false
};
boolean[] CheckHIT= {
false, false
};
void setup()
{
frameRate(10);
size(Width, Height);
update1();
update2();
}
void draw()
{
DrawBackground();
DrawCharacter();
DrawMonster();
TextShow();
frame++;
}
void keyPressed() //kEYPRESSED USER BUTTON FOR PLAY
{
if (key=='j' || key=='J')
{
if (xMove<220)
{
i++;
}
}
if (key=='f' || key=='F')
{
if (xMove>0)
{
i--;
}
}
xMove=Slot[i];
if (key=='r' || key=='R')
{
ClearGame();
}
}
void ClearGame()
{
i=0;
frame=0;
index[0]=0;
index[1]=0;
cis = true;
xMove=0;
Speed=20;
yPosMons[0][0]=300;
yPosMons[1][0]=320;
count=0;
update1();
update2();
DrawBackground();
DrawCharacter();
DrawMonster();
TextShow();
}
void update1() //update ball 1
{
indexMons[0]=int(random(0, 5)); //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
xPosMons[0]=PosMons[indexMons[0]];
}
void update2() //update ball 2
{
indexMons[1]=int(random(0, 5)); //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
xPosMons[1]=PosMons[indexMons[1]];
}
void DrawBackground() //BG - Moowhan
{
background(100, 100, 255);
int HeightHalf=Height/2;
int xStart_Line=0;
int xEnd_Line=50;
strokeWeight(0.25);
line(0, 175, width, 175);
strokeWeight(4);
fill(0);
for (xStart_Line=0 ; xStart_Line<Width ; xStart_Line+=110) {
xEnd_Line=xStart_Line+50;
line(xStart_Line, HeightHalf, xEnd_Line, HeightHalf);
}
}
void DrawCharacter() //Interface Character - Sinn
{
ellipse(188+xMove, 70, 50, 50); //Head
ellipse(188+xMove, 130, 30, 60); //Body
strokeWeight(4);
line(160+xMove, 175, 175+xMove, 160); //LeftLeg
line(200+xMove, 160, 215+xMove, 175); //RightLeg
fill(255);
strokeWeight(1);
ellipse(180+xMove, 70, 10, 10); //LeftEye
ellipse(200+xMove, 70, 10, 10); //RightEye
ellipse(190+xMove, 85, 30, 5); //Mouth
DrawHit();
}
int CountPoint() //CountPoint sinn+wat
{
for (int j=0;j<2;j++)
{
if (index[j]<=5) {
switch (indexMons[j]) {
case 0 :
if (xMove==Slot[0] && yPosMons[j][index[j]] == 180 && CheckHIT[j]==false)
{
count++;
CheckHIT[j]=true;
}
break;
case 1 :
if (xMove==Slot[1] && yPosMons[j][index[j]] == 180 && CheckHIT[j]==false)
{
count++;
CheckHIT[j]=true;
}
break;
case 2 :
if ((xMove==Slot[0] || xMove==Slot[2]) && yPosMons[j][index[j]] == 180 && CheckHIT[j]==false)
{
count++;
CheckHIT[j]=true;
}
break;
case 3 :
if (xMove==Slot[1] && yPosMons[j][index[j]] == 180 && CheckHIT[j]==false)
{
count++;
CheckHIT[j]=true;
}
break;
case 4 :
if (xMove==Slot[2] && yPosMons[j][index[j]] == 180 && CheckHIT[j]==false)
{
count++;
CheckHIT[j]=true;
}
break;
}
}
}
AutoHit();
return count;
}
void AutoHit()
{
for (int q=0;q<2;q++) {
if (yPosMons[q][index[q]] == 180) {
if (xMove==Slot[0])
{
if (indexMons[q]==0)
{
Hit[0]=true;
}
if (indexMons[q]==2)
{
Hit[1]=true;
}
}
if (xMove==Slot[1])
{
if (indexMons[q]==1)
{
Hit[0]=true;
}
if (indexMons[q]==3)
{
Hit[1]=true;
}
}
if (xMove==Slot[2])
{
if (indexMons[q]==2)
{
Hit[0]=true;
}
if (indexMons[q]==4)
{
Hit[1]=true;
}
}
}
}
}
void DrawHit() //draw hammer that hit - wat
{
fill(0);
if (Hit[0]==false)
{
quad(80+xMove, 20, 50+xMove, 50, 80+xMove, 80, 110+xMove, 50);
strokeWeight(3);
line(95+xMove, 67, 125+xMove, 100); //LeftHammerHandle
strokeWeight(8);
line(125+xMove, 100, 140+xMove, 117);//LeftHand
strokeWeight(4);
line(143+xMove, 120, 160+xMove, 125);//LeftArm
}//LeftNoHit
if (Hit[1]==false)
{
quad(295+xMove, 20, 265+xMove, 50, 295+xMove, 80, 325+xMove, 50);
strokeWeight(3);
line(250+xMove, 100, 280+xMove, 67);//RightHammerHandle
strokeWeight(8);
line(235+xMove, 117, 250+xMove, 100);//RightHand
strokeWeight(4);
line(213+xMove, 125, 233+xMove, 120);//RightArm
}//RightNoHit
if (Hit[0]==true) //ball check and slot check => draw********************************
{
quad(60+xMove, 130, 105+xMove, 130, 105+xMove, 175, 60+xMove, 175);//LeftHammer
strokeWeight(3);
line(100+xMove, 155, 125+xMove, 150);//LeftHammerHandle
strokeWeight(8);
line(125+xMove, 150, 140+xMove, 143);//LeftHand
strokeWeight(4);
line(143+xMove, 140, 160+xMove, 130);//LeftArm
Hit[0]=false;
}//LeftHit
if (Hit[1]==true)
{
quad(280+xMove, 130, 325+xMove, 130, 325+xMove, 175, 280+xMove, 175);//RightHammer
strokeWeight(3);
line(250+xMove, 150, 280+xMove, 155);//RightHammerHandle
strokeWeight(8);
line(235+xMove, 142, 250+xMove, 150);//RightHand
strokeWeight(4);
line(213+xMove, 130, 233+xMove, 140);//RightArm
Hit[1]=false;
}//RightHit
}
void TextShow() //OUTPUT POINT METHOD Moowhan
{
fill(0);
//del /* xxxxxxx */ if you run in Processing program
/*
textSize(40);
text("VERMIN", 300, 350);
text(CountPoint(), 500, 350);
if (yPosMons[0]<=150 || yPosMons[1] <=150)
{
background(0);
fill(255);
text("GAME OVER", 185, height/2-50);
text("Press R to Restart", 130, height/2);
text("Score : "+CountPoint(), 220, height/2+50);
}
*/
text("VERMIN", 300, 350);
text(CountPoint(), 500, 350);
if (index[0]>5 || index[1]>5)
{
background(0);
fill(255);
text("GAME OVER", 250, height/2-50);
text("Press R to Restart", 230, height/2);
text("Score : "+CountPoint(), 255, height/2+50);
}
}
void DrawMonster() //draw monster - wat
{
int r=20;
int j;
fill(0);
for (j=0;j<2;j++)
{
if (CheckHIT[j] == false)
{
if (j==0 && frame%Speed==0)
{
index[0]++;
}
if (j==1 && frame%Speed-2==0)
{
index[1]++;
}
if (j==0 && index[0]<=5)
{
ellipse(xPosMons[j], yPosMons[j][index[0]], r, r);
}
if (j==1 && index[1]<=5)
{
ellipse(xPosMons[j], yPosMons[j][index[1]], r, r);
}
if (CountPoint() % 10 == 0 && CountPoint() != 0 && cis == true && Speed >=16) {
Speed -= 2;
cis=false;
}
else if (CountPoint()%10 >= 1 && CountPoint() != 1)
{
cis=true;
}
}
if (CheckHIT[j] == true)
{
if (j==0)
{
update1();
index[0]=0;
}
if (j==1)
{
update2();
index[1]=0;
}
CheckHIT[j]=false;
}
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น