C++ :: Spaceship Game - Creating Gravity For Each Object Depending On Mass

Mar 27, 2012

I've been having trouble working on this physics engine of mine. Right now I'm having trouble adding gravity.

The game is a spaceship--which you control--flying around in space with asteroids and eventually the ability to shoot bullets. There should be a wrap on the edges of the screen and gravity for each object depending on their mass.

I'm creating a forceX and forceY for each force put onto each object, and then computing that force into a velX and velY which will determine the direction of each object and at which speed.

Where my problem arises:

Code:
//add gravity pulls to forces
for(int i = 0; i <= pushCount; i++) //add gravity pulls for each object {
for(int u = 0 ; u <= pushCount; u++) //each object should add a force for every other object {
if(i != u) {
switch(id[i])

[Code] ....

View 7 Replies


ADVERTISEMENT

C :: Creating A Pendulum With Gravity

Jan 11, 2014

I have recently begun programming c within my university course. I have been given a task to add arrays to a program I had previously made to make it record the values as I expect I will then quote them on an exported document.

Code:

#include <stdio.h>
#include <math.h>
main() {
int i; // step counter
float theta[10000]; // initial value for angle

[Code]....

The pendulum is meant to swing and take gravity into account, then it is meant to loop and record values for the step count, time, theta and omega (mainly theta and omega required). The boundaries are set so once the angle of theta reaches 180 degrees it then stops. I believe the problem lies in the way I have created my theta array, however, I don't properly know how to implement this. Upon launch it asks for omega, as required, after inputting the value it crashes.

View 1 Replies View Related

C++ :: Creating A Game - Read Prices Of Object Inputted By User From A File

Feb 19, 2013

How do i read a specific part of a file? I am trying to create a game that reads the prices of an object inputted by the user from a file. This is the code i have so far

#include <iostream>
#include <fstream>
using namespace std;
int main () {
ifstream infile;
infile.open ("Objects.txt", ifstream::in);

[Code] ....

The file contains this :

Example objects
( ) store items
(item) (purchase value)/(sell value)

Grocery Store Items
Fish 5 7
Vegetables 10 15
Drinks 20 30

Weapon Store Items
Pistol 300 375
Rifle 400 500
Ammunition 20 30

View 4 Replies View Related

C# :: Creating Controls Which Act Differently Depending On Mode

Apr 24, 2014

I am creating a C# windows application which allows it to connect to our devices and communicate with them.

Often we need to customise this application and I have made this easier by defining its appearance and actions within an XML file which gets read in every time the application starts up. This is working really well.

However editing this XML file can be pretty laborious and often requires many cycles to get everything correct again. So I have started to create a graphical editor which allows for the XML to be generated.

The problem I am facing is that I am using the same controls in the final program and the editor so my question is how should I structure the code so that each control knows when it is in "Normal" mode and when it is in "Edit" mode?

I have started using a simple boolean flag to indicate its mode, however this now means that within every function I need to check this flag and run code appropriate to that mode, this seems a bit over the top. Is there a better/standard way this sort of this is done?

View 1 Replies View Related

C++ :: Creating Function That Outputs Either 1 Or 0 Depending On Input After Checking

Feb 18, 2014

I am trying to simplify my code by creating a function which takes an input then checks whether it is "y" or "n" then outputs either 1 or 0 depending on the input. So far this is what I have

int Choice(string choice) {
while(choice.compare("n") != 0 && choice.compare("N") != 0 && choice.compare("y") != 0 && choice.compare("Y") != 0){
cout << "Please enter a valid input either [y/n] : " << endl;
cin.clear(); cin.ignore(); cin >> choice;

[Code] ...

And I call it in the program using

cout << "Do you wish to change the hubble type of any galaxies? [y/n]" << endl;
cin >> choice;
while(Choice(choice) == 1){
....
cout << "Do you wish to change the hubble type of another galaxy? [y/n]" << endl;
cin << choice;
}

It compiles fine but displays some bizarre behaviour, I need to end the line twice in order for the program to continue and sometimes it just stops working (doesn't exit just appears to be stuck in a loop).

View 2 Replies View Related

C++ :: Creating Game Using SFML

Apr 26, 2014

I'm currently working on a 2D space shooter game in C++ using SFML library. What I need to know is how make an object (ex:laser) fire up from object (ex:player) when a user press button??

View 1 Replies View Related

C++ :: Creating Computer AI For Tic Tac Toe Game

Dec 24, 2014

How I can go about creating a computer AI given the way that I structured my code.

main.cpp

Code:
#include <iostream>
#include "Board.h"
#include <limits>
#include <cctype>
using namespace std;
int main() {
// Welcoming message.

[Code] ...

View 14 Replies View Related

C :: Creating A Kind Of Connect 4 Game

Nov 14, 2014

I'm creating a kind of connect 4 game that will be due on November 30. I'm starting now so that I don't have to worry about it as much later. Anyways, I just started, and I already have some questions/problems. I want to be able to change that numPlayers outside of the function, so I used pointers like my instructor said to, but it is giving me an error that numPlayers(the argument) is not an int*. How do I fix this?

Code:

int numPlayers=0;
void promptNumPlayers(int *numPlayers)
{
printf("Enter the number of players: ");
*numPlayers=readInt(stdin);
if (*numPlayers != 1 && *numPlayers != 2)
}

[code]...

View 3 Replies View Related

C/C++ :: Creating Moving Objects For 2D Game

Oct 21, 2014

I'm working on designing a game in C++ that is similar to the "find the ball under the cup" game. I have a Sonic the Hedgehog icon (weird I know, but it was the first thing that came to mind) that will be hidden underneath one of three rectangular blocks.

Here is how I envision this working:

On the main menu I have 3 buttons which represent 3 different difficulty levels
Easy- blocks move 3 times at a slow speed
Medium- blocks move 5 times at a slightly faster speed
Hard- blocks move 10 times at a fast speed

When the user clicks one of these buttons they will be taken to the game screen.

Sonic will be displayed for 3 seconds and the user will then see him be covered with one of the three blocks.

The three blocks will then move in a random pattern along the middle of the screen at the speed and number of times associated with the button that was pressed.

Once the blocks stop moving, the user is to click on the one they think Sonic is underneath.

If they choose correctly, they'll be taken to a "Winning Screen" that displays a congratulatory message and 2 buttons. Play Again- returns the user to the main menu and the game starts over with a new random pattern. Quit- the window closes.

If they choose incorrectly, they'll be taken to a "Losing Screen" that displays a "Try Again" message and 2 buttons that have the same function as the buttons on the winning screen.

I have never worked with any kind of graphics before other than in HTML and Javascript. I have managed to create the main menu, but how to do the actual game portion of the project. I've been trying to take it a step at a time, (for example, I first figured out how to set the background color for the console window, after I got that right I figured out how to add buttons) but the rest of this seems to depend on each other.

Here is what I have so far:

Main menu:

#include "stdafx.h"
#include <iostream>
#include <Windows.h>
using namespace std;
class MainMenu

[Code]....

So I've got the screens pretty much designed now (with the exception of the game screen itself) but how to tie everything together.

In case my description wasn't too clear, here is a game that I found on Google that is pretty much exactly what I'm looking for. [URL]

View 2 Replies View Related

C/C++ :: Tic Tac Toe Game - Creating A Menu/choice

Nov 11, 2014

Im trying to create something like a menu in a tic tac toe game. I want the computer to ask the user "who starts first" is it the X or the O who starts first? Then the user should type in either X or O but if he types something else i want to ask again .

this is what ive done :

int main () {
printf("
");printf("
");
printf(" %c | %c | %c
", board[1], board[2], board[3]);

[Code] .....

View 10 Replies View Related

C++ :: Creating 2 Dimensional Console Base Game

Jun 13, 2013

what i got so for my code.

#include <iostream>
#include <windows.h>
using namespace System;
using namespace std;
int refreshDisplay(int , int);
const char wHole = '@';

[code]....

count <<" The oblective of the game is for the player to move around a 2 dimensional playing field and capture the star withought falling into a black hole or walking off the edge of the playing field. The controls are W = up S= down A=Left D=Right" <<endl; how implement 3 black hole X characters and 2 wormhole characters on field @ and a star *. all these char has to be randomly generated.

View 1 Replies View Related

C++ :: Creating A Game - Use Classes For Rendering Objects?

Mar 16, 2014

I am creating a game and I using classes for other things in my game, I was wondering if i should use classes for rendering objects?

View 2 Replies View Related

C/C++ :: Creating Two Dimensional Terminal Based Game?

Apr 4, 2014

i am working on class project in which i have to save the tank from canon....imy tank is moving only when i press the moving key.. and after that i see blank screen what should i do to run my process when i am not pressing moving keys....

View 8 Replies View Related

C# :: Creating A Class And Methods For Dice Game?

Mar 21, 2015

The only difficulty im having is creating a class and methods & being able to access them from my win form app. Can i get a few tips on the do's and donts of creating classes / methods and accessing them from form app.

This is what i have put together so far.

public partial class Form1 : Form {
private Image[] dicePics;
private int[] diceNum;
private Random randomize;
public Form1() {
InitializeComponent();

[code]....

View 3 Replies View Related

C++ :: Program To Find Quarks And Their Charge And Mass - Giving Error

Mar 3, 2013

I have been looking and i'm stuck on this. I wrote this program to find quarks and their charge and mass but i need it to give me 5 different ones. so i made an array but when i run it it gives me this

"Unhandled exception at 0x001631c6 in DiasQuarkP1V0.exe: 0xC0000005: Access violation reading location 0xd5bf0c38." and it shows the xstring library.

this is my main, is their anything wrong with my code?

#include "StdAfx.h"
#include <stdio.h>
#include <string>
using namespace std;
int main() {
Quark solution[5]={};

[Code] .....

View 1 Replies View Related

C++ :: Gravity Simulator Implementation

Jul 9, 2013

I've been working on creating a simulator to crash two galaxies together as part of a project to stress test a CUDA super computer. I've got a long way to go and am currently just working on correctly simulating n-body gravity functions. First I will use this to simulate the cores of the galaxies (the black holes) and eventually the stars.

So long story short I'm working on the beginnings of a gravity simulator. At this point I found some basic code that works well but doesn't quite give the effect I'm looking for.

The code below only pulls each object towards each other like a spring faster and faster until they shoot off into infinity. I try to give one of my bodies an initial velocity to get it to orbit another, but it always just shoots straight at the other body. I'm thinking I need to factor in inertia so that the initial velocity doesn't just get calculated away really fast by the other calculations.

I'm really looking for a bit of direction to get a real gravity simulator with orbits and such working right so eventually I can scale it up to a galaxy, throw in 100B stars and let the CUDA run for a month..

Code:
void update_galaxies(GLdouble elapsedTime) {
//Calculate gravity simulations
GLdouble r1, r2, r3;
r1 = r2 = r3 = 0.0;

for(unsigned int i = 0; i < galaxies.size(); i++)

[Code] ....

As you can see, I'm calculating all the bodies in a vector called "galaxies" with each other, and doing a basic gravity calculation to it. The update_position function simply takes the calculated acceleration and uses it to calculate the velocity and position based on the "elapsedTime".

I think I need to use the Varlet or Runge-Kutta integration methods, after doing a bit more research.

View 9 Replies View Related

C :: Creating Match-3 (Candy Crush) Game Using Arrays

Mar 6, 2015

I'm supposed to create a "game" that is similar to Candy Crush or Bejeweled. The assignment takes in a .txt file that contains a matrix of values from 1-5 and then assigns each value to a spot in a [10][10] array. Then an Escape Code function prints out colored pixels in place of the number values for each spot, creating a "game board" looking output. Finally, the program is supposed to look for any matches of 3 same-colored pixels and replace them with a white pixel and "XX". Then the program prints the corrected game board with the matches X'd out.

I have it mostly coded, but I've encountered a couple of issues.

1.) I am supposed to label the columns and rows 0-9, and while I have no problem coding the labels for the columns using printf( ), when I try to print the row labels I get a random string of numbers.

2.) I replaced the matches with white pixels by reassigning the value in the array to 7, for which the ANSI Escape Code is white. However, I'm unsure about how to print the "XX" in the same spot.

Here is the input(.txt) file and the output of the program so far:

And here is what I have coded at this point:

Code:
#include <stdio.h>
void printEscapeCode(int c);
int main(void)
{
/* Declare an image array to be gameboard */
int gameboard[10][10];
/* Declare variables and load in how many rows and columns */
int Nrows;
Nrows = 0;

[code]....

View 2 Replies View Related

C++ :: Creating Frog Leap Game That Starts At 1 And Finishes At 12

Feb 13, 2015

I have been given the task of creating a frog leap game that starts at 1 and finishes at 12. The layout is as follows. The '@' symbols are just included to show blank white space.

1-----2 @@ 3---4
|@@ |@@@ |
|@@ |@@@ |
5@@ 6------7-----8
|@@ @@@ |@@ |
|@@ @@@ |@@ |
9----10 @ 11 @12

Each number within the game will represent an object, the user will have to reach the 12th leaf start from leaf 1. the frog can only move in the directions of forwards backwards, left and right. Any starting points? E.g. using and array or list? i have a feeling this is going to be a big task. is inheritance possible?

View 1 Replies View Related

C++ :: Creating Game That Will Test The Attention And Mind Flexibility Of User

Mar 6, 2015

I want to create a game that will test the attention and mind flexibility of the user. So the challenge is The user will be given 50 rounds, and each round should generate a random combination of text and words.Then the user must Press 'Y' if the UPPER CASE text spells out a color that match the BACKGROUND. But if the text are in LOWERCASE the user must press 'N'.(Note: you can change the keys to any key from the keyboard if you wish to)

Then I also want my program to record the high score each time the program prompts the user if he/she wishes to play again.

I also want to control the combinations by NOT allowing the text color and background color to be the same.

I also want the combination to generate an AVERAGE of 50% correct combination and 50% wrong combinations. The I want to use is only Red, Blue and Green

HIGH SCORE Determinants:

1. Accuracy ( (Number of corrects / 50 ) * 100% ) - The higher the better.
2. Time in seconds (Time Ended - Time Started) - the lower the better.

Computation for high score: 10 000 * ( (Accuracy) - (2 x total Attempts - Time) )

View 6 Replies View Related

Visual C++ :: Dice Game - Creating Pass By Value Function Reference

Nov 27, 2014

i have a project where i create a dice game, the user rolls 2 dice and the computer roles 2 dice. the player that wins 3 out of 5 rolls wins the game. I have completed the requirements, but i wanted to create a pass by value function for "void Dice()", I'm not too sure how that works?

Code:

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
//creating my variables and their values
int compinput;

[Code] .....

View 5 Replies View Related

C++ :: Game Freezes When Applying Surface From One Object Onto Another?

May 28, 2013

Been trying to figure out why my program freezes. I know exactly what line of code is causing it, but I can't figure out WHY it's causing it. It compiles fine, there are no errors returned, and then the game just stalls and I have to ctrl+alt+del to kill it.

Anyway, what I have set up is something like this:

main.cpp
#include "SDL.h"
#include "SDL_gfxPrimitives.h"
#include "SDL_image.h"
#include "SDL_rotozoom.h"

[Code]....

This is the line of code that's freezing the program. Simply put, so that you don't really have to go through it piece by piece, what I have done is:

*each player gets their own drawing surface called PlayScreen
*each player gets an array of 360 drawing surfaces called ShipPic. These are to keep the game from having to render the rotation pics of the ship on the fly.
*Get_Ship clips the requested ship picture out of the ship sprite sheet and puts it in ShipPic[0] for the original angle.
*the original picture is rotated by 1 degree and put into the 360 ShipPic slots.
*when the player rotates their ship, the angle changes, and it calls the ShipPic with the same number as the player's angle and places it on the screen.

All of this works perfectly.

Then, in Player::draw_screen(), I have it set up so that each player looks at all the other players and gets their distance. If they're within range, it takes the other player's picture rotated by the other player's angle and puts it on the current player's PlayScreen. This is where it freezes.

I've checked for NULL pictures, I've checked to be sure the angle is between 0 and 359, nothing makes any difference. I know it's reading the other player's information since I can output all of the player's X & Y coordinates, angles, the width/height of their pictures, etc. on each other's screens. So they're definitely talking.

To test the code, I've changed it from

Apply_Surface(ShipX, ShipY, p[i].ShipPic[(int)p[i].angle], PlayScreen);
to
Apply_Surface(ShipX, ShipY, p[ID].ShipPic[(int)p[ID].angle], PlayScreen);

And it works perfectly, placing the player's OWN picture in for the other players. So the function works. It's just when I try to take another player's picture and place it on the current player's screen that it freezes.

I've tried quite a few different ideas, such as creating a temp drawing surface to blit the other player's picture onto, but again, it freezes as soon as I try using the other player's pictures.

View 5 Replies View Related

C++ :: Creating Object Without Default Constructor

Jun 24, 2013

I have a question about the default constructor.

To my best understanding, the compiler will provide me with a deafult constructor only if there are no any user defined constructors, at all. Now consider the following code:

Code: class MyClass
{
private:
int m_data;
public:
MyClass(int init):m_data(init){cout<<"Ctr called"<<endl;}

[Code] ....

How is it that suddenly, there is a default constructor?

View 3 Replies View Related

C# :: Creating Object That Uses Numeric Up / Down And Track Bar?

Nov 19, 2013

I want to create an object that uses visual C#'s Numeric Up/Down and a Track bar.

The reason is that I have a GUI that uses lots of these linked together with events and I want a common event handler for all of them.

Maybe just adding a property that is a Numeric Up/Down in the Track bar and vice-versa will allow me to create a common event for all of these pairs.

View 1 Replies View Related

C++ :: 2D Game - How To Handle Drawing Order Of Object Visibility

Feb 9, 2015

In 2D games, what's the best way to handle the order of drawing objects? Because most games have a background, tiles to be drawn behind the player, perhaps tiles to be drawn covering up the player, etc. My point is, with my current setup of simply looping through all objects and drawing, I have no control over what objects are drawn on top of or behind the others. My best idea so far is to hold a vector of object pointers, each vector representing a different "visibility level", like so:

class Level{
//...
std::vector<Object> allObjectInstances;
std::vector<Object*> visibilityOne; //background objects
std::vector<Object*> visibilityTwo; //objects in front of background but not necessarily all the way in front
//and so on for more objects
};

If I go through with this, I'm wondering how I could loop through all my objects and add them to each vector, then shorten whatever I have to loop through for subsequent visibility vectors. handling the order of drawing objects?

View 6 Replies View Related

C# :: Creating Instance Of A Class Given Its Assembly Object

Jan 15, 2015

Let's say I reference a dll in my project that has an abstract class in it:

public abstract class Module {
public string type;
public abstract string doSomething();
}

And then I have an Assembly object, loaded from a dll that is not referenced in project, but rather loaded during run-time, containing:

public class Tester : Module
{
public static string type = "Test";
public override void doSomething() {
//Stuff being done
return "hello";
}
}

How can I get the value of "type" in the class that is loaded during runtime? How do I use the "doSomething" method of it and get the returned object?

View 8 Replies View Related

C++ :: Dice Game - Receive Same Values When Roll Function Get Call Twice For Same Object

Nov 7, 2013

#include <iostream>
#include <cstdlib>
#include <time.h>
#include <conio.h>
using namespace std;
class Dice {

[Code] ....

Every time the roll_dice function get call twice for the same object, i receive the same dice values.

View 4 Replies View Related







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