<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Bewegung von Kreisen]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ich will ein kleines Spielchen programmieren, wo ich erstmal kreise bewegen will, welche auf Feldern stehen, und sich dann halt per Pfeiltasten bewegen können.</p>
<p>Hier ist der Code:</p>
<pre><code>#include &lt;windows.h&gt;
#include &lt;string&gt;

LRESULT CALLBACK wndproc(HWND, UINT, WPARAM, LPARAM);

const char titel[]=&quot;Titel&quot;;
bool tasten[4];
int punkte;
int x, y, xfeld, yfeld, xdav, ydav;
int feld[20][20];
char buffer[25];
int zahlerx, zahlery;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
                   PSTR szCmdLine, int iCmdShow)
{
     MSG msg;
     WNDCLASS wc;
     HWND hWnd;

     wc.style=CS_HREDRAW;
     wc.lpfnWndProc=wndproc;
     wc.lpszClassName=titel;
     wc.lpszMenuName=NULL;
     wc.cbClsExtra=0;
     wc.cbWndExtra=0;
     wc.hInstance=hInstance;
     wc.hCursor=NULL;
     wc.hIcon=NULL;
     wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);

     RegisterClass(&amp;wc);

     hWnd=CreateWindow(titel, titel, WS_OVERLAPPEDWINDOW,
                        CW_USEDEFAULT, CW_USEDEFAULT,
                        640,480,
                        NULL, NULL,
                        hInstance, NULL);

     ShowWindow(hWnd, iCmdShow);
     UpdateWindow(hWnd);

     x=120;y=120;
     feld[0][0]=1;
     feld[1][0]=1;
     feld[2][0]=1;
     while (GetMessage(&amp;msg, NULL, 0,0))
     {
           TranslateMessage(&amp;msg);
           DispatchMessage(&amp;msg);
           if (tasten[0] &amp;&amp; y&gt;100){ydav=y;y-=1;}
           if (tasten[1] &amp;&amp; y&lt;380){ydav=y;y+=1;}
           if (tasten[2] &amp;&amp; x&gt;50){xdav=x;x-=1;}
           if (tasten[3] &amp;&amp; x&lt;480){xdav=x;x+=1;}
           xfeld=(x-50)/20;
           yfeld=(y-100)/20;
           }

     return(msg.wParam);
}

LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
        switch (msg)
        {                 
               case (WM_DESTROY):
               {
                    PostQuitMessage(0);
                    return(0);
                    }
               case (WM_PAINT):
               {
                    PAINTSTRUCT ps;
                    HDC hDc;
                    HDC hDc2;
                    HBITMAP bitmap;
                    hDc=BeginPaint(hWnd, &amp;ps);
                    {
                          hDc2=CreateCompatibleDC(hDc);
                          bitmap=CreateCompatibleBitmap(hDc, 640,480);
                          SelectObject(hDc2, bitmap);
                          HBRUSH hOldBrush=(HBRUSH)SelectObject(hDc2, 
                                            CreateSolidBrush(RGB(255,255,255)));
                          RoundRect(hDc2, 0, 0,640, 480, 1, 1);
                          RoundRect(hDc2, 50,100,500,400,1,1);
                          for (zahlerx=0;zahlerx&lt;20;zahlerx++)
                          {
                              for(zahlery=0;zahlery&lt;20;zahlery++)
                              {
                                  if (feld[zahlerx][zahlery]==1)
                                  {   
                                      RoundRect(hDc2, 50+zahlerx*20,100+zahlery*20,
                                                50+zahlerx*20+20, 100+zahlery*20+20,1,1);}
                                      if (zahlerx==xfeld &amp;&amp; zahlery==yfeld)
                                      {
                                            x=xdav;y=ydav;
                                            } 
                              }
                          }
                          sprintf(buffer, &quot;Punkte: %d X: %d, Y: %d&quot;, punkte, xfeld, yfeld);
                          TextOut(hDc2, 50,50,buffer,sizeof(buffer)-1);
                          RoundRect(hDc2, x,y,x+20,y+20,20,20);
                          BitBlt(hDc, 0,0,640,480,hDc2, 0,0,SRCCOPY);
                          DeleteObject(bitmap);
                          DeleteDC(hDc2);
                          }
                    EndPaint(hWnd, &amp;ps);
                    }

               case WM_KEYDOWN:
                    {
                       switch (wParam)
                       {
                              case (VK_UP):{tasten[0]=true;break;}
                              case (VK_DOWN):{tasten[1]=true;break;}
                              case (VK_LEFT):{tasten[2]=true;break;}
                              case (VK_RIGHT):{tasten[3]=true;break;}
                              }
                              InvalidateRect(hWnd, NULL, false);
                              return(0);
                       }
               case WM_KEYUP:
                    {
                       switch (wParam)
                       {
                              case (VK_UP):{tasten[0]=false;break;}
                              case (VK_DOWN):{tasten[1]=false;break;}
                              case (VK_LEFT):{tasten[2]=false;break;}
                              case (VK_RIGHT):{tasten[3]=false;break;}
                              InvalidateRect(hWnd, NULL, false);
                              return(0);
                              }
                       }                               
        }

        return (DefWindowProc(hWnd,msg, wParam, lParam));
}
</code></pre>
<p>Das Problem: das bewegt sich nicht annährend so, wie ich mir das vorstelle(d.h., es kommt teilweise außerhalb des gezeichneten Randvierecks, und bewegt sich in dem Viereck langsamer). Kann mir jemand sagen, was ich ändern muss, damit eine Bewegung im Viereck möglich ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/146973/bewegung-von-kreisen</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Jul 2026 18:26:55 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/146973.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 12 May 2006 13:42:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Bewegung von Kreisen on Fri, 12 May 2006 13:42:26 GMT]]></title><description><![CDATA[<p>Hallo!</p>
<p>Ich will ein kleines Spielchen programmieren, wo ich erstmal kreise bewegen will, welche auf Feldern stehen, und sich dann halt per Pfeiltasten bewegen können.</p>
<p>Hier ist der Code:</p>
<pre><code>#include &lt;windows.h&gt;
#include &lt;string&gt;

LRESULT CALLBACK wndproc(HWND, UINT, WPARAM, LPARAM);

const char titel[]=&quot;Titel&quot;;
bool tasten[4];
int punkte;
int x, y, xfeld, yfeld, xdav, ydav;
int feld[20][20];
char buffer[25];
int zahlerx, zahlery;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
                   PSTR szCmdLine, int iCmdShow)
{
     MSG msg;
     WNDCLASS wc;
     HWND hWnd;

     wc.style=CS_HREDRAW;
     wc.lpfnWndProc=wndproc;
     wc.lpszClassName=titel;
     wc.lpszMenuName=NULL;
     wc.cbClsExtra=0;
     wc.cbWndExtra=0;
     wc.hInstance=hInstance;
     wc.hCursor=NULL;
     wc.hIcon=NULL;
     wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);

     RegisterClass(&amp;wc);

     hWnd=CreateWindow(titel, titel, WS_OVERLAPPEDWINDOW,
                        CW_USEDEFAULT, CW_USEDEFAULT,
                        640,480,
                        NULL, NULL,
                        hInstance, NULL);

     ShowWindow(hWnd, iCmdShow);
     UpdateWindow(hWnd);

     x=120;y=120;
     feld[0][0]=1;
     feld[1][0]=1;
     feld[2][0]=1;
     while (GetMessage(&amp;msg, NULL, 0,0))
     {
           TranslateMessage(&amp;msg);
           DispatchMessage(&amp;msg);
           if (tasten[0] &amp;&amp; y&gt;100){ydav=y;y-=1;}
           if (tasten[1] &amp;&amp; y&lt;380){ydav=y;y+=1;}
           if (tasten[2] &amp;&amp; x&gt;50){xdav=x;x-=1;}
           if (tasten[3] &amp;&amp; x&lt;480){xdav=x;x+=1;}
           xfeld=(x-50)/20;
           yfeld=(y-100)/20;
           }

     return(msg.wParam);
}

LRESULT CALLBACK wndproc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
        switch (msg)
        {                 
               case (WM_DESTROY):
               {
                    PostQuitMessage(0);
                    return(0);
                    }
               case (WM_PAINT):
               {
                    PAINTSTRUCT ps;
                    HDC hDc;
                    HDC hDc2;
                    HBITMAP bitmap;
                    hDc=BeginPaint(hWnd, &amp;ps);
                    {
                          hDc2=CreateCompatibleDC(hDc);
                          bitmap=CreateCompatibleBitmap(hDc, 640,480);
                          SelectObject(hDc2, bitmap);
                          HBRUSH hOldBrush=(HBRUSH)SelectObject(hDc2, 
                                            CreateSolidBrush(RGB(255,255,255)));
                          RoundRect(hDc2, 0, 0,640, 480, 1, 1);
                          RoundRect(hDc2, 50,100,500,400,1,1);
                          for (zahlerx=0;zahlerx&lt;20;zahlerx++)
                          {
                              for(zahlery=0;zahlery&lt;20;zahlery++)
                              {
                                  if (feld[zahlerx][zahlery]==1)
                                  {   
                                      RoundRect(hDc2, 50+zahlerx*20,100+zahlery*20,
                                                50+zahlerx*20+20, 100+zahlery*20+20,1,1);}
                                      if (zahlerx==xfeld &amp;&amp; zahlery==yfeld)
                                      {
                                            x=xdav;y=ydav;
                                            } 
                              }
                          }
                          sprintf(buffer, &quot;Punkte: %d X: %d, Y: %d&quot;, punkte, xfeld, yfeld);
                          TextOut(hDc2, 50,50,buffer,sizeof(buffer)-1);
                          RoundRect(hDc2, x,y,x+20,y+20,20,20);
                          BitBlt(hDc, 0,0,640,480,hDc2, 0,0,SRCCOPY);
                          DeleteObject(bitmap);
                          DeleteDC(hDc2);
                          }
                    EndPaint(hWnd, &amp;ps);
                    }

               case WM_KEYDOWN:
                    {
                       switch (wParam)
                       {
                              case (VK_UP):{tasten[0]=true;break;}
                              case (VK_DOWN):{tasten[1]=true;break;}
                              case (VK_LEFT):{tasten[2]=true;break;}
                              case (VK_RIGHT):{tasten[3]=true;break;}
                              }
                              InvalidateRect(hWnd, NULL, false);
                              return(0);
                       }
               case WM_KEYUP:
                    {
                       switch (wParam)
                       {
                              case (VK_UP):{tasten[0]=false;break;}
                              case (VK_DOWN):{tasten[1]=false;break;}
                              case (VK_LEFT):{tasten[2]=false;break;}
                              case (VK_RIGHT):{tasten[3]=false;break;}
                              InvalidateRect(hWnd, NULL, false);
                              return(0);
                              }
                       }                               
        }

        return (DefWindowProc(hWnd,msg, wParam, lParam));
}
</code></pre>
<p>Das Problem: das bewegt sich nicht annährend so, wie ich mir das vorstelle(d.h., es kommt teilweise außerhalb des gezeichneten Randvierecks, und bewegt sich in dem Viereck langsamer). Kann mir jemand sagen, was ich ändern muss, damit eine Bewegung im Viereck möglich ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1056481</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1056481</guid><dc:creator><![CDATA[DaGeRe]]></dc:creator><pubDate>Fri, 12 May 2006 13:42:26 GMT</pubDate></item></channel></rss>