C++ :: Vector - Multiple Bullets Acting As One

Sep 24, 2014

I'm trying to make a 2d shooter with SDL and I got as far as having multiple bullets but they act as one when a bullet goes off screen. I shoot 1st bullet, then I shoot 2nd bullet. 1st bullet goes off screen (deletes) and 2nd bullet disappears. I shoot 3rd bullet, 2nd bullet reappears where it disappeared and repeat.

class Bullet {
public:
static const int BULLET_WIDTH = 15;
static const int BULLET_HEIGHT = 25;
static const int BULLET_VEL = 5;

Bullet();
//xFire, yFire - position relative to player

[Code] ....

I'm guessing the problem is in the bullet_move function, but I just don't know what to do.

View 1 Replies


ADVERTISEMENT

C++ :: 2D Shooter - Collision Detection Design (Monsters And Bullets)

Jul 28, 2013

I have made a simple 2d shooter (bird eye view) and want implementing the collision detection between the monsters and bullets. The problem is as follows

Each monster has locationX, locationY as coordinates.
Each monster has a Rectangle representing its collision box, (if bullet inside rectangle then its a collision).
Each bullet has locationX, locationY as coordinates as well.

pretty standard up till now.

each frame I need to check if some bullet collided with some monster.

the brutal force is to keep a list of all the bullets and monsters and to check the possibility of collision between all of them which takes O(#bullets * #monsters).

View 2 Replies View Related

C++ :: Erase Multiple Values In A Vector

Mar 17, 2014

I wud like to delete multiple values from a vector using indexes as my values r not fixed they may change so using indexes i want to delete

For example: vector<int> v={1,2,3,4,5};

I want to erase 3,4,0 indexes

So resulting vector is 2,3

View 6 Replies View Related

C++ :: Search A Vector Element With Multiple Strings?

Nov 22, 2013

How could I search a vector element with multiple strings

i.e. vector.at(i) = This is a test

How could I search that to look for the word "test" in that element?

View 7 Replies View Related

C++ :: Accessing And Working With Vector From Multiple Threads

Oct 20, 2014

I have a vector that I would like to access and work with from multiple threads. I have created an example below to illustrate the functionality that I would like to accomplish.

The goals are to be (1) high speed, (2) thread safe, and (3) *if possible* continue to use vectors as my larger project uses vectors all over the place and as such I would like to maintain that.

However, if I need to switch from vectors to something else then I am open to that as well.

The following example below compiles but crashes rather quickly because it is not thread safe.

How I can fix the example below which I can then apply to my larger project?

#include <string>
#include <vector>
#include <ctime>
#include <thread>
#include <iostream>
#include <random>
#include <atomic>
#include <algorithm>
enum EmployeeType {

[Code] ....

View 1 Replies View Related

C++ :: Combine Multiple Vector Containing Binary Data To String?

Mar 16, 2012

Two questions:

1. I have some vector<unsigned char> containing binary data. I would like to combine them into one std::string. How is the correct way to accomplish this?

This is my best guess for sample code:

Code:
vector<unsigned char> data; //conatins some data
vector<unsigned char> data2; //contains more data
string temp(data.begin(), data.end());
temp.append(data2.begin(), data2.end());

Will this code work with binary data, or will it null terminate?

2. A similar problem.. I have some unsigned char* variables, and I want to combine them into one std::string. How can I accomplish this? will the member append() work here? or will it null terminate? Something like:

Code:
unsigned char* data; //conatins some data
unsigned char* data2; //contains more data
string temp(reinterpret_cast<const char*>(data));
temp.append(string(reinterpret_cast<const char*>(data2)));

Will the above sample code work without null termination?

View 4 Replies View Related

C# :: Multiple Desktop Display (Multiple Explorer Windows)

Jul 31, 2014

I want to develop an application which can host multiple views of explorer (window), where as each window is totally separate from others. So that I can have multiple desktop views through my single explorer. Any built in feature in .NET ?

View 11 Replies View Related

C/C++ :: How To Make Multiple Subroutine And Return Multiple Arrays

Aug 17, 2014

how to make subroutines and return multiple arrays.Before that, i wrote my program on matlab. could my program to be structured as following?

<header>
initial value of program;
subroutine1() {
calculating the first work;
return 2 or 3 arrays;

[code].....

View 14 Replies View Related

C :: Redirecting Multiple Pipes With Multiple Children

Mar 21, 2014

I've been working on a function that works like a pipeline of a shell but receives a directory, go over it an search for every file to send it to a filter, something like this in bash "cat dir/* | cmd_1 | cmd_2 | ... | cmd_N", The only problem i have with the code is the redirection of the pipe descriptors.

Code:

int main(int argc, char* argv[]){
char** cmd;
int Number_cmd;
cmd = &(argv[2]); /*list of cmds*/
Number_cmd = argc-2; /*number of cmds*/
}

[code]....

The code is seems to work fine except when i run it with more than one command in example ("./filter DIR wc rev") in this case it returns

wc: standard input: Bad file descriptor
wc: -: Bad file descriptor
0 0 0

View 2 Replies View Related

C++ ::  Multiple Files Causes (Multiple Definition) Error?

Jul 15, 2013

I'm using multiple C++ files in one project for the first time. Both have need to include a protected (#ifndef) header file. However, when I do that, I get a multiple definition error.

From what I found from research, adding the word inline before the function fixes the error. Is this the right way to do this, and why does it work? Should I make a habbit of just declaring any function that might be used in two .cpp files as inline?

View 5 Replies View Related

C++ :: Take Max Of Multiple Elements In Multiple Vectors?

Mar 1, 2012

Say I have 5 vectors of unsigned char each of size 5. I want to take the max of each index and store it in a new vector. What is the most optimal way to accomplish this?

My slow code:

Code:
vector<unsigned char> vec1;
vector<unsigned char> vec2;
vector<unsigned char> vec3;
vector<unsigned char> vec4;

[Code]....

View 3 Replies View Related

C++ :: Using Vector Push Back Function To Output Contents Of Vector (similar To Array)

Feb 9, 2015

How to output vector contents using the push_back function. My program reads in values just fine, but it does not output anything and I've been stuck on why.

here is my code:

#include <iostream>
#include <array>
#include <vector>
using namespace std;
int duplicate( vector < int > &vector1, const int value, const int counter)

[Code].....

View 3 Replies View Related

C++ :: Open File And Read In Rows To String Vector And Return Vector

Jun 7, 2012

I have a cpp app that reads in a number of files and writes revised output. The app doesn't seem to be able to open a file with a ' in the file name, such as,

N,N'-dimethylethylenediamine.mol

This is the function that opens the file :

Code:
// opens mol file, reads in rows to string vector and returns vector
vector<string> get_mol_file(string& filePath) {
vector<string> mol_file;
string new_mol_line;
// create an input stream and open the mol file
ifstream read_mol_input;
read_mol_input.open( filePath.c_str() );

[Code] ....

The path to the file is passed as a cpp string and the c version is used to open the file. Do I need to handle this as a special case? It is possible that there could be " as well, parenthesis, etc.

View 9 Replies View Related

C++ :: Create Class Vector As Template And Define Operations On Vector?

May 13, 2013

I need to create a class vector as a template and define operations on vectors.

And this is what I made.

#include<iostream>
using namespace std;
template<class T>

[Code].....

View 2 Replies View Related

C++ :: Recursive Function 2 - Create Vector Of Vector Of Integers

Mar 26, 2013

Lets say that I have a vector of vector of integers. <1,2,3,4> , <5,6,7,8>, <10,11,12,13>

How do I make a function that creates vector of vector of every different integers?

<1,5,10> , <1,5,11>, <1,5,12>, <1,5,13>
<1,6,10> , <1,6,11>, <1,6,12>, <1,6,13>
<1,7,10> , <1,7,11>, <1,7,12>, <1,7,13>
<1,8,10>, <1,8,11>, <1,8,12>, <1,8, 13>
<2,5,10>, <2,5,11>, <2,5,12>, <2,5,13>

and so on...

View 2 Replies View Related

C++ :: Find Function To A Vector Of Structures Vector

Jul 5, 2013

I have asked a related question before, and it was resolved successfully. In the past, when I wanted to use std::max_element in order to find the maximum element (or even sort by using std::sort) of a vector of structures according to one of the members of the structure, all I had to do was to insert a specially designed comparison function as the third argument of the function std::max::element. But the latter comparison function naturally accepts two arguments internally.

For instance, here is a test program that successfully finds the maximum according to just one member of the structure:

Code:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

[Code] ....

And the output was this, as expected:
Maximum element S.a of vector<S> vec is at: 9
[I]max element of vec.a between slot 3 and slot 6 is: 6, and its index is: 6 vec[6].a = 6
[I]max element of vec.a between slot 4 and slot 7 is: 7, and its index is: 7 vec[7].a = 7
[I]max element of vec.a between slot 5 and slot 8 is: 8, and its index is: 8 vec[8].a = 8
[I]max element of vec.a between slot 6 and slot 9 is: 9, and its index is: 9 vec[9].a = 9

However, I now need to search and find an element of vector<myStruct> according to just one member of myStruct, instead of finding the maximum or sorting as before. This presents a problem because the function std::find does not accept such a comparison function as its third argument.

This was the description of the std::find function that I found: find - C++ Reference

Code:
template <class InputIterator, class T> InputIterator find (InputIterator first, InputIterator last, const T& val);

I could also find another function called std::find_if, but this only accepts a unary predicate like this: find_if - C++ Reference

Code:
template <class InputIterator, class UnaryPredicate> InputIterator find_if (InputIterator first, InputIterator last, UnaryPredicate pred);

And once again this is either inadequate of I don't see how to use it directly, because for the third argument I would like to insert a function that takes two arguments with a syntax like this:

Code:
int x=7;
std::vector<S>::iterator result;
result = std::find(vec.begin(), vec.end(), []( const (int x, const S & S_1) { return ( x == S_1.a ) ; } ) ;

Is there another std function that I can use to make search and find an element according to just one member of myStruct?

Or perhaps there is a clever way to pass two arguments to the unary predicate.

View 4 Replies View Related

C/C++ :: Cannot Print Vector Of Vector Of Doubles

Mar 31, 2014

I am trying to print a matrix solution that I've stored in a vector of doubles. The original matrix was stored in a vector of vector of doubles. I want to print to the screen and an output file. Right now it just prints to screen column-style and the output file is horizontal-style. I tried to change the solution from vector of doubles to a vector of vector of doubles like the original matrix but when I run my code it crashes. Here is what I am referring to:

void readMatrix(vector<vector<double>> &matrix, vector<double> &b, int &N, string input) {
ifstream in(input);
in >> N;
matrix.resize(N);
b.resize(N);

[Code] ....

However when I change my printResult function to this (I removed the string argument because I just want to get it working to the screen first):

void printResult(vector<vector<double>> &sol, const int N) {
//ofstream out(output);
//int j;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++){

[Code] ....

The program crashes. Am I even printing the matrix correctly?

View 4 Replies View Related

C/C++ :: Swapping Vector Int And Vector Strings

Mar 30, 2013

I want to have it so that when i ask for the person witch item they want to drop on the ground it goes into another vector that i can pick back up the item if they want it back and erase when they walk away.

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <cmath>  
using namespace std;  
    struct InventoryItem

[Code] ....

View 4 Replies View Related

C++ :: Can't Read In Matrix Into Vector Of Vector Of Int

Mar 24, 2012

Code:
#include <iostream>
#include <istream>
#include <fstream>
#include <vector>

[Code]....

Why is it reading in nothing for the arrays, and also making the size of the total thing the total number of numbers? It should have a size of 2, not 5.

View 14 Replies View Related

C++ :: Copy Part Of Vector 1 To Vector 2

Jun 21, 2012

I am trying to copy vector to vector as follow:

Code:

std::vector<unsigned char> vec1;
//insert some values into vec1
std::vector<unsigned char> vec2;

Now I want to to copy 2 bytes from vec1 starting at index 5., why do i need to know how many bytes from the end of vec1?? can't i just specify how many bytes i want to copy from starting index?

std::copy(vec1.begin()+5, vec1.end()-??, vec2.begin());

View 2 Replies View Related

C++ :: Converting 1D Vector Into 2D Vector

Apr 20, 2013

Code:
#include <iostream>
#include <vector>
int main() {
std::vector<std::vector<double> > DV; //2d vector
std::vector<double>temp(8,0.0); //1d vector

[Code] .....

The conversion actually works but it does not give the expected the result. The output should be:

Code:
1 2 3
4 5 6
7 8

and it outputs:

Code:
123123123

View 5 Replies View Related

C++ :: What Is Another Name For A Vector Inside Of A Vector

Sep 11, 2013

What is another name for a Vector inside of a Vector. What is the name of this construct? Would it be a Constructor Vector? I think this is a trick question my teacher is asking...

View 4 Replies View Related

C/C++ :: Multiple Cin In One Line?

Apr 1, 2014

My professor asked my to make a program that makes the "FCFS","SWJ" operations using any programming language actually i preferred c++ i like it more than java so i started in it but i'm facing a little problem ,,, which is i cant enter multiple inputs with a space tabs between them if this possible , for example : i want to get the arrival time and execution time from user

arrival (spaces " ") execution >> i want the input be like this
input1 (spaces " ") input2

View 10 Replies View Related

C/C++ :: Multiple Class In A Map?

Jul 18, 2012

Class1 {
        public:
            int value;
            Class1(int value) {
                this->value = value;

[Code] .....

i want use like this for that what can i do ...

std::map<class, Class2> map_Class;

View 1 Replies View Related

C# :: XNA Quanternion Multiple Axis

Nov 28, 2011

I made a working version using absolute vextors being rotated by matrices and keeping relative vecotrs for translations. What I didnt like is that I HAVE TO use the standard XYZ axis for rotation.What I decided to do was use quanternions to store current rotation,cthen buffer rotations each time some were done and add it up.The way I see it, it should look somewhat like this:

(in the UpdateRotation part, plz dont mind any typos i make, this isnt the actual current code. Also on a small note I use dictionaries, so dont be surprised xD) Code: RelativeVectors["Up"] = Vector3.Transform(AbsoluteVectors["Up"], (Quanterion)CurrentRotation);
//repeat for Look and Right relative vectors
Quanternion Yaw = Quanternion.CreateFromAxisAngle(RelativeVectors["Up"], RotationBuffer["Yaw"]);
//repeat for roll and pitch
CurrentRotation = Quanternion.Contancate(CurrentRotation,(Yaw*Pitch*Roll));
//

clear the rotation buffer Whats happening right now tho, is that doing this exactly doesnt actually do anything, so I have to use standard axis anyway.

View 1 Replies View Related

C :: Multiple Functions Within A Program

Jan 22, 2013

I am getting an error on lines 31 and 36 about an expected identifier on my program that computes area and circumference. Is something wrong with my external functions outside of main?

Code:
#include <stdio.h>
#define PI 3.14159

double area;
double circum;

double find_circum (double radius);
double find_area (double radius);

[Code] ....

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved