Keyboard input for games...

Questions regarding game mechanics and graphic programming should go here.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

Keyboard input for games...

Postby Spam Bot » Wed Oct 08, 2003 5:37 pm

Here`s my code:

Code: Select all
char cmd;
  while(true) {
    cmd = getche();
    switch(cmd) {
      case 'w': case 'W':
        move(1); break; // Move up
      case 's': case 'S':
        move(2); break; // Move down
      case 'a': case 'A':
        move(3); break; // Move left
      case 'd': case 'D':
        move(4); break; // Move right
      case 27: return;    // Escape pressed so exit
    }
  }


The problem with this approach is that there doesn`t seem to be a way to detect key presses like arrow keys, FN, and detect if a key is down or up. I`ve looked into directinput and all I can say is, curse M$! I also looked for info but found nothing, maybe I was looking for the wrong thing?

Comments, suggestions, rants, flames, or spam are appreciated in advance :shock:
Spam Bot
 

Postby Wizard » Wed Oct 08, 2003 6:00 pm

Write a program that

1) wait for a key press
2) get the char
3) output the int value of the char
4) repeat ad nauseum

Run program and press the F# keys, the arrow keys, and any other keys you'd like to know.
I think you'll be pleasantly surprised. Don't expect any codes you come up with to be cross system, though. They may work on other machines, they may not. Back in the day (don't I feel old now), I had a config file, and a setup wherein the users could set the keys they wanted, saving them to this config file, which I later read into the program as "constants"
User avatar
Wizard
Site Admin
 
Posts: 3226
Joined: Mon Sep 22, 2003 4:52 pm
Location: ON, CA

Postby Spam Bot » Wed Oct 08, 2003 6:23 pm

Problem solved, lotsa thanx :D
Spam Bot
 

Postby devil_slayer » Thu Oct 09, 2003 9:15 am

If you're writing games you'd probably want to look at SDL or at least Allegro.
User avatar
devil_slayer
 
Posts: 489
Joined: Wed Oct 01, 2003 3:44 am
Location: Warsaw, POLAND

Postby Tracer » Thu Oct 09, 2003 1:49 pm

If you're writing games you'd probably want to get rid of Linux... But good luck anyhow! :wink:
(C++ TotalNewB)

if(!die(self));
self++;
User avatar
Tracer
 
Posts: 124
Joined: Wed Oct 08, 2003 4:07 am

Postby devil_slayer » Fri Oct 10, 2003 3:34 am

Oh Tracer, you're just looking for trouble, aren't you?!?!?!

For your information, there are millions of excelent games written to work under Linux and it's definitely not a bad platform to play games. Many games were rewritten on Linux and more and more of the popular games (Quake, SimCity, whatever you like) work also under Linux (especially the server-sides of these games)...

However, Linux is a great platform for wirting games. You have thousands of free tools to write and test your software and most of the games writen on Linux work on most of the platforms used today in our world, whlist DirectX works natively only on Windows! Just check the SDL site for a list of operating systems it supports... And while you're there check the list of free games that were written in SDL.
User avatar
devil_slayer
 
Posts: 489
Joined: Wed Oct 01, 2003 3:44 am
Location: Warsaw, POLAND

Postby raimo » Fri Oct 10, 2003 7:59 am

Tracer wrote:If you're writing games you'd probably want to get rid of Linux... But good luck anyhow! :wink:

That should be rewritten as if you do nothing but play games then you had better buy a game console instead of a PC.

Besides,

"Running Windows on a Pentium is like having a brand new Porsche but only be able to drive backwards with the handbrake on." -- Unknown source
User avatar
raimo
 
Posts: 372
Joined: Fri Sep 26, 2003 6:50 am
Location: Finland

Postby Spam Bot » Fri Oct 10, 2003 5:11 pm

I have SDL, and have used it in the past, it`s great and I`d recommend it to everyone, but I`m making a simple console based game and since sdl redirects all console output to a file called stdout.txt it`s not practical. I`m on winXP btw
Spam Bot
 

Postby Spam Bot » Fri Oct 10, 2003 5:19 pm

For anyone who`s interested here`s a link to the game so far, although it shouldn`t even be called a game yet. I might release the source later when I`m done and confortable with it cuz it`s still a bit messy.

http://www32.brinkster.com/vetox/cgame.zip[/url]
Spam Bot
 

Postby Guest » Thu Oct 16, 2003 12:13 pm

devil_slayer wrote:Oh Tracer, you're just looking for trouble, aren't you?!?!?!


I'm with you all the way devil_slayer! 8)

Tracer, if you are looking for better gameplay and better framerate, no BlueScreensOfDeath, no system crashes without having to reboot the computer, almost no viruses, free software, and simply not using crappy & insecure software, use linux (SuSE linux :) ).

if not, then by all means be a sucker and keep on using windows
Guest
 

BAH!

Postby JNighthawk » Wed Nov 12, 2003 5:55 pm

Why would use Windows users give up on a platform that hasn't failed us so far? It does everything we want, 95% of the world uses it (except for CHINESE COMMUNISTS!!!) It works as it's supposed to and if you're not a newbie, you won't get blue screens.

This is NOT a knock against Linux, but don't try persuading me or anyone. It's not happening. It's like trying to get Brent Sienna to use a PC.

(Good for you if you got the Brent reference, otherwise go to www.pvponline.com)
JNighthawk
 

Postby Wizard » Wed Nov 12, 2003 8:15 pm

must... resist... clicking....
*click*
dag nabbit.
me = addicted to another web-comic'
D'oh
User avatar
Wizard
Site Admin
 
Posts: 3226
Joined: Mon Sep 22, 2003 4:52 pm
Location: ON, CA

Re: BAH!

Postby Filter » Thu Nov 13, 2003 6:02 am

JNighthawk wrote:(Good for you if you got the Brent reference, otherwise go to www.pvponline.com)


Dude, we hate pvponline, on we're all penny-arcade junkies on this site;oP.
Oh, and to your point. I suppose that you live in a country where software piracy is easy going, because otherwise you would have thought about the small difference : Free software is free as in freedom. Can you say the same for Windows?
--
Filter www.ampoff.org
Filter
 

right..

Postby c0de » Mon Dec 01, 2003 11:45 am

Why would use Windows users give up on a platform that hasn't failed us so far? It does everything we want, 95% of the world uses it (except for CHINESE COMMUNISTS!!!)


oh right the Linux/commie connection..

We all care about that one... because of course... political preference is the basis for good software/tech... just look at the political BS that goes on with NASA...
:D
Linux ownz j00!

also you nighthawk mention that win is better because everyone uses it. ok then. What about Santa Claus? All children believe in him. Should I?
pvponline? bah... PENNYARCADE!!!
Link Less Think More
User avatar
c0de
 
Posts: 13
Joined: Tue Sep 30, 2003 11:30 pm


Return to Games and Graphics

Who is online

Users browsing this forum: No registered users and 1 guest