Humble Beginnings
"I taught myself how to play the guitar, which was a bad decision, cause I didn't know how to play it.
So I was a shitty teacher. I would never have went to me." -Mitch Hedberg
"I taught myself how to play the guitar, which was a bad decision, cause I didn't know how to play it.
So I was a shitty teacher. I would never have went to me." -Mitch Hedberg
My first impression of the programming world is that it's far bigger than I probably have time to explore — which doesn't mean I'm not going to try. The biggest problem is that I'm not totally certain what I actually want to do with any programming skills I might develop; my current major is a biochemistry/chemistry B.S. (although I'm only second year, so I haven't started on the upper division classes), so I don't really know how this would wind up applying. I just know that I'm interested in it, and that computer skills are the sort of thing that will generally come in handy somewhere, even if I don't have a plan for them now.
I know in my head that it would be impossible to explore it all, but my heart won't be satisfied until I've experienced every inch.
I'm programming on a Mac, so I build my programs in TextWrangler and run them in Terminal. I have Xcode and a few other tools downloaded for building larger projects, but since everything I'm doing now can largely fit in a single source file comfortably, I haven't started exploring those programs just yet. I don't really have any graphical tools at my disposal yet, but I wanted to do something other than program algorithms for comparing integers and such. So I built my first project (pictured above).
Right now, the program is just a model of an ascii stick figure on a 64x32 grid. I don't yet know how to output to a separate window where I specify the size, so I just resize Terminal to 64x33 manually (one extra line for input). It accepts w, a, s, d, and x as input. W, a, s, and d move the character around if he isn't at the edge of the game area. X exits the program.
Source code here: + Show Spoiler [Source Code] +
#include <stdio.h>
#define DIMX 64
#define DIMY 32
char display[DIMX][DIMY];
//gVariables
char input;
int end = 0;
struct object
{
int positionx;
int positiony;
int dimensionx;
int dimensiony;
char *modelp;
} player;
//Functions
int initializeObjects();
int standardDisplay();
void objectWriter(struct object writee);
int refresh(void);
//Object Models
char playerModel[3][3] =
{
{ 0x20, 0x6F, 0x20 }, /* o */
{ 0x2D, 0x7C, 0x2D }, /* -|- */
{ 0x2F, 0x20, 0x5C } /* / \ */
};
//This function sets the initial value for all objects.
int initializeObjects()
{
player = (struct object)
{
.positionx = 15,
.positiony = 29,
.dimensionx = 3,
.dimensiony = 3,
.modelp = &playerModel[0][0]
};
}
//This function displays the grid of characters that is the current screen.
int standardDisplay()
{
int i, j;
for (j=0; j<DIMY; j++)
{
for (i=0; i<DIMX; i++)
putchar(display[i][j]);
putchar('\n');
}
}
void objectWriter(struct object writee)
{
int id = writee.positionx, jd = writee.positiony, im, jm;
for (jm=0; jm < writee.dimensiony; jd++, jm++)
{
for (im = 0, id = writee.positionx; im < writee.dimensionx; id++, im++)
{
display[id][jd] =
(*(writee.modelp + writee.dimensionx * jm + im));
}
}
}
int refresh(void)
{
int i, j;
for (j=0; j<DIMY; j++)
for (i=0; i<DIMX; i++)
display[i][j] = 0x20;
return 0;
}
int movePlayer()
{
int movement[2]={0, 0};
input = getchar();
switch (input)
{
case 'w':
{
if(player.positiony > 1)
movement[1] = -1;
else
printf("/a");
break;
}
case 'a':
{
if(player.positionx > 1)
movement[0] = -1;
else
printf("/a");
break;
}
case 's':
{
if (player.positiony + player.dimensiony + 1 < DIMY)
movement[1] = 1;
else
printf("/a");
break;
}
case 'd':
{
if (player.positionx + player.dimensionx + 1 < DIMX)
movement[0] = 1;
else
printf("/a");
break;
}
case 'x':
{
end = 1;
break;
}
default:
break;
}
player.positionx += movement[0];
player.positiony += movement[1];
}
int main(void)
{
initializeObjects();
while(end != 1)
{
refresh();
objectWriter(player);
standardDisplay();
movePlayer();
}
return 0;
//So, uh, I should probably start thinking about Steam Greenlight, right?
}
#define DIMX 64
#define DIMY 32
char display[DIMX][DIMY];
//gVariables
char input;
int end = 0;
struct object
{
int positionx;
int positiony;
int dimensionx;
int dimensiony;
char *modelp;
} player;
//Functions
int initializeObjects();
int standardDisplay();
void objectWriter(struct object writee);
int refresh(void);
//Object Models
char playerModel[3][3] =
{
{ 0x20, 0x6F, 0x20 }, /* o */
{ 0x2D, 0x7C, 0x2D }, /* -|- */
{ 0x2F, 0x20, 0x5C } /* / \ */
};
//This function sets the initial value for all objects.
int initializeObjects()
{
player = (struct object)
{
.positionx = 15,
.positiony = 29,
.dimensionx = 3,
.dimensiony = 3,
.modelp = &playerModel[0][0]
};
}
//This function displays the grid of characters that is the current screen.
int standardDisplay()
{
int i, j;
for (j=0; j<DIMY; j++)
{
for (i=0; i<DIMX; i++)
putchar(display[i][j]);
putchar('\n');
}
}
void objectWriter(struct object writee)
{
int id = writee.positionx, jd = writee.positiony, im, jm;
for (jm=0; jm < writee.dimensiony; jd++, jm++)
{
for (im = 0, id = writee.positionx; im < writee.dimensionx; id++, im++)
{
display[id][jd] =
(*(writee.modelp + writee.dimensionx * jm + im));
}
}
}
int refresh(void)
{
int i, j;
for (j=0; j<DIMY; j++)
for (i=0; i<DIMX; i++)
display[i][j] = 0x20;
return 0;
}
int movePlayer()
{
int movement[2]={0, 0};
input = getchar();
switch (input)
{
case 'w':
{
if(player.positiony > 1)
movement[1] = -1;
else
printf("/a");
break;
}
case 'a':
{
if(player.positionx > 1)
movement[0] = -1;
else
printf("/a");
break;
}
case 's':
{
if (player.positiony + player.dimensiony + 1 < DIMY)
movement[1] = 1;
else
printf("/a");
break;
}
case 'd':
{
if (player.positionx + player.dimensionx + 1 < DIMX)
movement[0] = 1;
else
printf("/a");
break;
}
case 'x':
{
end = 1;
break;
}
default:
break;
}
player.positionx += movement[0];
player.positiony += movement[1];
}
int main(void)
{
initializeObjects();
while(end != 1)
{
refresh();
objectWriter(player);
standardDisplay();
movePlayer();
}
return 0;
//So, uh, I should probably start thinking about Steam Greenlight, right?
}
I wrote this program a few weeks ago, so even by now I've learned a few things I would probably do differently. I'll note my own criticisms just to seem slightly less inept when it comes to programming.
+ Show Spoiler [My Own Criticisms] +
-The "switch" decision construct doesn't need to put all the info for cases inside brackets. I dunno why I thought it did.
-I had just learned about global variables in this program and was excited to use them for the first time; I now know many people consider them to be bad form along the same lines as a "goto" command. If I wrote this again I would do it without global variables.
-At least in terminal, this program requires you to hit enter every time you input commands. Not only is this a hassle, but it means that if you enter multiple commands and then hit enter, the program carries out all those commands before waiting for input from you again. This appears to be an inherent characteristic of the getchar() function, so I've been investigating other possible functions to use. Some googling suggests getch() might be a possibility.
-I had just learned about global variables in this program and was excited to use them for the first time; I now know many people consider them to be bad form along the same lines as a "goto" command. If I wrote this again I would do it without global variables.
-At least in terminal, this program requires you to hit enter every time you input commands. Not only is this a hassle, but it means that if you enter multiple commands and then hit enter, the program carries out all those commands before waiting for input from you again. This appears to be an inherent characteristic of the getchar() function, so I've been investigating other possible functions to use. Some googling suggests getch() might be a possibility.
But ultimately, I'm looking for feedback from TL. What should I be doing differently? What should I focus on learning? I've read CecilSunkure's stuff on game design, and I think I'll try to buy some of the books he recommended in the near future. In the mean time, does anyone have any tips, tricks, or other manner of advice for me?