• 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 Runemark Studio
      Dark Fantasy Environment and Props





    • By bowcox
      Hi guys! 
      I have created a Pong game that has an AI that is almost beatable, changing the speed of the AI can make it ridiculously easy or hard depending on the way you go about it. 
       
      using System.Collections; using System.Collections.Generic; using UnityEngine; public class ComputerMovement : MonoBehaviour { private float speed; private float reAdjustSpeed = 1f; private Rigidbody2D computer2d; public static bool isTwoPlayer; GameObject theBall; Rigidbody2D rb2d; void Start() { computer2d = GetComponent<Rigidbody2D> (); } void FixedUpdate() { if (isTwoPlayer == true) { speed = 5f; if (Input.GetKey (KeyCode.W)) { computer2d.position += Vector2.up * speed * Time.deltaTime; } if (Input.GetKey (KeyCode.S)) { computer2d.position += Vector2.down * speed * Time.deltaTime; } } if (isTwoPlayer == false) { speed = 3f; if (theBall == null) { theBall = GameObject.FindGameObjectWithTag ("Ball"); } rb2d = theBall.GetComponent<Rigidbody2D> (); //Is the ball going left or right if (rb2d.velocity.x > 0) { if (rb2d.velocity.y > 0) { if (rb2d.position.y > computer2d.position.y) { MoveUp (); } if (rb2d.position.y < computer2d.position.y) { MoveDown (); } } if (rb2d.velocity.y < 0) { if (rb2d.position.y > computer2d.position.y) { MoveUp (); } if (rb2d.position.y < computer2d.position.y) { MoveDown (); } } } //Whilst it's not moving at the paddle, let it gain a slight reset by moving with the ball at a slower pace. if (rb2d.velocity.x < 0) { if (computer2d.position.y < 0) { computer2d.position += Vector2.up * reAdjustSpeed * Time.deltaTime; } if (computer2d.position.y > 0) { computer2d.position += Vector2.down * reAdjustSpeed * Time.deltaTime; } } } } void MoveDown() { if (Mathf.Abs(rb2d.velocity.y) > speed) { computer2d.position += Vector2.down * speed * Time.deltaTime; } else { computer2d.position += Vector2.down * speed * Time.deltaTime; } } void MoveUp() { if (Mathf.Abs (rb2d.velocity.y) > speed) { computer2d.position += Vector2.up * speed * Time.deltaTime; } else { computer2d.position += Vector2.up * speed * Time.deltaTime; } } }  
      I have looked up several posts across many different forums in order to create a much better AI. Most of the posts recommend that I use Raycasts to find out exactly where the ball might hit the paddle. I have looked up how to use them and I'm just completely lost, do raycasts consider collisions and go on infinitely or once they hit a wall, that's where it'll end up? Would anyone be able to help me understand raycasts a little better? 
      If you have another solution that enables me to calculate exactly where the ball will end up on the opponents side, I am more than willing to hear it
      Thanks again if you read this!
    • By isu diss
      How do I fill the gap between sky and terrain? Scaling the terrain or procedural terrain rendering?

  • Advertisement
  • Advertisement

Medieval RPG Project Needs YOU!

Recommended Posts

Hey there!

 

My name is Thomas, and I'm assembling a team of people to begin working on an RPG within Unity Engine. So far, the team consists of two Directors and a Programmer. 

The game is meant to be realistic and feature a world that is believable and could've happened. The game will feature a rich, detailed story, believable characters, and a unique lore.

Once the game is finished, it will be sold on the Steam Marketplace and any revenue will be shared with all who assist in the development of the game. 

Currently, we are looking for anyone to join, whether you be an aspiring writer, a seasoned programmer, or a talented artist. 

If you feel like helping out and being a part of something that could be big, or even asking some general questions, shoot me an email at: thomasmunson2277@gmail.com

 

Note: The game will be written entirely in C#.

My email: thomasmunson2277@gmail.com

Share this post


Link to post
Share on other sites
Advertisement

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