C++ :: Space Shooter Game In SDL
Apr 25, 2013
I'm really new to SDL and i've been trying to make a spaceshooter game, so far I've got a ship you can move around in using the arrow key (square shaped) and a scrolling background. I'm up to making my ship fire bullets at the moment and it's really not working, i've finished lazy foo's tutorials on SDL and there's nothing on this.
Here's my code
#include "SDL.h"
#include "SDL_image.h"
#include "SDL_mixer.h"
#include "SDL_ttf.h"
#include <string>
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
[Code] .....
View 19 Replies
ADVERTISEMENT
Jan 19, 2014
I started making a shooter game where enemies appear randomly and you have to shoot them. Everything works fine except sometimes whenever a bullet hits an enemy an error comes up that says "Expression: vector subscript out of range". It doesn't happen every time there is a collision, which confuses me. Here is the collision of the bullets with enemies.
for (unsigned int i = 0; i < bullets.size(); i++) {
if (bullets[i].type == 1) {
for (unsigned int j = 0; j < enemies.size(); j++) {
float distance = sqrt(pow(bullets[i].x - enemies[j].x, 2) + pow(bullets[i].y - enemies[j].y, 2));
if (distance < bullets[i].radius + enemies[j].radius) {
bullets.erase(bullets.begin() + i);
enemies.erase(enemies.begin() + j);
} } }
View 3 Replies
View Related
Sep 14, 2013
i am making a space game using sfml 2.0. i want it to move depending on its rotation. so if it is rotated 20 degrees it move in the direction it is facing. how do you do it?
View 17 Replies
View Related
Mar 5, 2013
You are programming a sideways scrolling shooter. This used 2D cell based maps that are very long (over 100,000 characters per row long, 24 rows of 40 characters on screen), and the only way you can get them to fit in memory is to compress each row of the map using run length encoding and to decompress each new column of the map on the right of the screen as the background moves from right to left. You maintain a list of pointers into the RLE data for each row of the screen. Columns that are scrolled off the left are discarded. This works very well and the game only just fits in the available memory. Suddenly the game designer decides that the game should also be able to scroll from left to right at any point, and for any duration. Stunned and dismayed, you explain to him that RLE compression only works in one direction, but he’s adamant. Figure out a way of doing what he wants without using much (no more that 1K of) extra memory. Explain the algorithm used for decompressing in both directions. (assume the RLE algorithm used is: a positive byte N followed by a byte B, indicates a run of N copies of B, a negative byte -N followed by N bytes indicates that those bytes should be copied directly. For example, the sequence 2,2,2,2,5,1,2,9,9,9,9,9 would be coded 4,2, -3,5,1,2, 5,9.)
how can I compress the information? My first thought was making a change to the RLE compression but i gave up on that thinking it wasn't possible.
View 2 Replies
View Related
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
Dec 21, 2014
I'm working on my first video game. So far I have a few classes in the game starting with the Game class which includes a list of GameObjects (another class). There are several classes that inherit from GameObjects used to implement things like bullets, explosions, various enemy types, etc.
The game essentially iterates through the list of GameObjects to update/render them. I would like to provide access to the Game's list of GameObjects inside another class (like the Bullet class) so I can put new objects on the list. For example, when a bullet hits, I want to add an explosion to the Game's GameObject list it can be updated/rendered.
How this should be setup? I was considering adding a pointer to the Game or GameObject list to the GameObject class (and methods to access it), but I was wondering if there is a better way to set this up?
View 4 Replies
View Related
Sep 13, 2014
I would like to make a program for calculating the total price of a game station, and a game. I made a program like this for just the price of a game in class, but I want to make one that does the game system as well.
View 7 Replies
View Related
Sep 20, 2014
how to input with space what i mean is like this, for example:
Product Code: 0000001
Product Name: Mobile Phone
if the users input is like that in the (Product Name)it will skip the next input that is the
Price: Quantity: 100
Manufacturer: Alcatel
something like that...
Heres the code
Code:
if(b<=10)
{/*Start for IF Statement*/
for(a=1;a<=b;a++)
{/*Start of FOR loop*/
printf("
");
printf("Product Code : ");
scanf("%s", &prod_code);
}
[code]....
View 14 Replies
View Related
Dec 2, 2014
I used pointer(or is it not?) to make it one part only alphabets and the other one digits. The coding, calculate_charges.c and the open file, customer.txt are attached at the end of the post.
Code:
#include <stdio.h>
#include <string.h>
#define SIZE 3
void trimback(char input[], int strnameindex);
void trimfrnt(char input[], int strnameindex);
}
[code]....
View 3 Replies
View Related
Feb 1, 2013
What would the worst, average and best case space complexity be for a data structure of type map<string, vector<int> > in big O notation? I'm parsing through a document and storing each word as a key and im attaching an associated int (in a vector) to it as the value.
View 4 Replies
View Related
Mar 16, 2013
Can we use using declaration within name space scope? is it safe to use it?
I think we can use using declaration for class scope and function scope only.
View 9 Replies
View Related
Sep 24, 2014
I want the user to be able to enter a command then a character, like for example: push r....I want the command to be stored in the array command, and the character to be stored in the variable c.
Now I wonder what the best way to get rid of the space is, using scanf or getchar (see below for code, only thing that I changed between the 2 versions is the statement before the comment "get rid of space")? Or maybe it doesnt matter?
Code:
include <stdio.h>
#define MAX 200
void push(char c); // Puts a new element last in queue
char pop(void); // Gets the first element in queue
static char s[MAX];
}
[code]....
View 6 Replies
View Related
Jan 15, 2013
I am allocating space only for two characters but it fits all of them, if you run this it will print the whole string literal "hello my friend". How is that possible?
I am using gcc 4.6.3., I know about strncpy().
#include<iostream>
#include<cstring>
using namespace std;
int main(){
char* str = new char[2];
strcpy(str, "hello my friend");
cout << str << endl;
return 0;
}
View 4 Replies
View Related
Sep 26, 2013
how can I read some strings that contains spaces and put them in a vector of strings, using the push_back() function?
I have a collection of functions, for example: [multiply_by_forty two, add_by_five]. All I want to do is to store the strings like: multiply_by, add_by in a vector of strings, and the arguments:forty two, five etc in another vector of strings, but with spaces. The function convert() converts written numbers to numbers (for ex the output of covert("forty two")is 42;)
Here is the code:
public:void split() {
vector < string > s1;
vector < string > s2;
[Code].....
View 1 Replies
View Related
Oct 12, 2013
In my code I have a template class.
In the contructor, I create a new array arrray.
A pointer to this array is saved as an attribute.
The purpose of this attribute is that I should be able to call the array from within another function be typing *p or *(p+1) etc.
The only thing I forgot is that the array doesn't exist anymore when the constructor is done, right?
This means the space is no longer reserved for this array and the space is used for other things.
Is there a way to keep the array space reserved (even when the array does not exist anymore at the end of the function)?
View 1 Replies
View Related
Jun 8, 2013
I was coding a program that can count space, new_line, and other characters in a paragraph, but it doesn't work.
#include <stdio.h>
int main(void)
{
[Code].....
View 1 Replies
View Related
Apr 29, 2014
I have a character Array 'Hello'
I want to add a space in whatever space the users chooses.
"Where do you want to add space? --> " 3 String after space is added --> 'Hel lo
View 4 Replies
View Related
Mar 24, 2014
I have a problem, caught the last line of a file and do the division of the same variables in, date, time and value, but the file contains excess spaces in all lines and the date is coming with cuts, example 24/4/2014 appears 4/4/2014. How can I remove the space in the string without affecting the division of the line?
if (file) {
std::string line = getLastLine(file);
std::istringstream iss(line);
getline(iss, date, ' ');
getline(iss, time, ' ');
getline(iss, t); //variavel para temperatura em string
}
else {
std::cout << "error file
";
View 5 Replies
View Related
Jan 23, 2014
I have created a prompt which prompts the user for an integer and I have set up a loop to check for if it is an integer or not. My "bug" is that a user can enter an "integer" and "space" and "enter" and it does not give any error and assumes that "All is FINE!". I have gotten the value from the ascii table of 'SPACE' and put it as a check in my parameter of while, but it does not work.
Here is my code:
int x, y, boolean, i;
char buff[256];
printf("Enter the first integer value: ");
scanf("%s", buff);
i = 0;
boolean = 0; //initializing our boolean var that will eventually decide if we have an error or not
[code]....
View 4 Replies
View Related
Nov 13, 2014
I am having trouble finding out how to space out the binary numbers that I am displaying. Currently they are displaying all as one EX: 10001000
How can I get them to be space out properly like: 1000 1000?
Im guessing its something in my loop. Here's my function for converting to binary:
void DisplayBinary(int num) {
int ctr;
unsigned int mask = 32768;
printf("
The input number in binary is: ");
for (ctr = 1; ctr <= 16; ctr++) {
[Code] ....
View 4 Replies
View Related
Mar 18, 2015
My code
#include<iostream>
#include<string>
using namespace std;
string strip(string message) { //removing elements that is not A-Z or a-z
string stripped;
for(int x = 0; x < message.length(); x++) {
[code]....
The output in my code shows like this:
[e]Encipher
[d]decipher
[x] Exit
Enter choice: e
Enter message to Encrypted:
i love you
Enter Key:
love
The encrypted message is: tzjzpmjy
Back to main menu? (y/n):
However , I want the output to display the spaces as the user's input.
ex. The encrypted message is: t zjzp mjy.
This is the same as i love you in the user's input.
View 14 Replies
View Related
Feb 13, 2014
how to carry out the conversions. The assignment is the normal hex to octal and Quart (base 4) via bit munipulation which I have worked out myself. However, I have been trying all day to figure out how to read in a string such as H1234, or O4567. How to parse the input I can handle the remainder myself. I'm just stuck and I've tried for hours.
View 5 Replies
View Related
Jan 23, 2013
this function has to check if an array is not descending it has to be recursive and it's space complexity has to be O(log(n))
Code:
int is_sorted(int a[ ], int n) {
int check=n-1;
if(n==1 || n==0) return 1;
if(a[check]<a[check-1])return 0;
else return(is_sorted(a,n-1));
}
this is what i came up with. i know it's space complexity is O(n) how do i make it O(log(n))?
View 2 Replies
View Related
Sep 2, 2013
I was just going through Radix Sort algorithm. Though I got the logic and the concept used in it, I am still pretty much confused about the space complexity being O(k+n) for this algorithm. (where, k is the max no of digits in a number, and n is the no. of inputs to be sorted).
View 1 Replies
View Related
Apr 20, 2013
I'm planning to make a C++ project using a 3D library to visualise space and planets, maybe using raytracing. I wanted to know which library is the most appropriate to achieve it.
View 1 Replies
View Related
Aug 26, 2014
If every record of a binary file is to be fixed length then shouldn't some space be wasted if variables are different size in a struct?
View 7 Replies
View Related