- Timestamp:
- 2012-07-06 02:01:31 (11 years ago)
- Location:
- 2012/27/DenisZ/TheDungeonGame
- Files:
-
- 47 added
- 1 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/Entity.cs
r3596 r3624 10 10 { 11 11 protected TheDungeonGame game; 12 p rotected int health;12 public int health, damage; 13 13 14 14 public EntityBase(TheDungeonGame game, Vector pos, Vector size, Shape shape) … … 18 18 Tag = "Enemy"; 19 19 Position = pos; 20 Collided += collided; 20 21 } 21 22 22 23 public virtual void init() { } 24 25 protected void collided(IPhysicsObject entity, IPhysicsObject target) 26 { 27 if (target.Tag.Equals("Player")) 28 { 29 Player player = (Player)target; 30 player.hit(damage); 31 } 32 } 23 33 24 34 public void hideEntity() … … 41 51 } 42 52 43 public v oidhit(int damage)53 public virtual bool hit(int damage) 44 54 { 45 55 health -= damage; 46 56 if (health <= 0) 57 { 47 58 Destroy(); 59 return true; 60 } 61 return false; 62 48 63 } 49 64 -
2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/EntityTemplates.cs
r3596 r3624 8 8 namespace Entity 9 9 { 10 public class Entities 11 { 12 public static EntityFly fly = new EntityFly((TheDungeonGame)TheDungeonGame.Instance, Vector.Zero, new Vector(40, 40), Shape.Circle); 13 public static EntityBase[] entities = { fly }; 14 } 15 16 17 public class TestEntity : EntityBase 18 { 19 public TestEntity(TheDungeonGame game, Vector pos, Vector size, Shape shape) 20 : base(game, pos, size, shape) 21 { 10 public class EntityFly : EntityBase 11 { 12 public EntityFly(TheDungeonGame game, Vector pos, Vector size, Shape shape) 13 : base(game, pos, size, shape) 14 { 15 damage = 1; 16 FollowerBrain brains = new FollowerBrain(game.Player, 100); 17 Brain = brains; 18 Brain.Active = false; 19 CollisionIgnoreGroup = CollisionGroups.Rocks; 20 Image[] frames = new Image[3]; 21 for (int i = 0; i < frames.Length; i++) 22 { 23 frames[i] = TheDungeonGame.LoadImage("animations/fly/fly" + (i + 1)); 24 } 25 Animation animation = new Animation(frames); 26 animation.FPS = 30; 27 Animation = animation; 28 Animation.Start(); 29 CanRotate = false; 22 30 } 23 31 24 32 public override void init() 25 33 { 26 //throw new NotImplementedException(); 27 } 28 } 29 30 public class EntityFly : EntityBase 31 { 32 public EntityFly(TheDungeonGame game, Vector pos, Vector size, Shape shape) 33 : base(game, pos, size, shape) 34 { 34 35 } 36 37 } 38 39 public class EntityZombie : EntityBase 40 { 41 public EntityZombie(TheDungeonGame game, Vector pos, Vector size, Shape shape) 42 : base(game, pos, size, shape) 43 { 44 damage = 2; 45 Color = Color.Red; 35 46 Brain = new FollowerBrain(game.Player, 100); 36 47 Brain.Active = false; 48 CanRotate = false; 49 50 Image[] frames = new Image[4]; 51 for (int i = 0; i < frames.Length - 1; i++) 52 { 53 frames[i] = TheDungeonGame.LoadImage("animations/zombie/frame" + (i + 1)); 54 } 55 frames[3] = TheDungeonGame.LoadImage("animations/zombie/frame2"); 56 Animation animation = new Animation(frames); 57 animation.FPS = 8; 58 Animation = animation; 59 Animation.Start(); 60 } 61 } 62 63 public class EntityDerpFace : EntityBase 64 { 65 public EntityDerpFace(TheDungeonGame game, Vector pos, Vector size, Shape shape) 66 : base(game, pos, size, shape) 67 { 68 damage = 2; 69 Color = Color.Green; 70 RandomMoverBrain brains = new RandomMoverBrain(10000); 71 brains.ChangeMovementSeconds = 0.5; 72 Brain = brains; 73 Brain.Active = false; 74 CanRotate = false; 75 76 Image[] frames = new Image[2]; 77 for (int i = 0; i < frames.Length; i++) 78 { 79 frames[i] = TheDungeonGame.LoadImage("animations/zombie2/frame" + (i + 1)); 80 } 81 Animation animation = new Animation(frames); 82 animation.FPS = 8; 83 Animation = animation; 84 Animation.Start(); 85 } 86 } 87 88 public class EntityDerpFly : EntityBase 89 { 90 public EntityDerpFly(TheDungeonGame game, Vector pos, Vector size, Shape shape) 91 : base(game, pos, size, shape) 92 { 93 damage = 1; 94 Color = Color.Blue; 95 RandomMoverBrain brains = new RandomMoverBrain(10000); 96 brains.ChangeMovementSeconds = 0.5; 97 Brain = brains; 98 Brain.Active = false; 37 99 CollisionIgnoreGroup = CollisionGroups.Rocks; 38 } 39 40 public override void init() 41 { 42 43 } 44 45 } 100 101 Image[] frames = new Image[3]; 102 for (int i = 0; i < frames.Length; i++) 103 { 104 frames[i] = TheDungeonGame.LoadImage("animations/fly2/fly" + (i + 1)); 105 } 106 Animation animation = new Animation(frames); 107 animation.FPS = 30; 108 Animation = animation; 109 Animation.Start(); 110 CanRotate = false; 111 } 112 } 113 114 115 public class EntityBossMario : EntityBase 116 { 117 private FollowerBrain followerBrain; 118 private RandomMoverBrain randomBrain; 119 private Timer brainTimer, randomMoveTimer; 120 private bool isPowerUpped = false; 121 private bool usedTurtles = false; 122 private double followingSpeed, randomSpeed; 123 124 private Image[] normalWalking = new Image[2]; 125 private Image marioIdle, marioAttack; 126 private Image[] powerupWalking = new Image[2]; 127 private Image marioPowerupIdle, marioPowerupAttack; 128 private Image turtleTexture, turtleTexturePowerup; 129 130 private Animation normalWalkingAnimation, powerupWalkingAnimation; 131 132 public EntityBossMario(TheDungeonGame game, Vector pos, Vector size, Shape shape) 133 : base(game, pos, size, shape) 134 { 135 damage = 1; 136 health = 75; 137 followingSpeed = 150; 138 randomSpeed = 10000; 139 brainTimer = new Timer(); 140 brainTimer.Interval = 5; 141 brainTimer.Timeout += changeBrains; 142 randomMoveTimer = new Timer(); 143 randomMoveTimer.Interval = 3; 144 randomMoveTimer.Timeout += perfomAttack1; 145 146 for (int i = 0; i < normalWalking.Length; i++) 147 { 148 normalWalking[i] = TheDungeonGame.LoadImage("animations/mario/normal/walk" + (i + 1)); 149 powerupWalking[i] = TheDungeonGame.LoadImage("animations/mario/powerup/walk" + (i + 1)); 150 } 151 marioIdle = TheDungeonGame.LoadImage("animations/mario/normal/idle"); 152 marioAttack = TheDungeonGame.LoadImage("animations/mario/normal/attack"); 153 marioPowerupIdle = TheDungeonGame.LoadImage("animations/mario/powerup/normal"); 154 marioPowerupAttack = TheDungeonGame.LoadImage("animations/mario/powerup/attack"); 155 turtleTexture = TheDungeonGame.LoadImage("animations/mario/turtle/turtle"); 156 turtleTexturePowerup = TheDungeonGame.LoadImage("animations/mario/turtle/poweredTurtle"); 157 normalWalkingAnimation = new Animation(normalWalking); 158 normalWalkingAnimation.FPS = 10; 159 powerupWalkingAnimation = new Animation(powerupWalking); 160 powerupWalkingAnimation.FPS = 10; 161 162 followerBrain = new FollowerBrain(game.Player, followingSpeed); 163 followerBrain.TargetCloseDistance = 100.0; 164 followerBrain.TargetClose += delegate { spawnDyingTurtles(5); }; 165 randomBrain = new RandomMoverBrain(randomSpeed); 166 randomBrain.ChangeMovementSeconds = 0.8; 167 168 Brain = randomBrain; 169 Brain.Active = true; 170 CanRotate = false; 171 Animation = normalWalkingAnimation; 172 Animation.Start(); 173 brainTimer.Start(); 174 Collided += collided; 175 } 176 177 public override void Destroy() 178 { 179 base.Destroy(); 180 brainTimer.Stop(); 181 randomMoveTimer.Stop(); 182 game.gui.destroyBossGauge(); 183 } 184 185 public override bool hit(int damage) 186 { 187 if (health <= 35 && !isPowerUpped) 188 upgradeMario(); 189 game.gui.bossHealth.Value -= damage; 190 return base.hit(damage); 191 } 192 193 private void upgradeMario() 194 { 195 Console.WriteLine("Upgrading..."); 196 if (isPowerUpped) return; 197 198 damage = 2; 199 isPowerUpped = true; 200 Animation = powerupWalkingAnimation; 201 Animation.Start(); 202 randomMoveTimer = new Timer(); 203 randomMoveTimer.Interval = 3; 204 randomMoveTimer.Timeout += perfomAttack2; 205 followingSpeed = 220; 206 randomSpeed = 1500; 207 } 208 209 private void changeBrains() 210 { 211 usedTurtles = false; 212 if (Brain == followerBrain) 213 { 214 Brain.Active = false; 215 randomBrain = new RandomMoverBrain(randomSpeed); 216 randomBrain.ChangeMovementSeconds = 0.8; 217 Brain = randomBrain; 218 Brain.Active = true; 219 randomMoveTimer.Start(); 220 } 221 else if (Brain == randomBrain) 222 { 223 Brain.Active = false; 224 randomMoveTimer.Stop(); 225 followerBrain = new FollowerBrain(game.Player, followingSpeed); 226 followerBrain.TargetCloseDistance = 100.0; 227 followerBrain.TargetClose += delegate { spawnDyingTurtles(5); }; 228 Brain = followerBrain; 229 Brain.Active = true; 230 } 231 } 232 233 private void turtleCollided(IPhysicsObject turtle, IPhysicsObject target) 234 { 235 if (target.Tag.Equals("Player")) 236 { 237 Player player = (Player)target; 238 if (isPowerUpped) 239 player.hit(2); 240 else player.hit(1); 241 } 242 } 243 244 private void perfomAttack1() 245 { 246 Animation = null; 247 Brain.Active = false; 248 Stop(); 249 if (isPowerUpped) 250 Image = marioPowerupAttack; 251 else Image = marioAttack; 252 Timer idleTimer = new Timer(); 253 idleTimer.Interval = 1.0; 254 idleTimer.TimesLimited = true; 255 idleTimer.Times.Value = 1; 256 idleTimer.Timeout += delegate 257 { 258 Image = null; 259 if (isPowerUpped) Animation = powerupWalkingAnimation; 260 else Animation = normalWalkingAnimation; 261 spawnDyingTurtles(10); 262 Brain.Active = true; 263 }; 264 idleTimer.Start(); 265 } 266 267 private void perfomAttack2() 268 { 269 Animation = null; 270 Brain.Active = false; 271 Stop(); 272 Image = marioPowerupAttack; 273 Timer idleTimer = new Timer(); 274 idleTimer.Interval = 1.0; 275 idleTimer.TimesLimited = true; 276 idleTimer.Times.Value = 1; 277 idleTimer.Timeout += delegate 278 { 279 Image = null; 280 Animation = powerupWalkingAnimation; 281 spawnDyingTurtles(15); 282 Brain.Active = true; 283 }; 284 idleTimer.Start(); 285 } 286 287 private void spawnDyingTurtles(int amount) 288 { 289 if (usedTurtles) return; 290 291 int turtleAmount = amount; 292 for (int i = 0; i < turtleAmount; i++) 293 { 294 PhysicsObject turtle = new PhysicsObject(50, 50); 295 turtle.Position = Position + RandomGen.NextVector(-20, 20); 296 if (isPowerUpped) 297 turtle.Image = turtleTexturePowerup; 298 else turtle.Image = turtleTexture; 299 turtle.LifetimeLeft = TimeSpan.FromSeconds(3); 300 turtle.Hit(RandomGen.NextVector(-300, 300)); 301 turtle.Collided += turtleCollided; 302 game.Add(turtle, 3); 303 } 304 usedTurtles = true; 305 } 306 } 307 46 308 } -
2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/InGameGui.cs
r3563 r3624 5 5 using Jypeli; 6 6 using Jypeli.Widgets; 7 using Entity; 7 8 8 9 namespace Gui … … 12 13 private TheDungeonGame game; 13 14 private Widget inventoryItem; 15 public IntMeter bossHealth; 16 private BarGauge bossMeterBar; 14 17 15 18 public InGameGui(TheDungeonGame game) 16 : base(TheDungeonGame.Screen.Width, TheDungeonGame.Screen.Height - (TheDungeonGame.ROOMHEIGHT +TheDungeonGame.ROOMTHICKNESS), Shape.Rectangle)19 : base(TheDungeonGame.Screen.Width, TheDungeonGame.Screen.Height - (TheDungeonGame.ROOMHEIGHT + TheDungeonGame.ROOMTHICKNESS), Shape.Rectangle) 17 20 { 18 21 this.game = game; … … 22 25 setupTexts(); 23 26 setupHealthMeter(); 24 setupInventory();27 // setupInventory(); 25 28 } 26 29 … … 42 45 healthAmount.TextColor = Color.Red; 43 46 healthAmount.TextScale = new Vector(1.5, 1.5); 44 healthAmount.Right = Right - 30;47 healthAmount.Right = Right - 40; 45 48 46 49 Add(healthAmount); 47 50 48 51 Image heartTexture = TheDungeonGame.LoadImage("gui/heart"); 49 Widget heartImage = new Widget(heartTexture.Width /4, heartTexture.Height/4);52 Widget heartImage = new Widget(heartTexture.Width / 4, heartTexture.Height / 4); 50 53 heartImage.Image = heartTexture; 51 heartImage.Right = healthAmount.Right - 30;54 heartImage.Right = healthAmount.Right - 50; 52 55 53 56 Add(heartImage); … … 65 68 inventoryItem = new Widget(64, 64); 66 69 setInventoryImage(game.Player.ItemInInventory); 67 inventoryItem.Right = itemText.Right +itemText.Width/4;68 inventoryItem.Top = itemText.Top -20;70 inventoryItem.Right = itemText.Right + itemText.Width / 4; 71 inventoryItem.Top = itemText.Top - 20; 69 72 inventoryItem.Color = Color.Transparent; 70 73 inventoryItem.BorderColor = Color.DarkGray; … … 81 84 } 82 85 86 public void setupBossGauge(EntityBase entity) 87 { 88 bossHealth = new IntMeter(entity.health, 0, entity.health); 89 90 bossMeterBar = new BarGauge(20, TheDungeonGame.Screen.Width / 4); 91 bossMeterBar.Angle = Angle.FromDegrees(270); 92 bossMeterBar.Color = Color.Red; 93 bossMeterBar.BarColor = Color.Green; 94 bossMeterBar.BorderColor = Color.White; 95 bossMeterBar.BindTo(bossHealth); 96 Add(bossMeterBar); 97 } 98 99 public void destroyBossGauge() 100 { 101 if (bossMeterBar != null) 102 bossMeterBar.Destroy(); 103 } 83 104 } 84 105 } -
2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/ItemEntity.cs
r3563 r3624 17 17 Tag = "Item"; 18 18 bindedItem = item; 19 Image = bindedItem.itemTexture; 20 CanRotate = false; 21 CollisionIgnoreGroup = CollisionGroups.Rocks; 19 22 } 20 23 } -
2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/ObjectDoor.cs
r3596 r3624 9 9 public class ObjectDoor : PhysicsObject 10 10 { 11 public bool IsLocked { get; set; } 11 private bool locked; 12 public bool IsLocked 13 { 14 get 15 { 16 return locked; 17 } 18 set 19 { 20 if (locked == value) return; 21 22 locked = value; 23 SoundEffect sound; 24 if (value == true) 25 sound = TheDungeonGame.soundEffects[0]; 26 else 27 sound = TheDungeonGame.soundEffects[1]; 28 29 sound.Play(); 30 } 31 } 12 32 13 33 public ObjectDoor(double width, double height) -
2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/Player.cs
r3598 r3624 9 9 using Jypeli.Assets; 10 10 using Items; 11 using Jypeli.Widgets; 11 12 12 13 namespace Entity … … 23 24 private TheDungeonGame game; 24 25 public Room currentRoom; 25 public IntMeter playerHealth = new IntMeter(5, 0, 30);26 public IntMeter playerHealth; 26 27 private Item itemInInventory; 27 28 private AssaultRifle weapon; … … 32 33 private Angle LeftAngle = Angle.FromDegrees(180); 33 34 35 public bool isDead = false; 36 37 private Image[] walkingImages = new Image[2]; 38 private Image idleTexture; 39 private Animation walkingAnimation; 40 private bool isAnimationRunning = false; 41 34 42 public Player(TheDungeonGame game, Vector pos, Image texture) 35 43 : base(playerWidth, playerHeight) 36 44 { 45 playerHealth = new IntMeter(10, 0, 50); 37 46 this.game = game; 38 47 keyboard = game.Keyboard; 39 48 CanRotate = false; 40 49 setupKeys(); 41 Image = texture; 42 itemInInventory = new TestItem(TheDungeonGame.LoadImage("items/testItem"), "Test Item", false); 50 idleTexture = texture; 51 Image = idleTexture; 52 for (int i = 0; i < walkingImages.Length; i++) 53 { 54 walkingImages[i] = TheDungeonGame.LoadImage("animations/player/walk" + (i + 1)); 55 } 56 walkingAnimation = new Animation(walkingImages); 57 walkingAnimation.FPS = 10; 43 58 Tag = "Player"; 44 59 } 60 61 public void setupWeapon() 62 { 45 63 weapon = new AssaultRifle(playerWidth / 3, playerHeight / 3); 46 64 weapon.Top = Top; … … 52 70 weapon.TimeBetweenUse = TimeSpan.FromSeconds(0.4); 53 71 weapon.ProjectileCollision = bulletCollided; 72 WeaponDamage = 1; 54 73 Add(weapon); 74 } 75 76 public void resetValues() 77 { 78 playerHealth = new IntMeter(10, 0, 50); 79 WeaponDamage = 1; 80 WeaponSpeed = TimeSpan.FromSeconds(0.4); 81 BulletLife = TimeSpan.FromSeconds(0.5); 82 isDead = false; 83 Animation = null; 84 isAnimationRunning = false; 85 Image = idleTexture; 55 86 } 56 87 … … 72 103 keyboard.Listen(Key.Left, ButtonState.Down, shootAmmo, "Shoot up", LeftAngle); 73 104 74 keyboard.Listen(Key.Space, ButtonState.Pressed, useItemInInventory, "Use Item");105 // keyboard.Listen(Key.Space, ButtonState.Pressed, useItemInInventory, "Use Item"); 75 106 } 76 107 77 108 private void bulletCollided(PhysicsObject collidingObject, PhysicsObject targetObject) 78 109 { 110 collidingObject.IsVisible = true; 79 111 if (targetObject.Tag.Equals("Enemy")) 80 112 { 81 113 EntityBase entity = (EntityBase)targetObject; 82 entity.hit(WeaponDamage); 114 if (entity.hit(WeaponDamage)) 115 currentRoom.EntityAmount--; 83 116 collidingObject.Destroy(); 84 currentRoom.EntityAmount--; 85 } 86 else if (targetObject.Tag.Equals("Wall") || targetObject.Tag.Equals("ObjectRock")) 117 } 118 else if (targetObject.Tag.Equals("Wall") || targetObject.Tag.Equals("ObjectRock") || targetObject.Tag.Equals("Item")) 87 119 collidingObject.Destroy(); 120 } 121 122 public void hit(int damage) 123 { 124 playerHealth.Value -= damage; 125 if (playerHealth.Value <= 0) 126 { 127 showLostScreen(); 128 } 129 130 } 131 132 public void showLostScreen() 133 { 134 if (isDead) return; 135 isDead = true; 136 string[] buttonNames = {"Retry", "Exit Game"}; 137 keyboard.DisableAll(); 138 MultiSelectWindow lostWindow = new MultiSelectWindow("Oh noes! You appear to be dead! \nBut, you can always start a new journey...", buttonNames); 139 lostWindow.AddItemHandler(0, game.restartGame); 140 lostWindow.AddItemHandler(1, game.Exit); 141 game.Add(lostWindow); 88 142 } 89 143 … … 121 175 { 122 176 weapon.Angle = angle; 123 weapon.Shoot(); 177 PhysicsObject bullet = weapon.Shoot(); 178 if (bullet != null) 179 bullet.IsVisible = true; 124 180 } 125 181 … … 196 252 movementVector = Vector.Zero; 197 253 Stop(); 254 198 255 } 199 256 200 257 isMoving = false; 201 258 202 Console.WriteLine(currentRoom.EntityAmount);203 204 259 if (currentRoom.EntityAmount == 0) 205 260 { 206 for each (ObjectDoor door in currentRoom.doors)261 for(int i = 0; i < 4; i++) 207 262 { 208 if (door != null) 209 door.IsLocked = false; 263 if (currentRoom.doors[i] == null) continue; 264 currentRoom.doors[i].IsLocked = false; 265 currentRoom.setDoorTexture(game.objectTextures[1], i); 210 266 } 211 267 } 212 268 else 213 269 { 214 foreach (ObjectDoor door in currentRoom.doors) 215 { 216 if (door != null) 217 door.IsLocked = true; 218 } 270 for (int i = 0; i < 4; i++) 271 { 272 if (currentRoom.doors[i] == null) continue; 273 currentRoom.doors[i].IsLocked = true; 274 currentRoom.setDoorTexture(game.objectTextures[0], i); 275 } 219 276 } 220 277 … … 229 286 if (vec.Y != 0) 230 287 movementVector.Y = vec.Y; 231 288 if (!isAnimationRunning) 289 { 290 Animation = walkingAnimation; 291 Animation.Start(); 292 isAnimationRunning = true; 293 } 232 294 Move(movementVector); 233 295 isMoving = true; … … 237 299 { 238 300 movementVector = VecMath.sub(movementVector, vec); 301 Animation = null; 302 isAnimationRunning = false; 303 Image = idleTexture; 239 304 } 240 305 } -
2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/Room.cs
r3596 r3624 27 27 public PhysicsObject wall; 28 28 public int EntityAmount { get; set; } 29 public String roomName; 29 30 30 31 public Room(TheDungeonGame game, Vector pos, Vector size, double thickness) … … 45 46 46 47 insideObjects = new PhysicsObject[bWidth, bHeight]; 48 roomName = "Basic Room"; 47 49 } 48 50 … … 54 56 while (entitiesSpawned < entityAmount) 55 57 { 56 EntityBase entity = RoomCreator.getEntity(Entities.entities.Length-1);57 58 59 58 EntityBase entity = RoomCreator.getEntity(RandomGen.NextInt(4)); 59 if (!addEntityAt(entity, RandomGen.NextInt(bWidth - 2) + 1, RandomGen.NextInt(bHeight - 2) + 1)) 60 continue; 61 entitiesSpawned++; 60 62 } 61 63 //for (int i = 0; i < entityAmount; i++) … … 71 73 int level = Game.LevelGen.level; 72 74 createBorders(Game.getTopBottomWall(level), Game.getLeftRightWall(level)); 73 addDoors( Game.objectTextures[0]);75 addDoors(); 74 76 roomDecorations.Add(createBackground(Game.getLevelBackground(level))); 75 77 } … … 97 99 else Game.Add(obj, 1); 98 100 } 99 101 100 102 } 101 103 … … 140 142 { 141 143 if (obj != null) 142 obj.IsVisible = false; 144 obj.IsVisible = false; 143 145 } 144 146 } … … 160 162 { 161 163 if (obj != null) 162 obj.IsVisible = true; 164 obj.IsVisible = true; 163 165 } 164 166 } … … 220 222 } 221 223 224 public IPhysicsObject getEntityAt(int bx, int by) 225 { 226 if (bx >= bWidth || bx < 0 || by >= bHeight || by < 0) return null; 227 return insideObjects[bx, by]; 228 } 229 222 230 public void deleteBlock(int bx, int by) 223 231 { … … 228 236 229 237 // En vitsinyt käyttää enempää aikaa tämän parantamiseksi. Helppo ja toimiva 230 public void addDoors(Image doorTexture) 231 { 238 public void addDoors() 239 { 240 Image doorTexture = Game.objectTextures[1]; 232 241 for (int i = 0; i < 4; i++) 233 242 { … … 242 251 door = new ObjectDoor(thickness, thickness); 243 252 door.Position = Position + new Vector((width + thickness) / 2, -thickness / 2); 244 door.Image = doorTexture;245 253 door.Tag = RoomDirection.North; 246 254 } 247 else 248 if (i == RoomDirection.East) 249 { 250 door = new ObjectDoor(thickness, thickness); 251 door.Position = Position + new Vector(width + thickness / 2, -(height + thickness) / 2); 252 door.Image = doorTexture; 253 door.Angle = Angle.FromDegrees(270); 254 door.Tag = RoomDirection.East; 255 } 256 else 257 if (i == RoomDirection.South) 258 { 259 door = new ObjectDoor(thickness, thickness); 260 door.Position = Position + new Vector((thickness + width) / 2, -height - thickness / 2); 261 door.Image = Image.Flip(doorTexture); 262 door.Tag = RoomDirection.South; 263 } 264 else 265 if (i == RoomDirection.West) 266 { 267 door = new ObjectDoor(thickness, thickness); 268 door.Position = Position + new Vector(thickness / 2, -height / 2 - thickness / 2); 269 door.Image = doorTexture; 270 door.Angle = Angle.FromDegrees(90); 271 door.Tag = RoomDirection.West; 272 } 255 else if (i == RoomDirection.East) 256 { 257 door = new ObjectDoor(thickness, thickness); 258 door.Position = Position + new Vector(width + thickness / 2, -(height + thickness) / 2); 259 door.Tag = RoomDirection.East; 260 } 261 else if (i == RoomDirection.South) 262 { 263 door = new ObjectDoor(thickness, thickness); 264 door.Position = Position + new Vector((thickness + width) / 2, -height - thickness / 2); 265 door.Tag = RoomDirection.South; 266 } 267 else if (i == RoomDirection.West) 268 { 269 door = new ObjectDoor(thickness, thickness); 270 door.Position = Position + new Vector(thickness / 2, -height / 2 - thickness / 2); 271 door.Tag = RoomDirection.West; 272 } 273 273 if (door != null) 274 274 { 275 275 roomObjects.Add(door); 276 276 doors[i] = door; 277 } 278 279 } 280 } 281 282 public PhysicsObject getDoor(int dir) 283 { 284 PhysicsObject result = null; 277 setDoorTexture(doorTexture, i); 278 } 279 280 } 281 } 282 283 public void setDoorTexture(Image tex, int dir) 284 { 285 ObjectDoor door = getDoor(dir); 286 287 if (door == null) return; 288 289 Room room = Game.LevelGen.getRoomAt(PosOnGrid + RoomDirection.getOffsetFromDir(dir)); 290 if (room.roomName == "Boss Room") 291 door.Image = Game.objectTextures[2]; 292 else door.Image = tex; 293 door.Angle = RoomDirection.getAngleFromDir(dir); 294 } 295 296 public ObjectDoor getDoor(int dir) 297 { 298 ObjectDoor result = null; 285 299 for (int i = 0; i < doors.Length; i++) 286 300 { 287 PhysicsObjectdoor = doors[i];301 ObjectDoor door = doors[i]; 288 302 if (door != null && (int)door.Tag == dir) 289 303 { … … 291 305 return result; 292 306 } 293 294 307 } 295 308 return result; … … 346 359 public const int West = 3; 347 360 361 public static Angle NorthAngle = Angle.Zero; 362 public static Angle EastAngle = Angle.FromDegrees(270); 363 public static Angle SouthAngle = Angle.FromDegrees(180); 364 public static Angle WestAngle = Angle.FromDegrees(90); 365 348 366 public static Vector getOffsetFromDir(int dir) 349 367 { … … 360 378 } 361 379 380 public static Angle getAngleFromDir(int dir) 381 { 382 if (dir == North) 383 return NorthAngle; 384 else if (dir == East) 385 return EastAngle; 386 else if (dir == South) 387 return SouthAngle; 388 else if (dir == West) 389 return WestAngle; 390 391 return Angle.Zero; 392 } 393 362 394 public static Vector getOffsetFromWorldDir(int dir) 363 395 { -
2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/RoomTemplates.cs
r3596 r3624 20 20 { 21 21 createLevelDecorations(); 22 23 22 24 } 23 25 } … … 39 41 addBlock(new ObjectRock(blockWidth, blockHeight), bWidth - 1, bHeight - 1, new Vector(0, -50)); 40 42 41 spawnRandomEntities( 5);43 spawnRandomEntities(RandomGen.NextInt(6)+1); 42 44 } 43 45 } … … 64 66 } 65 67 66 spawnRandomEntities( 5);68 spawnRandomEntities(RandomGen.NextInt(6) + 1); 67 69 } 68 70 } … … 99 101 } 100 102 101 spawnRandomEntities( 5);103 spawnRandomEntities(RandomGen.NextInt(6) + 1); 102 104 } 103 105 } … … 123 125 } 124 126 125 spawnRandomEntities( 5);127 spawnRandomEntities(RandomGen.NextInt(6) + 1); 126 128 } 127 129 } … … 147 149 148 150 deleteBlock(bWidth / 2 - 1, bHeight / 2); 149 spawnRandomEntities( 5);151 spawnRandomEntities(RandomGen.NextInt(6) + 1); 150 152 } 151 153 } … … 169 171 } 170 172 171 spawnRandomEntities( 5);173 spawnRandomEntities(RandomGen.NextInt(6) + 1); 172 174 } 173 175 } … … 178 180 : base(game, pos, size, thickness) 179 181 { 180 } 181 182 public override void initRoom() 183 { 184 createLevelDecorations(); 182 roomName = "Boss Room"; 183 } 184 185 public override void initRoom() 186 { 187 createLevelDecorations(); 188 189 addEntityAt(new EntityBossMario(Game, Vector.Zero, new Vector(30, 60), Shape.Rectangle), 3, 3); 185 190 } 186 191 } … … 216 221 if (id == 0) 217 222 ent = new EntityFly((TheDungeonGame)TheDungeonGame.Instance, Vector.Zero, new Vector(50, 50), Shape.Circle); 223 else if(id == 1) 224 ent = new EntityZombie((TheDungeonGame)TheDungeonGame.Instance, Vector.Zero, new Vector(60, 60), Shape.Rectangle); 225 else if(id == 2) 226 ent = new EntityDerpFace((TheDungeonGame)TheDungeonGame.Instance, Vector.Zero, new Vector(60, 60), Shape.Circle); 227 else if(id == 3) 228 ent = new EntityDerpFly((TheDungeonGame)TheDungeonGame.Instance, Vector.Zero, new Vector(50, 50), Shape.Circle); 229 //else if(id == 4) 230 // ent = new EntityDerpPistolZombie((TheDungeonGame)TheDungeonGame.Instance, Vector.Zero, new Vector(50, 50), Shape.Circle); 218 231 return ent; 219 232 } -
2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/TheDungeonGame.cs
r3596 r3624 32 32 public List<Image> levelBackGrounds = new List<Image>(); 33 33 public List<Image> objectTextures = new List<Image>(); 34 public static List<SoundEffect> soundEffects = new List<SoundEffect>(); 34 35 public InGameGui gui; 36 public static MediaPlayer soundPlayer; 35 37 36 38 public override void Begin() … … 38 40 IsMouseVisible = true; 39 41 SetWindowSize(800, 600); 42 showMainMenu(); 43 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Lopeta peli"); 44 } 45 46 private void showMainMenu() 47 { 48 MultiSelectWindow menu = new MultiSelectWindow("Welcome to: \nThe Dungeon Game!",new string[]{"Play!", "Exit"}); 49 menu.AddItemHandler(0, initGame); 50 menu.AddItemHandler(1, Exit); 51 Add(menu); 52 } 53 54 private void initGame() 55 { 40 56 Level.Width = ROOMWIDTH * 20; 41 57 Level.Height = ROOMHEIGHT * 20; 42 58 setupLevelTextures(1); 43 59 setupObjectTextures(); 60 setupSoundEffects(); 61 soundPlayer = MediaPlayer; 44 62 45 63 player = new Player(this, Vector.Zero, playerPic); 46 64 player.setupWeapon(); 65 47 66 generator = new LevelGenerator(this, Level.Size, new Vector(20, 20)); 48 67 generator.generateRandomLevel(10, 20); 49 68 generator.initDungeon(); 50 69 setupCamera(); 51 // Camera.Zoom(0.5);52 70 setupPlayer(); 53 54 71 72 gui = new InGameGui(this); 73 Add(gui); 74 55 75 AddCollisionHandler(player, player.performCollision); 56 76 AddCollisionHandler(player, "Item", player.handleItemPickup); 57 77 58 59 gui = new InGameGui(this); 60 Add(gui); 61 62 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Lopeta peli"); 63 Keyboard.Listen(Key.R, ButtonState.Pressed, regenerateLevel, null); 78 79 Keyboard.Listen(Key.R, ButtonState.Pressed, restartGame, null); 80 } 81 82 private void setupSoundEffects() 83 { 84 soundEffects.Add(LoadSoundEffect("sound/door_close")); 85 soundEffects.Add(LoadSoundEffect("sound/door_open")); 64 86 } 65 87 … … 68 90 for (int i = 1; i <= levels; i++) 69 91 { 70 levelTopBottoms.Add(LoadImage("level" +i+"/topBottom"));71 levelLeftRights.Add(LoadImage("level" +i+"/leftRight"));72 levelBackGrounds.Add(LoadImage("level" +i+"/levelBackground"));92 levelTopBottoms.Add(LoadImage("level" + i + "/topBottom")); 93 levelLeftRights.Add(LoadImage("level" + i + "/leftRight")); 94 levelBackGrounds.Add(LoadImage("level" + i + "/levelBackground")); 73 95 } 74 96 } … … 77 99 { 78 100 objectTextures.Add(LoadImage("objects/door_closed")); 79 //objectTextures.Add(LoadImage("objects/door_open")); 101 objectTextures.Add(LoadImage("objects/door_opened")); 102 objectTextures.Add(LoadImage("objects/bossdoor")); 80 103 } 81 104 … … 99 122 oldPos = player.currentRoom.Position + new Vector(ROOMWIDTH / 2 + ROOMTHICKNESS / 2, -ROOMHEIGHT / 2 + ROOMTHICKNESS / 4); 100 123 newPos = room.Position + new Vector(ROOMWIDTH / 2 + ROOMTHICKNESS / 2, -ROOMHEIGHT / 2 + ROOMTHICKNESS / 4); 101 oldRoom = player.currentRoom; 124 oldRoom = player.currentRoom; 125 102 126 if (room.isBuilt) room.restoreLevel(); 103 127 else room.buildLevel(); 128 104 129 oldRoom.killBrains(); 105 130 moveCameraTo(newPos - oldPos); … … 127 152 oldRoom.hideLevel(); 128 153 player.currentRoom.restoreBrains(); 154 155 if (player.currentRoom.roomName == "Boss Room") 156 { 157 EntityBossMario mario = (EntityBossMario)player.currentRoom.getEntityAt(3, 3); 158 gui.setupBossGauge(mario); 159 } 129 160 } 130 161 } … … 134 165 player.Position = generator.getRoomAt(generator.CenterRoom).Position + new Vector(ROOMWIDTH / 2, -ROOMHEIGHT / 2); 135 166 player.currentRoom = generator.getRoomAt(generator.CenterRoom); 136 player.currentRoom.buildLevel(); 167 player.currentRoom.buildLevel(); 137 168 Add(player, 2); 138 169 } … … 156 187 } 157 188 189 public void restartGame() 190 { 191 Keyboard.EnableAll(); 192 player.resetValues(); 193 gui.Destroy(); 194 gui = new InGameGui(this); 195 Add(gui); 196 regenerateLevel(); 197 } 198 158 199 int errorAmount = 0; 159 200 protected override void Update(Time time) … … 177 218 moveCameraPart(); 178 219 } 179 180 player.Update(time);220 if (player != null) 221 player.Update(time); 181 222 } 182 223 } -
2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGameContent/TheDungeonGameContent.contentproj
r3568 r3624 45 45 </ItemGroup> 46 46 <ItemGroup> 47 <Compile Include="animations\mario\normal\attack.png"> 48 <Name>attack</Name> 49 <Importer>TextureImporter</Importer> 50 <Processor>TextureProcessor</Processor> 51 </Compile> 52 <Compile Include="animations\mario\normal\walk1.png"> 53 <Name>walk1</Name> 54 <Importer>TextureImporter</Importer> 55 <Processor>TextureProcessor</Processor> 56 </Compile> 57 <Compile Include="animations\mario\normal\walk2.png"> 58 <Name>walk2</Name> 59 <Importer>TextureImporter</Importer> 60 <Processor>TextureProcessor</Processor> 61 </Compile> 62 <Compile Include="animations\mario\powerup\attack.png"> 63 <Name>attack</Name> 64 <Importer>TextureImporter</Importer> 65 <Processor>TextureProcessor</Processor> 66 </Compile> 67 <Compile Include="animations\mario\powerup\normal.png"> 68 <Name>normal</Name> 69 <Importer>TextureImporter</Importer> 70 <Processor>TextureProcessor</Processor> 71 </Compile> 47 72 <Compile Include="player.png"> 48 73 <Name>player</Name> … … 94 119 <Compile Include="objects\rock.png"> 95 120 <Name>rock</Name> 121 <Importer>TextureImporter</Importer> 122 <Processor>TextureProcessor</Processor> 123 </Compile> 124 </ItemGroup> 125 <ItemGroup> 126 <Compile Include="objects\door_opened.png"> 127 <Name>door_opened</Name> 128 <Importer>TextureImporter</Importer> 129 <Processor>TextureProcessor</Processor> 130 </Compile> 131 </ItemGroup> 132 <ItemGroup> 133 <Compile Include="sound\door_close.wav"> 134 <Name>door_close</Name> 135 <Importer>WavImporter</Importer> 136 <Processor>SoundEffectProcessor</Processor> 137 </Compile> 138 <Compile Include="sound\door_open.wav"> 139 <Name>door_open</Name> 140 <Importer>WavImporter</Importer> 141 <Processor>SoundEffectProcessor</Processor> 142 </Compile> 143 </ItemGroup> 144 <ItemGroup> 145 <Compile Include="animations\fly\fly1.png"> 146 <Name>fly1</Name> 147 <Importer>TextureImporter</Importer> 148 <Processor>TextureProcessor</Processor> 149 </Compile> 150 <Compile Include="animations\fly\fly2.png"> 151 <Name>fly2</Name> 152 <Importer>TextureImporter</Importer> 153 <Processor>TextureProcessor</Processor> 154 </Compile> 155 <Compile Include="animations\fly\fly3.png"> 156 <Name>fly3</Name> 157 <Importer>TextureImporter</Importer> 158 <Processor>TextureProcessor</Processor> 159 </Compile> 160 </ItemGroup> 161 <ItemGroup> 162 <Compile Include="animations\fly2\fly1.png"> 163 <Name>fly1</Name> 164 <Importer>TextureImporter</Importer> 165 <Processor>TextureProcessor</Processor> 166 </Compile> 167 <Compile Include="animations\fly2\fly2.png"> 168 <Name>fly2</Name> 169 <Importer>TextureImporter</Importer> 170 <Processor>TextureProcessor</Processor> 171 </Compile> 172 <Compile Include="animations\fly2\fly3.png"> 173 <Name>fly3</Name> 174 <Importer>TextureImporter</Importer> 175 <Processor>TextureProcessor</Processor> 176 </Compile> 177 </ItemGroup> 178 <ItemGroup> 179 <Compile Include="animations\zombie\frame1.png"> 180 <Name>frame1</Name> 181 <Importer>TextureImporter</Importer> 182 <Processor>TextureProcessor</Processor> 183 </Compile> 184 <Compile Include="animations\zombie\frame2.png"> 185 <Name>frame2</Name> 186 <Importer>TextureImporter</Importer> 187 <Processor>TextureProcessor</Processor> 188 </Compile> 189 <Compile Include="animations\zombie\frame3.png"> 190 <Name>frame3</Name> 191 <Importer>TextureImporter</Importer> 192 <Processor>TextureProcessor</Processor> 193 </Compile> 194 </ItemGroup> 195 <ItemGroup> 196 <Compile Include="animations\zombie2\frame1.png"> 197 <Name>frame1</Name> 198 <Importer>TextureImporter</Importer> 199 <Processor>TextureProcessor</Processor> 200 </Compile> 201 <Compile Include="animations\zombie2\frame2.png"> 202 <Name>frame2</Name> 203 <Importer>TextureImporter</Importer> 204 <Processor>TextureProcessor</Processor> 205 </Compile> 206 </ItemGroup> 207 <ItemGroup> 208 <Compile Include="animations\mario\powerup\walk1.png"> 209 <Name>walk1</Name> 210 <Importer>TextureImporter</Importer> 211 <Processor>TextureProcessor</Processor> 212 </Compile> 213 <Compile Include="animations\mario\powerup\walk2.png"> 214 <Name>walk2</Name> 215 <Importer>TextureImporter</Importer> 216 <Processor>TextureProcessor</Processor> 217 </Compile> 218 <Compile Include="animations\mario\turtle\turtle.png"> 219 <Name>turtle</Name> 220 <Importer>TextureImporter</Importer> 221 <Processor>TextureProcessor</Processor> 222 </Compile> 223 </ItemGroup> 224 <ItemGroup> 225 <Compile Include="animations\mario\normal\idle.png"> 226 <Name>idle</Name> 227 <Importer>TextureImporter</Importer> 228 <Processor>TextureProcessor</Processor> 229 </Compile> 230 </ItemGroup> 231 <ItemGroup> 232 <Compile Include="animations\mario\turtle\poweredTurtle.png"> 233 <Name>poweredTurtle</Name> 234 <Importer>TextureImporter</Importer> 235 <Processor>TextureProcessor</Processor> 236 </Compile> 237 </ItemGroup> 238 <ItemGroup> 239 <Compile Include="objects\bossdoor.png"> 240 <Name>bossdoor</Name> 241 <Importer>TextureImporter</Importer> 242 <Processor>TextureProcessor</Processor> 243 </Compile> 244 </ItemGroup> 245 <ItemGroup> 246 <Compile Include="animations\player\idle.png"> 247 <Name>idle</Name> 248 <Importer>TextureImporter</Importer> 249 <Processor>TextureProcessor</Processor> 250 </Compile> 251 <Compile Include="animations\player\walk1.png"> 252 <Name>walk1</Name> 253 <Importer>TextureImporter</Importer> 254 <Processor>TextureProcessor</Processor> 255 </Compile> 256 <Compile Include="animations\player\walk2.png"> 257 <Name>walk2</Name> 96 258 <Importer>TextureImporter</Importer> 97 259 <Processor>TextureProcessor</Processor>
Note: See TracChangeset
for help on using the changeset viewer.