elfprince13 wrote:
So is there any particular reason why this topic (and the first sentence in the first post) is still called "Asteriods" and not "Asteroids"?
Presumably because the OP was unsure of the proper spelling of the word? Smile Zelda: But you still know the maximum size of the "sprite" given any rotation and base point, so it's easy to grab a chunk equal to the maximum amount of space you'll need to restore. The trick will be avoiding overwriting the asteroids themselves at the same time.
Yeah my bad, my spelling is very bad if you all haven't noticed.
zeldaking wrote:
Yeah my bad, my spelling is very bad if you all haven't noticed.
It's not terrible. Just keep an eye on your spelling and grammar, and we'll be happy. Here at Cemetech, we care as much more the quality of your posts and making us (and yourself) look good than the quantity of your posts.
Okay, I compiled and it works great. So far all it does is allow a circle (ship substitute for testing) to move around, but it moves like an asteroids ship. Moving increases speed which slowly goes away. Now I am going to start adding the actual asteroids but have a questions. Can you use 2-dimensional arrays in C? If so that is what I'm going to be using for asteroid memory storage.
zeldaking wrote:
Can you use 2-dimensional arrays in C? If so that is what I'm going to be using for asteroid memory storage.



Code:
int twilight_is_best[100][100];  // new one

int a = twilight_is_best[3][3]; // element (3,3) of array, same as element 3*100+3 in memory-layout terms


Yes Smile
Zelda, have you looked at existing code? A question like "Can C do two dimensional arrays" is very quickly answered by either googling it, or looking at existing projects. For example, Minesweeper and Game of Life both use them. Some of the other questions you asked could be answered that way, too. I suggest looking at the code available in the archives to get a good grasp of what's been done.
KermMartian wrote:
elfprince13 wrote:
So is there any particular reason why this topic (and the first sentence in the first post) is still called "Asteriods" and not "Asteroids"?
Presumably because the OP was unsure of the proper spelling of the word? Smile


I figured someone might have fixed it after the couple weeks since the OP if it was unintentional. It's been bugging me every time I hit "View New Posts", but I didn't know if it was an intentional decision (for example to avoid a copyright/trademark issue with the game name).
Ahh okay. Just making sure, my programming book specifically stated 'in C++ arrays...' and didn't say anything about C. Thanks. So...

Code:

int asteroid_mem[][3] = {
// Vertex_X, Y, Size
... code...
} ;

This is correct right?
Why not use a struct for that? And then just have an array of asteroid structs?
Okay structs it is. How about:

Code:

struct asteroid_mem {
     int x_pos[];
     int y_pos[];
     int size[];
     int x_dir[];
     int y_dir[];
} x_pos, y_pos, size, x_dir, y_dir;

Do I need a variable that controls the size (amount) of asteroids, so the drawing loop knows when to stop?
You do indeed, and you'll need to malloc the array to create it, as well as realloc and copy as necessary when it changes size.
Okay sounds good. I should have something like this implemented by tonight. Is using a struct more efficient than having those arrays by themselves?
I am having a hard time using malloc, and realloc. First off I don't know how to use them and I don't understand why I would use them. Does anyone have a good explanation/code? If so I would be very much in your service.
Although double post, this is pretty much unrelated to the prevoius post i.e. new question. So here I go:

Code:

//asteroid memory
struct asteroid_mem { 
     int x_pos[]; 
     int y_pos[]; 
     int size[]; 
     int x_dir[]; 
     int y_dir[]; 
} x_pos, y_pos, size, x_dir, y_dir; 
int asteroid_amount;

That is just my code to define the struct before main starts, but compiling gives me hardships.

Code:

error: flexible array member not at end of struct

Does anyone know what this means? I for one am once again clueless. Sad I know it has nothing to do with malloc or memory.
The size of the array in the struct must be specified. You would change each array that has an undefined length (like int x_pos[]), and put the length of the array between the two brackets.
Hmm, I thought you can have undefined lengthed arrays. Am I wrong again? So I have to predefine a length, let's say one. Next when I want to enlarge it, that is when I use malloc grab the pointer, realloc and copy the data starting at pointer to new array, but this time it is enlarged by 1. Is that correct? If so I am beginning to understand this stuff.
Your struct shouldn't have arrays (this isn't always true, but is for how you're doing it). You should have an array of structs.

Code:
struct asteroid_mem { 
     int x_pos; 
     int y_pos; 
     int size; 
     int x_dir; 
     int y_dir; 
}

asteroid_mem[] asteroids;

I'm once again going to suggest that you look at existing code. Check out how Periodic handles the element data. The struct holds the element, and then there's an array of element structs that is all the elements.
Okay I am skipping the asteroid memory part, for now. I am going to do some trig here an draw the actual ship (triangle not circle) and I am wondering how I start. I know I am going to have to do some trig, for the line drawing. I'll get back on this when I have questions.
Does anyone have a good trig/line drawing routine that would be easily changed to my purposes?
Why not make the ship a sprite and draw it with CopySprite? It would be faster than calculating points and drawing lines.
Yeah, looking at the asm version of "Asteroids" I found that out. He used multiple sprites and a vector table to decide the thrust movement. I am going to do that. Also I coded the Asteroids in, I just used arrays Razz no structs for me. It works though.
For sprites, I was planning on using 16 or even 8 bit bitmaps. But I got a problem, I thought 16-bit has plenty of colors and shades but for some reason in paint using 16-bit it changed brown to a green and pink to gray, etc. I was wondering how come?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 4 of 5
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement