31
Computer Projects and Ideas / Designing Happy - OOP
« on: July 16, 2011, 05:25:10 am »
Ok, I'm trying to add OOP to Happy.
I only have a small problem:
Where do I place te objects, and how big?
It is simple with objects like this:
I can place this with the other vars after the code, and I know I need 2 bytes of space
But even this approach gives problems:
For example, how do I give it initial values?
Amd when using the stack, How do I know the amount of space left?
And this gives even more problems:
This one doesn't make sense, because we have the same data twice in RAM.
To make it short:
1. Happy doesn't always know how big it is
2. How can initial values be set?
3. How do I stop the program from corrupting things in RAM, with a ever-growing stack?
I only have a small problem:
Where do I place te objects, and how big?
It is simple with objects like this:
Code: [Select]
type point[2] {
ubyte x;
ubyte y;
}
// And in the program or global declarations:
point lol;
I can place this with the other vars after the code, and I know I need 2 bytes of space
But even this approach gives problems:
For example, how do I give it initial values?
Amd when using the stack, How do I know the amount of space left?
And this gives even more problems:
Code: [Select]
type string[] { // Yup, no native support
ubyte[] value;
empty create(ubyte[] in) { // empty is a subroutine type
// Loop and copy the string
}
}
This one doesn't make sense, because we have the same data twice in RAM.
Code: [Select]
type enemy[10] {
ubyte x;
ubyte y;
ubyte[8] sprite; // The monochtome sprite data
empty move(sbyte dx, sbyte dy) {
x = x + dx;
y = y + dy; // update the pos
}
}
To make it short:
1. Happy doesn't always know how big it is
2. How can initial values be set?
3. How do I stop the program from corrupting things in RAM, with a ever-growing stack?