/// <summary> /// Constructs a ParallaxBackground object. Needs the display object for the camera position. /// </summary> /// <param name="texture"> /// A <see cref="Texture"/> /// </param> /// <param name="parallaxFactor"> /// A <see cref="System.Double"/> /// </param> /// <param name="display"> /// A <see cref="Display"/> /// </param> /// <param name="motionBlur"> /// A <see cref="System.Boolean"/> /// </param> public ParallaxBackground(Texture texture, double parallaxFactorX, double parallaxFactorY, Display display) { this.texture = texture; this.parallaxFactorX = parallaxFactorX; this.parallaxFactorY = parallaxFactorY; this.display = display; }
/// <summary> /// Construct the renderer. /// </summary> /// <param name="texmode"> /// A <see cref="TextureMode"/>. Choose "TextureMode.NORMAL_MODE" if your graphics card supports non-power of 2 texture sizes, TextureMode.TEXTURE_RECTANGLE_EXT otherwise. /// </param> public Renderer(TextureMode texmode, Display display, ResourceManager resourceManager) { this.resourceManager = resourceManager; textureMode = texmode; try { CheckRendererStatus(); } catch (Exception e) { Log.Write("Could not initialize renderer: " + e.Message); throw e; } //Set some OpenGL attributes Gl.glDisable(Gl.GL_DEPTH_TEST); Gl.glEnable(GlTextureMode); Gl.glShadeModel(Gl.GL_SMOOTH); Gl.glHint(Gl.GL_PERSPECTIVE_CORRECTION_HINT, Gl.GL_NICEST); //Enable alpha blending Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA); Gl.glEnable(Gl.GL_BLEND); Ready = true; Gl.glColor4d(1, 1, 1, 1); /*Gl.glDrawBuffer(Gl.GL_BACK); Gl.glClearAccum(0.0f, 0.0f, 0.0f, 0.0f); Gl.glClear(Gl.GL_ACCUM_BUFFER_BIT);*/ }
public Camera(Display display, double xMin, double xMax, double yMin, double yMax) { this.display = display; X = display.CameraX; Y = display.CameraY; XMin = xMin; XMax = xMax; YMin = yMin; YMax = yMax; }
WorldPhysics worldPhysics = WorldPhysics.DefaultWorldPhysics; //Physics object used on this map. Attributes may be specified in the map file. #endregion Fields #region Constructors //Construct a levelstate object public LevelState(Game game, PlayerState player, string mapName) : base(game, player) { Activated += delegate { game.Display.Renderer.SetFont("verdana", 8); }; playerInfo = player; this.game = game; this.display = game.Display; this.mapName = mapName; // game.Display.CameraX = 50; //game.Display.CameraY = 100; //Load map MapDescriptor map = game.Resources.GetMapDescriptor(mapName); objectFactory = new ObjectFactory(game, this); tileMap = new TileMap(game.Display, game.Resources, map); //And set up the world physics attributes if (map.ExtraProperties.ContainsKey("gravity")) worldPhysics.Gravity = double.Parse(map.ExtraProperties["gravity"]); if (map.ExtraProperties.ContainsKey("ground-friction-factor")) worldPhysics.GroundFrictionFactor = double.Parse(map.ExtraProperties["ground-friction-factor"]); //Spawn all objects foreach (var o in map.Objects) { GameObject obj = objectFactory.Spawn(o.Name, new Vector(o.X, o.Y), new Vector(0,-100), worldPhysics); if (obj != null) { objects.Add(obj); if (o.Name == "mario") { this.player = (Player)objects[objects.Count-1]; } } } //Set the map background if (!string.IsNullOrEmpty(map.Background)) background = new ParallaxBackground(game.Resources.GetTexture(map.Background), 0.5, 0.2, game.Display); camera = new Camera(display, 0, map.Width * map.TileSize, 0, map.Height * map.TileSize); game.Audio.PlayMusic("overworld-intro", "overworld"); icons["coin"] = objectFactory.CreateIcon("coin", 0.7); //new Icon(game, Helpers. icons["mario"] = objectFactory.CreateIcon("mario-big", 0.5); //new Icon(game, marioIcon); }
public MapEditorState(Game game, EditorModel model) : base(game) { this.model = model; model.AddListener(this); display = game.Display; renderer = display.Renderer; input = game.Input; model.Display = display; model.Zoom = display.Zoom; }
//Convert window coordinates to world coordinates public Vector WindowToWorldPosition(Vector windowPos, Display display, bool relative) { double x = ((double)(windowPos.X * display.ViewportWidth)) / (double)display.WindowWidth; if (relative) return new Vector(x, -((double)(windowPos.Y * display.ViewportHeight)) / (double)display.WindowHeight); else return new Vector(x - (double)display.ViewportWidth / 2.0 + display.CameraX, (double)display.ViewportHeight / 2.0 - ((double)(windowPos.Y * display.ViewportHeight)) / (double)display.WindowHeight+display.CameraY); }
/// <summary> /// Initialize the game: Initialize display, load resources etc. /// </summary> /// <param name="width"> /// A <see cref="System.Int32"/> /// </param> /// <param name="height"> /// A <see cref="System.Int32"/> /// </param> /// <param name="fullscreen"> /// A <see cref="System.Boolean"/> /// </param> public void Initialize(int width, int height, bool fullscreen, string windowTitle) { Log.Write("Engine initializing at " + DateTime.Now); gameStates = new List<GameState>(); //Create resource manager and load resources from the main resource file resourceManager = new ResourceManager(); resourceManager.LoadResources("data"); //resourceManager.LoadResourceXML(ResourceManager.MainResourceFile); //Create the opengl display display = new Display(); display.Initialize(width, height, resourceManager, windowTitle); if (fullscreen) { display.Fullscreen = true; } input = new InputManager(); audioManager = new AudioManager(resourceManager); timer.Start(); SimulationSpeed = DefaultSimulationSpeed; }
/// <summary> /// Construct a tilemap. /// </summary> /// <param name="display"> /// The main display is required for camera positions and renderer /// </param> /// <param name="offsetX"> /// X offset for the tilemap, in case it's not desired that the drawing starts at (0,0) /// </param> /// <param name="offsetY"> /// Y offset /// </param> public TileMap(Display display, Tileset tileset, int width, int height, int layers, double offsetX, double offsetY, double tileSize) { this.display = display; Tileset = tileset; Tilesize = tileSize; Width = width; Height = height; Layers = layers; OffsetX = offsetX; OffsetY = offsetY; map = new Tile[width, height, layers]; for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { for (int z = 0; z < Layers; z++) { map[x,y,z] = (Tile)Tileset.GetTile(0).Clone(); } } } }
/// <summary> /// Create a tilemap from a descriptor. /// </summary> public TileMap(Display display, ResourceManager resources, MapDescriptor descriptor) { this.display = display; Width = descriptor.Width; Height = descriptor.Height; Layers = descriptor.Layers; Tilesize = descriptor.TileSize; OffsetX = descriptor.OffsetX; OffsetY = descriptor.OffsetY; Tileset = resources.GetTileset(descriptor.Tileset); map = new Tile[Width, Height, Layers]; for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { for (int z = 0; z < Layers; z++) { SetTile(x,y,z,Tileset.GetTile(descriptor.GetTile(x,y,z))); } } } }