A game (I have Dev C++)

Nov 16, 2013 at 9:12pm
closed account (jyU4izwU)
How Do you make a game with arrow keys, please, i need help.

0 = The Player
and
# = The Walls

1
2
3
4
5
6
7
8
9
10
11
##############
#            #
#            #
#            #
#            #
###  ####  ###
#            #
#            #
#     0      #
#            #
############## 
Nov 16, 2013 at 10:12pm
Is this a text based game? If so, you're gonna want to use WASD.
Nov 17, 2013 at 12:22am
Arrow keys are special case and don't work with normal char assignments. I tried doing the same a while back didn't think it worth the trouble of figuring out so did like dunnmifflsys said. Basically as simple as this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// get movement from user and map it on game board
cout << "Select a direction (w, a, s, d) or r to idle, q to quit.";
cin >> move;

if(move == 119)		// (w) up
{
	// move up
}
else if(move == 97)	// (a) left
{
	// move left
}
else if(move == 115)	// (s) down
{
	// move down 
}
else if(move == 100)	// (d) right
{
	// move right 
}
else if(move == 114)	// (r) stay in place
{
	// don't move but attack and/or get attacked
}
else if(move == 113)	// (q) quit
{
	return 0;
}


It would probably be easier to read if I had used the characters instead of the numbers and it could have been a case instead of if/else ifs, but that's basically all there is to it.
Nov 17, 2013 at 12:58am
Yeah arrow keys are really two ascii values.
Nov 30, 2013 at 2:31pm
closed account (jyU4izwU)
Okay, thanks for the help. (WASD it is)
Topic archived. No new replies allowed.