problem 2 chapter 11 (structures) from jumping into c++

the question says
"Create an array of space ship objects and write a program that continually updates their positions
until they all go off the screen. Assume that the size of the screen is 1024 pixels by 768 pixels."

I dont understand what it mean by "assume that the size of screen is 1024 by 768 , does it mean that I change the resolution of the console ?
or something else.
Probably refers to the limitations to be used in transforming world/actual x, y position of spaceship to screen coordinates.
hard to say without context.
- long ago, that was the default screen resolution and it stayed there for many years: this assignment may be very old?
- are you doing graphics, or is it a simulation of a virtual screen? That is, do you draw anything here?
- if it is graphics, you can just make a 1024x768 area and draw in it; its going to fit on any modern screen with room to spare.
- if its the console, you may need to resize it.
- it could be as againtry said... are you to scale screen as if it were square and translate that?
Last edited on
I am using console , and I didnt learn from the book how to set console resolution , so how do I know when the space ships reach the limitation
The spaceship will be on the perimeter of a 1024 X 768 pixel console when x == 0 or x == 1024 or y == 0 or y == 768, x and y are screen coordinates derived from a transformation of the world coordinates.

If you are just starting off then make it so the spaceship world coordinates are just the same as screen coordinates, thus no transformation required.
excuse me but I am little dumb , I dont really understand what are u saying .

so if u have free time , u could give me a code example.
if not I will try to figure out what ur saying myself.

edit
------
I figured out what are u trying to say but I don't know how to move characters on the screen.

do I use space to move them or what.
Last edited on
Why don't you show us some code?

First make a Spaceship class or struct with its x and y coordinates as properties.
 
struct Spaceship ... blah blah


Then create a Spaceship object (in main() ) and 'move' it around by changing its x and y values.

1
2
3
4
5
6
7
int main()
{
     Space sh;
     sh.x = ... blah blah

     ...
}


At each change in x,y position you can then draw it at that position. Use a character eg '*' for a start.

do I use space to move them or what.
Believe it or not, we are all, including your Spaceship, in space so I guess you meant the spacebar. You can use that if you like but to me that comes later - you're still at problem 1. Just type in the coordinates.
PS
I just saw chapter 11 of your book and all what I said seems to fit but, either way, the chapter gives you plenty of code to start with.
Baby againtry has pooped out some more code.
Mommy would be so proud!
so if I changed its coordinates which understand , how to I change its position by pixels in console , thats the thing I don't really understand .
do I make a matrix , or something else .
Last edited on
in the console you really do it as characters, not pixels, so extend console to support the extra wide and extra long buffer, then draw it over and over. To draw pixels in the console requires graphics libraries and a LOT more. Something like * can be a 'pixel' or a 'spaceship' ... whatever you want.
Last edited on
@OP
You best check with your teacher but my understanding of the chapter and question is that it is not necessary to try and display the ships but process the information. (If it is required, you still have to go through the exercise of calculating the position.)

Here's a simple start which you can extend for the y_coordinate and even like the chapter talks about, make an array of 1000 spaceships with random movements and checke whether any 'go off the screen'. You can show that with the numbers.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <string>

struct SpaceShip
{
    int x_coordinate;
    int y_coordinate;
    std::string name;
};

const int WIDTH{1024};
const int HEIGHT{768};

int main()
{
    SpaceShip ship;
    
    //START
    ship.x_coordinate = 150;
    ship.y_coordinate = 400;
    
    // MOVE
    ship.x_coordinate += 10;
    ship.y_coordinate += 20;
    
    // SHOW POSITION
    std::cout << ship.x_coordinate << '-' << ship.y_coordinate << '\n';
    
    // CHECK IF OFF-SCREEN
    if(ship.x_coordinate < 0 || ship.x_coordinate > WIDTH)
        std::cout << "Gone off screen\n";
    else
        std::cout << "Still on screen\n";
    
    return 0;
}


160-420
Still on screen
Program ended with exit code: 0
oh, so question wont ask me to print the actual space ship on the screen , I thought I will have to print a character 'o' that represent the space ship across the console , ok ty .
Last edited on
oh , so question wont ask me to print the actual space shop on the screen , I thought I will have to print a character 'o' that represent the space ship across the console , ok ty .

Like I said, from reading the chapter and question I don't think you have to display movement on the screen but you should check that with your teacher.
I dont have an teacher and the book didnt giv me information to move an object by pixels on the screen , so ty for replaying .
Topic archived. No new replies allowed.