Cita de: [EX3] en 02 de Mayo de 2009, 05:01:41 AM
Que lenguaje y que librerias estas usando?
Salu2...
A perdón jaja, es C#, lo estoy haciendo en XNA. :-X
Esta sección te permite ver todos los posts escritos por este usuario. Ten en cuenta que sólo puedes ver los posts escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes MenuCita de: [EX3] en 02 de Mayo de 2009, 05:01:41 AM
Que lenguaje y que librerias estas usando?
Salu2...
namespace WindowsGame6
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D fondo;
Texture2D Hongo;
Texture2D pis;
Texture2D mario;
Texture2D luigi;
Texture2D marioj;
Texture2D luigij;
Texture2D reset;
Texture2D playagain;
Texture2D start;
Texture2D instrucciones;
MouseState mouse;
double tiempo;
int gameover;
SpriteFont fuente;
Color color = Color.White;
Color color2 = Color.White;
Rectangle strt = new Rectangle(250, 380,250,50);
int[] arr = new int[7];
Rectangle[] arreglo = new Rectangle[7];
Rectangle rreset = new Rectangle(10,140,150,100);
Rectangle rplay = new Rectangle(350, 50, 200, 150);
Texture2D koopa;
int x = 0;
int y = 100;
int xm = 80;
int ym = 80;
bool inicia = true;
bool perder = true;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
this.IsMouseVisible = true;
arr[0] = 1;
arr[1] = 1;
arr[2] = 1;
arr[3] = 0;
arr[4] = 2;
arr[5] = 2;
arr[6] = 2;
for (int i = 0; i < 7; i++)
{
arreglo[i] = new Rectangle(i * 120, (graphics.GraphicsDevice.Viewport.Height) / 8 * 5 + 12, xm, ym);
}
tiempo = 0;
gameover = 0;
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
fondo = Content.Load<Texture2D>("fondo");
Hongo = Content.Load<Texture2D>("GoombaN");
pis = Content.Load<Texture2D>("GoombaP");
mario = Content.Load<Texture2D>("mario");
luigi = Content.Load<Texture2D>("luigi");
marioj = Content.Load<Texture2D>("marioj");
luigij = Content.Load<Texture2D>("luigij");
reset = Content.Load<Texture2D>("reset");
playagain = Content.Load<Texture2D>("playagain");
fuente = Content.Load<SpriteFont>("Verdana");
koopa = Content.Load <Texture2D>("koopa");
start = Content.Load<Texture2D>("start");
instrucciones = Content.Load<Texture2D>("instrucciones");
}
// TODO: use this.Content to load your game content here
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
///
int clicEn(int xmouse, int ymouse)
{
Rectangle rmouse;
rmouse = new Rectangle(xmouse, ymouse, 1, 1);
for (int x = 0; x < 7; x++)
{
if (rmouse.Intersects(arreglo[x]))
{
return x;
}
}
return 0;
}
int clicreset(int xmouse, int ymouse)
{
Rectangle rmouse;
rmouse = new Rectangle(xmouse, ymouse, 1, 1);
if (rmouse.Intersects(rreset))
{
return 1;
}
return 0;
}
int clicagain(int xmouse, int ymouse)
{
Rectangle rmouse;
rmouse = new Rectangle(xmouse, ymouse, 1, 1);
if (rmouse.Intersects(rplay))
{
return 1;
}
return 0;
}
int clicstart(int xmouse, int ymouse)
{
Rectangle rmouse;
rmouse = new Rectangle(xmouse, ymouse, 1, 1);
if (rmouse.Intersects(strt))
{
return 1;
}
return 0;
}
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
mouse = Mouse.GetState();
if (mouse.LeftButton == ButtonState.Pressed)
{
int a;
a = clicagain(mouse.X, mouse.Y);
if (a == 1)
{
this.Initialize();
perder = true;
}
}
if (perder == true)
{
for (int r = 1; r < graphics.GraphicsDevice.Viewport.Width; r++)
{
x += 2;
if (x == graphics.GraphicsDevice.Viewport.Width)
x = 0;
}
try
{
if (mouse.LeftButton == ButtonState.Pressed)
{
int pos = clicEn(mouse.X, mouse.Y);
if (arr[pos] == 1)
{
if (arr[pos + 1] == 0)
{
color = Color.Red;
arr[pos] = 0;
arr[pos + 1] = 1;
}
else if (arr[pos + 2] == 0)
{
color = Color.Red;
arr[pos] = 0;
arr[pos + 2] = 1;
}
}
else
{
pos = clicEn(mouse.X, mouse.Y);
if (arr[pos] == 2)
{
if (arr[pos - 1] == 0)
{
color2 = Color.Blue;
arr[pos] = 0;
arr[pos - 1] = 2;
}
else if (arr[pos - 2] == 0)
{
color2 = Color.Blue;
arr[pos] = 0;
arr[pos - 2] = 2;
}
}
}
}
else if (mouse.LeftButton == ButtonState.Released)
{
color = Color.White;
color2 = Color.White;
}
if (inicia == false)
{
if (tiempo < 60)
tiempo += gameTime.ElapsedGameTime.TotalSeconds;
else
tiempo = 0;
}
base.Update(gameTime);
}
catch (Exception)
{
}
if (mouse.LeftButton == ButtonState.Pressed)
{
int p;
p = clicreset(mouse.X, mouse.Y);
if (p == 1)
{
arr[0] = 1;
arr[1] = 1;
arr[2] = 1;
arr[3] = 0;
arr[4] = 2;
arr[5] = 2;
arr[6] = 2;
}
}
}
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
spriteBatch.Begin();
double segundos;
if(mouse.LeftButton == ButtonState.Pressed)
{
int d;
d = clicstart(mouse.X, mouse.Y);
if(d==1)
{
inicia = false;
}
}
if (inicia == true)
{
spriteBatch.Draw(instrucciones, new Rectangle(0, 0, graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height), Color.White);
spriteBatch.Draw(start, strt, color);
segundos = 61;
}
else if (inicia == false)
{
segundos = Math.Truncate(61.0 - tiempo);
spriteBatch.Draw(fondo, new Rectangle(0, 0, graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height), Color.White);
spriteBatch.Draw(Hongo, new Rectangle(5, (graphics.GraphicsDevice.Viewport.Height) / 8 * 6 + 4, 80, 80), Color.White);
spriteBatch.Draw(Hongo, new Rectangle((graphics.GraphicsDevice.Viewport.Width / 7) + 10, (graphics.GraphicsDevice.Viewport.Height) / 8 * 6 + 4, 80, 80), Color.White);
spriteBatch.Draw(Hongo, new Rectangle((graphics.GraphicsDevice.Viewport.Width / 7) * 2 + 15, (graphics.GraphicsDevice.Viewport.Height) / 8 * 6 + 4, 80, 80), Color.White);
spriteBatch.Draw(Hongo, new Rectangle((graphics.GraphicsDevice.Viewport.Width / 7) * 3 + 20, (graphics.GraphicsDevice.Viewport.Height) / 8 * 6 + 4, 80, 80), Color.White);
spriteBatch.Draw(Hongo, new Rectangle((graphics.GraphicsDevice.Viewport.Width / 7) * 4 + 25, (graphics.GraphicsDevice.Viewport.Height) / 8 * 6 + 4, 80, 80), Color.White);
spriteBatch.Draw(Hongo, new Rectangle((graphics.GraphicsDevice.Viewport.Width / 7) * 5 + 30, (graphics.GraphicsDevice.Viewport.Height) / 8 * 6 + 4, 80, 80), Color.White);
spriteBatch.Draw(Hongo, new Rectangle((graphics.GraphicsDevice.Viewport.Width / 7) * 6 + 30, (graphics.GraphicsDevice.Viewport.Height) / 8 * 6 + 4, 80, 80), Color.White);
spriteBatch.Draw(reset, rreset, Color.White);
spriteBatch.Draw(playagain, rplay, Color.White);
spriteBatch.Draw(koopa, new Rectangle(x, y, 80, 80), Color.White);
for (int xx = 0; xx < 7; xx++)
{
if (arr[xx] == 1)
{
spriteBatch.Draw(mario, arreglo[xx], color);
}
if (arr[xx] == 2)
{
spriteBatch.Draw(luigi, arreglo[xx], color2);
}
}
Vector2 V = new Vector2(graphics.GraphicsDevice.Viewport.Width - 125, 0);
if (gameover == 0)
spriteBatch.DrawString(fuente, segundos + "", V, Color.White);
if (segundos == 0)
{
{
spriteBatch.DrawString(fuente, "Game Over", new Vector2(350, 300), Color.White);
gameover = 1;
perder = false;
}
}
if (arr[0] == 2 && arr[1] == 2 && arr[2] == 2 && arr[4] == 1 && arr[5] == 1 && arr[6] == 1)
{
spriteBatch.DrawString(fuente, "You Won!!!", new Vector2(350, 300), Color.White);
GraphicsDevice.Clear(Color.Black);
perder = false;
gameover = 1;
}
}
spriteBatch.End();
base.Draw(gameTime);
}
}
}
if (mouse.LeftButton == ButtonState.Pressed)
{
int p;
p = clicreset(mouse.X, mouse.Y);//Clicreset es un metodo que hice para que el mouse intersecte con el rectangulo del botón
if (p == 1)
{
for (int n = 0; n <= 6; n++)
{
if (n < 3)
arr[n] = 1;
else if (n >= 4)
arr[n] = 2;
}
}
}
namespace WindowsGame6
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D fondo;
Texture2D Hongo;
Texture2D pis;
Texture2D mario;
Texture2D luigi;
Texture2D marioj;
Texture2D luigij;
Texture2D reset;
Texture2D playagain;
MouseState mouse;
double tiempo;
int gameover;
SpriteFont fuente;
Color color = Color.White;
int[] arr = new int[7];
Rectangle[] arreglo = new Rectangle[7];
Rectangle rreset = new Rectangle(10,140,150,100);
Rectangle rplay = new Rectangle(350, 50, 200, 150);
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
this.IsMouseVisible = true;
arr[0] = 1;
arr[1] = 1;
arr[2] = 1;
arr[3] = 0;
arr[4] = 2;
arr[5] = 2;
arr[6] = 2;
for (int i = 0; i < 7; i++)
{
arreglo[i] = new Rectangle(i * 120, (graphics.GraphicsDevice.Viewport.Height) / 8 * 5 + 12, 80, 80);
}
tiempo = 0;
gameover = 0;
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
fondo = Content.Load<Texture2D>("fondo");
Hongo = Content.Load<Texture2D>("GoombaN");
pis = Content.Load<Texture2D>("GoombaP");
mario = Content.Load<Texture2D>("mario");
luigi = Content.Load<Texture2D>("luigi");
marioj = Content.Load<Texture2D>("marioj");
luigij = Content.Load<Texture2D>("luigij");
reset = Content.Load<Texture2D>("reset");
playagain = Content.Load<Texture2D>("playagain");
fuente = Content.Load<SpriteFont>("Verdana");
}
// TODO: use this.Content to load your game content here
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
///
int clicEn(int xmouse, int ymouse)
{
Rectangle rmouse;
rmouse = new Rectangle(xmouse, ymouse, 1, 1);
for (int x = 0; x < 7; x++)
{
if (rmouse.Intersects(arreglo[x]))
{
return x;
}
}
return 0;
}
int clicreset(int xmouse, int ymouse)
{
Rectangle rmouse;
rmouse = new Rectangle(xmouse, ymouse, 1, 1);
if (rmouse.Intersects(rreset))
{
return 1;
}
return 0;
}
int clicagain(int xmouse, int ymouse)
{
Rectangle rmouse;
rmouse = new Rectangle(xmouse, ymouse, 1, 1);
if (rmouse.Intersects(rplay))
{
return 1;
}
return 0;
}
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
mouse = Mouse.GetState();
try
{
if (mouse.LeftButton == ButtonState.Pressed)
{
int pos = clicEn(mouse.X, mouse.Y);
if (arr[pos] == 1)
{
if (arr[pos + 1] == 0)
{
arr[pos] = 0;
arr[pos + 1] = 1;
}
else if (arr[pos + 2] == 0)
{
arr[pos] = 0;
arr[pos + 2] = 1;
}
}
else
{
pos = clicEn(mouse.X, mouse.Y);
if (arr[pos] == 2)
{
if (arr[pos - 1] == 0)
{
arr[pos] = 0;
arr[pos - 1] = 2;
}
else if (arr[pos - 2] == 0)
{
arr[pos] = 0;
arr[pos - 2] = 2;
}
}
}
}
if (tiempo < 60)
tiempo += gameTime.ElapsedGameTime.TotalSeconds;
else
tiempo = 0;
base.Update(gameTime);
}
catch (Exception)
{
}
if (mouse.LeftButton == ButtonState.Pressed)
{
int p;
p = clicreset(mouse.X, mouse.Y);
if (p == 1)
{
for (int n = 0; n <= 6; n++)
{
if (n < 3)
arr[n] = 1;
else if (n >= 4)
arr[n] = 2;
}
}
}
if (mouse.LeftButton == ButtonState.Pressed)
{
int a;
a = clicagain(mouse.X, mouse.Y);
if (a == 1)
this.Initialize();
}
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
spriteBatch.Begin();
double segundos = Math.Truncate(61.0 - tiempo);
spriteBatch.Draw(fondo, new Rectangle(0, 0, graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height), Color.White);
spriteBatch.Draw(Hongo, new Rectangle(5, (graphics.GraphicsDevice.Viewport.Height) / 8 * 6 + 4, 80, 80), Color.White);
spriteBatch.Draw(Hongo, new Rectangle((graphics.GraphicsDevice.Viewport.Width / 7) + 10, (graphics.GraphicsDevice.Viewport.Height) / 8 * 6 + 4, 80, 80), Color.White);
spriteBatch.Draw(Hongo, new Rectangle((graphics.GraphicsDevice.Viewport.Width / 7) * 2 + 15, (graphics.GraphicsDevice.Viewport.Height) / 8 * 6 + 4, 80, 80), Color.White);
spriteBatch.Draw(Hongo, new Rectangle((graphics.GraphicsDevice.Viewport.Width / 7) * 3 + 20, (graphics.GraphicsDevice.Viewport.Height) / 8 * 6 + 4, 80, 80), Color.White);
spriteBatch.Draw(Hongo, new Rectangle((graphics.GraphicsDevice.Viewport.Width / 7) * 4 + 25, (graphics.GraphicsDevice.Viewport.Height) / 8 * 6 + 4, 80, 80), Color.White);
spriteBatch.Draw(Hongo, new Rectangle((graphics.GraphicsDevice.Viewport.Width / 7) * 5 + 30, (graphics.GraphicsDevice.Viewport.Height) / 8 * 6 + 4, 80, 80), Color.White);
spriteBatch.Draw(Hongo, new Rectangle((graphics.GraphicsDevice.Viewport.Width / 7) * 6 + 30, (graphics.GraphicsDevice.Viewport.Height) / 8 * 6 + 4, 80, 80), Color.White);
spriteBatch.Draw(reset, rreset, color);
spriteBatch.Draw(playagain, rplay, color);
for (int xx = 0; xx < 7; xx++)
{
if (arr[xx] == 1)
{
spriteBatch.Draw(mario, arreglo[xx], Color.White);
}
if (arr[xx] == 2)
{
spriteBatch.Draw(luigi, arreglo[xx], Color.White);
}
}
Vector2 V = new Vector2(graphics.GraphicsDevice.Viewport.Width - 125, 0);
if (gameover == 0)
spriteBatch.DrawString(fuente, segundos + "", V, Color.White);
if (segundos == 0)
{
{
spriteBatch.DrawString(fuente, "Game Over", new Vector2(350, 300), Color.White);
gameover = 1;
//GraphicsDevice.Clear(Color.Black);
}
if (gameover == 1)
{
GraphicsDevice.Clear(Color.Black);
}
}
if (arr[0] == 2 && arr[1] == 2 && arr[2] == 2 && arr[4] == 1 && arr[5] == 1 && arr[6] == 1)
{
spriteBatch.DrawString(fuente, "GANASTE!!!!", new Vector2(350, 300), Color.White);
GraphicsDevice.Clear(Color.Black);
gameover = 1;
}
spriteBatch.End();
base.Draw(gameTime);
}
}
}
if (mouse.LeftButton == ButtonState.Pressed)
{
obj = clicEnLuigi(mouse.X, mouse.Y);
-> if (arr[obj - 1] == 0)//INDICE FUERA DE LOS LIMITES DE LA MATRÍZ
{
arr[obj] = 0;
arr[obj - 1] = 2;
}
else if (arr[obj - 2] == 0)
{
arr[obj] = 0;
arr[obj - 2] = 2;
}
}