Powered by Invision Power Board

 
  Pages: (10) « First ... 6 7 [8] 9 10  ( Go to first unread post ) Reply to this topicStart new topicStart Poll

> Giygas learns the art of C++
United States
OniLink10
Posted: Oct 18 2009, 10:37 PM
Quote Post


C++ Programmer, Unofficial Physicist, and Unofficial Chemist
[*][*]

Group Icon
Group: Members
Posts: 3920
Member No.: 4907
Joined: 19-February 08

Status: (0d) [--]


QUOTE (Giygas @ Oct 18 2009, 07:56 PM)
Well, after seeing the Tutorial for putting sprites in a graphic window ( all it did was let you move the sprite with the arrow keys ) I got inspired to do what I love to do.
**** with the script biggrin.gif
The Outcome? Klimsco, ******s first graphic SFML-using "game".
Okay, so I didn't add much, but I like how it turned out. Plus, messing with it got me to understand the code alot better.

So uh, if you care at all...


Klimso here will not only move in 8 different directions, he'll also face where he moves ( Took me a while to figure that out ._. ).
He moves at a walking pace, but you can running by pressing and holding X.
I added some walls- After a ****load of thinking, I took the easy and lazy way out and just made the colissions check where he was at. But he still can't move past them.

Now onto... Other things.

Excellent job figuring out things on your own! I'd really like to try out your game.

Also, maybe you could try MMF2-Styled Fastloop Collisions? If you don't know what those are, check this out. It's a tutorial for MMF2, but you can translate it to C++ pretty easily if you think about it.

This post has been edited by OniLink10 on Oct 18 2009, 10:41 PM


--------------------
QUOTE (Xgoff @ Sep 10 2009 @ 06:11 PM)
did you try hello's engine

make sure to not ****ing change anything before using it!
PMEmail PosterUsers WebsiteYahoo
Top
United States
Giygas
Posted: Oct 19 2009, 04:48 PM
Quote Post


Standard Member
[*]

Group Icon
Group: Members
Posts: 910
Member No.: 4767
Joined: 24-November 07

Status: (0d) [--]


QUOTE (OniLink10 @ Oct 18 2009, 10:37 PM)
Excellent job figuring out things on your own! I'd really like to try out your game.

Also, maybe you could try MMF2-Styled Fastloop Collisions? If you don't know what those are, check this out. It's a tutorial for MMF2, but you can translate it to C++ pretty easily if you think about it.

Thanks, I just need to memorize the functions to load the sprites and move them before I go on.

Honestly, what I realise is that using windows in a game makes the coding almost no different- you still use the basic and advanced functions you did with the non-SFML games, only now it looks better :3
PMEmail Poster
Top
United States
Giygas
Posted: Oct 21 2009, 05:33 PM
Quote Post


Standard Member
[*]

Group Icon
Group: Members
Posts: 910
Member No.: 4767
Joined: 24-November 07

Status: (0d) [--]


So i've been messing around with a platformer ( trying to see what I can do all by myself by expirmenting ) and after a long time, I have a couple of features that I hadn't put into the previous version.

Animations ( Oh god this part really sucked )
Jumping ( Working on gravity )
Acceleration ( Working on Deceleration... )

And uh, next i'm going to work out the Gravity and Deceleration, then see if I can get very basic block collisions.

:3
PMEmail Poster
Top
United States
OniLink10
Posted: Oct 21 2009, 05:57 PM
Quote Post


C++ Programmer, Unofficial Physicist, and Unofficial Chemist
[*][*]

Group Icon
Group: Members
Posts: 3920
Member No.: 4907
Joined: 19-February 08

Status: (0d) [--]


QUOTE (Giygas @ Oct 21 2009, 03:33 PM)
So i've been messing around with a platformer ( trying to see what I can do all by myself by expirmenting ) and after a long time, I have a couple of features that I hadn't put into the previous version.

Animations ( Oh god this part really sucked )
Jumping ( Working on gravity )
Acceleration ( Working on Deceleration... )

And uh, next i'm going to work out the Gravity and Deceleration, then see if I can get very basic block collisions.

:3

Animations are one of the worst parts. At the NCFC, I might release my game's source code so you can see how I did it. My technique is terrible and can be improved 10-fold, but it works.


--------------------
QUOTE (Xgoff @ Sep 10 2009 @ 06:11 PM)
did you try hello's engine

make sure to not ****ing change anything before using it!
PMEmail PosterUsers WebsiteYahoo
Top
United States
RetroXYZ
Posted: Oct 21 2009, 07:46 PM
Quote Post


Standard Member
[*][*]

Group Icon
Group: Members
Posts: 2714
Member No.: 4325
Joined: 27-August 07

Status: (0d) [--]


Animations: simple. Make a function for sleep (similar to that in GM):
CODE
#include <ctime>

void sleep(unsigned int milliseconds)
{
clock_t start,goal;
start=clock();
goal=start+milliseconds*CLOCKS_PER_SEC/1000;
while (start<goal)
 {
 start=clock();
 }
}

clock() returns the "clock ticks" since the beginning of the program. The ticks is usually some weird number, so we multiply the milliseconds we want by the clock ticks we want, and divide by 1000 so the time is in milliseconds instead of seconds. Pretty simple.

Now, in the loop for SFML:
CODE
while (program_not_done_check_whatever)
{
// events stuff

// animate sprite/perform steps/etc

sleep(16); // 1000/60 ~ 16, so 16 for ~60 FPS (32 for 30 FPS, 64 for 15, etc.)
}
PMEmail PosterMSN
Top
United States
OniLink10
Posted: Oct 21 2009, 09:58 PM
Quote Post


C++ Programmer, Unofficial Physicist, and Unofficial Chemist
[*][*]

Group Icon
Group: Members
Posts: 3920
Member No.: 4907
Joined: 19-February 08

Status: (0d) [--]


QUOTE (RetroXYZ @ Oct 21 2009, 05:46 PM)
Animations: simple. Make a function for sleep (similar to that in GM):
CODE
#include <ctime>

void sleep(unsigned int milliseconds)
{
clock_t start,goal;
start=clock();
goal=start+milliseconds*CLOCKS_PER_SEC/1000;
while (start<goal)
 {
 start=clock();
 }
}

clock() returns the "clock ticks" since the beginning of the program. The ticks is usually some weird number, so we multiply the milliseconds we want by the clock ticks we want, and divide by 1000 so the time is in milliseconds instead of seconds. Pretty simple.

Now, in the loop for SFML:
CODE
while (program_not_done_check_whatever)
{
// events stuff

// animate sprite/perform steps/etc

sleep(16); // 1000/60 ~ 16, so 16 for ~60 FPS (32 for 30 FPS, 64 for 15, etc.)
}

That's a terrible way to sleep. The while loop eats up CPU cycles. Unfortunately, there's no standard way to sleep, so you'll have to use MinGW's POSIX libraries, or use sf::Sleep(which is already used by RenderWindow.Display() to limit framerate).


--------------------
QUOTE (Xgoff @ Sep 10 2009 @ 06:11 PM)
did you try hello's engine

make sure to not ****ing change anything before using it!
PMEmail PosterUsers WebsiteYahoo
Top
United States
Giygas
Posted: Oct 22 2009, 05:37 PM
Quote Post


Standard Member
[*]

Group Icon
Group: Members
Posts: 910
Member No.: 4767
Joined: 24-November 07

Status: (0d) [--]


Well, as I said, I already programmed the animations in, using a very simple but pathetic excuse of a code.

I can't post the code I used atm, but all I did was something like

On the press left/right command:
CODE
(whatever goes here)
AS+=1;


AS Stands for Animation Speed. When you hold left or right, it goes up by one.

On the load image command:
CODE
{(BLAH);
Frame1="Mario Left 1.png";
Frame2="Mario Left 2.png";
Frame3="Mario Left 3.png";
Frame12="Mario Right 1";
Frame22="Mario Right 2";
Frame 32="Mario Right 3";
}


And then the code to switch frames:

CODE
if (AS>30)
if (Frame<3)
{
Frame+=1;
AS=0;
}
if (AS>30)
if (Frame>3)
{
AS=0;
Frame=1;
}


And then some other **** to make him stand when not moving, and jumping sprite when jumping. :U
PMEmail Poster
Top
United States
RetroXYZ
Posted: Oct 22 2009, 05:48 PM
Quote Post


Standard Member
[*][*]

Group Icon
Group: Members
Posts: 2714
Member No.: 4325
Joined: 27-August 07

Status: (0d) [--]


QUOTE (OniLink10 @ Oct 21 2009, 10:58 PM)
That's a terrible way to sleep. The while loop eats up CPU cycles.

What do you plan on doing to sleep, then? And, either way, I completely forgot about sf::Sleep(). :/
PMEmail PosterMSN
Top
United States
OniLink10
Posted: Oct 22 2009, 05:59 PM
Quote Post


C++ Programmer, Unofficial Physicist, and Unofficial Chemist
[*][*]

Group Icon
Group: Members
Posts: 3920
Member No.: 4907
Joined: 19-February 08

Status: (0d) [--]


QUOTE (RetroXYZ @ Oct 22 2009, 03:48 PM)
What do you plan on doing to sleep, then? And, either way, I completely forgot about sf::Sleep(). :/

usleep() in the POSIX libraries is included with MinGW, and turns off the program temporarily.


--------------------
QUOTE (Xgoff @ Sep 10 2009 @ 06:11 PM)
did you try hello's engine

make sure to not ****ing change anything before using it!
PMEmail PosterUsers WebsiteYahoo
Top
United States
Giygas
Posted: Oct 22 2009, 06:06 PM
Quote Post


Standard Member
[*]

Group Icon
Group: Members
Posts: 910
Member No.: 4767
Joined: 24-November 07

Status: (0d) [--]


Gravity was much easier than I thought it was going to be... Go figure :U
When in the "Left Jump" sprite and in the air, you can still move to the right but it no longer goes to the "Right Jump" sprite ( And Vice Versa ) in Mario Brothers honor.
As i've stated, gravity...
When hitting the floor, Mario also automatically changes to his "Left" or "Right" standing pose, depending on his last direction...
Animation now speeds up/slows down depending on how fast Mario is moving...
Hmm... Now I need to add Running, and make you jump higher when running. Then I can move onto some more complicated stuff :U
PMEmail Poster
Top
United States
RetroXYZ
Posted: Oct 22 2009, 06:23 PM
Quote Post


Standard Member
[*][*]

Group Icon
Group: Members
Posts: 2714
Member No.: 4325
Joined: 27-August 07

Status: (0d) [--]


QUOTE (OniLink10 @ Oct 22 2009, 06:59 PM)
usleep() in the POSIX libraries is included with MinGW, and turns off the program temporarily.

I didn't know that. :/

Anyways, you learn something new every day, I suppose.

Anyways, for gravity, simply do it the same way you did it in Game Maker/whatever you used before C++.
PMEmail PosterMSN
Top
United States
Giygas
Posted: Oct 22 2009, 06:33 PM
Quote Post


Standard Member
[*]

Group Icon
Group: Members
Posts: 910
Member No.: 4767
Joined: 24-November 07

Status: (0d) [--]


QUOTE (RetroXYZ @ Oct 22 2009, 06:23 PM)
I didn't know that. :/

Anyways, you learn something new every day, I suppose.

Anyways, for gravity, simply do it the same way you did it in Game Maker/whatever you used before C++.

um
I don't think that Gravity_Direction and Gravity_Force would work :U
PMEmail Poster
Top
United States
RetroXYZ
Posted: Oct 22 2009, 06:40 PM
Quote Post


Standard Member
[*][*]

Group Icon
Group: Members
Posts: 2714
Member No.: 4325
Joined: 27-August 07

Status: (0d) [--]


QUOTE (Giygas @ Oct 22 2009, 07:33 PM)
um
I don't think that Gravity_Direction and Gravity_Force would work :U

So? Make them yourself.

#define pi 3.1415926535898

// etc

x+=cos(gravity_direction*pi/180)*gravity;
y-=sin(gravity_direction*pi/180)*gravity;

Or, if it's just affecting one axis, just use y-=gravity or something of the like.

This post has been edited by RetroXYZ on Oct 22 2009, 06:41 PM
PMEmail PosterMSN
Top
United States
Giygas
Posted: Oct 22 2009, 06:54 PM
Quote Post


Standard Member
[*]

Group Icon
Group: Members
Posts: 910
Member No.: 4767
Joined: 24-November 07

Status: (0d) [--]


QUOTE (RetroXYZ @ Oct 22 2009, 06:40 PM)
So? Make them yourself.

#define pi 3.1415926535898

// etc

x+=cos(gravity_direction*pi/180)*gravity;
y-=sin(gravity_direction*pi/180)*gravity;

Or, if it's just affecting one axis, just use y-=gravity or something of the like.

I already have a decent system, but i'll mess around with defines and functions later... Would really make this easier. But for now, just a crude version of ******s First Game.

Running done, moving onto a Goomba that moves left and right. :UU:
PMEmail Poster
Top
United States
Giygas
Posted: Oct 22 2009, 09:48 PM
Quote Post


Standard Member
[*]

Group Icon
Group: Members
Posts: 910
Member No.: 4767
Joined: 24-November 07

Status: (0d) [--]


Well, done for the night.
Working on all this seems pretty easy so far, and I have not even moved on past "Displaying a Sprite".

I peeked a bit at Audio, though... Just because I can, I added a sound effect for jumping and stomping a goomba.
Speaking of Goomba's, it now moves left and right ( Reverses when it hits the adge of screen ) and has an animation. Jumping on it results in it being squished, mario doing a little hop, and a nice sound effect.

:3
PMEmail Poster
Top
United States
OniLink10
Posted: Oct 22 2009, 09:51 PM
Quote Post


C++ Programmer, Unofficial Physicist, and Unofficial Chemist
[*][*]

Group Icon
Group: Members
Posts: 3920
Member No.: 4907
Joined: 19-February 08

Status: (0d) [--]


QUOTE (Giygas @ Oct 22 2009, 07:48 PM)
Well, done for the night.
Working on all this seems pretty easy so far, and I have not even moved on past "Displaying a Sprite".

I peeked a bit at Audio, though... Just because I can, I added a sound effect for jumping and stomping a goomba.
Speaking of Goomba's, it now moves left and right ( Reverses when it hits the adge of screen ) and has an animation. Jumping on it results in it being squished, mario doing a little hop, and a nice sound effect.

:3

Excellent job! Are you using Object Lists, Object Vectors, or individual Objects for your game?


--------------------
QUOTE (Xgoff @ Sep 10 2009 @ 06:11 PM)
did you try hello's engine

make sure to not ****ing change anything before using it!
PMEmail PosterUsers WebsiteYahoo
Top
United States
Giygas
Posted: Oct 23 2009, 07:40 AM
Quote Post


Standard Member
[*]

Group Icon
Group: Members
Posts: 910
Member No.: 4767
Joined: 24-November 07

Status: (0d) [--]


QUOTE (OniLink10 @ Oct 22 2009, 09:51 PM)
Excellent job! Are you using Object Lists, Object Vectors, or individual Objects for your game?

Ondividual objects, but i'm going to have to change that soon once I can get Object Lists in.
PMEmail Poster
Top
United States
OniLink10
Posted: Oct 23 2009, 01:22 PM
Quote Post


C++ Programmer, Unofficial Physicist, and Unofficial Chemist
[*][*]

Group Icon
Group: Members
Posts: 3920
Member No.: 4907
Joined: 19-February 08

Status: (0d) [--]


QUOTE (Giygas @ Oct 23 2009, 05:40 AM)
Ondividual objects, but i'm going to have to change that soon once I can get Object Lists in.

Definitely use lists, and probably use a separate list for each kind of object. It makes searching for collisions with a certain type much easier, and hogs less time than Vectors, especially when adding new objects.
EDIT: Thanks for correction, Lightning.

This post has been edited by OniLink10 on Oct 23 2009, 03:24 PM


--------------------
QUOTE (Xgoff @ Sep 10 2009 @ 06:11 PM)
did you try hello's engine

make sure to not ****ing change anything before using it!
PMEmail PosterUsers WebsiteYahoo
Top
Unspecified
Lightning
Posted: Oct 23 2009, 03:16 PM
Quote Post


Ignorance isn't stupidity but choosing to remain ignorant is
[*][*]

Group Icon
Group: IRC Operators
Posts: 6381
Member No.: 583
Joined: 31-August 04

Status: (0d) [--]


QUOTE (OniLink10 @ Oct 23 2009, 02:22 PM)
Definitely use lists, and probably use a separate list for each kind of object. It makes searching for collisions with a certain type much easier, and hogs less memory than Vectors.

iirc (and it's been a while)


list:
struct list_node {
TYPE object; // sizeof(TYPE) bytes
struct list_node *next; // sizeof(void*) bytes
};

to store n objects in a list, you use (n * (sizeof(TYPE) + sizeof(void*))) bytes


vector:
m = next_highest_power_of_two(n) * sizeof(TYPE);
TYPE *array = malloc(m);

to store n objects in a vector, you use (n * sizeof(TYPE)) bytes in the best case, and ((2(n-1)) * sizeof(TYPE)) bytes in the worst case.


so there's not a clear-cut winner of who hogs more memory. I'd focus on the time-related efficiency more than anything.


--------------------
click here to change my avatar. / gosh why are you even here lightning
hacker, n.an individual who enjoys learning computer system details and how to capitalize on his or her capabilities...not a criminal.
(from webster's new world hacker dictionary)
fedora linux 10
Fedora 10 Final!

Download today!
quality web comics (stories):
  1. girl genius: adventure! romance! mad science!
  2. punch an' pie: try a slice of life, then swallow.
  3. dresden codak: most interesting comic ever
quality web comics (one-shots):
  1. a softer world: truth and beauty bombs
  2. smbc: saturday morning breakfast cereal
  3. buttersafe: pictures and probably some words
"Religion is comparable to a childhood neurosis." - Sigmund Freud
“It is not by delusion, however exalted, that mankind can prosper, but only by unswerving courage in the pursuit of truth.” - Bertrand Russell
“To kill an error is as good a service as, and sometimes better than, the establishing of a new truth or fact.” - Charles Darwin
PMUsers WebsiteMSN
Top
United States
OniLink10
Posted: Oct 23 2009, 03:30 PM
Quote Post


C++ Programmer, Unofficial Physicist, and Unofficial Chemist
[*][*]

Group Icon
Group: Members
Posts: 3920
Member No.: 4907
Joined: 19-February 08

Status: (0d) [--]


QUOTE (Lightning @ Oct 23 2009, 01:16 PM)
iirc (and it's been a while)


list:
struct list_node {
    TYPE object;  // sizeof(TYPE) bytes
    struct list_node *next; // sizeof(void*) bytes
};

to store n objects in a list, you use (n * (sizeof(TYPE) + sizeof(void*))) bytes


vector:
m = next_highest_power_of_two(n) * sizeof(TYPE);
TYPE *array = malloc(m);

to store n objects in a vector, you use (n * sizeof(TYPE)) bytes in the best case, and ((2(n-1)) * sizeof(TYPE)) bytes in the worst case.


so there's not a clear-cut winner of who hogs more memory.  I'd focus on the time-related efficiency more than anything.

Let's say an Object has a 4-Byte Pointer to a Sprite(SFML includes Positions), a 4-Byte Pointer to an Image, and a 1-Byte Animation number. This totals 9 Bytes.

100 of these Objects in a list would take (100*(9+4))=1300 Bytes.
100 of these Objects in a vector would take ((2(100-1))*9)=1782 Bytes.
Not really a big difference, but if you have 100s of objects, it adds up.

Also, vectors are fastest when you aren't adding objects on the fly and you aren't iterating through them(going through them 1-by-1). Lists are fastest when you need to add to them on the fly(most Mario-based games) and you are iterating through them(you probably will iterate for drawing them and collisions).

This post has been edited by OniLink10 on Oct 23 2009, 03:32 PM


--------------------
QUOTE (Xgoff @ Sep 10 2009 @ 06:11 PM)
did you try hello's engine

make sure to not ****ing change anything before using it!
PMEmail PosterUsers WebsiteYahoo
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

  Topic Options Topic Options Pages: (10) « First ... 6 7 [8] 9 10  Reply to this topicStart new topicStart Poll

 




[ Script Execution time: 0.1031 ]   [ 13 queries used ]   [ GZIP Enabled ]   [ Server Load: 1.44 ]