public void SetSprite(int x, int y) { //Update the sprite Sprite = new Sprite(null, LocalArea.OffsetX + x * Tile.TileSizeX, LocalArea.OffsetY + y * Tile.TileSizeY, Tile.Bitmap, Tile.Rectangle, Tile.NumberOfFrames); }
public void SetObjectSprite(int x, int y) { //Update the sprite ObjectSprite = new Sprite(null, LocalArea.OffsetX + x * Tile.TileSizeX, LocalArea.OffsetY + y * Tile.TileSizeY, ObjectTile.Bitmap, ObjectTile.Rectangle, ObjectTile.NumberOfFrames); if (ObjectTile.IsTransparent) { ObjectSprite.ColorKey = Color.FromArgb(75, 75, 75); } }
public GameWorld(State gameState, Dictionary<string, Tile> tiles, string mapFile) { _gameState = gameState; _tiles = tiles; //Read in the map file readMapfile(mapFile); //Find the start point _currentArea = _world[_startArea]; //Create and position the hero character _heroPosition = new Point(3, 3); _heroSprite = new Sprite(null, _heroPosition.X * Tile.TileSizeX + LocalArea.OffsetX, _heroPosition.Y * Tile.TileSizeY + LocalArea.OffsetY, _tiles["sha"].Bitmap, _tiles["sha"].Rectangle, _tiles["sha"].NumberOfFrames); _heroSprite.Flip = true; _heroSprite.ColorKey = Color.FromArgb(75, 75, 75); }
private void Init() { InitDragon(); InitSkeleton(); InitZombie(); InitSpider(); initArrow(); mScore = 0; mGameOver = false; mCurrentTime = 0; mStartTime = -100; mGame = new Game(this.pictureBox1.Size.Width, this.pictureBox1.Size.Height); #region grass mGrass = mGame.LoadBitmap("grass.bmp"); #endregion #region dragon //make dragon sprite mDragon = new Sprite[2]; Bitmap dragonBmp = mGame.LoadBitmap("dragonflying.png");//图片的分辨率是200,宽度是 1024, 而画布(设备)的分辨率是 96 , 所以它在画布上的大小是 (1024/200)*96 = 492 //如果要保持 1024 像素宽度,则图片的分辨率要降为 96 dragonBmp.SetResolution(96, 96); Sprite dragonleft = new Sprite(mGame.Device); Sprite dragonright = new Sprite(mGame.Device); for (int i = 2; i < 7; i += 4) { Bitmap[] temp = new Bitmap[8]; for (int j = 0; j < 8; j++) { temp[j] = mGame.CutBitmap(ref dragonBmp, j * 128, i * 128, 128, 128); } if (i == 2) { dragonright.Bitmaps = temp; }else if (i == 6) { dragonleft.Bitmaps = temp; } } mDragon[0] = dragonleft; mDragon[0].play(); mDragon[1] = dragonright; mDragon[1].play(); #endregion #region spider //make spider sprite mSpider = new Sprite[2]; Bitmap spiderBmp = mGame.LoadBitmap("redspiderwalking.png"); spiderBmp.SetResolution(96, 96); Sprite spiderleft = new Sprite(mGame.Device); Sprite spiderright = new Sprite(mGame.Device); for (int i = 2; i < 7; i += 4) { Bitmap[] temp = new Bitmap[8]; for (int j = 0; j < 8; j++) { temp[j] = mGame.CutBitmap(ref spiderBmp, j * 96, i * 96, 96, 96); } if (i == 2) { spiderright.Bitmaps = temp; } else if (i == 6) { spiderleft.Bitmaps = temp; } } mSpider[0] = spiderleft; mSpider[0].play(); mSpider[1] = spiderright; mSpider[1].play(); #endregion #region skeleton //make skeleton sprite mSkeleton = new Sprite[2]; Bitmap skeletonBmp = mGame.LoadBitmap("skeleton_walk.png"); skeletonBmp.SetResolution(96, 96); Sprite skeletonleft = new Sprite(mGame.Device); Sprite skeletonright = new Sprite(mGame.Device); for (int i = 2; i < 7; i += 4)//行 { Bitmap[] temp = new Bitmap[9]; for (int j = 0; j < 9; j++)//列 { temp[j] = mGame.CutBitmap(ref skeletonBmp, j * 96, i * 96, 96, 96); } if (i == 2) { skeletonright.Bitmaps = temp; } else if (i == 6) { skeletonleft.Bitmaps = temp; } } mSkeleton[0] = skeletonleft; mSkeleton[0].play(); mSkeleton[1] = skeletonright; mSkeleton[1].play(); #endregion #region zombie //make zombie sprite mZombie = new Sprite[2]; Bitmap zombieBmp = mGame.LoadBitmap("zombie walk.png"); zombieBmp.SetResolution(96, 96); Sprite zombieleft = new Sprite(mGame.Device); Sprite zombieright = new Sprite(mGame.Device); for (int i = 2; i < 7; i += 4)//行 { Bitmap[] temp = new Bitmap[8]; for (int j = 0; j < 8; j++)//列 { temp[j] = mGame.CutBitmap(ref zombieBmp, j * 96, i * 96, 96, 96); } if (i == 2) { zombieright.Bitmaps = temp; } else if (i == 6) { zombieleft.Bitmaps = temp; } } mZombie[0] = zombieleft; mZombie[0].play(); mZombie[1] = zombieright; mZombie[1].play(); #endregion #region archer //make archer sprite mArcher = new Sprite[1]; Bitmap archerBmp = mGame.LoadBitmap("archer_attack.png"); archerBmp.SetResolution(96, 96); Sprite archer = new Sprite(mGame.Device); Bitmap[] archerTemp = new Bitmap[10]; for (int j = 0; j < 10; j++)//列 { archerTemp[j] = mGame.CutBitmap(ref archerBmp, j * 96, 0, 96, 96); } archer.Bitmaps = archerTemp; mArcher[0] = archer; mArcher[0].stop(); mArcher[0].X = 252; mArcher[0].Y = 450; #endregion #region arrow //make arrow bitmap //mArrow = mGame.CutBitmap("arrow.png", 0, 0, 32, 32); Bitmap arrowBmp = mGame.LoadBitmap("arrow.png"); arrowBmp.SetResolution(96, 96); Bitmap[] bmp = new Bitmap[1]; bmp[0] = mGame.CutBitmap(ref arrowBmp, 0, 0, 32, 32); mArrow = new Sprite(mGame.Device, bmp); mArrow.X = mArrowX; mArrow.Y = mArrowY; #endregion }
public static bool Collision(Sprite sprite1, Sprite sprite2) { //See if the sprite rectangles overlap return ! ( sprite1.Location.X > sprite2.Location.X + sprite2.Size.Width || sprite1.Location.X + sprite1.Size.Width < sprite2.Location.X || sprite1.Location.Y > sprite2.Location.Y + sprite2.Size.Height || sprite1.Location.Y + sprite1.Size.Height < sprite2.Location.Y); }
public bool IsColliding(ref Sprite other) { return Bounds.IntersectsWith(other.Bounds); }
private void Init() { mGameOver = false; mCurrentTime = 0; mStartTime = -100; mDirection = 0; mPos = new PointF(0, 0); mSpeed = new Point(0, 0); mDragon = new Sprite[4]; mGame = new Game(this.pictureBox1.Size.Width, this.pictureBox1.Size.Height); mGrass = mGame.LoadBitmap("grass.bmp"); Bitmap dragonBmp = mGame.LoadBitmap("dragon.png"); #region test bitmap /* Bitmap temp = new Bitmap(256, 256); Graphics g = Graphics.FromImage(temp); g.DrawImage(dragonBmp,0,0,new Rectangle(256,256,256,256),GraphicsUnit.Pixel); game.DrawBitmap(ref temp); */ #endregion Sprite dragonup = new Sprite(mGame.Device); Sprite dragondown = new Sprite(mGame.Device); Sprite dragonleft = new Sprite(mGame.Device); Sprite dragonright = new Sprite(mGame.Device); for (int i = 0; i < 8; i += 2) { Bitmap[] temp = new Bitmap[8]; for (int j = 0; j < 8; j++) { temp[j] = mGame.CutBitmap(ref dragonBmp, j*256, i*256, 256, 256); } if (i == 0) { dragonup.Bitmaps = temp; } else if (i == 2) { dragonright.Bitmaps = temp; } else if (i == 4) { dragondown.Bitmaps = temp; } else if (i == 6) { dragonleft.Bitmaps = temp; } } mDragon[0] = dragonup; mDragon[0].play(); mDragon[1] = dragonleft; mDragon[1].play(); mDragon[2] = dragondown; mDragon[2].play(); mDragon[3] = dragonright; mDragon[3].play(); #region dragon test /*dragon[0].X = 50; dragon[0].Y = 50; dragon[0].play(); dragon[0].update();*/ #endregion }