Aide pong C#

Fermé
Jimbei - 24 sept. 2012 à 11:19
 Jimbei - 24 sept. 2012 à 17:51
Bonjour,
Je dois réaliser un pong en c# dans le cadre de mon apprentissage, je suis malheureusement bloqué. J'ai utilisé des vecteurs au niveau de positions mais j'ai un problème : la balle rebondis quelques fois et un moment se bloque entre deux côtés et n'arrête pas de rebondir. On m'a conseilé d'utiliser des angles mais je ne vois absolument pas comment on pourrait utiliser et calculer ces angles.
Pouvez-vous m'aiguillez ? Avez-vous des conseils ?
Merci d'avance !
A voir également:

2 réponses

ridhouan Messages postés 43 Date d'inscription dimanche 7 novembre 2010 Statut Membre Dernière intervention 5 avril 2016 1
24 sept. 2012 à 11:45
pour ce qui est des angles, n'oublie pas les fonctions ttrigonometriques, cos(a)=adjacent /hypothénuse, des truc comme ça, si tu pouvais montrer ton code source ce serait bien utile ;)
0
Voici le code en question (je précise au passage, au cas ou, qu'il est fait en forms):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace JeuDePingPong
{
public partial class PingPong : Form
{
public PingPong()
{
InitializeComponent();
}

Random random = new Random();
int hasard()
{
int iMin = -3;

return random.Next(iMin, 3);
}

//Mouvement bar de gauche.
private void PingPong_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Down && player1.Location.Y < 390)
{
player1.Location = new Point(player1.Location.X, player1.Location.Y + 10);
}
if (e.KeyCode == Keys.Up && player1.Location.Y > 0)
{
player1.Location = new Point(player1.Location.X, player1.Location.Y - 10);
}
if (e.KeyCode == Keys.S)
{
DirectionDepart();
}
}

public int iDepartX = 0;
public int iDepartY = 0;

public void DirectionDepart()
{
iDepartX = hasard();

if (iDepartX == 0)
{
iDepartX = iDepartX + 1;
}

iDepartY = hasard();

if (iDepartY == 0)
{
iDepartY = iDepartY + 1;
}

}


//Rebond haut et bas
public void TimerRebondBalle1_Tick(object sender, EventArgs e)
{

if (ball.Location.Y > 0)
{
ball.Location = new Point(ball.Location.X + iDepartX, ball.Location.Y + iDepartY);
}

if (ball.Location.Y <= 0)
{
TimerRebondBalle1.Enabled = false;
TimerRebondBalle2.Enabled = true;
}

if (ball.Location.Y >= 500)
{
TimerRebondBalle1.Enabled = false;
TimerRebondBalle3.Enabled = true;
}

if (ball.Location.X <= 30)
{
TimerRebondBalle1.Enabled = false;
TimerRebondBalle4.Enabled = true;
}

if (ball.Location.X >= 714)
{
TimerRebondBalle1.Enabled = false;
TimerRebondBalle5.Enabled = true;
}
}

public void TimerRebondBalle2_Tick(object sender, EventArgs e)
{
ball.Location = new Point(ball.Location.X + iDepartX, ball.Location.Y + (iDepartY * -1));

if (ball.Location.Y >= 500 || ball.Location.X <= 30 || ball.Location.X >= 714)
{
TimerRebondBalle2.Enabled = false;
TimerRebondBalle1.Enabled = true;
}
}

private void TimerRebondBalle3_Tick(object sender, EventArgs e)
{
ball.Location = new Point(ball.Location.X + iDepartX, ball.Location.Y + (iDepartY * -1));
actif";

if (ball.Location.Y <= 0 || ball.Location.X <= 30 || ball.Location.X >= 714)
{
TimerRebondBalle3.Enabled = false;
TimerRebondBalle1.Enabled = true;
}
}

private void TimerRebondBalle4_Tick(object sender, EventArgs e)
{
ball.Location = new Point(ball.Location.X + (iDepartX * -1), ball.Location.Y + iDepartY);

if (ball.Location.X >= 714 || ball.Location.Y <= 0 || ball.Location.Y >= 500)
{
TimerRebondBalle4.Enabled = false;
TimerRebondBalle1.Enabled = true;
}
}

private void TimerRebondBalle5_Tick(object sender, EventArgs e)
{
ball.Location = new Point(ball.Location.X + (iDepartX * -1), ball.Location.Y + iDepartY);

if (ball.Location.X <= 30 || ball.Location.Y <= 0 || ball.Location.Y >= 500)
{
TimerRebondBalle5.Enabled = false;
TimerRebondBalle1.Enabled = true;
}
}
}
}
0