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 5510 RedSon 5,000
Recognized Expert Expert
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?/
Savage 1,764
Recognized Expert Top Contributor
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
RedSon 5,000
Recognized Expert Expert
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
RedSon 5,000
Recognized Expert Expert
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 passing an ADO.NET DataSet Object
as a parameter to the Web Method in Web Service
Debugging using the Soap Extensions, clearly shows that the...
|
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")
I want to know in my appl what message to expect from "Task Manager",
when user will try to close my appl from the "Windows Task Manager".
what...
|
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 me.
This was inspired by Exercise 7 and Programming Problem 8 in Chapter 3 of
our text.
I have done Exercise 7 for you: Below you will find the...
|
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 and I'm sure you'll get their attention.
| Their usually very good:)
So here's my transplanted post
==========================================
| |
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 ;
using System.Data ;
using System.EnterpriseServices ;
using System.Diagnostics ;
|
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 checks whether any of the digits in the number appear more than once"
Hint: Use an array called digits_seen of size 10 whose base type is Boolean. It...
|
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.
The constructor Town(int numberhumans) has parameters, which says the number of humans the town can have (maximum). The program shall let the user do...
|
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 reloads except the row I am
trying to delete is still there. I believe it is something really easy, but I
cannot see it. The stored procedue works...
|
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 taken over by the big leagues and converted by a pro company to a web-based SQL database- well outside my realm of abilities.
I have one more duty to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |