//Tutorial de SDL.NET
//Archivo: cap3.cs
//Autor: Dark-N (naldo_go@hotmail.com)
//Fecha: 22-11-2006
//Capitulo 3: Mouse y Sonido
using System;
using System.Drawing;
using SdlDotNet;
using SdlDotNet.Sprites;
using System.Threading;
namespace tutorial
{
public class cap3
{
//variables que almacenan resolución de pantalla
int resx=400;
int resy=300;
Surface sur_bola;
Sprite spr_bola;
TextSprite texto;
Sound sonido;
Music musica;
public cap3()
{
Video.SetVideoModeWindow(resx, resy);
Video.WindowCaption = "Tutorial SDL: Capitulo 3";
Video.WindowIcon(new System.Drawing.Icon("../../Imagenes/mario3.ico"));
sur_bola = new Surface(@"..\..\Imagenes\bola.bmp");
spr_bola = new Sprite(sur_bola);
musica = new Music(@"..\..\Sonidos\m64bomb.mid");
sonido = new Sound(@"..\..\Sonidos\clic.WAV");
//creamos un texto informativo
SdlDotNet.Font fuente = new SdlDotNet.Font("../../fuentes/ARIAL.TTF", 14);
texto = new TextSprite("Haz clic en le Pantalla y escucha la música.", fuente, Color.Yellow, new Point(5,5));
texto.Render(Video.Screen);
texto = new TextSprite("Presiona Espacio para reproducir un sonido.", fuente, Color.Yellow, new Point(5,20));
texto.Render(Video.Screen);
//texto ESC: salir
texto = new TextSprite("ESC: salir", new SdlDotNet.Font("../../fuentes/ARIAL.TTF", 11), Color.White, new Point(resx-58,resy-15));
texto.Render(Video.Screen);
//el color negro será transparente
sur_bola.TransparentColor = Color.Black;
//tocamos musica de fondo, repeat:on
musica.Play(true);
Events.Tick += new TickEventHandler(Events_Tick);
}
private void Events_Tick(object sender, TickEventArgs e)
{
juego();
Video.Screen.Update();
}
// lógica de nuestro juego
private void juego()
{
if (Mouse.IsButtonPressed(MouseButton.PrimaryButton))
{
spr_bola.X = Mouse.MousePosition.X;
spr_bola.Y = Mouse.MousePosition.Y;
spr_bola.Render(Video.Screen);
}
}
public void Run()
{
Events.KeyboardDown +=new KeyboardEventHandler(this.Keyboard);
Events.Quit += new QuitEventHandler(Events_Salir);
Events.Run();
}
private void Events_Salir(object sender, SdlDotNet.QuitEventArgs e)
{
musica.Close();
sonido.Stop();
Events.QuitApplication();
}
private void Keyboard(object sender, KeyboardEventArgs e)
{
//Salimos del juego con tecla Escape
if(e.Key == Key.Escape)
{
musica.Close();
sonido.Stop();
Events.QuitApplication();
}
//Espacio para escuchar sonido
if(e.Key == Key.Space)
{
sonido.Play();
}
}
[STAThread]
public static void Main()
{
cap3 juego = new cap3();
juego.Run();
}
}
}
|