Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Pogresno shvatanje

[es] :: C/C++ programiranje :: C/C++ za početnike :: Pogresno shvatanje

[ Pregleda: 3452 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Parpil
Aleksa Ristic
Ucenik
Druga Ekonomska Skola
Beograd, Srbija

Član broj: 327493
Poruke: 4
95.180.26.*



Profil

icon Pogresno shvatanje27.01.2015. u 01:56 - pre 111 meseci
Nedavno sam poceo da ucim C++ i savladao sam neki deo osnovnih stvari i lako mi je da skapiram i napravim to, ali sada kad sam pokusao nesto bezveze da sklopim kako bi video sta sve mogu da uradim desilo mi se nesto cudno.


Napravio sam bool za pokupljen speed up (bool PickedSU) u .h fajlu sto mozete videti u sledecem kodu:

Code:
 #pragma once

#include "D3DGraphics.h"
#include "Keyboard.h"

class Game
{
public:
    Game( HWND hWnd,const KeyboardServer& kServer );
    void Go();
private:
    void ComposeFrame();
    void DrawTank(int xT1, int xY1, int xT2, int xY2);
    void DrawSpeedUp(int xSU, int ySU);
    /********************************/
    /*  User Functions              */

    // TODO: User functions go here

    /********************************/
private:
    D3DGraphics gfx;
    KeyboardClient kbd;
    /********************************/
    /*  User Variables              */
    int xT1;
    int xT2;
    int xY1;
    int xY2;
    int xTS;

    int xSU;
    int ySU;

    [b] bool PickedSU; [/b]
    // TODO: User variables go here

    /********************************/
};


Potom sam definisao u .cpp da mi PicedSU bude false ali kasnije kad sam mu stavio pod if da ukoliko je na true nacrta odredjeni predmet, on iako je false ga crta pa je moje pitanje do cega je to?

Evo drugog dela koda(cpp):
Code:

#include "Game.h"

Game::Game( HWND hWnd,const KeyboardServer& kServer )
:    gfx ( hWnd ),
    kbd( kServer ),
    xT1( 0 ),
    xT2( 0 ),
    xY1( 0 ),
    xY2( 0 ),
    xTS( 3 ),
    xSU( 100 ),
    ySU( 250 ),
    PickedSU( false )
{}

void Game::Go()
{
    gfx.BeginFrame();
    ComposeFrame();
    gfx.EndFrame();
}

void Game::DrawTank(int xT1, int xY1, int xT2, int xY2)
{
    gfx.DrawLine(910 + xT1, 880 + xY1, 910 + xT2, 800 + xY2, 255, 255, 255);
    gfx.DrawLine(911 + xT1, 880 + xY1, 911 + xT2, 800 + xY2, 255, 255, 255);
    gfx.DrawLine(912 + xT1, 880 + xY1, 912 + xT2, 810 + xY2, 255, 255, 255);
    gfx.DrawLine(913 + xT1, 880 + xY1, 913 + xT2, 810 + xY2, 255, 255, 255);
    gfx.DrawLine(914 + xT1, 880 + xY1, 914 + xT2, 810 + xY2, 255, 255, 255);
    gfx.DrawLine(915 + xT1, 880 + xY1, 915 + xT2, 815 + xY2, 255, 255, 255);
    gfx.DrawLine(916 + xT1, 880 + xY1, 916 + xT2, 815 + xY2, 255, 255, 255);
    gfx.DrawLine(917 + xT1, 880 + xY1, 917 + xT2, 820 + xY2, 255, 255, 255);
    gfx.DrawLine(918 + xT1, 880 + xY1, 918 + xT2, 820 + xY2, 255, 255, 255);
    gfx.DrawLine(919 + xT1, 880 + xY1, 919 + xT2, 830 + xY2, 255, 255, 255);
    gfx.DrawLine(920 + xT1, 880 + xY1, 920 + xT2, 830 + xY2, 255, 255, 255);
    gfx.DrawLine(921 + xT1, 880 + xY1, 921 + xT2, 830 + xY2, 255, 255, 255);
    gfx.DrawLine(922 + xT1, 880 + xY1, 922 + xT2, 830 + xY2, 255, 255, 255);
    gfx.DrawLine(923 + xT1, 880 + xY1, 923 + xT2, 830 + xY2, 255, 255, 255);
    gfx.DrawLine(924 + xT1, 880 + xY1, 924 + xT2, 830 + xY2, 255, 255, 255);

    gfx.DrawLine(909 + xT1, 880 + xY1, 909 + xT2, 800 + xY2, 255, 255, 255);
    gfx.DrawLine(908 + xT1, 880 + xY1, 908 + xT2, 810 + xY2, 255, 255, 255);
    gfx.DrawLine(907 + xT1, 880 + xY1, 907 + xT2, 810 + xY2, 255, 255, 255);
    gfx.DrawLine(906 + xT1, 880 + xY1, 906 + xT2, 810 + xY2, 255, 255, 255);
    gfx.DrawLine(905 + xT1, 880 + xY1, 905 + xT2, 815 + xY2, 255, 255, 255);
    gfx.DrawLine(904 + xT1, 880 + xY1, 904 + xT2, 815 + xY2, 255, 255, 255);
    gfx.DrawLine(903 + xT1, 880 + xY1, 903 + xT2, 820 + xY2, 255, 255, 255);
    gfx.DrawLine(902 + xT1, 880 + xY1, 902 + xT2, 820 + xY2, 255, 255, 255);
    gfx.DrawLine(901 + xT1, 880 + xY1, 901 + xT2, 830 + xY2, 255, 255, 255);
    gfx.DrawLine(900 + xT1, 880 + xY1, 900 + xT2, 830 + xY2, 255, 255, 255);
    gfx.DrawLine(899 + xT1, 880 + xY1, 899 + xT2, 830 + xY2, 255, 255, 255);
    gfx.DrawLine(898 + xT1, 880 + xY1, 898 + xT2, 830 + xY2, 255, 255, 255);
    gfx.DrawLine(897 + xT1, 880 + xY1, 897 + xT2, 830 + xY2, 255, 255, 255);
    gfx.DrawLine(896 + xT1, 880 + xY1, 896 + xT2, 830 + xY2, 255, 255, 255);
}

void Game::DrawSpeedUp(int xSU, int ySU)
{
    gfx.PutPixel(1 + xSU, 1 + ySU, 255, 255, 255);
    gfx.PutPixel(2 + xSU, 1 + ySU, 255, 255, 255);
    gfx.PutPixel(3 + xSU, 1 + ySU, 255, 255, 255);
    gfx.PutPixel(4 + xSU, 1 + ySU, 255, 255, 255);
    gfx.PutPixel(5 + xSU, 1 + ySU, 255, 255, 255);
    gfx.PutPixel(6 + xSU, 1 + ySU, 255, 255, 255);
    gfx.PutPixel(7 + xSU, 1 + ySU, 255, 255, 255);
    gfx.PutPixel(8 + xSU, 1 + ySU, 255, 255, 255);

    gfx.PutPixel(1 + xSU, 2 + ySU, 255, 255, 255);
    gfx.PutPixel(2 + xSU, 2 + ySU, 255, 255, 255);
    gfx.PutPixel(3 + xSU, 2 + ySU, 255, 255, 255);
    gfx.PutPixel(4 + xSU, 2 + ySU, 255, 255, 255);
    gfx.PutPixel(5 + xSU, 2 + ySU, 255, 255, 255);
    gfx.PutPixel(6 + xSU, 2 + ySU, 255, 255, 255);
    gfx.PutPixel(7 + xSU, 2 + ySU, 255, 255, 255);
    gfx.PutPixel(8 + xSU, 2 + ySU, 255, 255, 255);

    gfx.PutPixel(1 + xSU, 3 + ySU, 255, 255, 255);
    gfx.PutPixel(2 + xSU, 3 + ySU, 255, 255, 255);
    gfx.PutPixel(3 + xSU, 3 + ySU, 255, 255, 255);
    gfx.PutPixel(4 + xSU, 3 + ySU, 255, 255, 255);
    gfx.PutPixel(5 + xSU, 3 + ySU, 255, 255, 255);
    gfx.PutPixel(6 + xSU, 3 + ySU, 255, 255, 255);
    gfx.PutPixel(7 + xSU, 3 + ySU, 255, 255, 255);
    gfx.PutPixel(8 + xSU, 3 + ySU, 255, 255, 255);

    gfx.PutPixel(1 + xSU, 4 + ySU, 255, 255, 255);
    gfx.PutPixel(2 + xSU, 4 + ySU, 255, 255, 255);
    gfx.PutPixel(3 + xSU, 4 + ySU, 255, 255, 255);
    gfx.PutPixel(4 + xSU, 4 + ySU, 255, 255, 255);
    gfx.PutPixel(5 + xSU, 4 + ySU, 255, 255, 255);
    gfx.PutPixel(6 + xSU, 4 + ySU, 255, 255, 255);
    gfx.PutPixel(7 + xSU, 4 + ySU, 255, 255, 255);
    gfx.PutPixel(8 + xSU, 4 + ySU, 255, 255, 255);

    gfx.PutPixel(1 + xSU, 5 + ySU, 255, 255, 255);
    gfx.PutPixel(2 + xSU, 5 + ySU, 255, 255, 255);
    gfx.PutPixel(3 + xSU, 5 + ySU, 255, 255, 255);
    gfx.PutPixel(4 + xSU, 5 + ySU, 255, 255, 255);
    gfx.PutPixel(5 + xSU, 5 + ySU, 255, 255, 255);
    gfx.PutPixel(6 + xSU, 5 + ySU, 255, 255, 255);
    gfx.PutPixel(7 + xSU, 5 + ySU, 255, 255, 255);
    gfx.PutPixel(8 + xSU, 5 + ySU, 255, 255, 255);

    gfx.PutPixel(1 + xSU, 6 + ySU, 255, 255, 255);
    gfx.PutPixel(2 + xSU, 6 + ySU, 255, 255, 255);
    gfx.PutPixel(3 + xSU, 6 + ySU, 255, 255, 255);
    gfx.PutPixel(4 + xSU, 6 + ySU, 255, 255, 255);
    gfx.PutPixel(5 + xSU, 6 + ySU, 255, 255, 255);
    gfx.PutPixel(6 + xSU, 6 + ySU, 255, 255, 255);
    gfx.PutPixel(7 + xSU, 6 + ySU, 255, 255, 255);
    gfx.PutPixel(8 + xSU, 6 + ySU, 255, 255, 255);

    gfx.PutPixel(1 + xSU, 7 + ySU, 255, 255, 255);
    gfx.PutPixel(2 + xSU, 7 + ySU, 255, 255, 255);
    gfx.PutPixel(3 + xSU, 7 + ySU, 255, 255, 255);
    gfx.PutPixel(4 + xSU, 7 + ySU, 255, 255, 255);
    gfx.PutPixel(5 + xSU, 7 + ySU, 255, 255, 255);
    gfx.PutPixel(6 + xSU, 7 + ySU, 255, 255, 255);
    gfx.PutPixel(7 + xSU, 7 + ySU, 255, 255, 255);
    gfx.PutPixel(8 + xSU, 7 + ySU, 255, 255, 255);

    gfx.PutPixel(1 + xSU, 8 + ySU, 255, 255, 255);
    gfx.PutPixel(2 + xSU, 8 + ySU, 255, 255, 255);
    gfx.PutPixel(3 + xSU, 8 + ySU, 255, 255, 255);
    gfx.PutPixel(4 + xSU, 8 + ySU, 255, 255, 255);
    gfx.PutPixel(5 + xSU, 8 + ySU, 255, 255, 255);
    gfx.PutPixel(6 + xSU, 8 + ySU, 255, 255, 255);
    gfx.PutPixel(7 + xSU, 8 + ySU, 255, 255, 255);
    gfx.PutPixel(8 + xSU, 8 + ySU, 255, 255, 255);
}

void Game::ComposeFrame()
{

    if(PickedSU = true)
    {
        DrawSpeedUp(150, 500);
    }
    
    //=======================================================================
    //=======================================================================
    //=======================================================================
    if( kbd.RightIsPressed() )
    {
        xT1 = xT1 + xTS;
        xY1 = xY1 + xTS;
    }
    if( kbd.LeftIsPressed() )
    {
        xT1 = xT1 - xTS;
        xY1 = xY1 - xTS;
    }
    if( kbd.UpIsPressed() )
    {
        xT2 = xT2 - xTS;
        xY2 = xY2 - xTS;
    }
    if( kbd.DownIsPressed() )
    {
        xT2 = xT2 + xTS;
        xY2 = xY2 + xTS;
    }
    if( kbd.SpaceIsPressed() )
    {
        xTS++;
    }
    //=======================================================================
    //=======================================================================
    //=======================================================================
    DrawTank(xT1, xT2, xY1, xY2);
    
}
 
Odgovor na temu

Odin D.
Mlađi referent za automatizaciju
samoupravljanja

Član broj: 37292
Poruke: 2549



+8370 Profil

icon Re: Pogresno shvatanje27.01.2015. u 02:25 - pre 111 meseci
Ovo crveno ti je greška:

if(PickedSU = true)

Umjesto = treba ==.
 
Odgovor na temu

Parpil
Aleksa Ristic
Ucenik
Druga Ekonomska Skola
Beograd, Srbija

Član broj: 327493
Poruke: 4
95.180.26.*



Profil

icon Re: Pogresno shvatanje27.01.2015. u 02:48 - pre 111 meseci
Kolicna greska i nisam je primetio, svaki put kad stavljam = zaboravim da mora ==. Sve u svemu hvala ti. Bice jos dosta pitanja na ovom forumu od mene a vec pripremam jedno koje je isto vezano za ovo sto radim :)
 
Odgovor na temu

Odin D.
Mlađi referent za automatizaciju
samoupravljanja

Član broj: 37292
Poruke: 2549



+8370 Profil

icon Re: Pogresno shvatanje27.01.2015. u 03:52 - pre 111 meseci
Inače, ako si već definisao tu varijablu kao bool, stilski je bolje da pišeš

if (PickedSU)

nego

if (PickedSu == true).
 
Odgovor na temu

glorius
Damir Nikolic
C++ developer
SR

Član broj: 4366
Poruke: 428
*.dynamic.isp.telekom.rs.

ICQ: 208550327


+14 Profil

icon Re: Pogresno shvatanje27.01.2015. u 17:20 - pre 111 meseci
Iako ja licno taj nacin ne preferiram, da bi uvek bio siguran i da te kompajler na vreme upozori mozes koristiti sledecu sintaksu:

if(true == PickedSu)
{

}
EOF
 
Odgovor na temu

Burgos
Nemanja Borić
Amazon Web Services
Berlin

Član broj: 12484
Poruke: 1947
91.108.183.*

Sajt: stackoverflow.com/users/1..


+480 Profil

icon Re: Pogresno shvatanje27.01.2015. u 17:29 - pre 111 meseci
Dobar kompajler će te svakako upozoriti. Treba samo čitati upozorenja.
 
Odgovor na temu

[es] :: C/C++ programiranje :: C/C++ za početnike :: Pogresno shvatanje

[ Pregleda: 3452 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.