Like Tree10Likes
  • 3 Post By R41D3N
  • 2 Post By Neo1
  • 2 Post By manasij7479
  • 3 Post By VirtualAce

Need help in creating asteroids for Turbo C++ (Logical explanations)

This is a discussion on Need help in creating asteroids for Turbo C++ (Logical explanations) within the C++ Programming forums, part of the General Programming Boards category; Hello guys, I need to create a project for school, and I've decided on Asteroids. I've made Snake, last year, ...

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    1

    Need help in creating asteroids for Turbo C++ (Logical explanations)

    Hello guys, I need to create a project for school, and I've decided on Asteroids. I've made Snake, last year, so I'm moderately-versed with the standard library and <graphics.h>.

    The basic logic I used in snake was to use a loop and putpixel() to draw a green pixel that advanced as the user gave input and another putpixel behind it to draw black, hence simulating movement. Now, that won't fly here, as I need to create asteroids and a ship and projectiles and what not, so how do I go around moving things? Again, I'm not asking for the source code, just if someone could explain to me how I could draw, say, a space ship and move it (console application), I would be very grateful. Remember, this is Turbo C++, and I can't use any external libraries.

  2. #2
    Registered User R41D3N's Avatar
    Join Date
    Mar 2012
    Location
    ...Beyond Infinity, Behind a KeyBoard...
    Posts
    29
    Quote Originally Posted by Deepit View Post
    I've decided on Asteroids. I've made Snake, last year, so I'm moderately-versed with the standard library and <graphics.h>.
    ROFLMFAO whats this, Blast from the Past?

    ^again ...


    Refer for Asteroids


    TIP: Drop TC, it wont get you anywhere. If you are interested in graphics using C++, try working with Qt, but you will need to wake up to the current standards of C++.
    manasij7479, Elysia and antred like this.
    -- reserved for when I come up with 1 --

  3. #3
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    My first advice would be to find a school where you are not forced to use a 20+ year old compiler.

    My second advice would be to use OOP and have objects for each entity in the game (ship, asteroid, projectile), these objects would have an x and y coordinate, and a method for drawing themselves onto the screen at their current x/y coordinates. You could then store all your objects in a container (Does TC++ support std::vector?), and loop over this container every frame calling update() and draw().

    The hard part of this seems to be having the spaceship being able to rotate, since you are using text in lieu of proper graphics, you would need to limit the rotation to 0/90/180/360 or perhaps you could rotate in steps of 45 degrees, but it's gonna feel very mechanical i think.

    Edit:

    Doh, you're not using text, but actual graphics. Is this even possible with TC++? o.O

    Anyways, disregard my last comments.
    CoffeCat and antred like this.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  4. #4
    Registered User R41D3N's Avatar
    Join Date
    Mar 2012
    Location
    ...Beyond Infinity, Behind a KeyBoard...
    Posts
    29
    @Neo1: I think they have a vector.h in TC ... plus there arent any frames in the dos afaik O.o ...
    -- reserved for when I come up with 1 --

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    @Neo1: I think they have a vector.h in TC ... plus there arent any frames in the dos afaik O.o ...
    You do not need <vector> (it is not vector.h) to create asteroids. You will probably need to create a hybrid container to do what you want for that specific game.
    There aren't 'frames' in any language. Frames are a graphic concept. It can either mean a frame of animation, a keyframe, a 2D / 3D frame of orientation or a host of other things.
    Last edited by VirtualAce; 06-18-2012 at 04:31 PM.

  6. #6
    Registered User R41D3N's Avatar
    Join Date
    Mar 2012
    Location
    ...Beyond Infinity, Behind a KeyBoard...
    Posts
    29
    @Ace I was talking about the vector.h header in the stone-age TurboC, not std::vector ^^, plus I dont think any "graphic concept" will be applicable to OP's question (since hes on the dos/prompt) ..
    -- reserved for when I come up with 1 --

  7. #7
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,438
    It could certainly be created with the turbo c, and ye olde graphics.h and would look suitably retro, genuinely retro even, because of the ancient drawing method, - if you could get it to display. I have some graphics stuff written with it that still fires up and works fine, mostly it just bombs out though.

    Haha, i just ran a few, from 'archive' folder they look bloody fantastic - love those old colours, seems to work pretty good actually on this computer, still, has to be said if you are starting programming now, dont go with the turbo compiler etc, we have so many student questions that are being told to use it - is just wrong, wrong mate. You should get one of the excellent free compilers / IDE setups that are out there and also a large fish or suitable heavy food object from the market to slap your tutor with.

    This mashed my monitor up for a few seconds, but happy days:
    EDIT oh well not even the screenshot could be captured....there ya go - GIMP said no, gutted!
    Last edited by rogster001; 06-20-2012 at 03:03 PM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  8. #8
    Registered User
    Join Date
    May 2012
    Posts
    71
    What is the best way to rotate a spaceship with alot of details. A pixels must be re-drawn i think, but better i ask for a proper answer.
    Any best and fastest way?

  9. #9
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Quote Originally Posted by CoffeCat View Post
    What is the best way to rotate a spaceship with alot of details. A pixels must be re-drawn i think, but better i ask for a proper answer.
    Any best and fastest way?
    Use a transformation matrix.
    (Considering that your spaceship is composed of several points in space, multiplying each of them by the appropriate transformation matrix will give the new points.)
    For 2D, the matrix for x degrees of rotation is :
    Code:
    cos x    -sin x
    sin x     cos x
    This can also be used for scaling (Multiply the cos x terms with the appropriate scales in x and y direction respectively) , (and translation too if you use a 3x3 matrix using homogenous coordinates (w remaining 1, for 2D)).
    Last edited by manasij7479; 06-21-2012 at 04:59 AM.
    CoffeCat and R41D3N like this.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  10. #10
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Rotating bitmaps is fraught with problems if you are not using hardware acceleration and polygon fill rasterization. Dump the ancient stuff and use something built in the last decade. I would love to see how you are going to create a far pointer to A000:0000 in a Windows environment. Turbo C and Turbo C++ were designed to run in real mode and thus you can only transfer 64KB of memory at a time and are limited to the bottom 640KB of the available 1024mb in real mode. To break the 64kb barrier you either have to go to protected mode (IE: use DJGPP's 32-bit DOS extender) or use bank switching. In times past you could get a far pointer to the bank switch function on your video card which was far faster than firing off an interrupt every time you needed to bank switch. To access more memory than 640KB you will have to use EMM386.EXE via interrupts (2Fh or 21h..can't remember) or use HIMEM.SYS. Keep in mind none of this will work correctly in a Windows session and this stuff was hard enough to get working back in the day in pure DOS. Now you will have Windows standing in the way and will probably get some weird behavior if you attempt any of this.

    Even with DJGPP and their 32-bit DOS extender if you try to get a far pointer to the linear frame buffer of the video card Windows will frown heavily on it. In fact if I recall the far-pointer hack of times past for DJGPP does not work on any Microsoft OS newer than Windows 98. At the end of the day you are left with farnspoke and the like in DJGPP which is a waste of time.

    And before you attempt it please do not use BGI graphics in graphics.h. That should have been deprecated the day they released it. It probably doesn't even work on modern cards.
    Last edited by VirtualAce; 06-21-2012 at 05:27 PM.
    Elysia, Salem and iMalc like this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need explanations...
    By adnilsah017 in forum C Programming
    Replies: 2
    Last Post: 06-06-2011, 03:34 AM
  2. c++ definitions and explanations help
    By yosimba2000 in forum C++ Programming
    Replies: 10
    Last Post: 06-27-2010, 03:28 AM
  3. Need help creating game with Turbo C
    By Trafalgar Law in forum Game Programming
    Replies: 10
    Last Post: 09-17-2008, 06:54 AM
  4. Asteroids
    By IdioticCreation in forum Game Programming
    Replies: 16
    Last Post: 05-15-2007, 07:04 PM
  5. Help me in creating a scroll bar in Turbo C 3.0
    By developersubham in forum C Programming
    Replies: 0
    Last Post: 01-14-2007, 12:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21