Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help with creating an object.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Geog




PostPosted: Sat Mar 08, 2008 2:16 pm   Post subject: Help with creating an object.

Hello all...I am making a "procedural" asteroids game, where the asteroids are randomly generated in real time. I realize now that the best way to do this is to make each asteroid an object. I have read the tutorials on records, pointers, types, and I don't really understand how they work. Additionally, it appears that AsianSensation never made "Records, Part II" where he was to explain how to create an array with a variable number of fields. This is what my object must include;

Turing:

var asteroid : collection of
    record
        verticies := Rand.Int (5, 8)
        angles := array 1 .. verticies
    end record



Thanks for any help... if anybody has a better suggestion on accomplishing this, that would also be appreciated.
Sponsor
Sponsor
Sponsor
sponsor
A.J




PostPosted: Sat Mar 08, 2008 3:12 pm   Post subject: Re: Help with creating an object.

Instead of:
code:

var asteroid : collection of
    record
        verticies := Rand.Int (5, 8)
        angles := array 1 .. verticies
    end record


I'll advise you to do:
code:

type vertices:
     record
        x,y:int
    end record
var numofasteroids := Rand.Int (5, 8)
var asteroid : array 1..numofasteroids of vertices


Since you need both an abscissa and an ordinate to form an asteroid ( (x,y) determines a point), you need an array that holds both these values so that you can tamper with these values to your liking.

sry if this isn't what u wanted Very Happy
Geog




PostPosted: Sat Mar 08, 2008 11:12 pm   Post subject: Re: Help with creating an object.

Thanks for the help, I have a new idea about the structure of my program. But my asteroids are generated using random angles, so I need to be able to create an array which holds the x/y coordinates of each vertex. The main question is, how does one create an object array using a variable that is defined after the program is executed?

EDIT: Now I understand what you were trying to explain, A.J. Thanks for the help, I'll try it out.
EDIT: Wait, your code only works for storing coordinates for one asteroid. I thought that I would try making the asteroid as an object simply for the fact that I would have to generate several asteroids at once. Please elaborate if I am mistaken once again Confused
Saad




PostPosted: Sat Mar 08, 2008 11:59 pm   Post subject: RE:Help with creating an object.

The problem is collections and records require to be declared with one size, rather then a changing value.

What you can do is make it so that it stores the number of verticies and an array from 1 to your maximum number of verticies per asteroid.

However another more OOP approach would be to create an VertexArray class which wraps flexible array and has functions which allow for adding, getting, deleting verticies.
A.J




PostPosted: Sun Mar 09, 2008 1:17 am   Post subject: Re: Help with creating an object.

Like Saad said, creating a Vertex Array class would be helpful. Look through the turing walk through for some ideas on classes.
I think I misunderstood what you were asking for, so could you tell me what you were trying to say before, please?
(I am kinda slow Very Happy )
Geog




PostPosted: Sun Mar 09, 2008 1:52 am   Post subject: Re: Help with creating an object.

Let's put it this way: I want to make a template for "asteroid" data. I can take this template, and store a random number of x/y coordinates in it. I will call it again to move the coordinates. Then when I need to, I will take the same template to create yet another asteroid. I hope this explains my goal.

Also, do I need to make a class just to store the coordinates? From what I understand of classes right now, it appears that I can put this whole template in the class. Maybe an example? Laughing
A.J




PostPosted: Sun Mar 09, 2008 2:57 pm   Post subject: Re: Help with creating an object.

I am not too good with classes myself (and I am pretty sure Saad will be able to give a much better example than I can ever give).
But by "making a template for asteroids", do you mean like a making a record of random asteroid data that can be called over and over again?

If yes, I'll advise you to use MODULES.

I attached an example of modules below that generates a dice game, where the player (playing with 2 dice) must roll at least 6 to score. If he rolls x (including the rolls of both the dice), if x>6, he then scores x-3. (If this doesn't help WHATSOEVER, please make a point in telling me Very Happy)

The attached program is in word pad, as I don't have turing on my computer (I just formatted it).



dicegame(monitor).t
 Description:
here it is

Download
 Filename:  dicegame(monitor).t
 Filesize:  873 Bytes
 Downloaded:  50 Time(s)

Geog




PostPosted: Sun Mar 09, 2008 3:25 pm   Post subject: RE:Help with creating an object.

Looking at the modules tutorial, it seems that we are getting closer. But it appears so far that the modules are just like advanced procedures and functions. How would I go about making a module that stores several sets of a random number of values?
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: