hi.
i want to draw an object in C, and then i want to move the object according to the user's input. That is if the user presses the left arrow, the object should move left from its current position and if the user press right arrow, it should move to right and so with up and down keys. how to do this?
Can any one help me!!!!
thanks in advance.....
8 5499
hi.
i want to draw an object in C, and then i want to move the object according to the user's input. That is if the user presses the left arrow, the object should move left from its current position and if the user press right arrow, it should move to right and so with up and down keys. how to do this?
Can any one help me!!!!
thanks in advance.....
First you need to draw a shape (its a shape not an object, objects are special in C/C++), say you draw it at 50, 50 then you will have to detect keyboard input, when the user presses the left or right arrow button you will draw the shape at 49, 50 and then repaint the window.
How to detect the user input. that is, how to know which key was pressed by the user?/ i tried to find by checking the ascii value of those keys.. but i cant. Is there any function to do this?/
How to detect the user input. that is, how to know which key was pressed by the user?/ i tried to find by checking the ascii value of those keys.. but i cant. Is there any function to do this?/
ASCII values exist
LEFT 75
RIGHT 77
UP 72
DOWN 80
I know that in table those represent char's like K but it works.
You will need to use switch:
like: - contol=getch();
-
switch(control)
-
{
-
case UP:move object up;
-
break;
-
case DOWN: move object down;
-
break;
-
case LEFT move object left.
-
break;
-
case RIGHT:move object right;
-
break;
-
}
Note:All this must be inside do while loop which will terminate if user press key
which you have assigned for exit.
Savage
Thank you for your kind help
But since you are using a graphical device, you need to look and see how input is passed to the program. In windows the active window gets KEYDOW and KEYUP messages from the operating system. These messages are passed with the value of the key that is pressed.
Kind off topic but since I'm new to C, I have to ask a question. How do you actually "draw" shapes and images and stuff with C. In other words how do you display something other than text? Is there a special module you have to use or is it really complicated? I was just wondering because I wrote some games with python with pygame.
Thanks in advance
Kind off topic but since I'm new to C, I have to ask a question. How do you actually "draw" shapes and images and stuff with C. In other words how do you display something other than text? Is there a special module you have to use or is it really complicated? I was just wondering because I wrote some games with python with pygame.
Thanks in advance
First off, an off topic post is considered hijacking and is a no-no. But since you were polite about I'm going to let it slide. Its nice to see someone who is actually polite and has some etiquette so good job!
There are libraries in many languages to "draw" things to the display. In windows there are complete technologies that allow you to do this (GDI is one).
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Steven |
last post by:
Hi all
My problem is a little lengthy. But please help me. In my application,
ADO.NET DataSet object is not getting constructed in the Web Service Web
Method called by the Windows Application...
|
by: Pola |
last post by:
Please Help
I am using VC++.NET
In my appl I have to disable access to some disks in the network
How I can do it
thank you
Pol
|
by: Pola |
last post by:
Please Help
I am using VC++ in win 2000
In my appl (Win32 project) I want to control the close operation of the apl (for example if somebody will try to close appl from the "Windows Task Manager")...
|
by: Alan Bashy |
last post by:
Please, guys, In need help with this. It is due in the next week. Please,
help me to implement the functions in this programm especially the first
three constructor. I need them guys. Please, help...
|
by: Amanda |
last post by:
From a guy in Microsoft newsgroups:
| In *comp.databases.ibm-db2* there are always IBM guys
| from the Toronto labs on line.Post with the
| -for the love of god please help-
| line...
|
by: MrPolo |
last post by:
Please help!!!
I'm using a window 2000 machine with SP4.
I created a test class to see pooling in action and my code is the
following:
using System ;
using System.Data.SqlClient ;...
|
by: ericnyc |
last post by:
Hi,
I am a newbee in C++
Please review this is what I wrote , what so ever I understood so far,
My question is that I have to " Write a program C++ array that reads in an integer number and...
|
by: alphaville |
last post by:
Hi. I hope someone can help me with this-
First there is a category Human, which has information about name, gender, age and unique ID.
Human shall be saved in a class Town using a table.
...
|
by: Wannabe |
last post by:
I have been trying to figure this out for days now...can someone please help?
I am using ASP.Net 2.0 and have a gridview on my page. I have everything
working except the delete command. The page...
|
by: SyddyS |
last post by:
Hi all, please help ASAP!
Well, it's been a long and bumpy ride, but my little Access DB is finally graduating and moving out of the house. My homebrewed contact and sales database is being...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |