Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post Posted: September 30th, 2017, 1:41 am 
 

Joined: September 30th, 2017, 1:29 am
Posts: 1
I tried coding a program in which a box called car moves around a track with a green "zone" by minute 5 I had already failed, the car doesn't draw and I can't figure out the getters and setters, plz help...

The Header File:
Code:
#pragma once

#include "Keyboard.h"
#include "Mouse.h"
#include "Graphics.h"


class Game
{
public:
   Game( class MainWindow& wnd );
   Game( const Game& ) = delete;
   Game& operator=( const Game& ) = delete;
   void Go();
private:
   void ComposeFrame(int x = 1, int y = 1, int r = 0, int g = 0, int b = 0);
   void UpdateModel();
   /********************************/
   /*  User Functions              */
   /********************************/
private:
   MainWindow& wnd;
   Graphics gfx;
   /********************************/
   /*  User Variables              */
   int Carx = 100, Cary = 100; //Car X And Y Starting Coordinates
public:
   int Game::GetCarx(int x) //X Coordinate Getter
   {
      x = Carx;
      return x;
   }
   int Game::GetCary(int y) // Y Coordinate Getter
   {
      y = Cary;
      return y;
   }
   /********************************/
};

The Cpp File:
Code:
Game::Game( MainWindow& wnd )
   :
   wnd( wnd ),
   gfx( wnd )
{
}

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

void Game::UpdateModel()
{
}

void Game::ComposeFrame(int x, int y, int r, int g, int b)
{
   int screen_height, screen_lenght, DrawX, DrawY;
   GetCarx(DrawX); //Gets Car X and Y Coordinates Without Modisfyng them
   GetCary(DrawY);

   for (int DrawX; DrawX <= 200; DrawX++) //Suposed To Draw A Red Box
   {
      for (int DrawY; DrawY <= 300; DrawY++)
      {
         gfx.PutPixel(DrawX, DrawY, 200, 0, 0);
      }
   }


   for (int screen_height = 0; screen_height <= 799; screen_height++) //Draws The Green layer on the bottom of the screen
   {
      for (int screen_lenght = 400; screen_lenght <= 599; screen_lenght++)
      {
         gfx.PutPixel(screen_height, screen_lenght, 0, 200, 0);
      }
   }
   
}


Edited by albinopapa put code in code tags
Code:
[code][/code]


Top 
 Profile  
Reply with quote  
 Post Posted: September 30th, 2017, 5:56 am 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2908
Location: Oklahoma, United States
First, I'm a little confused by this
Code:
   int Game::GetCarx(int x) //X Coordinate Getter
   {
      x = Carx;
      return x;
   }
   int Game::GetCary(int y) // Y Coordinate Getter
   {
      y = Cary;
      return y;
   }

You pass in an X and Y, then assign a member CarX and CarY to them and pass out the X and Y, why not just pass out the CarX and CarY?
Code:
   int Game::GetCarx() //X Coordinate Getter
   {
      return Carx;
   }
   int Game::GetCary() // Y Coordinate Getter
   {
      return Cary;
   }


The next thing kind of explains the first thing I suppose
Code:
   int screen_height, screen_lenght, DrawX, DrawY;
   GetCarx(DrawX); //Gets Car X and Y Coordinates Without Modisfyng them
   GetCary(DrawY);

Your Get functions return a value, so you can treat them like values themselves.
Code:
   int screen_height, screen_lenght, DrawX, DrawY;
   int DrawX = GetCarx(); // Gets car X coordinate without modifying them
   int DrawY = GetCary(); // Gets car Y coordinate without modifying them

Since the functions return a copy of CarX/CarY you can do anything you want with the returned values.

There is a way to get the style you are going for to work, but I believe having them return a value and assigning the returned value to a new variable as I have shown is a better route.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post Posted: September 30th, 2017, 5:58 am 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2908
Location: Oklahoma, United States
Btw
Code:
int screen_height, screen_lenght

Declaring your variables at the top of the function is a bad idea, you should declare them just before using them and you should initialize them when you declare them if possible. You have those two declared at the top of ComposeFrame, but then you declare new instances of them in the two for loops at the bottom.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 3 posts ] 

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron