Ejemplo n.º 1
0
        public void draw()
        {
            // Draw a black background for now
            SDL.SDL_Rect r = new SDL.SDL_Rect();

            SDL.SDL_SetRenderDrawColor(Engine.renderer, 0, 0, 0, 255);
            SDL.SDL_RenderClear(Engine.renderer);

            // Draw the title at the top, centered
            uint f;     // scratch var
            int  a;     // scratch var

            SDL.SDL_QueryTexture(title, out f, out a, out r.w, out r.h);
            r.x = (Engine.GetContextWidth() / 2) - (r.w / 2);
            r.y = 16;

            SDL.SDL_SetRenderDrawColor(Engine.renderer, 255, 255, 255, 255);
            SDL.SDL_RenderCopy(Engine.renderer, title, IntPtr.Zero, ref r);

            // Draw all options
            for (int i = 0; i < options.Count; i++)
            {
                if (i == selected)
                {
                    SDL.SDL_SetTextureColorMod(options[i], 127, 127, 127);
                }

                SDL.SDL_QueryTexture(options[i], out f, out a, out r.w, out r.h);
                r.x = (Engine.GetContextWidth() / 2) - (r.w / 2);
                r.y = 128 + (32 * i);
                SDL.SDL_RenderCopy(Engine.renderer, options[i], IntPtr.Zero, ref r);

                if (i == selected)
                {
                    SDL.SDL_SetTextureColorMod(options[i], 255, 255, 255);
                }
            }

            // Present
            SDL.SDL_RenderPresent(Engine.renderer);
        }
Ejemplo n.º 2
0
        public void draw()
        {
            // Clear the renderer
            SDL.SDL_RenderClear(Engine.renderer);

            // Render the background
            SDL.SDL_RenderCopy(Engine.renderer, am.GetAsset("back"), IntPtr.Zero, IntPtr.Zero);

            // Render the map

            // Camera offset
            int cx, cy;

            cx = (int)(harambe.getX() + (harambe.getWidth() / 2)) - Engine.GetContextWidth() / 2;
            if (cx < 0)
            {
                cx = 0;
            }

            cy = (int)(harambe.getY() + (harambe.getHeight() / 2)) - (height * TILE_SIZE) + Engine.GetContextHeight() / 2;
            Console.WriteLine("cy: {0}", cy);
            if (cy > 0)
            {
                cy = 0;
            }

            // Iterate over the mapdata
            SDL.SDL_Rect r = new SDL.SDL_Rect();
            r.w = TILE_SIZE;
            r.h = TILE_SIZE;
            for (int mx = 0; mx < width; mx++)
            {
                for (int my = 0; my < height; my++)
                {
                    // Calculate render coordinates
                    r.x = mx * TILE_SIZE - cx;
                    r.y = (Engine.GetContextHeight() - (height * TILE_SIZE)) + (my * TILE_SIZE) - cy;

                    // Render the tile
                    // TODO: Change this to render based on the tilemap
                    if (mapdata[my * width + mx] == 1)
                    {
                        SDL.SDL_RenderCopy(Engine.renderer, am.GetAsset("tile"), IntPtr.Zero, ref r);
                    }
                }
            }

            // Render the player
            float x, y;

            x = harambe.getX();
            y = harambe.getY();

            r.x = (int)x - cx;
            r.y = (Engine.GetContextHeight() - (height * TILE_SIZE)) + (int)y - cy;
            r.w = 128;
            r.h = 128;
            //SDL.SDL_RenderCopy(Engine.renderer, am.GetAsset("player1"), IntPtr.Zero, ref r);
            SDL.SDL_SetRenderDrawColor(Engine.renderer, 255, 0, 0, 255);
            SDL.SDL_RenderFillRect(Engine.renderer, ref r);
            SDL.SDL_SetRenderDrawColor(Engine.renderer, 255, 255, 255, 255);

            // Present
            SDL.SDL_RenderPresent(Engine.renderer);
        }