• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By Kshitij Jhalak
      Objective :
      I want to draw a buffer of pixel (DWORD buf[WIDTH*HEIGHT]) to the whole client window. I am somewhat familiar with Winapi but not with GDI, reading the MSDN and other sources on the internet, I have came up with the following program.  
       
      Problem :
      The code is not working. I have initialised all elements of my buffer ( buf[] )  to 0. So I should get a black screen on my window, but I getting a regular white window. Can somebody point me what's wrong am I doing ?
       
      Code :
      #include<Windows.h>
      #include "stdafx.h"
      LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
      const int HEIGHT = 512;
      const int WIDTH = 512;
      DWORD buf[WIDTH * HEIGHT];
      BITMAPINFO bmi = { 0 };
      HDC hWinDC = NULL;
      HDC hbitDC = NULL;
      HBITMAP hBitmap = NULL;
      int WINAPI wWinMain(HINSTANCE hInstace, HINSTANCE hPrevInstace, LPWSTR lpCmdLine, int nCmdShow) {
          memset(buf, 0, sizeof(buf)/sizeof(DWORD));
          MSG msg = { 0 };
          WNDCLASS wnd = { 0 };
          wnd.lpfnWndProc = WndProc;
          wnd.hInstance = hInstace;
          wnd.lpszClassName = L"Window";
          if (!RegisterClass(&wnd)) {
              return 0;
          }
          HWND hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, wnd.lpszClassName, L"Window",
              WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, WIDTH, HEIGHT, NULL, NULL, hInstace, NULL);
          if (!hwnd) {
              return 0;
          }
          ShowWindow(hwnd, nCmdShow);
          UpdateWindow(hwnd);
          while (GetMessage(&msg, NULL, 0, 0)) {
              TranslateMessage(&msg);
              DispatchMessage(&msg);
          }
          return msg.wParam;
      }
      LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){
          HDC hWdc = NULL;
          switch (msg){
              case WM_CREATE:
                  bmi.bmiHeader.biSize = sizeof(BITMAPCOREHEADER);
                  bmi.bmiHeader.biWidth = WIDTH;
                  bmi.bmiHeader.biHeight = HEIGHT;
                  bmi.bmiHeader.biPlanes = 1;
                  bmi.bmiHeader.biBitCount = 32;
                  bmi.bmiHeader.biCompression = BI_RGB;
                  break;
              case WM_PAINT:
                  PAINTSTRUCT ps;
                  hWdc = BeginPaint(hwnd, &ps);
                  hWinDC = GetDC(hwnd);
                  hbitDC = CreateCompatibleDC(hWinDC);
                  hBitmap = CreateDIBSection(hWinDC, &bmi, DIB_RGB_COLORS, (void**)&buf, NULL, NULL);
                  SelectObject(hbitDC, hBitmap);
                  BitBlt(hWdc, 0, 0, WIDTH, HEIGHT, hbitDC, 0, 0, SRCCOPY);
                  EndPaint(hwnd, &ps);
                  break;
              case WM_KEYUP:
                  if (wParam == 0x41) {
                      SendMessage(hwnd, WM_PAINT, NULL, NULL);
                  }
                  break;
              case WM_DESTROY:
                  DeleteDC(hbitDC);
                  ReleaseDC(hwnd, hWinDC);
                  PostQuitMessage(0);
                  break;
          }
          return DefWindowProc(hwnd, msg, wParam, lParam);
      }
       
       
    • By eldwin11929
      We're looking for a Unity (C#) Programmer for our 2D Project. We're looking for a new lead programmer to continue with an existing project.
       
      Project is an open-world RTS, and is very close to a prototyping (playable) phase. Our existing lead, unfortunately, has no more time for the project, and thus we are in search of a new one who is interested.
       
      Game is purely fantasy based, and we'll be able to give you much more detailed info about the project as we begin to work you into it.
       
      You'll be working with our junior developer, who has been here since the beginning.
       
      Primary skills needed are just being able to work within Unity. But skills within XML are also a plus.
       
      Our list of major goals we'd need you to do is minimal, yet still fairly extensive:
      -Edit our current Pathfinding system to account for a few extra features.
      -Setup our global map system. You’ll be working off an existing random node-map web generator and existing random map generation system and essentially linking the two together. This includes handling random spawns (which has already been semi-setup) unique to each node’s respective map.
      -Further implementation of an existing random spawning algorithm (used to spawn things like enemies randomly across the Map).
      -Making sure to Save and Record all respective aspects of what was mentioned above.
      -Handling our XML database- database is created, but we’ll need to be integrating it. This includes all various things from units to abilities and so forth. Will also need to handle implementing an object’s unique attributes we cannot take care of within XML.
      -Various Content Implementation (to be done once our XML has been integrated).
      -Various Saving and Recording of all respective aspects of the database info mentioned above.
      -Various Performance Enhancements.
      -Potential for various misc things, such as further UI work.
      -Setting up a Menu system.
       
      We have a considerable amount of things done already- however I must warn ahead of time we have quite a bit of unclean code, which may be fairly overwhelming for a new developer on the project.
       
      Let me know your rates per hour, and we'll see if we can work out a good deal between both of us. Royalties are also included.
       
      If interested, send an email to: eldwin11929@yahoo.com
       
      Thanks!
    • By Ronan Hayes
      So i am working on a java swing breakout game and am on the last task to complete, which is detecting collision with a brick and then deleting it from the array so it cannot be seen on the screen. I have created a for loop which is somewhat working however the ball bounces off the bat/paddle and goes straight through the first few rows of bricks and then start to detect only the rows around the 6/7th row. Here is the loop i am working on. 
      public void runAsSeparateThread() { final float S = 3; // Units to move (Speed) try { synchronized ( Model.class ) // Make thread safe { GameObj ball = getBall(); // Ball in game GameObj bat = getBat(); // Bat ArrayList<GameObj> bricks = getBricks(); // Bricks } while (runGame) { synchronized ( Model.class ) // Make thread safe { float x = ball.getX(); // Current x,y position float y = ball.getY(); // Deal with possible edge of board hit if (x >= W - B - BALL_SIZE) ball.changeDirectionX(); if (x <= 0 + B ) ball.changeDirectionX(); if (y >= H - B - BALL_SIZE) // Bottom { ball.changeDirectionY(); addToScore( HIT_BOTTOM ); } if (y <= 0 + M ) ball.changeDirectionY(); // As only a hit on the bat/ball is detected it is // assumed to be on the top or bottom of the object. // A hit on the left or right of the object // has an interesting affect boolean hit = false; // *[3]******************************************************[3]* // * Fill in code to check if a visible brick has been hit * // * The ball has no effect on an invisible brick * // ************************************************************** for ( int i = 0; i <= 60; i++ ){ GameObj brick1 = bricks.get(i); if ( brick1.hitBy(ball) ){ bricks.remove(i); //hit = true; ball.changeDirectionY(); //ball.changeDirectionX(); addToScore(50); } } if (hit) ball.changeDirectionY(); if ( ball.hitBy(bat) ) ball.changeDirectionY(); } modelChanged(); // Model changed refresh screen Thread.sleep( fast ? 2 : 20 ); ball.moveX(S); ball.moveY(S); } } catch (Exception e) { Debug.error("Model.runAsSeparateThread - Error\n%s", e.getMessage() ); } } } i need to be able to break each brick individually and for them to rebound ... this is the code that i am working with so far 
      for ( int i = 0; i <= 60; i++ ){ GameObj brick1 = bricks.get(i); if ( brick1.hitBy(ball) ){ bricks.remove(i); //hit = true; ball.changeDirectionY(); //ball.changeDirectionX(); addToScore(50); } }  
    • By Jiraya
      For a 2D game, does using a float2 for position increases performance in any way?
      I know that in the end the vertex shader will have to return a float4 anyway, but does using a float2 decreases the amount of data that will have to be sent from the CPU to the GPU?
       
    • By ThunderTwonk
      Hello everyone, I am working on a game idea and since I am still in the process of learning C# and the features available in unity I was hoping some of you might be able to offer me a little insight on things in general for getting started.
      I guess the basic components of what I'm wanting to create would be a Multi-levels management/city builder/rpg.
      The goal is to provide a framework for players to interact with, build in and affect the world both from a 3rd person action RPG as well as a zoomed out 4x style view (This would be something unlocked through gameplay)
       
      As for my questions go I was wondering if anyone had resources that could help me learn.  I've been on youtube as well as enrolled in an online course for basic unity and C# and will continue those but if anyone has any words of advice, a place that has good information and tutorials etc.
       
      Thanks for your time.
  • Advertisement
  • Advertisement

How to determine whether a region of a tiled hexmap is convex?

Recommended Posts

I have a set of tiles in an hexagonal coordinate system, and I want to see whether it forms an "almost convex" region. By almost convex, I mean that a square with zigzaging hex edges would still count as convex.

The idea is to split non convex regions into convex ones, and merge small regions into larger convex ones.

What I don't want is merging a corridor with a room or 2 rooms separated by a wall together.

XJ1YVKx.png

I was thinking about sweeping a line along 2 axis and see whether it goes through any missing tile (in case of diagonal, the check would fail only if both tiles are missing).

Would that work?

Edit: it wouldn't, as a L or cross shaped area would pass.

 

 

How can I do it?

Edited by Galdred

Share this post


Link to post
Share on other sites
Advertisement

 

I found a way to do it:

 

First of all, tiles that were surrounded by 4 tiles of another region were converted to this region to avoid weird borders, until there was no such tile left.

The polygon theorem says that all the angles of a polygon should be clockwise or counter clockwise.

In a hexmap, that would translate more or less to: no hexagon that is not in the area should be adjacent to 3 or more hexagons of the area.

convex3.png.20b5abf8fd1bd6fbc0c21a8479b490fe.png

If we didn't care about the quasi convex corner cases, just checking that no neighbors  is close to 3 region hex would be enough, but we also have to make sure our algorithm does not throw away cases we want to keep.

 

One way to do that would be to check that the region does not cross the zigzaging line passing through one of these neighbors:(cf image convex3b.png) 

 

convex3b.png

 

In my game, I chose to accept a more lenient check that still result in reasonably

shaped areas. (because it works better with the shape of my walls).

convex3_gamerule.png.19533ebb25199e3c194f86db343aaa44.png

 

 

Edited by Galdred

Share this post


Link to post
Share on other sites

Indee,d that is what I planned to do first. One nice property is that it would work well with the zigzaging vertical lines indeed,, but then, I would still have to floodfill to check whether all tiles inside the convex hull are inside the area (by floodfilling?) to see whether it is convex,, no?

And it seems slower than just checking the border tiles and check their neighbors (especially since I already had to track them).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement