Page 1 of 2

Null Purification.

Posted: Thu Feb 24, 2005 5:49 pm
by Falco Girgis
For those of you who didn't know, I'm pretty much rewriting Null only this time I'm using good programming practices.

I just wanna show something off:

Code: Select all

class Player {
private:
    float x, y;
    float xvel, yvel;
	uint16 width, height;

	uint16 life;

    bool run;
	bool jump;
    bool letgo;       //keeps track if the user is holding down jump
	bool canshoot;    //keeps track if the user can shoot
    bool dir;
	bool dieing;
    float jumptimer;
	uint32 runtimer;
	uint64 deathtimer;
public:
	block Block[8];
	buster Buster;

    Player() {
        x = 0;
        y = 0;
        xvel = 0;
        yvel = 0;
        jump = false;
        letgo = true;
        jumptimer = 0;
		canshoot = true;
		run = false;
		runtimer = 0;
		dieing = false;
		width = 32;
		height = 64;
		life = 20;
    }

	float get_x() { return x; }
	void set_x(int nx) { x = nx; }
	float get_y() { return y; }
	void set_y(int ny) { y = ny; }
	float get_xvel() { return xvel; }
	void set_xvel(float x) { xvel = x; }
	float get_yvel() { return yvel; }
	void set_yvel(float y) { yvel = y; }

	uint16 get_life() { return life; }
	void set_life(uint16 l) { life = l; }
	uint16 get_width() { return width; }
	void set_width(uint16 w) { width = w; }
	uint16 get_height() { return height; }
	void set_height(uint16 h) { height = h; }

	bool get_run() { return run; }
	void set_run(bool r) { run = r; }
	bool get_jump() { return jump; }
	void set_jump(bool j) { jump = j; }
	bool get_letgo() { return letgo; }
	void set_letgo(bool l) { letgo = l; }
	bool get_canshoot() { return canshoot; }
	void set_canshoot(bool c) { canshoot = c; }
	bool get_dir() { return dir; }
	void set_dir(bool d) { dir = d; }
	bool set_dieing() { return dieing; }
	void set_dieing(bool d) { dieing = d; }
	float get_jumptimer() { return jumptimer; }
	void set_jumptimer(float t) { jumptimer = t; }
	uint32 get_runtimer() { return runtimer; }
	void set_runtimer(uint32 t) { runtimer = t; }
	uint64 get_deathtimer() { return deathtimer; }
	void set_deathtimer(uint64 t) { deathtimer = t; }

	void DrawPlayer() {
		if(!dieing) {
			draw_tr_quad((int)x + 16 - Gemini.scroll_x, (int)y + 16 - Gemini.scroll_y, 1, width, height, 1, 256-1, 256-140, 256-255);
			draw_tr_quad((int)x + 16 - Gemini.scroll_x, (int)y + 16 - Gemini.scroll_y, 2, width - 4, height - 4, 1, 256-1, 256-1, 256-255);
		}
	}

	void UpdateMisc() {
		//simulate gravity (probably should be in jump function later)
        yvel = yvel + Gravity;

        //simulate friction
        if(xvel < 0) xvel = xvel + Gravity;
        if(xvel > 0) xvel = xvel - Gravity; 

        //sorry, can't jump while falling :D
        if(yvel > 1) jump = true;
	
		//Keep dude from moving too fast.
	    if( abs((int)xvel) > 3 )
            (xvel < 0)? xvel = -3 : xvel = 3;
	}

	void Die();
	friend int MoveHorizontal();
	friend int MoveVertical();
	void Bleed();
	void Update();
	void DrawLife();
};
C'mon, look at that baby. God would be proud...

Posted: Fri Feb 25, 2005 7:42 am
by JS Lemming
My style is not to make all vars accessor deals. I only use accessor methods when I want to add checking, for example:

Code: Select all

void SetLife(int value)
{
   life = value;
   if(life > maxlife) { life = maxlife; }
}

Posted: Fri Feb 25, 2005 8:38 am
by Falco Girgis
According to over 90% of all programmers you have a crappy style then. I NEVER used accessor methods.

I just recently conformed. I've talked to people who do that sort of thing for a living (my uncle most specifically). When you look for work, they really do look for stuff like that. They aren't going to hire some guy who codes like an ass.

Posted: Fri Feb 25, 2005 3:57 pm
by TiredSikTwisted
The code that JS wrote is the same way you do code in most other languages... I don't see the issue with it.

Posted: Fri Feb 25, 2005 4:37 pm
by JS Lemming
GyroVorbis wrote:According to over 90% of all programmers you have a crappy style then. I NEVER used accessor methods.

I just recently conformed. I've talked to people who do that sort of thing for a living (my uncle most specifically). When you look for work, they really do look for stuff like that. They aren't going to hire some guy who codes like an ass.
Whoa dude... since when are you the all knowing master of the only correct style of programming. I say, whatever works best for the individual programmer and/or program.

And I don't think I will have a hard time getting a job if that is what you are impling.

Posted: Fri Feb 25, 2005 4:53 pm
by Falco Girgis
Err... no, I wasn't implying anything of that nature. I was just 1) giving you a hard time. 2) giving you a more hard time. :D
TiredSikTwisted wrote:The code that JS wrote is the same way you do code in most other languages... I don't see the issue with it.
Of course there isn't an issue. What I posted can be done and same with his. Mine is just more standardized and recommended. That's why you have private in C++. If you're going to make everything public, then why have private?

The goal is not to let any part of the program have direct access to the member variables (in theory). When your program gets long ass and gigantic, it can cause problems and lots of bugs.

Posted: Fri Feb 25, 2005 5:59 pm
by JS Lemming
It would only cause problems later on IF you made an error in you programming anyway. Its not like there is a bug with not using the acc methods. But yeah, you do enjoy giving me a hard time don't you.

Posted: Fri Feb 25, 2005 6:03 pm
by Falco Girgis
Yep. :D How's the chainsaw game comin' ?

Posted: Fri Feb 25, 2005 6:14 pm
by JS Lemming
Slow as poot. I'm currently lacking motivation to do much.

Posted: Wed Mar 02, 2005 10:16 pm
by Falco Girgis
I've decided to stick with private data members with classes. But, that's only when I do use classes. I'm reducing my use of classing to only about 10% of my OO needs. Everything else will be nice structs.

Structs
Structs
Structs
Strucs

penis?

Posted: Wed Mar 02, 2005 10:57 pm
by DJ Yoshi
Some damn sexy code, but Gyro's right about the private. Or at least, I agree with him ;)

Posted: Wed Mar 02, 2005 11:04 pm
by Falco Girgis
Everybody welcome DJ Yoshi to the deep, dark regions of the secret development forums. Welcome.

Posted: Wed Mar 02, 2005 11:33 pm
by DJ Yoshi
<_< >_>

SHTI!

Posted: Thu Mar 03, 2005 7:27 am
by JS Lemming
Why is Dj Yoshi admitted in here. Is he developing anything? New people, heed the warning about squeling anything. I'm serious.

Posted: Thu Mar 03, 2005 1:21 pm
by DJ Yoshi
I'm currently learning SDL, and I'm a fairly good friend of Falco's IRL.

Trust me, I wouldn't squeal. I'm into that kind of thing ;)