using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
namespace drag_and_lock_grid
{
class Puzzlepiece
{
private int id;
private Vector2 position;
private Vector2 previousPosition;
private Boolean dragging;
private Vector2 correctPosition;
private Texture2D texture;
private Boolean disabled = false;
private Texture2D plu;
private Vector2 lightUpPostion;
private int delay = 3;
private int delayTimer = 0;
private int frame = 1;
private Boolean descending = false;
private Boolean stopAnimation;
public Puzzlepiece(int id, Vector2 position, Texture2D texture, Vector2 correctPosition)
{
this.id = id;
this.position = position;
this.texture = texture;
this.correctPosition = correctPosition;
lightUpPostion = new Vector2(correctPosition.X - 5, correctPosition.Y - 5);
}
public void Draw()
{
Game1.spriteBatch.Draw(texture, position, Color.White);
if (disabled)
{
if (!stopAnimation)
{
plu = Game1.content.Load<Texture2D>("images/pieceslightup/plu_" + frame);
Game1.spriteBatch.Draw(plu, lightUpPostion, Color.White);
delayTimer++;
if (delayTimer > delay)
{
if (frame < 3)
{
if (!descending)
{
frame++;
delayTimer = 0;
}
}
else
descending = true;
if (descending)
{
frame--;
delayTimer = 0;
}
if (frame == 0)
{
stopAnimation = true;
}
}
}
}
}
public void Update()
{
}
public void touchDown(float x, float y)
{
//Game1.spriteBatch.GraphicsDevice.Clear(Color.White);
}
public void touchMove(float x, float y)
{
//if(!dragging)
//{
// dragging = true;
// previousPosition.X = x;
// previousPosition.Y = y;
//}
if (!disabled)
{
if (isWithinPuzzle(x, y))
{
position.X = x - (texture.Width / 2);
position.Y = y - (texture.Height / 2);
}
}
}
public void touchUp(float x, float y)
{
if (isWithinPuzzle(x, y))
{
if (isWithinCorrectPosition(x, y))
{
position.X = correctPosition.X;
position.Y = correctPosition.Y;
disabled = true;
}
}
//dragging = false;
//position.X = previousPosition.X;
//position.Y = previousPosition.Y;
}
public Boolean isWithinPuzzle(float x, float y)
{
if (x > position.X && x < position.X + texture.Width && y > position.Y && y < position.Y + texture.Height)
{
return true;
}
return false;
}
public Boolean isWithinCorrectPosition(float x, float y)
{
if (x > correctPosition.X && x < correctPosition.X + texture.Width && y > correctPosition.Y && y < correctPosition.Y + texture.Height)
{
return true;
}
return false;
}
}
}
//public void addPoint()
//{
// if (!pointAdded)
// {
// Game1.noc++;
// pointAdded = true;
// }
|