コード例 #1
0
        public bool PixelCollition(Pengo pengo)
        {
            int top = Math.Max(hitbox.Top, pengo.hitbox.Top);
            int bottom = Math.Min(hitbox.Bottom, pengo.hitbox.Bottom);
            int left = Math.Max(hitbox.Left, pengo.hitbox.Left);
            int right = Math.Min(hitbox.Right, pengo.hitbox.Right);

            for (int y = top; y < bottom; y++)
            {
                for (int x = left; x < right; x++)
                {
                    Color colorA = texData[texture.Width * (y - hitbox.Y) + x - hitbox.X];
                    int index = pengo.texture.Width * (y - pengo.hitbox.Y + pengo.srcRect.Y) + x - pengo.hitbox.X + pengo.srcRect.X;
                    Color colorB = pengo.texData[index];
                    if (colorA.A + colorB.A > 256)
                    {
                        return true;
                    }
                }
            }
            return false;
        }
コード例 #2
0
 private void ObjectFactory(char objectChar, char option, int row, int col, int tileSize, Point startPos)
 {
     Vector2 pos = new Vector2(tileSize * col + startPos.X, tileSize * row + startPos.Y);
     switch (objectChar)
     {
         case 'F':
             FloorTile ft = new FloorTile(iceTile, pos);
             floortile.Add(ft);
             spriteBatchObjects.Add(ft);
             break;
         case 'S':
             pengoRespawnPos = pos;
             pengo = new Pengo(penguin, pos);
             spriteBatchObjects.Add(pengo);
             break;
         case 'W':
             WaterTile wt = new WaterTile(waterTile, pos);
             watertile.Add(wt);
             spriteBatchObjects.Add(wt);
             break;
         case 'T':
             Trap trp = new Trap(spike, pos);
             trap.Add(trp);
             spriteBatchObjects.Add(trp);
             break;
         case 'E':
             enemy = new Enemy(snowball, pos);
             spriteBatchObjects.Add(enemy);
             break;
         case 'L':
             Ladder ldr = new Ladder(ladderTile, pos);
             ladder.Add(ldr);
             spriteBatchObjects.Add(ldr);
             break;
         case 'M':
             OptionCollisionTile mt = new OptionCollisionTile(waterTile, pos, option, handleOptionDelegate);
             menuTiles.Add(mt);
             spriteBatchObjects.Add(mt);
             break;
         case 'B':
             int optionValue = option == '0' ? 0 : 1;
             backgrounds.EnableBackground(option * Convert.ToInt32(Math.Pow(2, col)));
             break;
     }
 }