示例#1
0
 public bool IsColliding(FloorTile floorTile)
 {
     if (hitbox.Intersects(floorTile.leftHitbox))
     {
         currentHitState = HitState.left;
         return true;
     }
     else if (hitbox.Intersects(floorTile.rightHitbox))
     {
         currentHitState = HitState.right;
         return true;
     }
     else
     {
         return false;
     }
 }
示例#2
0
 public void HandleCollision(FloorTile floorTile)
 {
     switch (currentHitState)
     {
         case HitState.top:
             isOnGround = true;
             speed.Y = 5.0f;
             speed.X = 0;
             hitbox.Y = floorTile.topHitbox.Y - hitbox.Height;
             pos.Y = hitbox.Y;
             break;
         case HitState.left:
             speed.X = 0;
             if (currentSprite == SpriteShow.slide)
             {
                 hitbox.X = (int)pos.X - 4;
             }
             else
             {
                 hitbox.X = (int)pos.X - 2;
             }
             pos.X = hitbox.X;
             break;
         case HitState.right:
             speed.X = 0;
             if (currentSprite == SpriteShow.slide)
             {
                 speed.X = 0;
                 hitbox.X = hitbox.X + 4;
             }
             else
             {
                 speed.X = 0;
                 hitbox.X = hitbox.X + 2;
             }
             pos.X = hitbox.X;
             break;
         case HitState.none:
             break;
     }
 }
 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;
     }
 }