Tennis Mini-Game (Not Fully Ready)

Tennis Mini-Game (Not Fully Ready)
This commit is contained in:
Ben987 2019-10-25 09:36:21 -04:00
parent 5ed66c1bd5
commit 7242cf6e54
8 changed files with 113 additions and 33 deletions

Binary file not shown.

After

(image error) Size: 174 KiB

Binary file not shown.

After

(image error) Size: 16 KiB

Binary file not shown.

After

(image error) Size: 16 KiB

View file

@ -6,6 +6,30 @@ var TennisCharacterLeftPoint = 0;
var TennisCharacterRightPoint = 0;
var TennisCharacterLeftRacket = 500;
var TennisCharacterRightRacket = 500;
var TennisBallX = 1000;
var TennisBallY = 500;
var TennisBallSpeed = 100;
var TennisBallAngle = 0;
// When a player serves
function TennisServe(CharacterLeftServe) {
TennisBallSpeed = 100;
TennisBallAngle = (CharacterLeftServe ? 0 : Math.PI) + Math.PI * 0.5 * (0.8 + Math.random() * 0.4);
TennisBallX = CharacterLeftServe ? 600 : 1400;
TennisBallY = 500;
}
// Returns the score for a player
function TennisGetScore(PointFor, PointAgainst) {
if (PointFor + PointAgainst >= 6) {
if (PointFor >= PointAgainst + 2) return TextGet("Winner");
if (PointFor >= PointAgainst + 1) return TextGet("Advantage");
if (PointFor == PointAgainst) return TextGet("Deuce");
return "";
}
if (PointFor >= 4) return TextGet("Winner");
else return TextGet("Point" + PointFor.toString());
}
// Loads the tennis mini game and sets the difficulty
function TennisLoad() {
@ -13,9 +37,10 @@ function TennisLoad() {
TennisCharacterRightPoint = 0;
TennisCharacterLeftRacket = 500;
TennisCharacterRightRacket = 500;
MiniGameDifficultyRatio = 10;
if (MiniGameDifficulty == "Normal") MiniGameDifficultyRatio = 15;
if (MiniGameDifficulty == "Hard") MiniGameDifficultyRatio = 20;
MiniGameDifficultyRatio = 100;
if (MiniGameDifficulty == "Normal") MiniGameDifficultyRatio = 175;
if (MiniGameDifficulty == "Hard") MiniGameDifficultyRatio = 250;
TennisServe(Math.random() > 0.5);
}
// Runs the tennis mini game
@ -24,36 +49,98 @@ function TennisRun() {
// Draw the characters
DrawCharacter(TennisCharacterLeft, 0, 100, 0.9);
DrawText(TennisCharacterLeft.Name, 225, 30, "white");
DrawText(TextGet("Point" + TennisCharacterLeftPoint.toString()), 225, 80, "white");
DrawText(TennisGetScore(TennisCharacterLeftPoint, TennisCharacterRightPoint), 225, 80, "white");
DrawCharacter(TennisCharacterRight, 1550, 100, 0.9);
DrawText(TennisCharacterRight.Name, 1775, 30, "white");
DrawText(TextGet("Point" + TennisCharacterRightPoint.toString()), 1775, 80, "white");
DrawText(TennisGetScore(TennisCharacterRightPoint, TennisCharacterLeftPoint), 1775, 80, "white");
MiniGameTimer = MiniGameTimer + Math.round(TimerRunInterval);
// If the mini game is running
if (!MiniGameEnded) {
// Sets the new progress
if (MiniGameTimer >= 5000) MiniGameProgress = -1;
if (MiniGameTimer >= 5000) MiniGameProgress = 0;
// Draw the intro text or progress bar
if (MiniGameProgress == -1) {
DrawText(TextGet("Intro1"), 1000, 400, "white");
DrawText(TextGet("Intro2"), 1000, 500, "white");
DrawText(TextGet("StartsIn") + " " + (5 - Math.floor(MiniGameTimer / 1000)).toString(), 1000, 600, "white");
}
DrawText(TextGet("Intro1"), 1000, 400, "black");
DrawText(TextGet("Intro2"), 1000, 500, "black");
DrawText(TextGet("StartsIn") + " " + (5 - Math.floor(MiniGameTimer / 1000)).toString(), 1000, 600, "black");
} else {
// Moves the ball
TennisBallX = TennisBallX + Math.sin(TennisBallAngle) * TennisBallSpeed / TimerRunInterval;
TennisBallY = TennisBallY + Math.cos(TennisBallAngle) * TennisBallSpeed / TimerRunInterval;
// Shows the rackets
DrawImage("Screens/" + CurrentModule + "/" + CurrentScreen + "/Racket.png", 550, TennisCharacterLeftRacket - 50);
DrawImage("Screens/" + CurrentModule + "/" + CurrentScreen + "/Racket.png", 1450, TennisCharacterRightRacket - 50);
// Moves the player and opponent racket (speeds up with difficulty)
if ((MouseY >= 0) && (MouseY <= 999)) TennisCharacterLeftRacket = MouseY;
if (TennisBallY < TennisCharacterRightRacket - 55) TennisCharacterRightRacket = TennisCharacterRightRacket - (MiniGameDifficultyRatio / TimerRunInterval);
if (TennisBallY > TennisCharacterRightRacket + 55) TennisCharacterRightRacket = TennisCharacterRightRacket + (MiniGameDifficultyRatio / TimerRunInterval);
// Bounces on upper side
if (TennisBallY < 20) {
TennisBallY = 20 + (20 - TennisBallY);
if (Math.sin(TennisBallAngle) > 0) TennisBallAngle = Math.acos((Math.cos(TennisBallAngle) * -1));
else TennisBallAngle = Math.acos((Math.cos(TennisBallAngle) * -1));
}
// Bounces on lower side
if (TennisBallY > 980) {
TennisBallY = 980 - (TennisBallY - 980);
if (Math.sin(TennisBallAngle) > 0) TennisBallAngle = Math.acos((Math.cos(TennisBallAngle) * -1));
else TennisBallAngle = Math.acos((Math.cos(TennisBallAngle) * -1));
}
// If the player on the left bounces the ball
if ((Math.sin(TennisBallAngle) < 0) && (TennisBallX >= 500) && (TennisBallX <= 550) && (TennisBallY >= TennisCharacterLeftRacket - 110) && (TennisBallY <= TennisCharacterLeftRacket + 110)) {
TennisBallAngle = Math.PI * 0.5 * (1 - ((TennisBallY - TennisCharacterLeftRacket) / 165));
TennisBallSpeed = TennisBallSpeed + 25;
}
// If the player on the right bounces the ball
if ((Math.sin(TennisBallAngle) > 0) && (TennisBallX >= 1450) && (TennisBallX <= 1500) && (TennisBallY >= TennisCharacterRightRacket - 110) && (TennisBallY <= TennisCharacterRightRacket + 110)) {
TennisBallAngle = Math.PI + (Math.PI * 0.5 * (1 - ((TennisCharacterRightRacket - TennisBallY) / 165)));
TennisBallSpeed = TennisBallSpeed + 25;
}
// Shows the rackets and ball
DrawImage("Screens/" + CurrentModule + "/" + CurrentScreen + "/RacketLeft.png", 500, TennisCharacterLeftRacket - 75);
DrawImage("Screens/" + CurrentModule + "/" + CurrentScreen + "/RacketRight.png", 1450, TennisCharacterRightRacket - 75);
DrawImage("Screens/" + CurrentModule + "/" + CurrentScreen + "/TennisBall.png", TennisBallX - 20, TennisBallY - 20);
// If the opponent scores
if (TennisBallX < 450) {
MiniGameProgress = -1;
MiniGameTimer = 2000;
TennisServe(true);
TennisCharacterRightPoint++;
if ((TennisCharacterRightPoint >= 4) && (TennisCharacterRightPoint >= TennisCharacterLeftPoint + 2)) {
MiniGameVictory = false;
MiniGameEnded = true;
}
}
// If the player scores
if (TennisBallX > 1550) {
MiniGameProgress = -1;
MiniGameTimer = 2000;
TennisServe(false);
TennisCharacterLeftPoint++;
if ((TennisCharacterLeftPoint >= 4) && (TennisCharacterLeftPoint >= TennisCharacterRightPoint + 2)) {
MiniGameVictory = true;
MiniGameEnded = true;
}
}
}
} else {
// Draw the end message
if (MiniGameVictory && (TennisCharacterRightPoint == 0)) DrawText(TextGet("Perfect"), 1000, 400, "white");
else if (MiniGameVictory) DrawText(TextGet("Victory"), 1000, 400, "white");
else DrawText(TextGet("Defeat"), 1000, 400, "white");
DrawText(TextGet("ClickContinue"), 1000, 600, "white");
if (MiniGameVictory && (TennisCharacterRightPoint == 0)) DrawText(TextGet("Perfect"), 1000, 400, "black");
else if (MiniGameVictory) DrawText(TextGet("Victory"), 1000, 400, "black");
else DrawText(TextGet("Defeat"), 1000, 400, "black");
DrawText(TextGet("ClickContinue"), 1000, 600, "black");
}
@ -65,10 +152,6 @@ function TennisVerifyEnd() {
MiniGameVictory = true;
MiniGameEnded = true;
}
if ((TennisCharacterRightPoint >= 4) && (TennisCharacterRightPoint >= TennisCharacterLeftPoint + 2)) {
MiniGameVictory = false;
MiniGameEnded = true;
}
}
// When the user clicks in the tennis mini game
@ -78,8 +161,4 @@ function TennisClick() {
if (MiniGameEnded && (MouseX >= 0) && (MouseX <= 450) && (MouseY >= 100) && (MouseY <= 999))
CommonDynamicFunction(MiniGameReturnFunction + "()");
// If the game has started, we check the click position and send it as a move
if ((MiniGameTimer > 5000) && (MouseX >= 450) && (MouseX < 750) && (MouseY >= 0) && (MouseX < 1000) && (MiniGameProgress != -1) && !MiniGameEnded)
TennisCharacterLeftRacket = MouseY;
}

Binary file not shown.

After

(image error) Size: 3.1 KiB

View file

@ -7,7 +7,8 @@ Point2,30
Point3,40
Deuce,Deuce
Advantage,Advantage
Perfect,Perfect victory!
Winner,Winner
Perfect,Victory! Perfect game.
Victory,You won the game.
Defeat,You lost the game.
ClickContinue,Click on yourself to continue.

1 StartsIn Starts in
7 Point3 40
8 Deuce Deuce
9 Advantage Advantage
10 Perfect Winner Perfect victory! Winner
11 Perfect Victory! Perfect game.
12 Victory You won the game.
13 Defeat You lost the game.
14 ClickContinue Click on yourself to continue.

View file

@ -96,7 +96,7 @@ function CollegeTennisGameStart(Difficulty) {
function CollegeTennisGameEnd() {
CommonSetScreen("Room", "CollegeTennis");
CharacterSetCurrent(CollegeTennisJennifer);
if ((Difficulty == "Hard") && MiniGameVictory && (CollegeTennisJennifer.Name != "Jennifer")) CharacterChangeMoney(Player, 50);
if ((MiniGameDifficulty == "Hard") && MiniGameVictory && (CollegeTennisJennifer.Name != "Jennifer")) CharacterChangeMoney(Player, 50);
if (CollegeTennisJennifer.Name == "Jennifer") CollegeTennisJennifer.Stage = MiniGameVictory ? "100" : "200";
else CollegeTennisJennifer.Stage = MiniGameVictory ? "1100" : "1200";
CollegeTennisJennifer.CurrentDialog = DialogFind(CollegeTennisJennifer, MiniGameVictory ? "TennisVictory" : "TennisDefeat");

View file

@ -17,9 +17,9 @@ TennisDefeat,,,(She looks happy.) Good game! But you need some practice. We c
0,20,"Mentor, I've found a wonderful club.",A club my protege? What kind of club?,,"JenniferStatusIs(""Owner"")"
0,20,"My girl, I've found a wonderful club.",A club Mentor? What kind of club?,,"JenniferStatusIs(""Owned"")"
0,,I need to go. (Leave her.),,DialogLeave(),
10,,An easy game ok? (Play tennis.),,"StartGame(""Easy"")",
10,,A game for honor? (Play tennis.),,"StartGame(""Normal"")",
10,,You'll bite the dust. (Play tennis.),,"StartGame(""Hard"")",
10,,An easy game ok? (Play tennis.),,"GameStart(""Easy"")",
10,,A game for honor? (Play tennis.),,"GameStart(""Normal"")",
10,,You'll bite the dust. (Play tennis.),,"GameStart(""Hard"")",
10,0,Maybe we can play later.,Of course. You can come back whenever you want.,,
20,21,It's called the Bondage Club.,(She giggles.) I've heard of it. It's an adult club downtown?,,
20,21,Its a BDSM club.,"Oh yes, I've heard of the adult club downtown.",,
@ -50,12 +50,12 @@ TennisDefeat,,,(She looks happy.) Good game! But you need some practice. We c
1000,,How do tennis points work?,"The first point is 15, second is 30 and third is 40. You win if you score after 40. There's a tie breaker if we are both at 40.",,
1000,1010,We could play a tennis game.,"Absolutely, have you played before? I can go easy on you if you're a beginner.",,
1000,,I need to go. (Leave her.),,DialogLeave(),
1010,,Please go easy. (Play tennis.),,"StartGame(""Easy"")",
1010,,Let's do a regular game. (Play tennis.),,"StartGame(""Normal"")",
1010,,Please go easy. (Play tennis.),,"GameStart(""Easy"")",
1010,,Let's do a regular game. (Play tennis.),,"GameStart(""Normal"")",
1010,1011,We can bet some money on the game.,Are you willing to bet 25$ on the game? The winner keeps everything.,,DialogMoneyGreater(25)
1010,,We can bet some money on the game.,You're too poor for that. Get 25$ and we can bet it on a tennis match.,,!DialogMoneyGreater(25)
1010,1000,Maybe we can play later.,"Sure, let me know when you're ready.",,
1011,,"Here's 25$, you're going down. (Play tennis.)",,"StartGame(""Hard"")",
1011,,"Here's 25$, you're going down. (Play tennis.)",,"GameStart(""Hard"")",
1011,1000,Forget it.,Chicken!,,
1100,1010,Another match? Sure!,"Perfect, this time I will crush you.",,
1100,1000,"No, that's enough.","Alright, you can come back to play anytime.",,

1 PlayerGagged (She laughs.) If you play tennis like that, I'll keep the score.
17 0 20 Mentor, I've found a wonderful club. A club my protege? What kind of club? JenniferStatusIs("Owner")
18 0 20 My girl, I've found a wonderful club. A club Mentor? What kind of club? JenniferStatusIs("Owned")
19 0 I need to go. (Leave her.) DialogLeave()
20 10 An easy game ok? (Play tennis.) StartGame("Easy") GameStart("Easy")
21 10 A game for honor? (Play tennis.) StartGame("Normal") GameStart("Normal")
22 10 You'll bite the dust. (Play tennis.) StartGame("Hard") GameStart("Hard")
23 10 0 Maybe we can play later. Of course. You can come back whenever you want.
24 20 21 It's called the Bondage Club. (She giggles.) I've heard of it. It's an adult club downtown?
25 20 21 Its a BDSM club. Oh yes, I've heard of the adult club downtown.
50 1000 How do tennis points work? The first point is 15, second is 30 and third is 40. You win if you score after 40. There's a tie breaker if we are both at 40.
51 1000 1010 We could play a tennis game. Absolutely, have you played before? I can go easy on you if you're a beginner.
52 1000 I need to go. (Leave her.) DialogLeave()
53 1010 Please go easy. (Play tennis.) StartGame("Easy") GameStart("Easy")
54 1010 Let's do a regular game. (Play tennis.) StartGame("Normal") GameStart("Normal")
55 1010 1011 We can bet some money on the game. Are you willing to bet 25$ on the game? The winner keeps everything. DialogMoneyGreater(25)
56 1010 We can bet some money on the game. You're too poor for that. Get 25$ and we can bet it on a tennis match. !DialogMoneyGreater(25)
57 1010 1000 Maybe we can play later. Sure, let me know when you're ready.
58 1011 Here's 25$, you're going down. (Play tennis.) StartGame("Hard") GameStart("Hard")
59 1011 1000 Forget it. Chicken!
60 1100 1010 Another match? Sure! Perfect, this time I will crush you.
61 1100 1000 No, that's enough. Alright, you can come back to play anytime.