Homebrew RELEASE game-example - console mode game

Dontwait00

Unknown
OP
Member
Joined
Sep 3, 2017
Messages
272
Trophies
0
Age
31
XP
701
Country
Italy
game-example v1.0.0 (updated on 11/09/2018)


what is it?
first, is my first game im creating in C.
second, is a game made entirely on CONSOLE MODE with no graphics and no sound. I will create a GTA style game in 2D in the near future.


CONTROLS:

UP = up
RIGHT = right
DOWN = down
LEFT = left

A = Unknown still


game-example must do/finish:
•add gun
•add life
•add zombies
•add touch screen support (which i want to try this, so you can play it without joycons!)
•port on Wii: see here
•port on WiiU
•port on Xbox 360

How did you start developing this? :huh:
Heh, wasn't simple for me.

I started developing on useless programs, and i wanted to start something less useless to help others noob like me to try coding.
so then i started developing from scratch, using printf and other basic codes just to see want i could do.
And then i thought, if i could make a player to move up, down, left, right using variables.

My idea (which wasn't after i know it) was to use the rows and column as a player to move free
here's a concept:
lets make a simple room 8x8:
W = wall
f = floor
P = player

.....r_o_w_s
c 0...1..2..3..4..5..6..7
o..1 W W W W W W W
l...2 W f...f...f...f...f...W
u..3 W f...f...f...f...f..W
m.4 W f...f...f...f...P..W
n..5 W f...f...f...f...f..W
....6 W f...f...f...f...f...W
....7 W W W W W W W

if i press up = [3][6] = floor, which means i can move
if i press right = [4][7] = wall, which means i cant move there
if i press down = [5][6] = floor, which means i can move
if i press left = [4][5] = floor, which means i can move
Now, after a bit of theory, we need practice on it.
Lets start:
...
// now lets start using int as variables
int a, b;

//then i need to operate like this to use rand()
srand(time(NULL));

//now i can use rand() to rand some numbers
a = rand() % 10;
b = rand() % 20;

//now i can assemble a and b to be the player.
//\x1b[r;cH is for printing on the screen where you want,
//which r stands for Rows and c for Columns
printf("\x1b[%d;%dHx", a, b);

//lets start doing the player move!
if (kDown & KEY_DUP) {
//now that we printed the player, we need to delete the footstep behind him
printf("\x1b[%d;%dH ", a, b);
a = a - 1;
//now lets move the player up!
printf ("\x1b[%d;%dHx", a, b);
}
//now we have to do this step every single step for every direction pad.
if (kDown & KEY_DDOWN) {
// so on
...
}
Now we can move the player UP, DOWN, RIGHT and LEFT.
But we still need the collision like the wall!
lets start:
...
//we need to compare the collision with a wall called X,
//so we need a new int
int wall_y;
int wall_x;

wall_y = 10;
wall_x = 10;

if (kDown & KEY_DUP) {
if (a == wall_y && b == wall_x) {
a = a + 1;
printf ("\x1b[%d;%dHX", wall_y, wall_x);
printf ("\x1b[&d;%dHx", a, b);
}
}
//so on with every direction pad
...
I hope i helped you, if so, feel free to drop a like!:creep: thanks

i may written badly somewhere, feel free to DM me, thanks

changelog:
v0.1 - added player moving on screen; bugs everywhere

v0.3 - added collision! (was my first time using logic interpreters)
- fixed minor bugs, still a lot of bugs!

v0.5 - added wall using collision! (those XXXX are walls ;P)

v0.7 - fixed all the bugs like:
1) numbers printed on screen when touching end of the screen;
2) player disappearing from the screen;
3) collision worked only from the front of the player;
4) player now cant get out of the screen using collision.
5) ???
6) profit

v1.0.0 - just everything fixed

Download: https://github.com/Dontwait00/game-example/releases/latest
 
Last edited by Dontwait00,
D

Deleted-442439

Guest
game-example v0.7 (updated on 10/09/2018)


what is it?
first, is my first game im creating in C.
second, is a game made entirely on CONSOLE MODE with no graphics and no sound. I will create a GTA style game in 2D in the near future.


CONTROLS:

UP = up
RIGHT = right
DOWN = down
LEFT = left

A = Unknown still


game-example must do/finish:
•add gun
•add life
•add zombies
•add touch screen support (which i want to try this, so you can play it without joycons!)
•port on Wii
•port on WiiU
•port on Xbox 360

How did you start developing this?
Heh, wasn't simple for me.

I started developing on useless programs, and i wanted to start something less useless to help others noob like me to try coding.
so then i started developing from scratch, using printf and other basic codes just to see want i could do.
And then i thought, if i could make a player to move up, down, left, right using variables.

My idea (which wasn't after i know it) was to use the rows and column as a player to move free
here's a concept:
lets make a simple room 8x8:
W = wall
f = floor
P = player

.....r_o_w_s
c 0...1..2..3..4..5..6..7
o..1 W W W W W W W
l...2 W f...f...f...f...f...W
u..3 W f...f...f...f...f..W
m.4 W f...f...f...f...P..W
n..5 W f...f...f...f...f..W
....6 W f...f...f...f...f...W
....7 W W W W W W W

if i press up = [3][6] = floor, which means i can move
if i press right = [4][7] = wall, which means i cant move there
if i press down = [5][6] = floor, which means i can move
if i press left = [4][5] = floor, which means i can move

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

// now i started using int as variables
int main() {
int a, b;

//then i need to operate like this to use rand()
srand(time(NULL));

//now i can use rand() to rand some numbers
a = rand() % 10;
b = rand() % 20;

//now i can assemble a and b to be the player.
//\x1b[r;cH is for printing on the screen where you want,
//which r stands for Rows and c for Columns
printf("\x1b[%d;%dHx", a, b);

//so on
}
sorry but i havent much time now, so i will finish as soon as possible :(
changelog:
v0.1 - added player moving on screen; bugs everywhere

v0.3 - added collision! (was my first time using logic interpreters)
- fixed minor bugs, still a lot of bugs!

v0.5 - added wall using collision! (those XXXX are walls ;P)

v0.7 - fixed all the bugs like:
1) numbers printed on screen when touching end of the screen;
2) player disappearing from the screen;
3) collision worked only from the front of the player;
4) player now cant get out of the screen using collision.
5) ???
6) profit

Good job! Keep learning and trying new things, you will soon be able to create more advanced stuff, always nice to see people that are willing to learn.
 

Dontwait00

Unknown
OP
Member
Joined
Sep 3, 2017
Messages
272
Trophies
0
Age
31
XP
701
Country
Italy
Nice! Have you coded in C before?
I know some C# but no C.:(
Not really, no :(

What i like about C is that you can make it for every OS with just few steps which is awesome! I like program in C, but never did such a big project like this, so im looking forward for this!

Don't you like C? I thought C# was much more difficult then C.
 

lordelan

Well-Known Member
Member
Joined
Jan 4, 2015
Messages
5,784
Trophies
1
Age
44
XP
6,507
Country
Germany
I thought C# was much more difficult then C.
I'd say C# is one of the easiest to learn languages out there lol.
Great work by the way. It was wise to share your work here. As you can see everyone appreciate it although they probably won't stop playing Splatoon for it but it's a good entry. :)
 
  • Like
Reactions: Dontwait00

Dontwait00

Unknown
OP
Member
Joined
Sep 3, 2017
Messages
272
Trophies
0
Age
31
XP
701
Country
Italy
I'd say C# is one of the easiest to learn languages out there lol.
Great work by the way. It was wise to share your work here. As you can see everyone appreciate it although they probably won't stop playing Splatoon for it but it's a good entry. :)
i thought of it, but i like coding and i dont mind people playing it or not. This is just basic project.
(which now i have released 1.0.0 finally, so if you want to see it is here: https://github.com/Dontwait00/game-example/releases) :ha:
 
  • Like
Reactions: lordelan

Jay Griggs

Active Member
Newcomer
Joined
Jan 4, 2016
Messages
34
Trophies
0
Age
42
XP
772
Country
United States
Never did C so I cant compare.
Got friends that do C and they say the biggest differences are that C# is object oriented, C# handles all your garbage collection and with C you need to include your headers.
 

Kevoot

Well-Known Member
Newcomer
Joined
May 23, 2018
Messages
67
Trophies
0
Age
40
XP
430
Country
United States
To OP: It's a good start. You should pick up the book (or steal the PDF) "Introduction to Algorithms"
Link: https://mitpress.mit.edu/books/introduction-algorithms-third-edition

Additionally, do some research into using data structures in C. I can see that you have an idea to establish rules and turn that into code which is the first step. The next step is to define the code in a reuseable, readable, and less-time consuming way (both in terms of running time and how long it takes to write). You have a ton of repeated code which is overkill and leads to a litany of issues, those two resources will get you going in a better direction.

For reference, if you look up my github account and find my checkers3ds, that was where I was at about 4 years ago. Comparing that to the code I write these days makes my butthole clench. Do yourself the favor and look into those topics.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    K3Nv2 @ K3Nv2: It's mostly the ones that are just pictures and no instructions at all