public bool IsTouchingRight(sprite sprite) { return(_thisSprite.CollisionRectangle.Left + _thisSprite.Velocity.X < sprite.CollisionRectangle.Right && _thisSprite.CollisionRectangle.Right > sprite.CollisionRectangle.Right && _thisSprite.CollisionRectangle.Bottom > sprite.CollisionRectangle.Top && _thisSprite.CollisionRectangle.Top < sprite.CollisionRectangle.Bottom); }
public bool IsTouchingBottom(sprite sprite) { return(_thisSprite.CollisionRectangle.Top + _thisSprite.Velocity.Y < sprite.CollisionRectangle.Bottom && _thisSprite.CollisionRectangle.Bottom > sprite.CollisionRectangle.Bottom && _thisSprite.CollisionRectangle.Right > sprite.CollisionRectangle.Left + _offset && _thisSprite.CollisionRectangle.Left < sprite.CollisionRectangle.Right); }
private static void ParseSprite(ref ent ent, vector pos, XmlNode node) { var s = new sprite(pos); foreach (XmlNode n in node.ChildNodes) { try { if (n.Name == "static") { s.isstatic = n.InnerText == "true"; } if (n.Name == "solid") { s.solid = n.InnerText == "true"; } if (n.Name == "texture") { s.SetTexture(n.InnerText); } if (n.Name == "offset") { s.SetPos(s.pos + ParseVector(n.InnerText)); } } catch (Exception e) { log.WriteLine("parsing error: " + e.Message); } } ent = s; }
public static TextureAtlas CreateFromStringCSV(string csv) { TextureAtlas ta = new TextureAtlas(); ta.imagePath = ""; ta.width = 0; ta.height = 0; var lines = csv.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (var l in lines) { var ws = l.Split(new char[] { ',' }); sprite s = new sprite(); s.n = ws[0]; s.x = int.Parse(ws[1]); s.y = int.Parse(ws[2]); s.w = int.Parse(ws[3]); s.h = int.Parse(ws[4]); ta.sprites.Add(s); } return(ta); }
return(new SpriteRenderable(sprite, pos, offset, zOffset, palette, scale, alpha, newTint, newTintModifiers, isDecoration));
/// <summary> /// Загружаем спрайт из изображения /// </summary> /// <param name="pic">Исходное изображение</param> /// <param name="position">Параметры положения и размера спрайта</param> /// <param name="replacement">Заменяемый цвет</param> /// <param name="animationDelay">Cкорость смены кадров</param> /// <param name="animation">Параметры анимации</param> /// <param name="id">Уникальный идентификатор спрайта</param> /// <param name="density">Плотность спрайта</param> /// <returns>ЗАгруженный спрайт</returns> public sprite load(long id, Bitmap pic, positionParams position, double density, Color?replacement = null, animationParams animation = null) { //Итоговый спрайт sprite ex = null; //Ширина одного кадра int frameWidth; //Координата начала нового кадра int x0; //Кадр, считанный из картинки List <framePixel> frame; try { //Если параметры анимации не указаны if (animation == null) { //Проставляем дефолтные animation = new animationParams(); } //Инициализируем новый спрайт ex = new sprite(position.size, animation, id, density); //Если нужно менять цвет if (replacement.HasValue) { //Генерируем рандомный цвет rand = Color.FromArgb(r.Next(0, 256), r.Next(0, 256), r.Next(0, 256)); } //Запоминаем инфу о замене цвета this.replacement = replacement; //Получаем ширину одного кадра frameWidth = pic.Width / animation.countFrames; //Начало первого кадра всегда в ноле x0 = 0; //Проходимся по всем кадрам for (int i = 0; i < animation.countFrames; i++) { //Считываем все пиксели кадра frame = loadFrame(x0, frameWidth, pic, position); //Переходим к следующему кадру x0 += frameWidth; //Добавляем новый кадр в спрайт ex.addFrame(frame.Count); //Проходимся по всем считанным пикселям for (int j = 0; j < frame.Count; j++) { //Добавляем пиксель в кадр ex.setPixel(frame[i], i); } } //Завершаем загрузку кадров ex.completeLoad(); } catch { ex = null; } //Возвращаем спрайт return(ex); }
/// <summary> /// LoadContent はゲームごとに 1 回呼び出され,ここですべてのコンテンツを /// 読み込みます. /// </summary> protected override void LoadContent() { // 新規の SpriteBatch を作成します.これはテクスチャーの描画に使用できます. spriteBatch = new SpriteBatch(GraphicsDevice); //シーンのロード textureTitle = Content.Load <Texture2D>("title"); sceneTextureList.Add(textureTitle); textureGameScene = Content.Load <Texture2D>("stage1"); sceneTextureList.Add(textureTitle); textureClear = Content.Load <Texture2D>("clear"); sceneTextureList.Add(textureClear); textureGameover = Content.Load <Texture2D>("gameover"); sceneTextureList.Add(textureGameover); //オブジェクトのロード textureArrow = Content.Load <Texture2D>("arrow"); title = new Titlescene(textureTitle, textureArrow); SceneList.Add(title); gamescene = new Gamescene(textureGameScene); SceneList.Add(title); clearscene = new Gamescene(textureClear); SceneList.Add(clearscene); gameoverscene = new Gamescene(textureGameover); SceneList.Add(gameoverscene); textureEnemy1 = Content.Load <Texture2D>("watermelon"); enemyTextureList.Add(textureEnemy1); textureEnemy1 = Content.Load <Texture2D>("melon"); enemyTextureList.Add(textureEnemy1); textureEnemy1 = Content.Load <Texture2D>("kingyo"); enemyTextureList.Add(textureEnemy1); textureEnemy1 = Content.Load <Texture2D>("stagbeetle"); enemyTextureList.Add(textureEnemy1); textureEnemy1 = Content.Load <Texture2D>("pantsu"); enemyTextureList.Add(textureEnemy1); textureEnemy1 = Content.Load <Texture2D>("bura"); enemyTextureList.Add(textureEnemy1); textureTama = Content.Load <Texture2D>("tamatate"); tamaTextureList.Add(textureTama); textureTama = Content.Load <Texture2D>("tama1"); tamaTextureList.Add(textureTama); textureTama = Content.Load <Texture2D>("tama2"); tamaTextureList.Add(textureTama); textureTama = Content.Load <Texture2D>("tama3"); tamaTextureList.Add(textureTama); textureTama = Content.Load <Texture2D>("tama4"); tamaTextureList.Add(textureTama); textureTama = Content.Load <Texture2D>("tama5"); tamaTextureList.Add(textureTama); textureTama = Content.Load <Texture2D>("tama6"); tamaTextureList.Add(textureTama); textureItem = Content.Load <Texture2D>("item1"); itemTextureList.Add(textureItem); textureItem = Content.Load <Texture2D>("item2"); itemTextureList.Add(textureItem); textureItem = Content.Load <Texture2D>("item3"); itemTextureList.Add(textureItem); textureItem = Content.Load <Texture2D>("item4"); itemTextureList.Add(textureItem); textureItem = Content.Load <Texture2D>("item5"); itemTextureList.Add(textureItem); textureItem = Content.Load <Texture2D>("item6"); itemTextureList.Add(textureItem); textureEffect = Content.Load <Texture2D>("effect1"); EffectSp = new sprite(textureEffect, new Vector2(0, 0), new Point(100, 100), new Point(2, 1), 200); effectspriteList.Add(EffectSp); textureEffect = Content.Load <Texture2D>("effect2"); EffectSp = new sprite(textureEffect, new Vector2(0, 0), new Point(50, 50), new Point(4, 1), 400); effectspriteList.Add(EffectSp); texturePlayer = Content.Load <Texture2D>("beetle"); playerSp = new sprite(texturePlayer, new Vector2(0, 0), new Point(40, 60), new Point(3, 1), 5000); soundeffect = Content.Load <SoundEffect>("soundclear"); //0 soundeffectList.Add(soundeffect); soundeffect = Content.Load <SoundEffect>("soundgameover"); //1 soundeffectList.Add(soundeffect); soundeffect = Content.Load <SoundEffect>("soundhpreduce"); //2 soundeffectList.Add(soundeffect); soundeffect = Content.Load <SoundEffect>("soundgetitem"); //3 soundeffectList.Add(soundeffect); soundeffect = Content.Load <SoundEffect>("soundenemypowerdown"); //4 soundeffectList.Add(soundeffect); soundeffect = Content.Load <SoundEffect>("soundshoot1"); //5 soundeffectList.Add(soundeffect); soundeffect = Content.Load <SoundEffect>("soundshoot2"); //6 soundeffectList.Add(soundeffect); soundeffect = Content.Load <SoundEffect>("soundshoot3"); //7 soundeffectList.Add(soundeffect); soundeffect = Content.Load <SoundEffect>("soundshoot4"); //8 soundeffectList.Add(soundeffect); soundeffect = Content.Load <SoundEffect>("soundshoot5"); //9 soundeffectList.Add(soundeffect); soundeffect = Content.Load <SoundEffect>("soundshoot6"); //10 soundeffectList.Add(soundeffect); soundeffect = Content.Load <SoundEffect>("soundshoot7"); //11 soundeffectList.Add(soundeffect); soundeffect = Content.Load <SoundEffect>("soundshoot8"); //12 soundeffectList.Add(soundeffect); soundeffect = Content.Load <SoundEffect>("soundshoot9"); //13 soundeffectList.Add(soundeffect); soundeffect = Content.Load <SoundEffect>("soundshoot10"); //14 soundeffectList.Add(soundeffect); //bgm = Content.Load<Song>("bgm"); //敵のステータスのロード EnemyStatus ene; ene = new EnemyStatus(1, 1, 10, 1); //スイカ enemyStatusList.Add(ene); ene = new EnemyStatus(2, 1, 20, 1); //メロン enemyStatusList.Add(ene); ene = new EnemyStatus(3, 1, 100, 1); //金魚 enemyStatusList.Add(ene); ene = new EnemyStatus(4, 1, 1000, 10); //クワガタ enemyStatusList.Add(ene); ene = new EnemyStatus(5, 1, 100, 10); //パンツ enemyStatusList.Add(ene); ene = new EnemyStatus(5, 1, 100, 10); //ブラ enemyStatusList.Add(ene); // TODO: this.Content クラスを使用して,ゲームのコンテンツを読み込みます. }
public CollisionManager(sprite _sprite, int _offset) { _thisSprite = _sprite; this._offset = _offset; }
/// <summary> /// LoadContent はゲームごとに 1 回呼び出され,ここですべてのコンテンツを /// 読み込みます. /// </summary> protected override void LoadContent() { // 新規の SpriteBatch を作成します.これはテクスチャーの描画に使用できます. spriteBatch = new SpriteBatch(GraphicsDevice); //シーンのロード textureTitle = Content.Load<Texture2D>("title"); sceneTextureList.Add(textureTitle); textureGameScene = Content.Load<Texture2D>("stage1"); sceneTextureList.Add(textureTitle); textureClear = Content.Load<Texture2D>("clear"); sceneTextureList.Add(textureClear); textureGameover = Content.Load<Texture2D>("gameover"); sceneTextureList.Add(textureGameover); //オブジェクトのロード textureArrow = Content.Load<Texture2D>("arrow"); title = new Titlescene(textureTitle, textureArrow); SceneList.Add(title); gamescene = new Gamescene(textureGameScene); SceneList.Add(title); clearscene = new Gamescene(textureClear); SceneList.Add(clearscene); gameoverscene = new Gamescene(textureGameover); SceneList.Add(gameoverscene); textureEnemy1 = Content.Load<Texture2D>("watermelon"); enemyTextureList.Add(textureEnemy1); textureEnemy1 = Content.Load<Texture2D>("melon"); enemyTextureList.Add(textureEnemy1); textureEnemy1 = Content.Load<Texture2D>("kingyo"); enemyTextureList.Add(textureEnemy1); textureEnemy1 = Content.Load<Texture2D>("stagbeetle"); enemyTextureList.Add(textureEnemy1); textureEnemy1 = Content.Load<Texture2D>("pantsu"); enemyTextureList.Add(textureEnemy1); textureEnemy1 = Content.Load<Texture2D>("bura"); enemyTextureList.Add(textureEnemy1); textureTama = Content.Load<Texture2D>("tamatate"); tamaTextureList.Add(textureTama); textureTama = Content.Load<Texture2D>("tama1"); tamaTextureList.Add(textureTama); textureTama = Content.Load<Texture2D>("tama2"); tamaTextureList.Add(textureTama); textureTama = Content.Load<Texture2D>("tama3"); tamaTextureList.Add(textureTama); textureTama = Content.Load<Texture2D>("tama4"); tamaTextureList.Add(textureTama); textureTama = Content.Load<Texture2D>("tama5"); tamaTextureList.Add(textureTama); textureTama = Content.Load<Texture2D>("tama6"); tamaTextureList.Add(textureTama); textureItem = Content.Load<Texture2D>("item1"); itemTextureList.Add(textureItem); textureItem = Content.Load<Texture2D>("item2"); itemTextureList.Add(textureItem); textureItem = Content.Load<Texture2D>("item3"); itemTextureList.Add(textureItem); textureItem = Content.Load<Texture2D>("item4"); itemTextureList.Add(textureItem); textureItem = Content.Load<Texture2D>("item5"); itemTextureList.Add(textureItem); textureItem = Content.Load<Texture2D>("item6"); itemTextureList.Add(textureItem); textureEffect = Content.Load<Texture2D>("effect1"); EffectSp = new sprite(textureEffect, new Vector2(0, 0), new Point(100, 100), new Point(2, 1), 200); effectspriteList.Add(EffectSp); textureEffect = Content.Load<Texture2D>("effect2"); EffectSp = new sprite(textureEffect, new Vector2(0, 0), new Point(50, 50), new Point(4, 1), 400); effectspriteList.Add(EffectSp); texturePlayer = Content.Load<Texture2D>("beetle"); playerSp = new sprite(texturePlayer, new Vector2(0, 0), new Point(40, 60), new Point(3, 1), 5000); soundeffect = Content.Load<SoundEffect>("soundclear");//0 soundeffectList.Add(soundeffect); soundeffect = Content.Load<SoundEffect>("soundgameover");//1 soundeffectList.Add(soundeffect); soundeffect = Content.Load<SoundEffect>("soundhpreduce");//2 soundeffectList.Add(soundeffect); soundeffect = Content.Load<SoundEffect>("soundgetitem");//3 soundeffectList.Add(soundeffect); soundeffect = Content.Load<SoundEffect>("soundenemypowerdown");//4 soundeffectList.Add(soundeffect); soundeffect = Content.Load<SoundEffect>("soundshoot1");//5 soundeffectList.Add(soundeffect); soundeffect = Content.Load<SoundEffect>("soundshoot2");//6 soundeffectList.Add(soundeffect); soundeffect = Content.Load<SoundEffect>("soundshoot3");//7 soundeffectList.Add(soundeffect); soundeffect = Content.Load<SoundEffect>("soundshoot4");//8 soundeffectList.Add(soundeffect); soundeffect = Content.Load<SoundEffect>("soundshoot5");//9 soundeffectList.Add(soundeffect); soundeffect = Content.Load<SoundEffect>("soundshoot6");//10 soundeffectList.Add(soundeffect); soundeffect = Content.Load<SoundEffect>("soundshoot7");//11 soundeffectList.Add(soundeffect); soundeffect = Content.Load<SoundEffect>("soundshoot8");//12 soundeffectList.Add(soundeffect); soundeffect = Content.Load<SoundEffect>("soundshoot9");//13 soundeffectList.Add(soundeffect); soundeffect = Content.Load<SoundEffect>("soundshoot10");//14 soundeffectList.Add(soundeffect); //bgm = Content.Load<Song>("bgm"); //敵のステータスのロード EnemyStatus ene; ene = new EnemyStatus(1, 1, 10, 1); //スイカ enemyStatusList.Add(ene); ene = new EnemyStatus(2, 1, 20, 1); //メロン enemyStatusList.Add(ene); ene = new EnemyStatus(3, 1, 100, 1); //金魚 enemyStatusList.Add(ene); ene = new EnemyStatus(4, 1, 1000, 10); //クワガタ enemyStatusList.Add(ene); ene = new EnemyStatus(5, 1, 100, 10); //パンツ enemyStatusList.Add(ene); ene = new EnemyStatus(5, 1, 100, 10); //ブラ enemyStatusList.Add(ene); // TODO: this.Content クラスを使用して,ゲームのコンテンツを読み込みます. }
return(new SpriteRenderable(sprite, pos, offset, zOffset, palette, scale, newTint, isDecoration, ignoreWorldTint));
public void initlize() { string all = File.ReadAllText("sprites\\sprite.txt"); all = all.Replace(System.Environment.NewLine, string.Empty); int semi = 0, oldsemi = 0; do { semi = all.IndexOf(";", semi + 1); if (semi > -1) { string file; if (oldsemi == 0) { file = all.Substring(oldsemi, semi); } else { file = all.Substring(oldsemi + 1, semi - (oldsemi + 1)); } int n = 0, oldn = 0; do { n = file.IndexOf(":", oldn + 1); sprite x = new sprite(); if (n > -1) { if (oldn == 0) { d2.Add(file.Substring(oldn, n - oldn)); } else { d2.Add(file.Substring(oldn + 1, n - (oldn + 1))); } x.frames = new List <Image>(); int n2 = file.IndexOf(":", n + 1); if (n2 > -1) { string txt = file.Substring(n + 1, n2 - (n + 1)); int f = 0, fold = 0; do { f = txt.IndexOf(",", f + 1); if (f > -1) { string frame; if (fold == 0) { frame = txt.Substring(fold, f); } else { frame = txt.Substring(fold + 1, f - (fold + 1)); } x.frames.Add(Bitmap.FromFile("sprites\\" + frame)); } else { if (fold == 0) { fold = -1; } string frame = txt.Substring(fold + 1, txt.Length - (fold + 1)); x.frames.Add(Bitmap.FromFile("sprites\\" + frame)); } fold = f; } while (f > -1); int tm = 0; int l = file.IndexOf("time"); if (l > -1) { int e = file.IndexOf("=", l); if (e > -1) { tm = int.Parse(file.Substring(e + 1, file.Length - (e + 1))); } } if (tm > 0) { x.frameratetime = tm; } else { x.frameratetime = 1000; } } oldn = n2; x.size = x.frames[0].Size; if (x.frames.Count == 1) { x.animateable = false; } else { x.animateable = true; } d1.Add(x); } } while (n > -1); } oldsemi = semi; } while (semi > -1); }
static void Main(string[] args) { //Méret állítása (szükség esetén) //Console.WindowHeight = 16; //Console.WindowWidth = 32; int screenwidth = Console.WindowWidth; int screenheight = Console.WindowHeight; Random rnd = new Random(); //Base int score = 1; int gameover = 0; //Kígyó feje, kezdő "koordináta" + színe + értelme(iránya) sprite shead = new sprite(); shead.xpos = screenwidth / 2; shead.ypos = screenheight / 2; shead.mycolor = ConsoleColor.Red; string movement = "RIGHT"; //Kígyó teste List <int> xbody = new List <int>(); List <int> ybody = new List <int>(); //Kaja random helyre int foodx = rnd.Next(0, screenwidth); int foody = rnd.Next(0, screenheight); //Idő az update-hez (ne villogjon a kép) DateTime time1; DateTime time2; //Keystate check változó string buttonpressed; //Gameloop while (true) { Console.Clear(); //State check if (shead.xpos == screenwidth - 1 || shead.xpos == 0 || shead.ypos == screenheight - 1 || shead.ypos == 0) { gameover = 1; } //Keret for (int i = 0; i < screenwidth; i++) { Console.SetCursorPosition(i, 0); Console.Write("#"); } for (int i = 0; i < screenwidth; i++) { Console.SetCursorPosition(i, screenheight - 1); Console.Write("#"); } for (int i = 0; i < screenheight; i++) { Console.SetCursorPosition(0, i); Console.Write("#"); } for (int i = 0; i < screenheight; i++) { Console.SetCursorPosition(screenwidth - 1, i); Console.Write("#"); } //Console.ForegroundColor = ConsoleColor.Green; //Score system if (foodx == shead.xpos && foody == shead.ypos) { score++; foodx = rnd.Next(1, screenwidth - 3); foody = rnd.Next(1, screenheight - 3); } //Test logika for (int i = 0; i < xbody.Count(); i++) { Console.SetCursorPosition(xbody[i], ybody[i]); Console.Write("o"); if (xbody[i] == shead.xpos && ybody[i] == shead.ypos) { gameover = 1; } } //Ha gameover, akkor kilépünk a gameloopból if (gameover == 1) { break; } //Start setup Console.SetCursorPosition(shead.xpos, shead.ypos); Console.ForegroundColor = shead.mycolor; //Kígyó feje Console.Write("O"); Console.SetCursorPosition(foodx, foody); Console.ForegroundColor = ConsoleColor.Green; //Kaja kinézete Console.Write("X"); time1 = DateTime.Now; buttonpressed = "no"; while (true) { time2 = DateTime.Now; //Update intervallum (két update között eltelt idő definiálása) //A játék dinamikusságának növelés/csökkentése //A 150 msec ideális, mivel így még normálisan lehet irányítani a kigyót //Kisebb értéknél nyomkodni kell a gombokat, hogy érzékelje az irányváltoztatást if (time2.Subtract(time1).TotalMilliseconds > 150) { break; } //User Input definiálása if (Console.KeyAvailable) { ConsoleKeyInfo mkeys = Console.ReadKey(true); if (mkeys.Key.Equals(ConsoleKey.UpArrow) && movement != "DOWN" && buttonpressed == "no") { movement = "UP"; buttonpressed = "yes"; } if (mkeys.Key.Equals(ConsoleKey.DownArrow) && movement != "UP" && buttonpressed == "no") { movement = "DOWN"; buttonpressed = "yes"; } if (mkeys.Key.Equals(ConsoleKey.LeftArrow) && movement != "RIGHT" && buttonpressed == "no") { movement = "LEFT"; buttonpressed = "yes"; } if (mkeys.Key.Equals(ConsoleKey.RightArrow) && movement != "LEFT" && buttonpressed == "no") { movement = "RIGHT"; buttonpressed = "yes"; } } } //Test mozgás xbody.Add(shead.xpos); ybody.Add(shead.ypos); //Mozgás switch (movement) { case "UP": shead.ypos--; break; case "DOWN": shead.ypos++; break; case "LEFT": shead.xpos--; break; case "RIGHT": shead.xpos++; break; } //A kígyó test utolsó elemének törlése minden update után (mozgás) if (xbody.Count() > score) { xbody.RemoveAt(0); ybody.RemoveAt(0); } } //Eredmény kiírása string mszoveg = "Game over! Pontszám: "; Console.SetCursorPosition((screenwidth / 2) - (mszoveg.Length / 2), screenheight / 2); Console.WriteLine(mszoveg + score); Console.SetCursorPosition(screenwidth / 2, screenheight / 2 + 1); Console.ReadKey(); }
//int num; public Effect(sprite setsp, Vector2 setsize, Vector2 setposition, int num) { sp = setsp; size = setsize; position = setposition; exist = true; num = 0; sw = new Stopwatch(); sw.Start(); }
/// <summary> /// プレイヤーコンストラクタ /// </summary> /// <param name="posi">プレイやを表示する位置</param> /// <param name="sprite">プレイヤーのテクスチャ</param> /// <param name="setsize">プレイヤーのサイズ</param> /// <param name="setHP">プレイヤーのヒットポイント</param> /// <param name="setspeed">プレイヤーのスピード</param> /// <param name="setzanki">プレイヤーの残機</param> public Player(Vector2 posi, sprite settexture, Vector2 setsize, int setHP, Vector2 setspeed, int setzanki) { shokiHP = setHP; shokiposition = posi; position = new Vector2(posi.X, posi.Y); sp = settexture; //うまくいかなかったらここ size = new Vector2(setsize.X, setsize.Y); HP = setHP; speed = setspeed * 3; exist = true; status = 1; level = 0; t = 0; sw1 = new Stopwatch(); swforstatus = new Stopwatch(); zanki = setzanki; }