SFML community forums

General => SFML projects => Topic started by: Hapax on August 23, 2015, 08:47:23 pm

Title: My Practice Beginner Games
Post by: Hapax on August 23, 2015, 08:47:23 pm
Foreword
I realised that I have avoided programming those beginner games that everyone does to learn stuff and for general practice so I decided that I'm going to finally attempt them.

This project (of multiple games) doubles as practice for using GitHub too so it will all be available on GitHub. The repositories are the actual files that I am working on so you so you will be able to see my workings, mistakes, and re-factoring (I tend to do that a lot, I think). This also means that you can feel free to raise issues on the repository and the like.

Of course, SFML will be the base library for all games. Who actually wants to write console-only games?  :P
I also will be using a few small libraries of my own - all of which are completely available on GitHub.

I'll be up for discussions on any part of the project - including suggestions - but not really questions about C++ that should be, at the very least, first googled.

Games
Complete:
Current Work In Progress:

Early video of MTD (v0.0.2):
http://youtu.be/K5IZUl_7BaY

Video of Puzza (v1.0.0):
http://youtu.be/Hp1IyuBLyRE

(click to show/hide)

The Code
Click here to visit the GitHub repository (https://github.com/Hapaxia/MyPracticeBeginnerGames).

Disclaimer
These "games" are work(s) in progress and no guarantees to their working success are given.
I may or may not decide to work on more than one game at a time.
None of this can be considered tutoring. It is not intended to teach. I am learning and this is what I am doing. That is all.
Title: Re: My Practice Beginner Games
Post by: SeriousITGuy on August 27, 2015, 09:39:33 am
Hey Hapax,

same thing here. I was working on my RPG for the last year and I also did not tackle "the practice games" ;)
Didn't finish anything before, so I started going back to the basics three weeks ago and guess what, my Pong clone comes along nicely with all the things I learned the last year. And it is a great project for getting 2D-vector math straight, atm I work on a mathematically and physically correct colision and reflection logic for the game ball.
I'll look on your code, maybe there is something to learn also ;) Oh and btw, why do you use an 8-space wide tab? It makes code anoying to read, I work with two whitespace tabs.

Keep on! ;)

Edit: something to stay entertained while coding Pong https://www.youtube.com/watch?v=cNAdtkSjSps ;)
Title: Re: My Practice Beginner Games
Post by: Hapax on August 27, 2015, 01:06:47 pm
Hi!

Thanks for the comments. They are always appreciated.  :)

I don't think I'm going to be implementing physically accurate ball collision. It's only pong :P
However, I do have something slightly different planned to make it more interesting  ;)

Haha at the Pong song. I've seen it before though. Hehe

Oh and btw, why do you use an 8-space wide tab? It makes code anoying to read, I work with two whitespace tabs.
I don't; I use 4-space wide tabs but they're still tabs so GitHub displays them as 8 spaces.
You can add ?ts=4 (my original layout) or ?ts=2 (your preference) to the end of the URL in GitHub to change its tab size.
e.g.
https://github.com/Hapaxia/MyPracticeBeginnerGames/blob/master/Puzza/main.cpp?ts=4

Title: Re: My Practice Beginner Games
Post by: Hapax on August 27, 2015, 02:25:17 pm
Added a Windows build of its current state to a GitHub release (https://github.com/Hapaxia/MyPracticeBeginnerGames/releases/tag/puzza-v0.1.0).

Feel free to try it if you can (via the build or the code). I always appreciate feedback  :)
Title: Re: My Practice Beginner Games
Post by: SeriousITGuy on August 28, 2015, 08:54:52 am
Oh I did not know about the tab space feature of github, now it is better ;)

Tested your release, mouse movement is interesting especially with acceleration, plays nice. Stoping/Reseting the ball manually is a nice feature for debugging, I will integrate this also ;)
Maybe I can do an upload today.

Cheers!
Title: Re: My Practice Beginner Games
Post by: Hapax on August 28, 2015, 02:24:10 pm
It's a shame that you can't set an account preference in GitHub for displaying tabs.

I generally add so loads of control over things during development (not that I finish many things and remove them!); F12 in Puzza is a forced exception  ;D

Did you notice that you can control the ball with the arrow keys?  ;)

If you can build from source (which may or may not be possible as my libraries don't work for everyone), you could try the add-spin-to-ball branch. Guess what that does  ;)

I keep tweaking the paddle control. The player paddle in the latest version is much more responsive but the acceleration etc. is useful for 'dumbing down' the AI.

Thanks again for taking the time to try it and for the feedback. I look forward to testing yours  ;)

p.s. If the smileys in this post are anything to go by, I must have something in my eye...
Title: Re: My Practice Beginner Games
Post by: SeriousITGuy on August 28, 2015, 03:01:17 pm
If Diablo 3 Season 4 Start nets some free time this weekend I try to build it myself and see your interesting branch. And yes I noticed the arrow keys as I started using them to control the paddle before realizing I need the mouse to do that  :D

I threw together a first playable version of mine https://github.com/SeriousITGuy/SFML-Pong
Should compile without problems, you only need to set the additional include paths to Pong/inc/ and SFML respectively. As I do not want to clutter your thread with my project I will setup an own project thread the coming days and leave this only here for you to dig through ;)

Cheers and TGIF!
Title: Re: My Practice Beginner Games
Post by: Hapax on August 28, 2015, 04:47:58 pm
Just updated spin branch to be more interesting. AI was almost too intelligent so added error based on spin and reduced its maximum speed. The spin also affects the angle that it bounces too.

@SeriousITGuy
Just built your version. It's...green! hehe
Works well. Looks like you stole my keys for the stopping and resetting of the ball!  :P
Stopping the ball in yours is a little less useful since it can't be started again. Maybe you could modify it to toggle the speed rather than just zero it, or add another control to start it moving again.
One thing I did notice is that you have a method called "handleEvents" that only processes keys that are currently pressed. These are not events. They are "input", though  ;)
I'm curious, why is it labelled as a tutorial?
Title: Re: My Practice Beginner Games
Post by: Cryonic on August 28, 2015, 09:08:01 pm
Hmm, wouldn't you want to inline your 1-liner functions such as in "ball.cpp": "ball.getPosition()"?
Title: Re: My Practice Beginner Games
Post by: Jesper Juhl on August 28, 2015, 09:45:49 pm
It really doesn't matter. The compiler will usually spot such things - and even if it doesn't, the performance impact is probably negligible.
Title: Re: My Practice Beginner Games
Post by: Hapax on August 28, 2015, 10:10:44 pm
Performance-wise, there are a lot of things that could be done here. Storing results from function calls and re-using them instead of constantly calling the same functions would be prefered usually but in the case of this simple game, I don't think it requires such optimisations. It is only Pong (sort of), after all!

I sometimes even write one-liners in the header but, for interface clarity, it's better without them.
Title: Re: My Practice Beginner Games
Post by: Hapax on August 29, 2015, 03:03:41 pm
Added a Windows build of its current state (v0.2.0) to a GitHub release (https://github.com/Hapaxia/MyPracticeBeginnerGames/releases/tag/puzza-v0.2.0).

Spin has been added to the ball for added manoeuvrability. AI has been improved and may actually be too intelligent. Tried to dumb it down slightly and gave it a speed handicap (as mentioned above).

Feedback and suggestions are wanted as, if the game is in correct working state, the next modifications are all cosmetic.
Title: Re: My Practice Beginner Games
Post by: Hapax on August 29, 2015, 03:31:51 pm
Added video of Puzza v0.2.0 to the original post.
Title: Re: My Practice Beginner Games
Post by: SeriousITGuy on September 01, 2015, 09:55:30 am
Hi Hapax,

nice progress on your Pong. The ball spin feature gives it a very nice touch, gives me some preasure to find my own unique feature for it ;) Btw, after getting your libs included correctly building it from scratch was no problem.

For your questions: the first commit was based on a pong tutorial I read, thus the commit message. ;)
I know about handleEvents(), not satisfied with it either. It origins from my game framework which is based upon the code from the book SFML Game Developement. Maybe I make a seperate function handleInput() for the real time inputs and leave handleEvents() just for windows events which are processed in Application.cpp. Maybe when I advance my "command pattern" from simple bool values to something more elaborate ;)
And I did not stole your keys, I just had some inspiration on key bindings :p
Title: Re: My Practice Beginner Games
Post by: Hapax on September 01, 2015, 06:15:30 pm
Hi, and thanks  :)

In yours, "tutorial" is also shown in the sub-title to the repository (https://github.com/SeriousITGuy/SFML-Pong), directly above "5 commits".
You could just rename handleEvents to handleInput. Events are a form of inputs but not inputs are events.

No worries about the keys. Just thought F2 seemed like a good reset key  ::)
In the latest version, I've included F5 to restart completely (as in Play Again), and F6 to do the same but with the ball stopped  ;)
Speaking of the latest version, audio has been added, and the add-graphics branch is currently being worked on (it has static graphics - needs frame animation!).

Did you have any troubles with the libraries themselves? What platform are you building on?
Title: Re: My Practice Beginner Games
Post by: Hapax on September 06, 2015, 12:04:26 am
Puzza has been completed! (https://github.com/Hapaxia/MyPracticeBeginnerGames/releases/tag/puzza-v1.0.0)

Here's a video:
http://youtu.be/Hp1IyuBLyRE

(click to show/hide)

The link at the top of this post takes you to the release on GitHub, which also includes a Windows build of the game.
Title: Re: My Practice Beginner Games
Post by: Brax on September 06, 2015, 12:39:09 am
Looks good., especially the effects when the ball hits the paddle.  :D
Title: Re: My Practice Beginner Games
Post by: Hapax on September 08, 2015, 12:23:52 am
Thanks, Brax  :)

The recorded video unfortunately has a very low frame rate. It looks nicer for real  ;)
Title: Re: My Practice Beginner Games
Post by: Cryonic on September 08, 2015, 04:51:37 am
Yeah, even though the paddles look like a Red vs. Blue (Halo) end of a broom battle, the animations when the ball hits them looks awesome. Did you do that solely with a bunch of images in SFML, or did you use some outside program?
Title: Re: My Practice Beginner Games
Post by: Hapax on September 08, 2015, 01:23:43 pm
Blue (allies) vs red (enemies) is a rather common standard amongst games. It can't be 'credited' to Halo  :P

The paddle animations are frame animations that were drawn manually in an image editor.
Here's the spritesheet (click for full size):
(http://i.imgur.com/oM5VV9r.png) (http://i.imgur.com/oM5VV9r.png)

Glad you like the animations  :)


The 'idea' behind the graphics is that the ball is electrically charged and the current charge is passed to the paddle when it touches it. The paddles then directs that charge to the pole at the back which, I guess, would then remotely send a signal to the ball to speed up. Meanwhile, after the ball's charge is lost, it regenerates a new one from its centre.

Although this 'story' is not necessary here, especially since it's not explained in the game, I still felt it gave me some direction for how the animations should act.
Title: Re: My Practice Beginner Games
Post by: Cryonic on September 08, 2015, 09:18:38 pm
Yeah, your right. The Allied/Soviet armies from Command & Conquer: Red Alert are more notable. lol
https://www.youtube.com/watch?v=hxVIREh915A
Title: Re: My Practice Beginner Games
Post by: Hapax on September 08, 2015, 11:48:50 pm
Haha. Fair enough.
I've found that the blue/red de facto standard is even present in MMORPGs.

There's a technical reason for the colours, by the way. It's due to the fact that we generally see green as good/okay and red as bad/danger. However, due to the commonness of red-green colour blindness, blue (or blue-green) often replaces green.
Title: Re: My Practice Beginner Games
Post by: Otherian on September 09, 2015, 11:42:26 pm
Mhm, looks nice! I like the elctro-theme and the fitting sounds.
How long did it take you to get the game finished?

Imo the reflecting of the ball is a little bit "easy". As it is right now its really hard to beat the NPC cause he just moves with the ball and you dont have the tools necessary to get a big direction change. It would be nice if you would reflect stronger in one direction if you hit the ball with a corner of the paddle or smth like this.
Title: Re: My Practice Beginner Games
Post by: SpeCter on September 09, 2015, 11:54:36 pm
To me it looks like the ball gets faster and its trajectory gets curvy if you cut it fast enough, could be my imagination though
Title: Re: My Practice Beginner Games
Post by: Otherian on September 10, 2015, 12:19:57 am
To me it looks like the ball gets faster and its trajectory gets curvy if you cut it fast enough, could be my imagination though
Nah, it is definitely this way but the overall effect is kinda small and negligible. You taking a huge risk of moving the paddle this fast only to get the ball slightly curvy and eventually score a point after 5 "moving-reflects". I think it would be nice to induce a bigger reflection-change independent of the speed you move the paddle but dependent on the area in which the paddle gets hit (center=ideal reflection | corners=steep reflection).
Title: Re: My Practice Beginner Games
Post by: Hapax on September 14, 2015, 03:47:13 pm
Thanks for the interesting feedback.

I always thought that the original pong-style of reflecting at a difference angle depending on where it hit it was odd considering that it's a completely flat surface.

The ball speeds up after each hit and the opponent is locked to a maximum speed. Use this to your advantage to overcome its skill.

you dont have the tools necessary to get a big direction change
Consider using spin on the ball to make the angle more vertical to increase its chance to pass the opponent.
Spin is affected more as the speed increases. It's often better to just stick to a short rally to get the speed up and then create some angles!

Spin is, as SpeCter mentioned, created by 'cutting' the ball.

There is a glitch, which I left in on purpose, that makes the opponent get confused and move to the bottom if the ball is spinning to anti-clockwise by a specific amount (it's -10). It's possible to do this on the first hit, which means that you win that point  ;)
(If you spin it anti-clockwise on the first hit and it bounces off the wall (top of the window) at around the opponent's score, you should get the point)

By the way, the opponent doesn't just "stick to the same position of the ball", it actually moves to a place in front of it, a little more like humans do  ;)

Mhm, looks nice! I like the elctro-theme and the fitting sounds.
Thank you :)

How long did it take you to get the game finished?
Modified the code a small amount each day. It took 13 days from
"Create Simple Ball" (https://github.com/Hapaxia/MyPracticeBeginnerGames/commit/8b1e77f33178aad0ffea0933ebca7880fe072ff1)
to
"Finalize" (https://github.com/Hapaxia/MyPracticeBeginnerGames/commit/28696ca86d836d8ea3034b6bf47c1ba9a27f5400)

Here is the complete list of commits (https://github.com/Hapaxia/MyPracticeBeginnerGames/commits/master?page=1) :)
Title: Re: My Practice Beginner Games
Post by: Hapax on September 14, 2015, 04:05:03 pm
Currently trying to decide on next game being Space Invaders or Asteroids  ;D
Title: Re: My Practice Beginner Games
Post by: shadowmouse on September 14, 2015, 06:15:05 pm
1 vote for space invaders. I want to see what cool spin you can do on it.
Title: Re: My Practice Beginner Games
Post by: SeriousITGuy on September 16, 2015, 09:16:07 am
After Pong I would go for Breakout, one can add interesting features to Breakout ;)
Title: Re: My Practice Beginner Games
Post by: Mortal on September 16, 2015, 01:05:23 pm
me too i vote for space invaders, it is easy and fun,
btw, i really like your mini-libs it's awesome. i will use them in my next game ;)
Title: Re: My Practice Beginner Games
Post by: Hapax on September 20, 2015, 09:00:11 pm
I want to see what cool spin you can do on it.
I'm not sure if you intended this pun but it amused me regardless  ;D

After Pong I would go for Breakout, one can add interesting features to Breakout ;)
The similarity is why I didn't want to do Breakout. Breakout is pretty much just pong on its side. Plus, I'm already bored of balls  :D

btw, i really like your mini-libs it's awesome. i will use them in my next game ;)
Thanks. I hope you find them useful. I know that I can't live without them!
If you have any problems or errors with them, let me know and I'll see what I can do (someone told me about some trouble they had compiling Plinth with Code Blocks)
Title: Re: My Practice Beginner Games
Post by: Mortal on September 22, 2015, 11:42:35 am
i found time this morning to test Plinth. it seems work fine here. i used VS 2015 and SFML2.3.1-RCx32 night built but i haven't tested rest of library yet only Anchor::Local headers file. i will tell you if i had any problems later with Plinth or Kairos.  :)
Title: Re: My Practice Beginner Games
Post by: Hapax on September 24, 2015, 06:52:47 pm
Oh, I do love my Anchor headers  ;D

Thank you for your suggestions on which game I should base next. I have started work on MTD, which is based on Space Invaders.
The game will be developed on its own branch this time: MTD branch (https://github.com/Hapaxia/MyPracticeBeginnerGames/tree/mtd)

I currently has a player that is able to fire bullets (all just rectangles).
The state progression is taken from Puzza so it might not seem to make sense at the moment unless you've played that (you need to press Tab first to be able to play - now skips first state so starts in "running" state).
Keys:
[left]/[right] move
[space] fire
[tab] state progression
[esc] quit
Title: Re: My Practice Beginner Games
Post by: Mortal on September 25, 2015, 04:35:23 pm
i have downloaded MTD last night, also, i made static library for Plinth, Kairos and DEV. and i linked them with MTD, it works beautifully in my machine.

after spending some time with those library i realized that i took a lot of effort and time to accomplish that. i would really thank you for that. i'm now studying and working out on this game too. ;)

sorry i forget to say that i got warning when i compile Plinth

(click to show/hide)
Title: Re: My Practice Beginner Games
Post by: Hapax on September 25, 2015, 09:01:27 pm
Plinth/Sfml needs to be built separately so that it can be omitted. This way, the main part of Plinth can be used without SFML. When using SFML, Plinth and Plinth/Sfml can both be used. Building separately should alleviate the similarly named error as they aren't being built into the same library.

I use Plinth.lib and Plinth-Sfml.lib

It's also why there are inclusion headers in the root of the repository: Plinth.hpp and PlinthSfml.hpp
Plinth.hpp does not include any of the SFML related stuff.
PlinthSfml.hpp includes everything Plinth.hpp does but also includes all of the SFML related stuff.

As for MTD, just added some enemies (blocks that can't be hit)
Title: Re: My Practice Beginner Games
Post by: Hapax on October 23, 2015, 03:03:24 am
Unfortunately, I've been away for a while so not a lot of progress here.
MTD now has ability to kill enemies, enemies speed up after one of them dies, and ends the game automatically when enemies are all destroyed.

Here's a video of its current state:
http://youtu.be/HRE_5AENPco
Title: Re: My Practice Beginner Games
Post by: Hapax on February 11, 2016, 09:43:37 pm
I decided that MTD needed attention so thought I'd make some progress on it, even if it isn't very much.

The enemies now "approach" - or "drop" - downwards constantly. The speed of that drop is increased whenever the enemies change/toggle their direction. The game now also automatically ends when any enemy reaches the bottom of the screen.

Here's a video of its current state:
http://youtu.be/K5IZUl_7BaY
Title: Re: My Practice Beginner Games
Post by: Mortal on February 12, 2016, 01:35:25 pm
great, you back to MTD  :)

frankly, i didn't expect the enemies will behave like that, i mean they drop with slop angle unlike the topical space invaders game-like . this is a new idea and it looks great.

keep up great work  ;)