pong

Colision detection p5.js

若如初见. 提交于 2020-01-11 11:55:10
问题 just trying to make a simple pong game in p5.js. I have very recently gotten into JavaScript and can't manage to figure out collision detection between the ball and the bat. I have tried a few ways of doing it but it mostly just stopped my code from running.. etc.. would love any help! Here is my source code: function setup() { createCanvas(750, 750); } var x = 50; var y = 50; var direction = 5; var arrow = 0; var ball; var bat; function draw() { background(220); fill ('white'); ball =

Java Pong ball glides on paddle

无人久伴 提交于 2020-01-06 08:15:42
问题 im making a pong game in java, i've run into a problem. The bug is that when the pong ball intersects with either the AI or player paddles, the ball will sometimes collide multiple times. It basically looks like like the ball is gliding on the paddle. Sometimes, the ball will even get stuck behind the paddle infinitely. Had anyone ever encountered this error or something similar? I am confused with this multiple collision stuff :( my ball class is below: package ponggame; import java.awt.*;

keeping a variable inside a range in python

时光总嘲笑我的痴心妄想 提交于 2020-01-06 06:58:27
问题 i am trying to write a code for the game pong but i am facing a problem when trying to control the range of the paddles positions , the question is that : is there a way in python to keep a variable inside a certain range (with a maximum value and minimum value )that when the variable changes (to be increasing ) it will stuck on the maximum value of that range , and when this variable decreases it will stuck on the minimum value ? . i had written this code : Range = range(HALF_PAD_HEIGHT,

Java pong can't move both paddles at once

余生长醉 提交于 2020-01-04 08:06:17
问题 Trying to make pong in java but can't move both paddles at once. You can move one or the other but not both at the same time. Do I need to create 2 threads with 2 different pannels? Here is where I am specifying the key events public void keyPressed(KeyEvent e) { if(e.getKeyCode() == KeyEvent.VK_A || e.getKeyCode() == KeyEvent.VK_S || e.getKeyCode() == KeyEvent.VK_QUOTE || e.getKeyCode() == KeyEvent.VK_SEMICOLON){ if(e.getKeyCode() == KeyEvent.VK_A){ y-=10; } if(e.getKeyCode() == KeyEvent.VK

PyGame Collision detection for pong and keeping the paddles on screen

我怕爱的太早我们不能终老 提交于 2019-12-25 02:57:07
问题 So my problem here is that I don't want to use classes because I don't fully understand them yet nor do I want to use sprites. I have uploaded two images to the program I am able to move the paddles and get the ball to move and bounce off the top and bottom. However I cannot get the ball to bounce off the paddles. Also I cannot keep the paddles from going down off the screen or above off the screen. Any help would be appreciated thank you. import sys import pygame pygame.init() size = width,

Unity - how to use Vector2.Reflect()

耗尽温柔 提交于 2019-12-20 04:38:16
问题 I have looked everywhere including the Unity documentation but cannot seem to find any good examples of how to use Unity's Vector2.Reflect() function. I am trying to use this to control the direction of the ball (in a 2D Breakout game) when it hits a wall. It takes 2 arguments (inDirection, inNormal) but I cannot seem to figure out how to use this. Any help would be appreciated. 回答1: Vector2 Reflect(Vector2 inDirection, Vector2 inNormal) : inDirection : black arrow inNormal : red arrow return

Counting Wins in a Ping Pong game

若如初见. 提交于 2019-12-13 04:42:33
问题 Create a method in Scores.java that takes 2 arguments: player1Scores and player2Scores. The method should print out the number of games player1 won and the number of games player2 won. This is the last part to an assignment given by our teacher and I can't figure out where to start. I was thinking a simple compare each win but thats not provided by the Player1Score. It only stores the current score of the game thats going on. I need to be able to calculate all the games that have happened.

Unable to fix broken ball movement in pygame pong

ε祈祈猫儿з 提交于 2019-12-13 04:14:10
问题 I'm fairly new to programming, game programming especially. I'm trying to make pong using pygame, but have run into a slight issue. Essentially, the ball hits a paddle, stops, and then keeps going once the paddle is out of the way. Obviously I want the ball to bounce back, but I can't figure out why it won't, when I've coded (what I thought was) the appropriate logic for ball-paddle collisions. Here's my code: # importing stuff import sys, pygame from pygame.locals import * # starting pygame

Need better way of making the ball angle in pong game

ぐ巨炮叔叔 提交于 2019-12-12 02:43:35
问题 I'm making a pong clone to practice my coding, and I've become stuck on making the ball be able to change angle when hit by the paddle. My current implementation has a deltaX and deltaY for the ball, which moves with the game loop to move the ball. The way I have done it is that if you hit the ball while the paddle is moving, the deltaY is increased or decreased depending on the direction of the paddle, but this does not feel natural at all for the game. Does anyone know a better way of doing

User input while program still running

佐手、 提交于 2019-12-10 10:45:02
问题 I'm making a pong game. I got everything working but the user moving the paddle. I am using a while (true) loop in which all the methods are invoked. How can I move the paddle with WASD? I want the program to keep going while waiting for user input. I tried using Console.ReadKey() but it freezes the program 回答1: While I would suggest using a game library (although I can't find any specifically for a terminal there is Curses Sharp which might be useful), this can be done manually .. The core