The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: D&P3 on May 27, 2012, 06:16:28 PM

Title: Pong Minigame
Post by: D&P3 on May 27, 2012, 06:16:28 PM
My first game that I ever made in C++ was Pong, so it seems only fitting that my first ever Ruby script be Pong as well :)

Pong Game
Version: 1.1
Author: DiamondandPlatinum3
Date: July 1, 2012



Planned Future Versions


Description


This script allows you to play an old retro game called pong in your game.
It would generally be used as a mini game of some sorts, or just a plain old easter egg.

Pong is a game featuring two players and a ball, the ball moves back and forth from one player to the other and the objective is to never miss the ball.
If you miss the ball, your opponent will score a point and the same goes for you, should the opponent miss the ball.
The first person to score 6 points will win the match.

Features


Screenshots
Spoiler for:
(http://img4host.net/upload/302322464fef6e269dfc0.png)

(http://img4host.net/upload/302326434fef6f1358afa.png)
Instructions

Instructions are inside the script, but for immediate need to know:

Script


Get it from here (http://www.diamondandplatinum3.net/rpg-maker-scripts/rpg-maker-vx/pong-minigame/)

Credit



Thanks

Spoiler for Before:
(http://img4host.net/upload/271705284fc242b813b5f.JPG)


Support


Post in this thread or PM me.

Known Compatibility Issues

There should be no compatibility issues. :)

Demo


A demo is unnecessary for a script such as this.

Author's Notes


This script is pretty much a port of my C++ Pong Game code (albeit with much more stuff and better code), if you are interested in seeing what it looks like, it can be found here (http://pastebin.com/ba1SYBSi)

Terms of Use


You may find my Terms of Use Here (http://www.diamondandplatinum3.net/rpg-maker-scripts/terms-of-use/).
Title: Re: Pong Minigame
Post by: Little Psycho on June 24, 2012, 06:35:09 PM
I get an error about Data/System.rvdata2 it says is can't find such an object in that map...
Shouldn't that be Data/System.rvdata?

Title: Re: Pong Minigame
Post by: D&P3 on June 25, 2012, 10:19:14 AM
Unless you're using VXA, you shouldn't be getting any error about rvdata2 :-\

But the bug report about the map not containing a certain object isn't very helpful, that could be a number of things.

Could you recreate the error in a new project and upload it please :)



I also updated the script to give two new options in the editable region.
Title: Re: Pong Minigame
Post by: Little Psycho on June 25, 2012, 11:50:17 AM
Unless you're using VXA, you shouldn't be getting any error about rvdata2 :-\

But the bug report about the map not containing a certain object isn't very helpful, that could be a number of things.

Could you recreate the error in a new project and upload it please :)



I also updated the script to give two new options in the editable region.
Solved it already... Tried it in a new project and it appeared to be an error in a different script, so don't worry!

You might also want to add something else to the editable region. Perhaps BGMvolume and BGMpitch so that people can change that too if they like?

Also, I'd love to see a popup window saying what the score is if a point is made :)
Title: Re: Pong Minigame
Post by: D&P3 on June 26, 2012, 02:57:52 PM
After going back into my script, I noticed that I named a class 'Instruction_Window' ...
No doubt, there are bound to be other scripts that will have an instruction window to tell people what to do, so I renamed mine.
That should hopefully resolve any conflicts that may have created.

Added the BGM Volume and BGM Pitch to the editable region :)
Plus some extra.

I also added windows telling you what the scores are for each side, although it is unfortunate that I'm not really sure how to make it pop-up, since I feel like that would have been a very nice addition to the game.
But I'll come back to that in the future.
Title: Re: Pong Minigame
Post by: Little Psycho on June 26, 2012, 05:39:19 PM
I'll check it out... But what I'd love to see is a way to make a switch in game turn on if you get a specified number of wins otherwise it's off and also being able to set a specified number of wins for either party so that the game ends. Just so that I can make a competition of some sort :)

Perhaps with something like \setwins{x} and \winswitch{x}??
Title: Re: Pong Minigame
Post by: DoctorTodd on June 27, 2012, 03:34:25 AM
This is pretty cool, I like it how you used Pong_Scene rather than Scene_Pong.  :)
Also wouldn't it be a good idea to put an option for your screen dimensions in the module?
Title: Re: Pong Minigame
Post by: D&P3 on June 28, 2012, 12:14:34 PM
I'll check it out... But what I'd love to see is a way to make a switch in game turn on if you get a specified number of wins otherwise it's off and also being able to set a specified number of wins for either party so that the game ends. Just so that I can make a competition of some sort :)

Perhaps with something like \setwins{x} and \winswitch{x}??
Definitely do-able, I'll put it in when I get the chance.


This is pretty cool, I like it how you used Pong_Scene rather than Scene_Pong.  :)
Also wouldn't it be a good idea to put an option for your screen dimensions in the module?
Thanks Todd :)
It wouldn't be a bad thing to put those options in the editable region, I'd just have to include some error guards to stop people from putting in bad numbers (Actually, I should probably do that for everything :| )


By the way Todd, you might have seen that I used (Pong_Options::Right_Paddle_Height * 0.5)  and wondered why.
In case you didn't already know, computers are more efficient at multiplying than they are at dividing (but you don't really notice because they do everything so fast), so multiplying it by 0.5 was pretty much the same as telling it to divide by 2.

Just something I thought I'd let you know so that when you start scripting a lot of code, you know of a way to make it more efficient :)
Title: Re: Pong Minigame
Post by: DoctorTodd on June 28, 2012, 04:28:47 PM
Thanks (I actually had no idea), I typically multiply unless I'm using Graphic.width (or height), then I'll do Graphics.width / 2. Would it be better to just multiply by 0.5?  :)
Title: Re: Pong Minigame
Post by: D&P3 on June 28, 2012, 04:45:11 PM
Yeah :) it's better to multiply by 0.5 if you're dividing by 2
or to multiply by 0.2 if you're dividing by 5.

You don't have to go overboard with it; It doesn't improve performance that much and I don't know what I would multiply to get the division of 522, so I would just divide that.


The thing is, it's also something you should comment.
Cause not everyone does it, so you'll have people wondering why you did that.
I was gonna do that for Pong, but I haven't gotten around to commenting it yet :-[
Title: Re: Pong Minigame
Post by: Little Psycho on June 28, 2012, 05:00:23 PM
You don't have to go overboard with it; It doesn't improve performance that much and I don't know what I would multiply to get the division of 522, so I would just divide that.
You would be multiplying by 0.0019157 if you were to divide by 522 :P

But there's this question I have about the script.
Would it also be possible to create a score board for it (with turning on or off if user wants to)?
And perhaps also a possibility to change pictures ingame? Like perhaps, on pressing X you'll let a window popup asking what you want to do: "Exit - Options - Scoreboard - Help" or something like that???
These are just ideas but it would be great if you could do that in this or perhaps an additional script?
Title: Re: Pong Minigame
Post by: D&P3 on June 29, 2012, 10:25:35 AM
I would question how you figured that out, but I'm not too sure I want to know the answer.

It would be possible to do those things, I'll get around to it soon.
Title: Re: Pong Minigame
Post by: Little Psycho on June 29, 2012, 10:45:45 AM
I would question how you figured that out, but I'm not too sure I want to know the answer.

It would be possible to do those things, I'll get around to it soon.
There's this thing that is a standard program in Windows, it's called a Calculator. I did it just to troll a bit  ::)
Though, I AM using this in my game!! :)
Title: Re: Pong Minigame
Post by: D&P3 on June 29, 2012, 11:09:52 AM
I think you'd find that a calculator comes standard with a lot of operating systems.
And I see that you just divided 1 by 522 :P ::)
Title: Re: Pong Minigame
Post by: Little Psycho on June 29, 2012, 12:02:10 PM
I think you'd find that a calculator comes standard with a lot of operating systems.
And I see that you just divided 1 by 522 :P ::)
Well, yeah...
Dividing tables:
1/2 = 0.5
1/3 = 0.3333333333...
1/4 = 0.25
1/5 = 0.2
1/6 = 0.1666666666...
1/8 = 0.125
1/10 = 0.01
1/100 = 0.001
1/200 = 0.005
1/250 = 0.004
1/500 = 0.002

so 1/522 must be something very close to 0.002 ;)
Title: Re: Pong Minigame
Post by: D&P3 on June 30, 2012, 10:07:42 PM
I honestly didn't think it would take so long... :-[

Buuuut, the minigame now has a menu that includes options. And it also uses in game variables to store the total wins and losses of the player which can be used as if they were a variable in any ordinary event.

Check the instructions and editable region again.


The script has gone from being 413 lines of code to 3147 lines of code :V
I originally planned to comment the entire thing so that even people who have never scripted before could understand everything;
But I'm definitely not motivated to do that to over 3000 lines of code, so this is not gonna happen.
Instead I have just commented on anything that won't be so clear to other scripters.


If there is nothing else that needs to be added... I think this script is finished ;8
Title: Re: Pong Minigame
Post by: Little Psycho on July 01, 2012, 06:20:36 PM
I've edited it a bit, don't know if it's useful but here it is.

Added:
Code: line 129 [Select]
Points_to_win           = 2                 #  How many points needed to win a game. Standard = 6

Also, if added, all lower lines will move down 2 lines as well.

Edited:
Code: line 212 [Select]
 
    if playerOne_Score == Points_to_win

Just so that people can change how many wins for winning a match :)

That was needed to create my 3 matches. Also you need to win 2 out of 3 matches to get a special item for Kiki. As the little girl in the pub (the bartender's daughter) has a page of the in total 12 pages for the Sacred Chord song for Piano.

Though still testing that to see if I did it right :P
EDIT: Apparently, there's a problem with this somewhere as it doesn't say you won when I got two points...
EDIT2: I think I found the problem and I altered that too. Maybe it works now. Still testing though...
Title: Re: Pong Minigame
Post by: D&P3 on July 01, 2012, 07:18:48 PM
Did it for you, get the latest update from that same pastebin url :P

Also bear in mind that you can edit the stuff in the editable region outside of the script and in the project.


So, should you want to change the amount of points to win at anytime, you would insert a script call saying
Code: [Select]
Pong_Options::Points_To_Win = 2

or to edit music per match

Code: [Select]
Pong_Options::Game_BGM = "Town2"
Title: Re: Pong Minigame
Post by: Little Psycho on July 01, 2012, 08:48:13 PM
Yeah, but, was I on the right path for fixing this thing myself?

Also, could you add a possibility to disable and enable the menu and options access?
I want to make it so that I can change the access for the menu after you won from the girl the first time.
Title: Re: Pong Minigame
Post by: D&P3 on July 01, 2012, 09:50:24 PM
You were on the right track, yes :)

You created a variable in the editable region to modify the score needed to win, good.
When you went down and changed the players score statement.

You said
Code: [Select]
if playerOne_Score == Points_to_win

That should have been
Code: [Select]
if playerOne_Score == Pong_Options::Points_to_win


You were correct in changing this, but even so, it didn't do anything.
This is because you changed a statement in a function that isn't called until it's gameover.
That statement that you changed actually checks if player one's score is equal to the winning conditions; and if it is, then Player One must have won, otherwise player two has won.

The other line that needed to be changed was
Code: Line 2899 [Select]
if @gameover == false && ((@playerOne_Score == 6) || (@playerTwo_Score == 6))


That was all ;)
So yes, you were on the right path :D



Updated script to suit your request :)
Title: Re: Pong Minigame
Post by: Little Psycho on July 02, 2012, 04:46:46 AM
YAAAAAAY and I found out, right after you added the new script  ;8

Anyway, thanks for the adding of enabling and disabling.
Title: Re: Pong Minigame
Post by: Little Psycho on July 10, 2012, 05:17:25 PM
I still have this problem, my game freezes after I've scored a match point. Also, I deleted the scene_map.new bit if a player presses ESC so they have to win or lose 3 matches...
But it freezes  :o

What's the sollution?
Title: Re: Pong Minigame
Post by: D&P3 on July 10, 2012, 06:09:42 PM
After you score a match point, the game is supposed to freeze.
Removing the '$scene = Scene_Map.new' was essentially removing your only way of quitting the game.

The other way was to allow access to the menu and use the reset option or exit option to either restart or quit.



Anyway, I updated the code, you can now press 'Z, Enter, Space' to reset after a player has won.
I also hopefully fixed a little bug I noticed that would cause the right paddle to momentarily disappear when it hit the top right corner. So it's probably a good idea to get the update ;8


For your problem specifically, go to line 3088 and change
Code: [Select]
if Input.trigger?(Input::B)                   
        if Pong_Options::Access_Menu == true
          open_command_window   
        else
          $scene = Scene_Map.new
        end
      end   
to this
Code: [Select]
if Input.trigger?(Input::B)                   
        if Pong_Options::Access_Menu == true
          open_command_window   
        elsif $game_variables[Pong_Options::Win_Count_Variable_ID] == ? || $game_variables[Pong_Options::Loss_Count_Variable_ID] == ?
          $scene = Scene_Map.new
        end
      end
Change the question marks to a number of however many matches you want the player to have won or lost before they can quit.
Title: Re: Pong Minigame
Post by: Little Psycho on July 10, 2012, 06:19:37 PM
So in my case, if I put in this:
Code: [Select]
if Input.trigger?(Input::B)                   
        if Pong_Options::Access_Menu == true
          open_command_window   
        elsif $game_variables[Pong_Options::Win_Count_Variable_ID] == Pong_Options::Matches || $game_variables[Pong_Options::Loss_Count_Variable_ID] == Pong_Options::Matches
          $scene = Scene_Map.new
        end
      end

And adding Matches to the Pong_Options (just so I can change this outside of the code) would also be a good sollution to my problem? Or did I just make a mistake up there?
Title: Re: Pong Minigame
Post by: D&P3 on July 10, 2012, 06:52:21 PM
If you actually create a variable called 'Matches' in the module (editable region) and set it to equal an integer number (a whole number like 1, 2, 6, 132; decimal point numbers like 2.0, 3.14, 82.5256 are called floats instead of an integers) then yes, that will work just fine.
Title: Re: Pong Minigame
Post by: DoctorTodd on July 10, 2012, 07:03:04 PM
Couldn't you change this line
Code: [Select]
if Input.trigger?(Input::B)                   
        if Pong_Options::Access_Menu == true
to this?
Code: [Select]
if Input.trigger?(Input::B) && Pong_Options::Access_Menu == true
I'm pretty sure you can do something like that in RGSS 3. There's nothing wrong with the way you wrote it but it just seems cleaner.  :)
Title: Re: Pong Minigame
Post by: Little Psycho on July 10, 2012, 07:49:57 PM
If you actually create a variable called 'Matches' in the module (editable region) and set it to equal an integer number (a whole number like 1, 2, 6, 132; decimal point numbers like 2.0, 3.14, 82.5256 are called floats instead of an integers) then yes, that will work just fine.

YAAAAAAAAY, thank you D&P3!!! You are helping me to learn RGSS on my own!!!!!!!!!!!

If I knew how to + you, I would!
Title: Re: Pong Minigame
Post by: D&P3 on July 10, 2012, 07:53:57 PM
Couldn't you change this line
Code: [Select]
if Input.trigger?(Input::B)                   
        if Pong_Options::Access_Menu == true
to this?
Code: [Select]
if Input.trigger?(Input::B) && Pong_Options::Access_Menu == true
I'm pretty sure you can do something like that in RGSS 3. There's nothing wrong with the way you wrote it but it just seems cleaner.  :)
Yes but then I would of had to have done

Code: [Select]
if Input.trigger?(Input::B) && Pong_Options::Access_Menu == true
#do stuff
elsif Input.trigger?(Input::B) && Pong_Options::Access_Menu == false
#do stuff
end

Which means that I am checking four things.
Whereas
Code: [Select]
if Input.trigger?(Input::B)                   
        if Pong_Options::Access_Menu == true
          open_command_window   
        else
          $scene = Scene_Map.new
        end
      end
Means that I'm only checking one thing and not checking anything else unless that one thing is true.

YAAAAAAAAY, thank you D&P3!!! You are helping me to learn RGSS on my own!!!!!!!!!!!

If I knew how to + you, I would!
You're most welcome :)
Title: Re: Pong Minigame
Post by: amerk on December 26, 2012, 05:18:49 PM
A bit out of date, but hell why not? Awesome job with this so far, D&P3. I'm just trying to figure something out.

In my game, this should be a one-time occurrence. Basically one of the villains will challenge you to a game of pong; and if you win you move on, but if you lose it's game over.

So basically I have my event take place, a game of pong commences, and then the outcome of that game will determine what happens next. I've disabled access to the menu, set my BGM, images sizes, points to win, and what not. Everything works smoothly until the final point is scored. Then it just sits there waiting for the player to either hit the "escape" key to leave or the "enter" key to play again.

Is there a way to automatically dispose of this window and return to my event once the game has been won or lost?

Thanks again!
Title: Re: Pong Minigame
Post by: D&P3 on December 27, 2012, 04:22:44 AM
I believe if you replace this:

Code: line 2919 [Select]

 if @gameover == true
        if Input.trigger?(Input::C)
          process_pong_reset
        end
      end


with this:
Code: [Select]
if @gameover == true
       $scene = Scene_Map.new
      end

it should work.

This code is very old though, so I don't remember if I had provided a way to test who won a match.
Title: Re: Pong Minigame
Post by: amerk on December 27, 2012, 04:34:40 AM
No problems, I'll give it a whirl and see if it works. Thanks for your help!
Title: Re: Pong Minigame
Post by: EvilM00s on March 06, 2014, 05:52:59 PM
Nice stuff here, D&P3. It's in the new game.