| Usuario |
Problema con C# |
Desconocido
|
| Enviado - 26/9/2004 |
| ? |
Tengo que hacer que una imagen se mueva con los botones del teclado y que salte moverla es muy facil, pero como hago para que esta imagen salte(el salto debe ser como de mario bross) aqui esta el codigo
using System.Windows.Forms;
using System;
using System.Drawing;
class mainClass
{
public static int x;
public static int y;
public static void Main()
{
Form frm = new Form();
frm.Height = 640;
frm.Width = 480;
frm.Show();
x=100;
y=100;
Image img = Image.FromFile(@"D:\nave.bmp");
frm.BackColor = Color.DeepSkyBlue;
frm.Show();
frm.KeyDown += new KeyEventHandler(tecla);
while(frm.Created)
{
Application.DoEvents();
frm.CreateGraphics().DrawImage(img,x,y);
Graphics gr = frm.CreateGraphics();
gr.DrawImage(img,(int) x,(int) y);
gr.Clear(Color.PaleGreen);
}
}
private static void tecla(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Right)
{
x++;
}
if(e.KeyCode == Keys.Left)
{
x--;
}
if(e.KeyCode == Keys.Space)
{
y++;
}
}
} |
| ? |
|
|
|