Changeset 3525
- Timestamp:
- 2012-07-04 10:50:43 (10 years ago)
- Location:
- 2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/Player.cs
r3515 r3525 17 17 public bool isMoving = false; 18 18 private Keyboard keyboard; 19 p rivatedouble speed = 200;19 public double speed = 200; 20 20 21 21 public Player(Game game, Vector pos) … … 24 24 keyboard = game.Keyboard; 25 25 CanRotate = false; 26 // MakeStatic(); 26 27 setupKeys(); 27 28 } … … 40 41 } 41 42 42 public void tick()43 public override void Update(Time time) 43 44 { 44 if ( isMoving)45 if (!isMoving) 45 46 { 46 47 movementVector = Vector.Zero; … … 48 49 } 49 50 50 isMoving = false; 51 isMoving = false; 52 53 base.Update(time); 51 54 } 52 55 -
2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/Room.cs
r3517 r3525 10 10 abstract class Room 11 11 { 12 13 public Vector Position;12 13 public Vector Position; 14 14 public double width, height, thickness; 15 15 protected List<IPhysicsObject> roomObjects = new List<IPhysicsObject>(); … … 22 22 public Game Game { get; set; } 23 23 public Vector PosOnGrid { get; set; } 24 public PhysicsObject wall; 24 25 25 26 public Room(Game game, Vector pos, Vector size, double thickness) … … 31 32 this.thickness = thickness; 32 33 33 insidePos = VecMath.add( pos, new Vector(thickness, -thickness));34 insidePos = VecMath.add(Position, new Vector(thickness, -thickness)); 34 35 insideWidth = width - thickness; 35 36 insideHeight = height - thickness; … … 81 82 public void addBlock(IPhysicsObject obj, int bx, int by) 82 83 { 83 if (bx > bWidth || bx < 0 || by >bHeight || by < 0 || insideObjects[bx, by] != null) throw new Exception("Can't put block to " + bx + " , " + by);84 if (bx >= bWidth || bx < 0 || by >= bHeight || by < 0 || insideObjects[bx, by] != null) throw new Exception("Can't put block to " + bx + " , " + by); 84 85 obj.Left = insidePos.X + (bx * blockWidth); 85 obj.Top = insidePos.Y +(by * blockHeight);86 obj.Top = insidePos.Y - (by * blockHeight); 86 87 insideObjects[bx, by] = obj; 88 } 89 90 public void addBlockAt(IPhysicsObject obj, double x, double y) 91 { 92 obj.Left = Position.X + x; 93 obj.Top = Position.Y + y; 94 roomObjects.Add(obj); 95 } 96 97 98 // En vitsinyt käyttää enempää aikaa tämän parantamiseksi. Helppo ja toimiva 99 public void addDoors(int[] directions) 100 { 101 if(directions.Length > 4) throw new ArgumentException("Argument's length must be 4!"); 102 103 for (int i = 0; i < directions.Length; i++) 104 { 105 if(directions[i] == -1) continue; 106 107 if (directions[i] == RoomDirection.North) 108 { 109 PhysicsObject doorTop = PhysicsObject.CreateStaticObject(thickness, thickness); 110 doorTop.Position = Position + new Vector((width + thickness) / 2, -thickness / 2); 111 doorTop.Tag = "Top Door"; 112 roomObjects.Add(doorTop); 113 }else 114 if (directions[i] == RoomDirection.East) 115 { 116 PhysicsObject doorRight = PhysicsObject.CreateStaticObject(thickness, thickness); 117 doorRight.Position = Position + new Vector(width + thickness / 2, -(height + thickness) / 2); 118 doorRight.Tag = "Right Door"; 119 roomObjects.Add(doorRight); 120 } 121 else 122 if (directions[i] == RoomDirection.South) 123 { 124 PhysicsObject doorBottom = PhysicsObject.CreateStaticObject(thickness, thickness); 125 doorBottom.Position = Position + new Vector((thickness + width) / 2, -height - thickness / 2); 126 doorBottom.Tag = "Bottom Door"; 127 roomObjects.Add(doorBottom); 128 } 129 else 130 if (directions[i] == RoomDirection.West) 131 { 132 PhysicsObject doorLeft = PhysicsObject.CreateStaticObject(thickness, thickness); 133 doorLeft.Position = Position + new Vector(thickness / 2, -height / 2 - thickness / 2); 134 doorLeft.Tag = "Left Door"; 135 roomObjects.Add(doorLeft); 136 } 137 } 87 138 } 88 139 … … 96 147 wallDown.Color = Color.Black; 97 148 PhysicsObject wallRight = createWall(VecMath.add(Position, new Vector(width, -thickness)), thickness, height - thickness); 149 wallRight.Color = Color.Orange; 98 150 roomObjects.Add(wallTop); 99 151 roomObjects.Add(wallLeft); … … 104 156 public PhysicsObject createWall(Vector pos, double width, double height) 105 157 { 106 PhysicsObjectwall = PhysicsObject.CreateStaticObject(width, height);158 wall = PhysicsObject.CreateStaticObject(width, height); 107 159 wall.Left = pos.X; 108 160 wall.Top = pos.Y; -
2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/TestRoom.cs
r3489 r3525 19 19 public override void initRoom() 20 20 { 21 int[] doorLocations = { RoomDirection.North, RoomDirection.South, RoomDirection.West, RoomDirection.East }; 21 22 createBorders(); 22 23 roomObjects.Add(createBackground()); 24 addDoors(doorLocations); 25 // PhysicsObject testblock = PhysicsObject.CreateStaticObject(blockWidth, blockHeight); 26 // addBlock(testblock, 0, 1); 23 27 // addBlock(new PhysicsObject(blockWidth, blockHeight), 0, 0); 24 28 } -
2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/TheDungeonGame.cs
r3518 r3525 12 12 public class TheDungeonGame : PhysicsGame 13 13 { 14 public const double ROOMWIDTH = 850; 15 public const double ROOMHEIGHT = 500; 16 public const double ROOMTHICKNESS = 70; 14 public const double ROOMTHICKNESS = 60; 15 public const double ROOMWIDTH = 800 - ROOMTHICKNESS; 16 public const double ROOMHEIGHT = 450; 17 17 18 public static Vector roomSize = new Vector(ROOMWIDTH, ROOMHEIGHT); 18 19 private Player player; … … 25 26 Level.Width = ROOMWIDTH * 20; 26 27 Level.Height = ROOMHEIGHT * 20; 27 // Level.CreateBorders();28 Camera.ZoomToLevel();29 28 30 29 generator = new LevelGenerator(this, Level.Size, new Vector(20, 20)); 31 generator.generateRandomLevel( 10, 15);30 generator.generateRandomLevel(5, 10); 32 31 generator.buildDungeon(); 32 Room centerRoom = generator.getRoomAt((int)(generator.CenterRoom.X), (int)(generator.CenterRoom.Y)); 33 Camera.Position = centerRoom.Position + new Vector(ROOMWIDTH/2 + ROOMTHICKNESS/2, -ROOMHEIGHT/2 + ROOMTHICKNESS/4); 33 34 34 35 player = new Player(this, Vector.Zero); 35 Add(player, 1); 36 // Camera.Follow(player); 36 setupPlayer(); 37 37 38 38 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Lopeta peli"); 39 39 Keyboard.Listen(Key.R, ButtonState.Pressed, regenerateLevel, null); 40 } 41 42 private void setupPlayer() 43 { 44 player.Position = generator.getRoomAt((int)(generator.CenterRoom.X), (int)(generator.CenterRoom.Y)).Position + new Vector(ROOMWIDTH / 2, -ROOMHEIGHT / 2); 45 Add(player, 1); 40 46 } 41 47 … … 66 72 } 67 73 68 player. tick();74 player.Update(time); 69 75 } 70 76 }
Note: See TracChangeset
for help on using the changeset viewer.