Pong Minigame

0 Members and 1 Guest are viewing this topic.

*
*crack*
Rep:
Level 63
2012 Best Newbie2012 Most Unsung MemberFor frequently finding and reporting spam and spam bots
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

  • <Version 1.1> Input a menu and Score. Check ;8
  • <Version 1.2> Whatever else needs to be fixed at this point.

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

  • Minigame to add for your actual game, can be used for multiple things. A game master challenge using this script along with others comes to mind.
  • Can set your own sprites and music to be used for the minigame, you also chose the sprite dimensions, which means that you can play against a brick wall if you so desire.
  • A command list that can be accessed in the minigame at any time, allowing you to make changes if you're losing to gain that edge you need to win (or to make the game harder if you swing that way).
  • Allows you to set a variable count which you can use in other events to give items or ridicule to the player depending on how they're fairing in the minigame.

Screenshots
Spoiler for:



Instructions

Instructions are inside the script, but for immediate need to know:
  • Paste the script under Materials but above Main in your script editor
  • Either copy the sprites in the attachments or create your own and place them in the pictures folder where your game is located on your computer.
  • You can change the names of the sprite images in the editable region.
  • You can use In Game Variable to manage the wins and losses count conditions the same way you would use a variable in an event.
  • Call the game by using a script command with this line of code.
    $scene = Pong_Scene.new

Script


Get it from here

Credit


  • DP3 / DiamondandPlatinum3

Thanks

  • mcf_10 - for requesting the script
  • Zylos - Because I used his Mastermind Script as a template for my own.
  • Modern Algebra - for helping me with sprite dimensions
Spoiler for Before:


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

Terms of Use


You may find my Terms of Use Here.
« Last Edit: June 27, 2014, 08:50:38 AM by D&P3 »

***
Rep:
Level 56
Miiiiaf =^+^=
GIAW 14: ParticipantParticipant - GIAW 11
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?



As blonde as can be!!!
Doesn't mean I'm the dumb one...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Spoiler for supporting!:


*
*crack*
Rep:
Level 63
2012 Best Newbie2012 Most Unsung MemberFor frequently finding and reporting spam and spam bots
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.

***
Rep:
Level 56
Miiiiaf =^+^=
GIAW 14: ParticipantParticipant - GIAW 11
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 :)
« Last Edit: June 25, 2012, 12:00:45 PM by Amycha19 »


As blonde as can be!!!
Doesn't mean I'm the dumb one...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Spoiler for supporting!:


*
*crack*
Rep:
Level 63
2012 Best Newbie2012 Most Unsung MemberFor frequently finding and reporting spam and spam bots
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.

***
Rep:
Level 56
Miiiiaf =^+^=
GIAW 14: ParticipantParticipant - GIAW 11
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}??


As blonde as can be!!!
Doesn't mean I'm the dumb one...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Spoiler for supporting!:


****
Rep:
Level 71
The Doctors in!
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?
« Last Edit: June 27, 2012, 03:37:35 AM by DoctorTodd »

*
*crack*
Rep:
Level 63
2012 Best Newbie2012 Most Unsung MemberFor frequently finding and reporting spam and spam bots
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 :)

****
Rep:
Level 71
The Doctors in!
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?  :)

*
*crack*
Rep:
Level 63
2012 Best Newbie2012 Most Unsung MemberFor frequently finding and reporting spam and spam bots
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 :-[

***
Rep:
Level 56
Miiiiaf =^+^=
GIAW 14: ParticipantParticipant - GIAW 11
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?


As blonde as can be!!!
Doesn't mean I'm the dumb one...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Spoiler for supporting!:


*
*crack*
Rep:
Level 63
2012 Best Newbie2012 Most Unsung MemberFor frequently finding and reporting spam and spam bots
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.

***
Rep:
Level 56
Miiiiaf =^+^=
GIAW 14: ParticipantParticipant - GIAW 11
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!! :)


As blonde as can be!!!
Doesn't mean I'm the dumb one...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Spoiler for supporting!:


*
*crack*
Rep:
Level 63
2012 Best Newbie2012 Most Unsung MemberFor frequently finding and reporting spam and spam bots
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 ::)

***
Rep:
Level 56
Miiiiaf =^+^=
GIAW 14: ParticipantParticipant - GIAW 11
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 ;)
« Last Edit: June 29, 2012, 12:05:05 PM by Amycha19 »


As blonde as can be!!!
Doesn't mean I'm the dumb one...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Spoiler for supporting!:


*
*crack*
Rep:
Level 63
2012 Best Newbie2012 Most Unsung MemberFor frequently finding and reporting spam and spam bots
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

***
Rep:
Level 56
Miiiiaf =^+^=
GIAW 14: ParticipantParticipant - GIAW 11
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...
« Last Edit: July 01, 2012, 06:59:31 PM by Amycha19 »


As blonde as can be!!!
Doesn't mean I'm the dumb one...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Spoiler for supporting!:


*
*crack*
Rep:
Level 63
2012 Best Newbie2012 Most Unsung MemberFor frequently finding and reporting spam and spam bots
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"
« Last Edit: July 01, 2012, 07:24:02 PM by D&P3 »

***
Rep:
Level 56
Miiiiaf =^+^=
GIAW 14: ParticipantParticipant - GIAW 11
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.


As blonde as can be!!!
Doesn't mean I'm the dumb one...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Spoiler for supporting!:


*
*crack*
Rep:
Level 63
2012 Best Newbie2012 Most Unsung MemberFor frequently finding and reporting spam and spam bots
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 :)

***
Rep:
Level 56
Miiiiaf =^+^=
GIAW 14: ParticipantParticipant - GIAW 11
YAAAAAAY and I found out, right after you added the new script  ;8

Anyway, thanks for the adding of enabling and disabling.


As blonde as can be!!!
Doesn't mean I'm the dumb one...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Spoiler for supporting!:


***
Rep:
Level 56
Miiiiaf =^+^=
GIAW 14: ParticipantParticipant - GIAW 11
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?


As blonde as can be!!!
Doesn't mean I'm the dumb one...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Spoiler for supporting!:


*
*crack*
Rep:
Level 63
2012 Best Newbie2012 Most Unsung MemberFor frequently finding and reporting spam and spam bots
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.

***
Rep:
Level 56
Miiiiaf =^+^=
GIAW 14: ParticipantParticipant - GIAW 11
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?


As blonde as can be!!!
Doesn't mean I'm the dumb one...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Spoiler for supporting!:


*
*crack*
Rep:
Level 63
2012 Best Newbie2012 Most Unsung MemberFor frequently finding and reporting spam and spam bots
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.