473,322 Members | 1,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

please help! in moving an object using C

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.....
Mar 28 '07 #1
8 5499
RedSon
5,000 Expert 4TB
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.
Mar 28 '07 #2
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?/
Mar 31 '07 #3
Savage
1,764 Expert 1GB
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:
Expand|Select|Wrap|Line Numbers
  1. contol=getch();
  2. switch(control)
  3. {
  4.   case UP:move object up;
  5.                 break;
  6.   case DOWN: move object down;
  7.                       break;
  8.   case LEFT move object left.
  9.                    break;
  10.   case RIGHT:move object right;
  11.                     break;
  12. }
Note:All this must be inside do while loop which will terminate if user press key
which you have assigned for exit.


Savage
Mar 31 '07 #4
Thank you for your kind help
Apr 2 '07 #5
RedSon
5,000 Expert 4TB
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.
Apr 2 '07 #6
ilikepython
844 Expert 512MB
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
Apr 2 '07 #7
RedSon
5,000 Expert 4TB
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).
Apr 2 '07 #8
hehe...............
Apr 2 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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...
2
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
0
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")...
7
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...
2
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...
0
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 ;...
2
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...
8
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. ...
0
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...
1
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
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...
0
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...
0
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...
0
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...
1
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)...
1
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...
1
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....
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.