Friday, June 6, 2008

Wednesday, June 4, 2008

JJJFFFJFJFJFJFJFJJJFFFFFFJJJFFFJJJJFJFF

Ok ... type to learn lesson one: F and J

Actually I made the background scroll with the guy ... soon this will be added to the website, but I need to be at home to do that...

Here is the segment of code used:

if(_root.player._y > 100){
_root.player._y -= 2;
} else {
_root.wall._y += 2;
}
Okayyy, so here we have an if statement determined by the position of the player on the y axis. If the player's y value is greater than 100 (remember y axis is reversed in flash) the player will move up (y-2) and if the player is less than 100 (near the top) the wall will move down instead of the player moving up.

This all gives the effect of the player moving up, yet the player will never reach the edge of the screen because as soon as it hits the y = 100 point the wall will move instead!

SWF coming soon!

Tuesday, June 3, 2008

ASDFGHJKL

Here are a few of my .swf's :

http://www.maxhardcastle.com/Indy2008/IndyIndex.html

Hope that clears up the program from before (It's the one titled Trigonometry) ...

Monday, June 2, 2008

ABCDEFGHIJKLMNOPQRSTUVWXYZ

OKAAAAAAAAYYYY

So the four corner point thing didn't work out so well... It's basically a lot more buggy than the first version, but perhaps I messed up a corner. Who knows.

In other news I've been working with some trig and managed to make a rotating circle program. I think I might dedicate a page of my website to Flash swf's since I learned the other day that I have 300gigs of space to use (maxhardcastle.com server thing).

Here's a snippet of code from that program outlining some new stuff:

angle = Math.atan(mousex/mousey)

xval = _root.circle._x + radius*Math.cos(angle);
yval = _root.circle._y - radius*Math.sin(angle);


New terms:
Math.atan - This is the "arctan" or inverse tangent function ... returns a value in radians ...
Math.cos - cosine...
Math.sin - sine...
and later on:
Math.PI - 3.141592653584626 (That's all I can remember... might be wrong)

Here the code finds the angle that the mouse creates in relation to the center of the coordinate plane designated by the center of the movie clip that this code resides in. That might seem complicated, but it really isn't. There is a circle on the screen, the center of the circle is the origin. Imagine there is a point where the mouse is, now draw a line from that point to the origin, and then find the angle of that line in relation to the x axis.

The second part calculates the x and y coordinates where the imaginary line from the mouse crosses the circle on the screen.

As I mentioned earlier, all this would be so much easier with an example of this program because it's hard to describe exactly what I have created.

if( mousey > 0 ){
degrees = ((((Math.atan(mousex/mousey))*(180/Math.PI))+90)+180);
}
if( mousey < 0 ){
degrees = (((Math.atan(mousex/mousey))*(180/Math.PI))+90);
}


This code finds the angle the mouse creates in degrees (normally it's in radians) hence the name of the variable "degrees" ...

Flash movies coming soon! (I hope)

Friday, May 30, 2008

BLOGGERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR

That's not going to be an annoying title!

wELCOME TO www.b.loggar.net (it's dot com!)

here is some new code for wall hit test that works relly G00D(ly):

onClipEvent(enterFrame){

var radius:Number;
radius = ((_root.player._width)/2)

var position:Array = new Array();
position[0] = (_root.player._x); //up
position[1] = (_root.player._y - radius);
position[2] = (_root.player._x + (radius*cos(45)));
position[3] = (_root.player._y - (radius*sin(45)));
position[4] = (_root.player._x + radius); //right
position[5] = (_root.player._y);
position[6] = (_root.player._x + (radius*cos(45)));
position[7] = (_root.player._y + (radius*sin(45)));
position[8] = (_root.player._x); //down
position[9] = (_root.player._y + radius);
position[10] = (_root.player._x + (radius*cos(45)));
position[11] = (_root.player._y - (radius*sin(45)));
position[12] = (_root.player._x - radius); //left
position[13] = (_root.player._y);
position[14] = (_root.player._x - (radius*cos(45)));
position[15] = (_root.player._y - (radius*sin(45)));

if(Key.isDown(Key.DOWN)){
if(!(_root.wall.hitTest(position[8], position[9], true))){
_root.player._y += 2;
}
}
if(Key.isDown(Key.UP)){
if(!(_root.wall.hitTest(position[0], position[1], true))){
_root.player._y -= 2;
}
}
if(Key.isDown(Key.LEFT)){
if(!(_root.wall.hitTest(position[12], position[13], true))){
_root.player._x -= 2;
}
}
if(Key.isDown(Key.RIGHT)){
if(!(_root.wall.hitTest(position[4], position[5], true))){
_root.player._x += 2;
}
}
}


So yeah... I haven't implemented the four corner points yet but the other ones work.

Explanation: the player can move right unless the right side of the body hits the wall etc.

shreck is a darth red and black painted person

btw player is a mc that is shape in a circal

Thursday, May 29, 2008

Maybe A good blog

I have been working on AI:

var time:Number = 16.66;
var delay:Number = 16.66;

function walk(){
_root.circle._x += 3;
clearInterval(delay);
}

delay = setInterval(walk, time);


Sets two variables, creates a walk function, and the final line executes the walk function over an interval (setInterval). Delay is how often it executes the interval and time is how often it executes the function (I think).

Friday, May 16, 2008

Game is coming along fine now.

TODO:
1) write better blogs. (ones that have capital letters at the beginning of each "sentence")
2) limit power on the laser (chance for upgrades)
3) make levels and make Ethan draw cool pictures for the levels

Monday, May 12, 2008

A better post than the last one

Third level contains walls. They continue to be a pain since walls near each other conflict and cause the player to be jumpy. The player also sticks to the walls (cannot move diagonally away).

Levels 1 and Too

Two levels are complete. They are actually fairly difficult... Evil things, money, and weird camo tables with watering cans inhabit the desolate green landscape. There really isn't a point to this game yet.

Tuesday, April 29, 2008

From Here on Out

Good song! In any case, my plan for post-windmill construction is to generate a list of all things that have to get done on the game. This will make things move a lot smoother because I can choose a task, focus on it, get it done, and then do the next one. Once these are all done, the product will be a game engine. From that point creating the game will only take a little work and a lot of Ethan's creative brain.

Soon to come: Plan of Action v. 1.0.4.9.1.0.4a.f5.b or whatever the 'first' one normally is.

Wednesday, April 16, 2008

Wind Power in Compy Class?

It's still electricity! Well, not really the same, but today I spent the majority of class learning about the new data logger that Richard has. It's super cool, we got the distance measurer to work. Before I got distracted by that, however, I made an ActionScript file from some code for the player mc. I've dabbled around with includes at home, so that wasn't exactly new, but I commented in the file to make it more universal. For instance, there were some instance-name-specific things in the code, so I just specified what things on the playing field had to be named.

After that, I played around with the enemy mc and now when he gets laser'd he turns into a little money sign. Perhaps I can make it drop random objects, that would be pretty cool! I suppose I would use some sort of random number generator to generate a number from say, 1 to 5. If 1, go to frame A, if 2, go to frame B, etc. The code for what the object is would be on the hitTest on each item frame. I'm really amazed how flexible flash is. The movie clip hierarchy system is very well designed and provides an incredibly easy system for working with more complex things. I think it was wise for Ethan and I to switch from C++ to this because of how basic C++ is, but there are a few other things I want to address in C++. I'll probably just do that on my own time though.

Saturday, April 12, 2008

Ahhhh

My variables are failing me!.. Actually, I'm just using them wrong, but I've implemented the previous knowledge in making the code more streamlined. The savegame function is my next big challenge. To do this, I will have to record the position of the player as _x and _y values, the rotation of the player, which part of the map the player is located in, which items have been taken, which enemies have been killed, etc. It's going to be complicated to get the system up and running, but once it's there things will be easier. The idea is that we're working towards a game engine and once that is figured out we can make challenges, etc. for use in the game itself (so that it's actually fun to play).

Wednesday, April 9, 2008

Variables

Today I figured out a bit more about variables. It seems that in Flash, everything is 'placed' within layers. The layers are determined by movie clips within movie clips.. etc. For instance, to access a clip (foot1) inside of another clip (player) the programmer would have to write _root.player.foot1 This approach goes for variables as well. If a variable (speed) is declared in the foot1 mc, then to access it the programmer must write _root.player.foot.speed ... seems simple enough, right? Well coming from the background of C++ where there were no layers, I assumed that the variables would all be accessible from all code anywhere. Wrong... but the good news is, making variables is very easy. It's as simple as:

var variablename:variabletype = some_initial_value;

For instance...

var money:Number = 0;
//code placed at the very top level of the movie (not in any mc's)

To access this from any mc I would write:

_root.money

For instance, if I wanted to add 50 to the value of money when the player gets 50 moneys, I would put this code:

_root.money += 50;

Simple! This is the great part about AS, once I figure out what the syntax is, it's very fast. I could write out the code to make a pulldown menu function with only a few lines.

Something else that I found out was AS supports "include" files. For instance, I have some chunk of code that makes the mc move with the arrow keys. I could create an actionscript file (.xml if I am remembering correctly) called "arrowkeycontrol.xml" which could be saved in the same directory as the .fla file. I could then type the code #include "arrowkeycontrol.xml" into any mc in that program and it would be controlled by the arrow keys. I could very well have the syntax wrong here, but finding that out is very easy with the actionscript library! I've found it to be the most useful help menu I've encountered!

Tuesday, April 8, 2008

Some homework... =o

At home, I created a movie to test pulldown menus. It worked well, to say the least. I used the code:

on(rollOver){
code;
}
on(rollOut){
code;
}

This controls what happens to movie clips when the cursor moves from being off the movie clip, to on the movie clip (and vice versa). There is one problem however. When the user puts the mouse overtop of the clip to be pulled down, the mask moves and reveals the menu, but when the user goes to click on a menu item, it moves off the original clip to be pulled down, and the menu disappears. I did a little research and downloaded some .fla's from FK but my CS3 trial ran out a while back. I'll have to extract the actionscript while I'm at school, or have someone on the ActionScript.org forums help me out. Menus are something intrinsic to most Flash applications etc. Even if they aren't necessary, they can be very beneficial.

Monday, April 7, 2008



Hope this works!

At a later date: It seems the quality is quite bad, but here's a 'commentary':

The user clicks "New Game" and a game begins. The character (in blue) is controlled by the arrow keys, and the space bar activates his laser beam eyes to kill an enemy. He then goes to collect money and as seen, the inventory records what happens. At the end, the player runs into the castle and wins the game.

Rather basic, but the money took a while and is far from being completed. 'NaN' stands for Not a Number and was a common error while working with the code to get the money to work. Here, it's an item that does nothing... =)

awkefbakwjefbkwaebfgakwgbkwjangkrgr

Today: worked on the game 'engine' ... more specifically, I researched how to use variables! Something that is usually important when programming... I also found out how to change dynamic text from actions (hitTest, buttons, if statement, etc.) Dynamic text is very handy for dynamic things that are text! The one I was working with was money. If the player runs over a hunk of money they have to be able to see the money in their inventory. TODO: figure out how to define global variables or 'more universal' variables. It seems that the variable that I made can only be used within one movie clip.

Thursday, April 3, 2008

Updateeeee

Haven't posted in a while... Here's an update:

Created a laser-eyed player that can zap bad guys and run to the finish with one minor bug of not moving diagonally away from the walls... However, hitting the bad guys results in losing the game...

In the process of: Creating a savegame system. I'm not sure how to store data for users... to the best of my knowledge, Flash doesn't have file I/O built in for security reasons (heavily used for web ads, etc.).

I know there are flash games out there with save options, etc... so we'll see how it goes. I may use level codes and quicksaves...

In any case, it's looking like there will be an actual game this year!

Thursday, March 27, 2008

A Game!

There is now a game! It has instructions, it has a way to win, it can get really boring, and it has bugs! woohoo!

Wednesday, March 26, 2008

Universal Wall Code

The moment of truth... a C&Pable chunk of wall! I have formulated some code to be applied to an mc(movie clip) so that it becomes a wall. It was pretty easy now that I know what I'm doing. I also figured out how to control the movie clip from hitTest.

Here is the code for the universal wall:

onClipEvent(enterFrame){ //code applied to the mc of the wall
if(this.hitTest(_root.player.head)){
_root.player._x = this._x - 13;
}
}

And here is the code applied to the player to make the hitTest control the movie itself:

if(this.hitTest(_root.win)){
this.stop();
_root.gotoAndStop(20);
}

Turns out I have to stop the movie before I switch frames...

In other news, the naming scheme is as such: Graphical entities are name_g, Movie Clip entities are movieClip_mc, and Button entities are button_b (this was a naming scheme I adapted from the flash book back in 9th grade...)

Monday, March 24, 2008

-insert title here-

So I haven't sketched so much detail yet... although I do have some. One thing I'm struggling with is hitTest combined with clip control. For instance, when el protagonist runs into the random blue square ... the movie goes to a new scene. However, that hasn't worked thus far.

onClipEvent(enterFrame){
if(_root.winsquare, hitTest(_root.player)){
gotoAndStop(5);
}
}

The above code has no affect on the movie....

//this code to go in main actions layer...
if(_root.winsquare, hitTest(_root.player)){
gotoAndStop(5);
}

This, however, seems to skip straight to frame 5 even if the player has not hit the block yet....

AGH! ... =D

in other news, Richard helped out with the FTP site, so I'll have to get Ethan set up with that soon... and I'll also have to cram some of my movies up there. If I can figure out how to make a folder public I can post links from this blog so that people can see my progress. Otherwise it'll be peering over shoulders, posted code, and screenshots!

Friday, March 21, 2008

Arrow keys > four buttons?

Arrow keys have become much more than four buttons. Combining acceleration, deceleration, rotations, achieving 'static' position, angle movements, and a zillion other things have added to the confusion of the four buttons known as "the arrow keys." Of course, this poses the question: what exactly do I want the keys to do? Is acceleration the best thing for a person walking on the ground? For a car? Is the deceleration the same for a rolling ball and a car? Perhaps it's time for the sketchbook again...! This time I'm much more informed about how detailed I can make things while not even working on the computer. That way if I have a goal in mind, I can program exactly that goal and not get distracted. I've noticed this urge in myself to see if I can do something even if it doesn't help me achieve the goal at hand. This is actually pretty stupid because if I spend too much time figuring out a zillion ways to use arrow keys, I'll never have anything to show other than a zillion arrow key programs... or one, if I keep changing the same thing! Conclusion: SKETCHBOOK.

AccelerationnnnnnnnnnNNNNNN

Figured out some code for acceleration and applied it to my little car that I've been testing things on. Here's some code:

_x += speedh;
speedh += .1;
//happens if Key.isDown

Apparently the computer will determine my variable types for me. If I C&P that code right there into any if(Key.isDown(Key.KEY)){ thing it will work. I don't have to define what speedh is anywhere else. (speedh stands for horizontal speed)

I'm going to set up an FTP so that I can host files on my domain name. After I do that I'll be able to post links to .swf files to make reading this more fun =D

Flash++

While working in C++, I found that in order to make a few little things, I would have to type a zillion lines of code. Most of this was the process of creating visuals. Without visuals, programs are reduced to the bare minimum: function only. Sometimes, however, it's nice to have some graphics! Flash, a program written in C++, provided a very flexible process for making visuals as well as an intuitive programming language of it's own (ActionScript). Of course, there are more limitations for this, but the fact of the matter is, I can make a program in Flash that would take years of typing in C++, and technically, I'm still working in C++!!! It would be interesting to figure out how to input and output to ascii files from Flash... being C++ based, it shouldn't be much different (although, as we've discussed, most programming languages are about the same).

Thursday, March 20, 2008

Movements and hitTests

Figured out diagonal movement and a better method for arrow keys:

onClipEvent(enterFrame){
if(Key.isDown(Key.LEFT)){
_x -= 2;
}
}
//left arrow key moves the guy leftwards WHEN THE KEY IS DOWN as opposed to when it is pressed... which is much more jumpy.

Also:

onClipEvent(enterFrame){
if(Key.isDown(Key.LEFT) && Key.isDown(Key.UP)){
_x--;
_y--;
_rotation = 315;
}
}
//moves left AND up (and rotates the object 315 degrees so that it faces the top left of the screen

Wednesday, March 19, 2008

hitTest

Tried to figure out how to configure a hitTest between two objects in actionscript 2 (AS2). Unsuccessful! Went here to get a tutorial/movie thing:

http://www.kirupa.com/developer/actionscript/hittest.htm

It was made for Flash 5, however it worked fine in MX04. Mine didn't work... I still have to figure that out. Perhaps it's because I have a zillion scenes in the 'movie' which are mostly useless menus. I tried to loop the one scene by using two frames and using 'gotoAndPlay' to itself. It seems like I still have a bit of tinkering to do, because I have an idea where I might nest the hitTest down in the movie clip objects to isolate it. If that fails..... who knows o.O

Monday, March 17, 2008

Screenshots soon?

Well I decided to re-explore flash because I was getting sick of how limited C++ is. I made a basic menu interface within one class period, which is rather impressive compared to what I've been able to do all year with C++. Ethan found two of my syntax errors and debugged them with his mystical powers of Ethan-is-good-at-debuggingness. Perhaps I'll have some screenshots soon!

Thursday, March 13, 2008

VC Is A PAIN

After two class periods I finally got Microsoft Visual C++ installed on this computer. The program I wrote in it at home didn't work for some reason, and when I made a new "blank" project it had enough code to fill 309 pages of a MS Word document! When I ran the program it made a blank window... Perhaps tomorrow I'll figure out how to start with a "void" program or something... blank didn't seem to be the right thing to start with!

Friday, February 22, 2008

G....g...graphics?

Read up on OpenGL today. It seems rather complex and the tutorial code didn't work in Dev C++. It had a strange header file which was a .h file (C style). Many of the introductory things for OpenGL I have had experience with in programs like Wings 3D.

The code bit had some very cool information however. By reading the code I could understand what it was telling the computer to do... very good!

Here's a link of what I was reading...
http://glprogramming.com/red/

One thing that continues to haunt me is... why is a teapot a primitive!

Wednesday, February 20, 2008

Errorrss


void readpage(char readfile[500]){
****fstream file(readfile[500],ios::in); *********
if( !file.is_open() ){
quit();
}
else{
for ( int x = 0; x < 20; x++ ){
file.getline (output, 500);
cout << output << "\n";
}
file.close();
cin.get();
}
}


This code is giving me the error of "invalid conversion from `char' to `const char*'" on the line that I starred.

It's being accessed by the line "readpage("welcomescreen.txt"); in the main program. So when I open the file it should be opening something called 'welcomescreen.txt' ... perhaps it can't use variables for file names?

Basically this accesses a file (welcomescreen.txt) reads 20 lines and prints them in succession. I had this working in main but decided to make a function out of it for simplicity...

Zhanar.... help? =D

Aside from all that, my finger has grown accustomed to pushing the ; button after I type every line;
I'm much more comfortable typing out code;
I can type code much more quickly now;
Provided I know what I want to type;

Tuesday, February 12, 2008

Classeses

*fireworks*

Classes seem to be very useful things. The C++ book has enlightened me on their use (and what they are), but not their creation (yet).

A class is a data type, more or less. One example would be 'string.' Used like this:

string words; //defines a string called 'words'

The example class used in the book was 'human' which would be used like this:

human maxHardcastle; //defines a human called maxHardcastle

I would then be a human, as opposed to an integer or string. Classes are much like structures except they can have other function like things inside of them. For instance, string.getline() would be a function inside of the class string. A structure couldn't do that.

Perhaps that makes sense... perhaps it doesn't. I don't know the syntax for classes, but it's probably complicated! =D

Monday, February 11, 2008

Kamchatka!!!

The new Kamchatka RPG is up and exiting. So far I made a program that either shows nothing, or closes itself. If an error occurs opening the .txt file, the program will terminate using the "exit" command that Zhanar showed me. She seems to have this weird communication thing going on with the computer that I can't understand. In any case, it's helpful for me! The setup for the program is as follows:

"areas" of the game will be read from .txt files. For instance, the loading screen will be a .txt file that will load and display whatever is inside of it. Then when the player flies their helicopter of doom to the Commander Islands, a new .txt (probably commanderislands.txt) will load and display all of its text. This will keep the program code much simpler.

On a further note, there will be .txt files for skills and inventory that can be accessed. There are ways to get lines of code from a text file until it reaches a certain point, and then take the code after that. For instance, the skills.txt file would look like this:

helicopter flying
15

The program would look through the file until it found "helicopter flying" and then take the next line which will be the level the player has obtained (15 here)

Inventory/Equipment will probably be similar unless someone smart suggests a much better way to do this.

Monday, February 4, 2008

New STUFF!

So in class today, I figured out how to read from files. Pretty easy, but took a while to figure out the basics, as with most things. Also Zhanar presented her program of su doku which was so smart. I learned about void functions, syntax for goto, how pointers can be used...etc. I think I learned something else too, but I'm not sure...

Sunday, February 3, 2008

Time Blogging?

I've been spending almost as much time blogging my work as I have been working on the work...

So here's to short blogs:

I've been working with loops to access specific lines in ascii files.

Friday, February 1, 2008

FINALLY I get to work on C++

Well somehow I managed to miss all classes this week except Monday. Too bad, but today the ski meet ended early and now I can PROGRAM! I've been experimenting with file I/O because whether or not I ever figure out windows, I should probably learn this. On Monday I'm going to look through the books to try to get one on Windows programming. That will be much easier than trying to read these tutorials.

I used the header "fstream" which included ifstream and ofstream to input and output to files to create a program that creates a file with some words in it. To create the file (or open it) I use the lines:

ofstream fout; //fout is a handle, I think
fout.open("file.txt"); //opens file.txt with the fout handle thing

To output to the file the line is:

fout << "word"; //pretty simple, right?

I've messed around a bit with reading from files too. If I open a file with "ifstream" instead of "ofstream" (ifstream = i-f-stream = input-file-stream) I have the ability to read from the file. I can then input the text to a string. The problem here is that the input line looks like this:

fin >> string; //problem = too simple... how can I specify what to get?

So now we have the text inside of the string, and it reads all the text up to any blank spots (spaces or returns). If I put:

fin >> string;
fin >> string;

It inputs up to the blank spot, then inputs whatever is past the blank spot and overwrites the first thing. Therefore if the file contained "a b" string would contain "b".

That's about as far as I've gotten so far... but I have about a weeks time to make up so there's much more to come!

Monday, January 28, 2008

Yay...Error!

For computer class today I typed up quite a bit of code. It was code for a windows program and typing it up helped a lot. What didn't help is the fact that the compiler wasn't able to run it (quite the list of errors I might add!). I think I'm going to try C&Ping the code into Microsoft C++ compiler. Makes sense that the windows program should work in the Microsoft compiler...

I'm not really sure how to use MS Visual C++ but it's been mentally added to the list of things to learn. I had a pretty bad headache during comp class today and had to drink water every few minutes, but luckily it didn't hang around all day!

...water is such a good invention...

http://www.cprogramming.com/tutorial/opengl_first_windows_app.html

(link = code I typed (!C&P) into Dev C++)

Sunday, January 27, 2008

Windows App?

So I started finding out about tutorials on windows applications in C++. I asked Zhanar about it but all I could get out of her was "explore" so that's what I'm doing. I did a bit of research and it seems that there is some 'tension' between people using Microsoft DirectX and OpenGL. I decided to learn how to use OpenGL because that's the one I have a tutorial for. It seems the major difference between the two is that DirectX includes things for video and sound and other devices whereas OpenGL is solely video.

The tutorial is from the same website that I have been using (www.cprogramming.com). It has an easy to read format and makes sense to me most of the time. Details are described, which is important. There are tons of 'complicated' things to know about windows programs. For instance, the include thing is not but rather which makes sense, I guess.

One thing I instantly noticed about windows code was that it had things that I remembered from Visual Basic. Glancing at the example of code (hello world) on the cprogramming tutorial I could see a section where things such as size, cursor, or background could be assigned. The Visual Basic alternative would be the nice list of parameters for each form.

If all goes well, things should begin to sink in soon. I'm still rather baffled by all of this weird windows ... things? I don't even know what to call them......

Friday, January 25, 2008

Endless Loops

So I edited my help menu and while debugging ran into something nasty. When I type in a bunch of random letters I get an endless amount of error text. I need to then shut down the game. This is no good, but it must be solved at a later date.

Add it to the to-do list :]

Configurationsering

So as of now:

At school I have a login on a computer as Indy which is configured with Dev C++ and Firefox (tabbed for cprogramming.com and blogger.com perhaps?)

At home I'm configured for everything I do....

I have my intermediary flash drive with my programs on it. If this dies, all is not lost, for I have multiple copies on my home computer.

TODO: I've drawn up this concept in my mind. I'd like to be designing a "game engine" as such that when it is run, the code accesses ASCII files. If these files are then modified, the game can be easily edited without having to read pages of code, sí? Sí.

As of now, the program has all the text embedded in the code. Trying to edit this is like trying to edit a document that has been typed in notepad with returns for the end of the page. It's hard, to say the least.

Future goal: break away from this stupid little command window thingy :]

Wednesday, January 23, 2008

Strings!

Ok, so I've just learned some things about strings. My first RPG was rather lame. It had no loops (only if statements) and all the code was inside main (no functions... although none were 'needed'). I've been developing a more advanced version of the same RPG to make use of constant actions such as "get" or "inv" (to fill or access the characters inventory full of deviousness). Here is a sample of code:



#include
#include


using namespace std;

int main(){

char action[50]; //para: what do you want to do?

int actionnum; //a number assigned to the action for case

while( x == 1 ){
cin.getline ( action, 50, '\n' );

if( strcmp ( action, "get" ) == 0 || strcmp ( action, "take" ) == 0 ){
actionnum = 1;
cout<<"You get some stuff.\n";
}
}
}


So this program will prompt for the string "action" (cin.getline ... ). It then checks to see if the string "action" has the text "get" inside of it. This is done with the strcmp function. "strcmp" checks to see if two strings are equal or greater than or less than. If the first string is less than the second, it will return a negative value, if they are equal, it will return zero, and if the first string is greater, it will return a positive value. The if statement here just checks to see if they are equal. If they are, the function displays some text. ("You get some stuff.")

I've tested this setup in my program and it seems to be working quite well!

First Program

This summary is not available. Please click here to view the post.