Two player pong processing code

We are about to switch to a new forum software. Until then we have removed the registration on this forum. Hello everyone, i am currently developing a two-player pong game for android. In order to enable multitouch, i used the code i found online:. Basically, everything is working fine, and the 2 "pongs" or paddles move fine when they are 2 fingers holding down at both ends of the screen.

However, the problem arises when one person decides to let go of the screen at the second person puts 2 fingers on their side of the screen, which results in the second person getting 2 paddles and the 1st person not able to get any. Is it possible for me to have a maximum of 1 paddle 1 touch in each side of the screen so there will still be two touches in totaland if so, how?

I'm assuming this is set up like a classic Pong screen, divided into two halves, with one paddle in each half? You could check the touch positions in surfaceTouchEventand only allow one paddle per half-screen. If there are two touchpoints in the same half-screen, ignore one of them. As im pretty unfamiliar with this, how do i check if there are two touch points in either half of the screen, and how do i enable the code to "ignore" one of them?

Also, i tried doing this to differentiate between touchpoints that are in the top half and touchpoints that are in the bottom half. Actually, your code should end up with at most one point each in tempPoint or tempPointB. If there are 2 points in say tempPoint, the second one will write over the first one. And if points. When there are 2 points in one side, while the first one does overwrite the second one, it still ends up with two paddles in one side.

To top it off, the player in the other side of the screen is then not able to get a paddle even when he touches the screen. Despite all this, i still end up getting 2 rectangles with 2 fingers on the same side of the screen. If you just leave pointerCount to however many touch points there are, you should be ok.

Infact, even though the x-coordinate of the rectangle is set as an integer variable "pongCenter", 2 rectangles are still drawn. This seems to suggest that the variable has 2 different values at the same time, which i know is not possible.

Upon doing some research, i have found that multitouch can be handled by getPointerIndex and some other methods within the surfaceTouch, however, i dont know how to use it. Do you have any idea about it? Howdy, Stranger! Sign In. Categories Recent Discussions Unanswered. Categories All Categories In this Discussion billhsu March knowyourenemy March March in Questions about Code. Thanks in advance.

Tagged: android pong mousefunction multi-touch multiplayer. March March edited March Thank you for your reply. Thanks once again. Is there a situation that I'm not thinking about? Thanks once again for the reply. What has gone wrong in my code? Once again, thank you for your help.Thank you. I am reading Learning Processing and have just started doing little programs. I have this, it's more complex and 2 player. It has some bugs and still need to do the scoreboard. If want to try use:.

Skip to content. Instantly share code, notes, and snippets. Code Revisions 3 Stars 8 Forks 2. Embed What would you like to do? Embed Embed this gist in your website. Share Copy sharable link for this gist. Learn more about clone URLs. Download ZIP. Simple Pong Game in Processing. This comment has been minimized. Sign in to view. Copy link Quote reply. Thks you vry much All the best. If want to try use: 'w' and 's' for left.

The comments are in spanish. You have 2 options: limit the speed or make a system within the bar hitbox is bigger so the ball can't go through the bar. Hope it helps. El lun. Any ideas on how to fix? Sign up for free to join this conversation on GitHub. Already have an account?

two player pong processing code

Sign in to comment. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window.This sketch is created with an older version of Processing, and doesn't work on browsers anymore.

View Source Code. Drop files here or select. Also, many other sublime shortcuts are supported. Every time sketch is saved, a version history is created. You can view and restore below. Save as Fork Save Submit. Sketches Start coding in seconds, experiment, and create. Explore Sketches Create a Sketch. Classes Teach coding, collaborate, and showcase class work.

Explore Classes Create a Class. Archived Sketch This sketch is created with an older version of Processing, and doesn't work on browsers anymore. How to interact with it e. Tags e. Who can see your sketch? Who can see the code? Who can comment? Delete Sketch? Learn more.

Showcase Sketch. Infinite Loop Protection. Save or fork the sketch to upload files.In this tutorial we are going to build an arduino-based controller that we can use to control a 2 player game of pong. Did you use this instructable in your classroom? Add a Teacher Note to share how you incorporated it into your lesson. Our two potentiometers are both going to need power, so our first job is to connect the 5v and GND pins on the Arduino to the breadboard power lines.

Use a red wire to connect the 5v pin on the Arduino to the positive power line on the breadboard - this is the vertical column of holes marked with a red line next to them.

Then use a black wire to connect the GND pin on the Arduino to the ground line on the breadboard - this is the vertical column of holes marked with a black or sometimes blue line next to them. The next step is to wire up your first dial potentiometer - connect the left pin to the positive power line and the right pin to the ground line as shown in the image above.

Now we must connect the outputs of the potentiometers the middle pins to the input pins of the Arduino. Using white wires so as not to get confused with the black and red ones we have used already connect the middle pin of one potentiometer to pin A1 on the Arduino, then the middle pin of the other potentiometer to Arduino pin A0. See the photos above to see how this should look. The next step is to write some code to read the current value of the two potentiometers and pass it on via the USB cable to your computer.

Download TennisController. Note: In order to connect to the pong game in the next step of this tutorial, you are going to need to know which serial port your Arduino is attached to. Make a note of the port name at the bottom right of the Arduino window see the red box in the above screenshot. Once your have uploaded your code, it's a good idea to check that everything is working correctly.

Click on the magnifying glass button at the top righthand side of the Arduino window. This will open up the "Serial Monitor" window, which should show all of the data being sent by the Arduino. If everything is working properly, you should see a stream of pairs of numbers, which should change if you turn the potentiometer dials. To run the game, you are going to need to install the Processing programming tool.

Before you can run the game, you need to tell the programme which serial port your Arduino is attached to. Simply open up the data folder in the TennisGame project and replace the background, the ball and the bat images check out the space themed game in the image above.I am using the paddles instead of the joy stick and I have made it for 2 players.

Also I added some sound. I put the electronics in an Iphone box. Did you use this instructable in your classroom? Add a Teacher Note to share how you incorporated it into your lesson. The picture shows another but I am sure others would work fine. Atari paddles - I had from an old system being stored in the basement. I see them on eBay. I started with a small piece of wood which I cut to fit inside the box. The idea was I would secure everything to this piece and then secure the box to the wood.

I glued another small piece of wood to the larger to be used as a place to secure the Arduino.

Subscribe to RSS

Following the instructions from Kyle's Instructable, I soldier a 1k ohm and a ohm resistor to the center pin of the video out RCA jack. I also connected the 75 ohm that is shown in the diagram. It made the picture a little less bright but much clearer and it stopped a lot of the flickering. The RCA plug for the sound is straight forward: The center plug goes to Arduino pin 11 and the ground side goes to ground. The bottom part of the diagram is different than what I did.

The code I used is in the text file below. Early testing was done on the Mickey Mouse TV. But it works ok on large TV as shown in step 1. After some testing, I placed everything into the Iphone box and secured it.

Getting Started With Arduino - Two Player Arduino Pong

Hey awesome work Thank you so much! I love the pong game. I have an arduino nano and a arduino uno. I am going to upload the program to both and combine both wiring onto the breadboard so that the tv screen will have better contrast!

Keep up the Good work! Have a good day.

two player pong processing code

I love this project.This is the second part of the ultimate guide to the Processing language. In the first partI gave a basic Processing language walkthrough. The next step for you to learn Processing is simply more hands-on programming. In this article, I will show you how to use Processing to implement your own game, step by step.

Each step will be explained in detail. Then, we will port the game to the web. Before we begin the Processing tutorial, here is the code of the DVD logo exercise from the previous part. If you have any questions, be sure to leave a comment. The reason I picked a game like this is that it has most of the concepts that beginners struggle with when learning game development. This is based on my experience from when I was a teaching assistant, helping new programmers learn how to use Processing.

Flappy Pong has all of them in it. Play Game Now! Without using object-oriented programming OOP concepts, it is not easy to build complex games, such as platform games with multiple levels, players, entities etc.

I did my best to keep this Processing tutorial organised and simple. I advise you to follow the article, grab the full code, play with it on your own, start thinking about your own game as quickly as possible, and start implementing it.

The first step is to initialize our project. For starters, we will write our setup and draw blocks as usual, nothing fancy or new. Then, we will handle different screens initial screen, game screen, game over screen etc. So the question arises, how do we make Processing show the correct page at the correct time? Accomplishing this task is fairly simple. We will have a global variable that stores the information of the currently active screen.

We then draw the contents of the correct screen depending on the variable. In the draw block, we will have an if statement that checks the variable and displays the contents of the screen accordingly. Whenever we want to change the screen, we will change that variable to the identifier of screen we want it to display. With that said, here is what our skeleton code looks like:.

two player pong processing code

This may look scary at first, but all we did is build the basic structure and separate different parts with comment blocks. As you can see, we define a different method for each screen to display. In our draw block, we simply check the value of our gameScreen variable, and call the corresponding method. The first line of this method changes gameScreen variable to 1, the game screen.This sketch is created with an older version of Processing, and doesn't work on browsers anymore. View Source Code.

Drop files here or select. Also, many other sublime shortcuts are supported. Every time sketch is saved, a version history is created. You can view and restore below. Save as Fork Save Submit. Sketches Start coding in seconds, experiment, and create. Explore Sketches Create a Sketch. Classes Teach coding, collaborate, and showcase class work. Explore Classes Create a Class. Archived Sketch This sketch is created with an older version of Processing, and doesn't work on browsers anymore.

Two Player Pong. Top player: Press "a" to move the paddle to the left Press "d" to move the paddle to the right Bottom player: Press the left arrow key to move the paddle to the left Press the right arrow key to move the paddle to the right.

Pong, two players

How to interact with it e. Tags e. Who can see your sketch? Who can see the code? Who can comment? Delete Sketch? Learn more. Showcase Sketch. Infinite Loop Protection. Save or fork the sketch to upload files. Get More Space.


comments

Leave a Reply

Your email address will not be published. Required fields are marked *