using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
//사운드를 재생한다
namespace SoundEx
{
public class Game1 : Microsoft.Xna.Framework.Game
{
//시스템
private GraphicsDeviceManager graphics;
private ContentManager content;
private SpriteBatch spBatch;
private Texture2D texture;
private Texture2D texture1;
private int width;
private int height;
//사운드
private AudioEngine audioEngine; //오디오엔진
private WaveBank waveBank; //Wave뱅크
private SoundBank soundBank; //Sound뱅크
//마우스
private int x = 100; //X좌표
private int y = 100; //Y좌표
private ButtonState rightButton = ButtonState.Released;
//왼쪽버튼 상태
//속도
private int dx = 1;
private int dy = 1;
private int z = 0;
private int q = 0;
//constructor
public Game1()
{
graphics = new GraphicsDeviceManager(this);
content = new ContentManager(Services);
IsFixedTimeStep = true;
TargetElapsedTime = new TimeSpan(500000);
}
//초기화
protected override void Initialize()
{
//사운드 읽어오기
audioEngine = new AudioEngine("tests.xgs");
waveBank = new WaveBank(audioEngine, "Wave Bank.xwb");
soundBank = new SoundBank(audioEngine, "Sound Bank.xsb");
width = graphics.GraphicsDevice.Viewport.Width;
height = graphics.GraphicsDevice.Viewport.Height;
//초기화
base.Initialize();
}
//그래픽스 컨텐츠 데리고 오기
protected override void LoadGraphicsContent(bool loadAllContent)
{
if (loadAllContent)
{
spBatch = new SpriteBatch(graphics.GraphicsDevice);
texture = content.Load<Texture2D>("imagine08");
texture1 = content.Load<Texture2D>("ininIMG_2121");
//←Assent Name 지정
}
}
//그래픽스 컨텐츠 놓아주기
protected override void UnloadGraphicsContent(bool unloadAllContent)
{
if (unloadAllContent == true)
{
content.Unload();
}
}
//업뎃
protected override void Update(GameTime gameTime)
{
//마우스 XY위치추적
MouseState mouseState = Mouse.GetState();
x = mouseState.X;
y = mouseState.Y;
Cue sound = null;
//마우스왼쪽버튼 상태가 변경되었다면
if (rightButton != mouseState.RightButton)
{
rightButton = mouseState.RightButton;
//Enter를 누르면
if (mouseState.RightButton == ButtonState.Pressed)
{
//사운드 재생
sound = soundBank.GetCue("a");
sound.Play();
}
}
KeyboardState keyboardState = Keyboard.GetState();
if (keyboardState.IsKeyDown(Keys.S))
soundBank.GetCue("b").Play();
if (keyboardState.IsKeyDown(Keys.Escape))
Exit();
//이동량(매초 400픽셀)
int move = (int)(400 *
(float)gameTime.ElapsedRealTime.TotalMilliseconds / 1000.0f);
//이동
z += dx * move;
q += dy * move;
if (z < 0 || width < z) dx = -dx;
if (q < 0 || height < q) dy = -dy;
//베이스 업뎃
base.Update(gameTime);
}
//그리기
protected override void Draw(GameTime gameTime)
{
//배경색
graphics.GraphicsDevice.Clear(Color.Black);
//텍스쳐
spBatch.Begin();
Vector2 pos1 = new Vector2(z - 200, q - 200);
Vector2 pos = new Vector2(x - 100, y - 50); //←좌표지정
spBatch.Draw(texture1, pos1, Color.White);
spBatch.Draw(texture, pos, Color.White);
spBatch.End();
//베이스그리기
base.Draw(gameTime);
}
}
}
|
댓글