Null Purification.

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Null Purification.

Post 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...
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post 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; }
}
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post 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.
TiredSikTwisted
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 72
Joined: Sat Feb 05, 2005 1:11 pm
Location: /root
Contact:

Post 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.
Image
精神の屈折:復讐
#animeflix @ irc.aniverse.com
Official Internet Relay Chat Moderator Guy (OircMG) of animeflix.info
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post 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.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post 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.
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post 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.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

Yep. :D How's the chainsaw game comin' ?
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

Slow as poot. I'm currently lacking motivation to do much.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post 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?
DJ Yoshi
Game Developer
Game Developer
Posts: 1021
Joined: Wed Mar 02, 2005 9:12 pm
Location: Madison, AL

Post by DJ Yoshi »

Some damn sexy code, but Gyro's right about the private. Or at least, I agree with him ;)
There is no signature.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

Everybody welcome DJ Yoshi to the deep, dark regions of the secret development forums. Welcome.
DJ Yoshi
Game Developer
Game Developer
Posts: 1021
Joined: Wed Mar 02, 2005 9:12 pm
Location: Madison, AL

Post by DJ Yoshi »

<_< >_>

SHTI!
There is no signature.
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post 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.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
DJ Yoshi
Game Developer
Game Developer
Posts: 1021
Joined: Wed Mar 02, 2005 9:12 pm
Location: Madison, AL

Post 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 ;)
There is no signature.
Post Reply