| |
Giygas learns the art of C++
OniLink10 |
|

C++ Programmer, Unofficial Physicist, and Unofficial Chemist
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![Secret Santa Badge [*]](https://archive.mfgg.net/html/badges/present.gif)

Group: Members
Posts: 3920
Member No.: 4907
Joined: 19-February 08
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
| 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  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! |
|
|
|
OniLink10 |
|

C++ Programmer, Unofficial Physicist, and Unofficial Chemist
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![Secret Santa Badge [*]](https://archive.mfgg.net/html/badges/present.gif)

Group: Members
Posts: 3920
Member No.: 4907
Joined: 19-February 08
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
| 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! |
|
|
|
Giygas |
|

Standard Member
![Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/happyheart.gif)

Group: Members
Posts: 910
Member No.: 4767
Joined: 24-November 07
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
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
|
|
|
OniLink10 |
|

C++ Programmer, Unofficial Physicist, and Unofficial Chemist
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![Secret Santa Badge [*]](https://archive.mfgg.net/html/badges/present.gif)

Group: Members
Posts: 3920
Member No.: 4907
Joined: 19-February 08
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
| 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! |
|
|
|
Lightning |
|

Ignorance isn't stupidity but choosing to remain ignorant is
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![MFGG Awards 2008 Winner [*]](https://archive.mfgg.net/html/badges/award08.gif)

Group: IRC Operators
Posts: 6381
Member No.: 583
Joined: 31-August 04
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
| 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 lightninghacker, 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 10 Final! Download today! | quality web comics (stories):- girl genius: adventure! romance! mad science!
- punch an' pie: try a slice of life, then swallow.
- dresden codak: most interesting comic ever
quality web comics (one-shots):- a softer world: truth and beauty bombs
- smbc: saturday morning breakfast cereal
- 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
|
|
|
OniLink10 |
|

C++ Programmer, Unofficial Physicist, and Unofficial Chemist
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![Secret Santa Badge [*]](https://archive.mfgg.net/html/badges/present.gif)

Group: Members
Posts: 3920
Member No.: 4907
Joined: 19-February 08
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
| 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! |
|
|
|
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Track this topic
Receive email notification when a reply has been made to this topic and you are not active on the board.
Subscribe to this forum
Receive email notification when a new topic is posted in this forum and you are not active on the board.
Download / Print this Topic
Download this topic in different formats or view a printer friendly version.
[ Script Execution time: 0.1031 ] [ 13 queries used ] [ GZIP Enabled ] [ Server Load: 1.44 ]
| |