C++ :: SDL - Check For A Key That Is Hold Down?
Sep 13, 2013
I'm using SDL to try to create a Run and Shoot game. But I do not know how to check if a key is down while the user is HOLDING it.
I do know how to check if a key was pressed.
I have tried with the "event.key.keysym.sym" and "Uint8 *keystate = GetKeyState(NULL)" both worked to check if a key was down but I thought that the GetKeyState(); Function would even check when a key where HELD down
I want my player to move while holding down left or right arrow. So I did something like:
Code:
Uint8 *keystate = GetKeyState(NULL);
if (keystate[SDLK_RIGHT]) {
apply_surface(x++, y, player, screen);
}
How to check if a key is held down?
View 2 Replies
ADVERTISEMENT
May 15, 2013
I had a program (on console) that uses a third-part software to draw some graphs. In order to hold the graphs on the screen, I used cin.get(); and that worked.
Now I created a GUI with Qt. The code remains generally the same. The code continues to call the software to draw graphs (during drawing graphs, there is a console opened automatically). Butcin.get(); in the code cannot hold the graphs on screen anymore. The graphs appear and disappear immediately.
View 4 Replies
View Related
Feb 12, 2014
Is there a variable that can hold string and int in the same time?
If not, what can I do if I want to input data with string and int like a password for an example.
View 3 Replies
View Related
Apr 8, 2013
I have a task to hold a number like 4.0000000000000000199e+30 and, in a variable like long double (the largest of the data type) doesn't hold the whole number, holds only 4.099e+30, like that.
Any way to hold the whole number?
View 1 Replies
View Related
Oct 4, 2014
So far i know that the pointer is address value to the real variable. Pointer size depends on operation system right?
for example
32bit systems: 4byte pointers
64bit systems: 8byte pointers
128bit systems: 16byte pointers?
Anyways, there have to be an variable type in c++ what can hold a pointer.
Let's imagine that the int is the thing im looking for
struct stc1 {
char *chars;
int ints;
}
struct stc2 {
char *chars;
float floats;
[Code]....
My wish is to hold different types of variable or groups of different type of variables in one variable.
I am developing program in windows now yet it will be used in linux and who knows with what x bit systems.
View 2 Replies
View Related
Dec 11, 2013
How would I use the list container to hold a class?
class A {
private : int x;
public : void setX(int val) { x = val; }
};
class B {
private : std::list<A> pdata;
public : void addToList();
};
For adding, I thought of trying something like
void B::addToList() {
A *tmp = new A;
if(A != 0) {
tmp->setX(5);
pdata.insert(tmp);
delete tmp;
}
}
How would I do what I'm trying to do? Or is this the wrong way to go about it? For the actual program, "B" would contain several lists of various classes.
View 2 Replies
View Related
Nov 15, 2014
I have an abstract class named Terrain, and a class named RoadMap, which supposed to hold an N*N array of Terrains. But I'm not sure what type should the RoadMap class hold:
Code:
#ifndef TERRAIN_H
#define TERRAIN_H
class Terrain {
[Code] ....
I can't use an array of refernces here, so I tried this:
Code: Terrain** terrain; and then I thought this was the way to go:
Code: Terrain (*terrain)[]; But now I'm not sure.
The N*N matrix size supposed to be determined according to a given input... What type should I use there?
View 2 Replies
View Related
Apr 3, 2013
// This program creates a structure to hold data for a kennel
#include<iostream.h>
struct KennelList {
int dogID;
char gender;
int age;
[Code] ....
View 2 Replies
View Related
Aug 27, 2014
im doing a program to store name, age, time and fitness. and i need to hold a table of 5 such records.can i do this?
#include <iostream>
using namespace std;
int name1, age1, time1, fitness1;
int name2, age2, time2, fitness2;
int name3, age3, time3, fitness3;
int name4, age4, time4, fitness4;
int name5, age5, time5, fitness5;
[code].....
View 3 Replies
View Related
Mar 6, 2015
For the past couple of weeks I have been working on a template to hold two-dimensional arrays. Right now I am puzzling over an indexing question.
There are many places in the template where I would like to use initializer_lists to refer to user-specified row and column ranges, particularly in member function arguments. A typical example would be a member function whose declaration would be along the lines of:
Code:
Array<Type>::some_function(std::initializer_list<int> columns, std::initializer_list<int> rows); which could get called via
Code:
arrayInstance.some_function({3:4}, {5:8});
It would be really nice to be able to use Matlab-style indexing to specify the last column, or the last row, in the Array object -- along the lines of
Code:
arrayInstance.some_function({3:4}, {5:END}); where END takes the value -1, and can be defined in Array, or somewhere else.
The way I have tackled this so far was to write myself an Indices PODS class with two elements to hold start and finish values, and a constructor-from-initializer_list that looks something like this:
Code:
Indices::Indices(std::initializer_list<int> range, int replace_value) {
int const *it = range.begin();
start = (*it == END) ? replace_value : *it ; ++it;
finish = (*it == END) ? replace_value : *it ;
...
}
So the elements of "range" give the values of Indices::start and Indices::finish -- but if either of them are entered as END by the user, they will be replaced by replace_value. (The default value of replace_value is END, so Indices::start and Indices::finish will never change if it is omitted.)
I also defined an Indices::endset(int) function to do the same thing for existing Indices objects:
Code:
Indices::endset(int replace_value) {
if (start == END) start = replace_value;
if (finish == END) finish = replace_value;
} Using Indices::endset, you can code up Array::some_function by modifying the above signature to something like
Code:
Array<Type>::some_function(Indices columns, Indices rows) {
columns.endset(this->M);
rows.endset(this->N);
...
}
This does work, and I've been able to use it in practice. However, it is klutzy. What I would really like to be able to do is have the Indices constructor handle value-replacements in "columns" and "rows", instead of needing to put calls to Indices::endset in every single Array<Type> member function that uses this approach.
The basic problem is that, when Array<Type>::some_function is called, there is no easy way of inserting Array<Type>::M and Array<Type>::N into the optional argument of the Indices constructor when "columns" and "rows" are being built.
The Indices class needs somehow to get access to these, and know which one is being used, M or N. So it needs to have some sort of deeper connection to Array<Type>, but I don't know what that connection should be.
View 2 Replies
View Related
Jun 14, 2013
I need to dynamically create a new Memo structure to hold memorized fib #'s.I have two structures:
Code:
typedef struct HugeInteger
{
//array to hold the digits of a huge integer
int *digits;
//number of digits in the huge integer
int length;
}
[code]....
am having trouble with initializing the struct inside of the new Memo, I need the digit fields to null and the length field to 0 to indicate that F[i] has not yet been memoized...I have F->digits and F->length in the for loop but this just simply doesn't work..
View 2 Replies
View Related
Jan 25, 2013
Consider a new data type, the mikesint, which can hold 9 bits.
(a) What is the largest integer that an unsigned mikesint can hold?
(b) What is the largest positive integer that a signed mikesint can hold?
(c) What is the largest negative integer that a signed mikesint can hold?
Not sure how to determine this. I'm stuck.
View 5 Replies
View Related
Feb 10, 2015
Using SFML, I had a Board class which held multiple vectors of all of my object types in the game, and then it also held a vector of pointers to the memory addresses of these object instances, like this
class Board{
//...
std::vector<AbstractObject*> GetAllLevelObjects(){ return allLevelObjects; }
//so these are used to hold my object instances for each level
[Code]....
When looping through this vector and drawing the sprites of the objects, I get the runtime error 0xC0000005: Access violation reading location 0x00277000. I solved this error by storing the vector of pointers in the class that holds my Board instance, but I'm wondering why only this solution worked? Why couldn't I just have my vector of pointers in the same class that the instances of those objects were in?
View 2 Replies
View Related
Jul 30, 2014
In pseudocode and in C code, declare two 1-dimensional parallel arrays of Integers to store the age and weight of a group of people that will hold the information of up to 10 people. Use a For loop to iterate through the array and input the values. This is the code i have, but my array is showing up as 11 and not 10?
Code:
#include <stdio.h>
int main() {
//Define Variables
float Age_Data[10],Weight_Data[10];
float Age_Input,Weight_Input;
[Code] .....
View 3 Replies
View Related
Jun 19, 2014
I am working with a new text adventure. The way i want to construct it is by having a class for all living things. in the class you have basic things as: health, gold, vector for inventory holding "struct item". etc...
There is also a class called world, wich navigates through the world.
World class contains of: player location, and a map containing info about the room etc...
Here comes the problem. I want there to be characters to be placed out in different maps, so basically i want the world class to hold objects from Character.
How to do it. In world class i made a map...
std::map<int,"content">
content is a struct i made above in world class:
struct content{
std::string name; // location name
std::string info; // info about location
std::vector<Character>characters;
std::vector<item>items;
};
To sum it up, i have a std::map<int,content>map the int stands for location id. Content holds more info about the room and what's in it
btw the classes are in different files and that means i have to include "Character.h" in the world file so i can set up the vector of characters.
View 2 Replies
View Related
Nov 12, 2014
This has been bothering me for a while now, and I finally put together an example:
#include <iostream>
#include <string>
using namespace::std;
[Code]....
In the code above, the two classes hold pointers to each other, and that's fine but it doesn't seem right since C++ prefers to pass by reference. Yes, it can still do that (see testbox and testball) but even that seems odd to me because still you need to use pointer notation for the enclosed object. Am I the only one who feels this way, and should I just get over it? Or am I missing something that would allow an object to hold a reference?
View 4 Replies
View Related
Nov 12, 2013
I am writing a console program for a class. I have satisfied the assignment, but I want to clear up what is mostly a cosmetic problem. The program prints a form to the console and places the cursor at a location on the form where the user inputs data. The problem occurs when the user presses the enter key without entering data. The cursor goes to the beginning of the next line. If the user enters data after this, the program functions correctly. I want to know how I can reposition the cursor if the user enters no data.
This is the code that reads one of the values:
Code:
void getHousing(HANDLE screen, MonthlyBudget &inputBudget) {
placeCursor(screen, HOUSING_ROW, ACTUAL_COL);
cin >> inputBudget.housing;
while (!validateEntry(screen, inputBudget.housing)) {
placeCursor(screen, HOUSING_ROW, ACTUAL_COL);
cout << SEVEN_SPACES << endl;
placeCursor(screen, HOUSING_ROW, ACTUAL_COL);
cin >> inputBudget.housing;
}
}
validateEntry checks that the entered value is >= 0 SEVEN_SPACES is a string of seven spaces to cover up the previous entry.
View 3 Replies
View Related
Mar 16, 2014
I'm currently trying to write a while loop that checks if the text file has read all the contents inside. I've tried using
while(!in.eof())
but as usual it executes my loop an extra iteration, printing my last output twice. I am reading my data in from a method inside a class, so I cannot use getline as my while test to check if the file has read input or not. Is there any way to force my loop to check if the end of file has been read before the eof() test is executed?
View 9 Replies
View Related
Apr 14, 2014
write a program to check the number is even or odd using (For loop) in c++ ?
View 10 Replies
View Related
Sep 22, 2013
I'm getting a stack overflow error because for large numbers, this code I'm working on allocates too much on the stack.
Is there a way of tracking stack allocations specifically?
Will multithreading solve my problem if each thread is doing the static allocations?
Would I really have to use malloc or new every time I wanted to use memory just to make my code scale to huge numbers?
View 11 Replies
View Related
Mar 6, 2015
I want to check whether a certain character is in a string or not but my code is not working
Code:
#include<stdio.h>
#include<string.h>
int main()
{
[Code].....
View 7 Replies
View Related
Sep 24, 2013
I've tried retyping the code several times and didn't work for some reason the If wont accept both Q and q it just accepts Q.
Code:
#include <stdio.h>
int main(void)
{
printf("A menu will show up and you choose the number for the selection you want.
[Code].....
View 9 Replies
View Related
Sep 24, 2013
1. Input an dimension and elements of an array from the keyboard. Count the odd elements of an array and that number join to variable K, then sort the last K elements in decreasing order.
Code:
#include <stdio.h>
main ()
{
int A[100], i, n, j, K = 0;
printf ("Type in the dimension of an array:
");
scanf ("%d", &n);
[Code]....
View 7 Replies
View Related
Apr 27, 2013
Code:
char value;
printf_s("enter:");
if (scanf_s("%c", &value) != 1)
{
printf_s("oppppssss
");
}
else
{
printf_s("ok");
}
I wanted to check whether the input is a character or not, if a character is given then the output suppose to be "ok", but the output is always "oppppssss", where is the problem here?
View 1 Replies
View Related
Oct 26, 2013
Any chances for a c program to check for browser inputs?
View 1 Replies
View Related
Sep 18, 2014
I was wondering if it is possible to check if two addresses, so pointers are equal.I was saving the address of an array, and later wanted to identify it by the address, so if my area has the address: int *my_array; // is equal to: 0x1e9aa3a2c ...Later when I go through a list of pointers like:
list=
0x1e9c7e060
0x1e9ba6640
0x1e9aa3a2c <== my address
0x1e9aa3a2c
I want the third one to be equal to my list, but with == it didn't work for me.
View 3 Replies
View Related