using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Input; //using Microsoft.Xna.Framework.Input.Touch; using System.IO; namespace Colto1 { class Level1 { Texture2D backgroundImage; public Game1 parent; public Animal animal; public Rectangle location = new Rectangle(0, 0, 1024, 768); public int[] xs = { 300, 500, 700 }; public int floor = 700, floorup=600, left=200, right=800; public float jumpdistance = 10, jumpspeedup=-6, jumpg=(float)0.2; public int wordcollidedistance = 30; public Word w1; public WordManager wordManager; public ScoreBoard scoreBoard; public CoinBoard coinBoard; public int rights = 0; public int wrongs = 0; public int levelscompleted = 0; public datetime starttime=DateTime.Now; public Level1(Game1 parent, int w, int h) { this.parent = parent; animal = new Animal(this); w1=new Word(this, "Hello"); wordManager = new WordManager(this); scoreBoard = new ScoreBoard(this); coinBoard = new CoinBoard(this); location.Width = w; location.Height= h; //w = w * 11 / 12; xs = new int[] {w*1/3, w/2, w*2/3 }; floor = h * 8 / 10; floorup = h * 7 / 10; left = w / 4; right = w * 3 / 4; scoreBoard.position.X = w * 0.85f; scoreBoard.position.Y = h * 0.1f; wordManager.wBoard.position.Y = (int)(h * 0.8); wordManager.wBoard.position.X = (int)(w * 0.03); wordManager.wBoard.position.Width = (int)(w * 0.4); wordManager.wBoard.position.Height = (int)(h * 0.2); animal.location.Width = (int)(w / 8); animal.location.Height = (int)(h / 6); // jumpdistance = (float)(w / 40.0); jumpdistance = 3; // wordManager.readWordData("animal"); wordManager.readWordData("people"); wordManager.RandomWords(); wordManager.StartFalling(); } public void LoadContent(ContentManager manager, string filename){ backgroundImage = manager.Load(filename); animal.LoadContent(manager, "01", "01_1"); Word.LoadContent(manager); wordManager.LoadContent(manager); scoreBoard.LoadContent(manager); coinBoard.LoadContent(manager); } public void Update(GameTime time) { // long gameseconds=DateTime.Now.Subtract(starttime). KeyboardState state=Keyboard.GetState(); //animal.speed.X=0; //animal.speed.Y=0; if (state.IsKeyDown(Keys.Left)) { animal.setSpeedX( -1); } if (state.IsKeyDown(Keys.Right)) { animal.setSpeedX( 1); } if (state.IsKeyDown(Keys.Up)) { animal.speed.Y = -1; } if (state.IsKeyDown(Keys.Down)) { animal.speed.Y = 1; } if (state.IsKeyDown(Keys.Space)) { if (animal.location.Y > floorup) { animal.setSpeedX(0); } else { if(((animal.speed.X>0 && animal.location.X xs[0])) && (!animal.jump) && (animal.speed.X!=0)) animal.speed.Y = jumpspeedup; if (animal.speed.X == 1) { animal.speed.X = 2; } if (animal.speed.X == -1) { animal.speed.X = -2; } animal.jump = true; animal.location.X += (int)animal.speed.X; } } if (Mouse.GetState().LeftButton == ButtonState.Pressed) { if (Mouse.GetState().X > animal.location.X) { animal.direction = 1; } if (Mouse.GetState().X < animal.location.X) { animal.direction = -1; } animal.location.X = Mouse.GetState().X; animal.location.Y = Mouse.GetState().Y; animal.speed.X = 0; animal.speed.Y = 0; animal.jump = false; } animal.Update(); //w1.position.Width = 30; //w1.position.Height = 40; wordManager.Update(); // w1.Update(); checkAnimalWordCollision(); } public void Draw(SpriteBatch batch) { batch.Draw(backgroundImage, location, Color.White); animal.Draw(batch); // w1.Draw(batch); wordManager.Draw(batch); scoreBoard.Draw(batch); coinBoard.Draw(batch); } void checkAnimalWordCollision() { int found = -1; int ax = animal.location.X; int ay = animal.location.Y; int sq=wordcollidedistance*wordcollidedistance; for (int i = 0; i < 3; i++) { int wx = (int)wordManager.words[i].position.X; int wy = (int)wordManager.words[i].position.Y; int dx=ax-wx; int dy=ay-wy; if (dx * dx + dy * dy < sq) { found = i; } } if(found!=-1){ if (wordManager.words[found].answer == wordManager.wBoard.content) { rights++; //coinBoard.results.Add(1); coinBoard.addResult(1); if (rights+wrongs > wordManager.wordsperlevel) { wordManager.loadNextLevel(); rights = 0; wrongs = 0; // coinBoard.results.Clear(); coinBoard.resetResults(); levelscompleted++; scoreBoard.levelcontent = levelscompleted + ""; } } else { wrongs++; // coinBoard.results.Add(-1); coinBoard.addResult(-1); } scoreBoard.content = rights + " / " + (rights + wrongs); wordManager.RandomWords(); wordManager.StartFalling(); } if (wordManager.words[0].position.Y > floor) { wordManager.RandomWords(); wordManager.StartFalling(); } //animal.location.Intersects(wordManager.words[0].position); } } }