Jeszcze chciałbym zadać pytanie bardziej skierowane dla tych którzy mieli styczność ze środowiskiem XNA, i ewentualnie posiadają je zainstalowane, a nie chcę zakładać nowego tematu.
Otóż emulator wp7 nie reaguje na żadne wywołanie zdarzenia jak kliknięcie przycisku na klawiaturze. Ogólnie program jakby stał w miejscu. Wiem to,że żeby używać klawiatury fizycznej przyciska się pg up.
Nie mam stosownego doświadczenia w tym środowisku i dlatego zamieszczę kod programu składającego się z jednej klasy. Ogólnie chodzi o to że poruszamy się tym kwadracikiem i kiedy kwadracik najdzie na przeszkodę, zmienia się kolor przeszkody. Ponadto planowałem losowe poruszanie się przeszkody w poziomie(co 2 sekundy losuje czy w lewo czy w prawo będzie się poruszał). Chciałem najpierw się przekonać czy to zadziała.
using System;
using System.Collections.Generic;
using System.Linq;
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.Input.Touch;
using Microsoft.Xna.Framework.Media;
using System.Threading;
namespace proba_3
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D przeszkoda,uciekinier;
Vector2 wspolrzedna = new Vector2(100,50),kierunek=new Vector2(15,0),namiary = new Vector2(200,200);
int lewo_prawo;
Random losuj = new Random(1);
bool kolor;
int skala_x = 80, skala_y = 50;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
// Frame rate is 30 fps by default for Windows Phone.
TargetElapsedTime = TimeSpan.FromTicks(333333);
// Extend battery life under lock.
InactiveSleepTime = TimeSpan.FromSeconds(1);
}
/// <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
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);
uciekinier = Content.Load<Texture2D>("pudelko");
przeszkoda = Content.Load<Texture2D>("kreska");
// 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>
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if(zwrot()==true)
wspolrzedna += kierunek;
if(zwrot()==false)
wspolrzedna-=kierunek;
if (wspolrzedna.X <= 0)
lewo_prawo = 1;
if (wspolrzedna.X >= GraphicsDeviceManager.DefaultBackBufferWidth - uciekinier.Width)
lewo_prawo = 0;
if (Keyboard.GetState().IsKeyDown(Keys.W))
namiary += new Vector2(8, 0);
if (Keyboard.GetState().IsKeyDown(Keys.S))
namiary += new Vector2(-8, 0);
if (Keyboard.GetState().IsKeyDown(Keys.A))
namiary += new Vector2(0, -8);
if (Keyboard.GetState().IsKeyDown(Keys.D))
namiary += new Vector2(0, 8);
if (kolizja())
kolor = true;
if (Keyboard.GetState().IsKeyDown(Keys.Space))
namiary = new Vector2(50, 50);
// TODO: Add your update logic here
base.Update(gameTime);
}
/// <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);
spriteBatch.Begin();
if(kolizja())
spriteBatch.Draw(przeszkoda, new Rectangle((int)wspolrzedna.X,(int)wspolrzedna.Y,(int)skala_x,(int)skala_y), Color.White);
else
spriteBatch.Draw(przeszkoda, new Rectangle((int)wspolrzedna.X,(int)wspolrzedna.Y,(int)skala_x,(int)skala_y), Color.Yellow);
spriteBatch.Draw(uciekinier, new Rectangle((int)namiary.X, (int)namiary.Y, (int)uciekinier.Width, (int)uciekinier.Height), Color.White);
spriteBatch.End();
// TODO: Add your drawing code here
base.Draw(gameTime);
}
public bool zwrot()
{
Thread.Sleep(2000);
lewo_prawo = losuj.Next();
if (lewo_prawo == 1)
return true;
else return false;
}
public bool kolizja()
{
Rectangle pudelko = new Rectangle((int)wspolrzedna.X, (int)wspolrzedna.Y, skala_x, skala_y);
Rectangle ucieczka = new Rectangle((int)namiary.X, (int)namiary.Y,uciekinier.Width,uciekinier.Height);
return pudelko.Intersects(ucieczka);
}
}
}
Byłbym wdzięczny gdyby ktoś obiektywnie skrytykował tu zawarty tok myślenia.