Skip to content

Commit ebbd700

Browse files
committed
Work on adding struct member functions
1 parent 21124b6 commit ebbd700

File tree

12 files changed

+766
-500
lines changed

12 files changed

+766
-500
lines changed

examples/pong/main.asa

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77

88
gameObject :: struct{
9-
vector3 position;
10-
vector3 rotation;
9+
position : vector3;
10+
rotation : vector3;
1111
}
1212

1313
vector2 :: struct{
@@ -24,64 +24,64 @@ vector2 :: struct{
2424
}
2525

2626
sprite2d :: struct{
27-
image2d image = void;
28-
vector2 scale = vector2(1, 1);
29-
vector2 position = void;
30-
float rotation = void;
27+
image : image2d = void;
28+
scale : vector2 = vector2(1, 1);
29+
position : vector2 = void;
30+
rotation : float = void;
3131

32-
create :: (string path){
32+
create:: (path : string){
3333
image = create_image2d(path);
3434
}
35-
create :: (string path, vector2 s){
35+
create:: (path : string, s : vector2){
3636
scale = s;
3737
image = create_image2d(path);
3838
}
3939

40-
draw :: (){
40+
draw:: (){
4141
draw_image(image, position, rotation, scale);
4242
}
4343
}
4444

4545
paddle :: gameObject :: struct{
4646
moveSpeed = 1;
47-
vector2 minMax = vector2(0, screen_height);
48-
sprite2d sprite = sprite2d("./square.png", vector2(0.2, 1));
47+
minMax = vector2(0, screen_height);
48+
sprite = sprite2d("./square.png", vector2(0.2, 1));
4949

50-
move :: (float dT){
50+
move:: (dT : float){
5151
nextPosition = position.y + moveSpeed * dT;
5252
if((nextPosition > position.y && nextPosition<minMax.y) ||
5353
(nextPosition < position.y && nextPosition>minMax.x))
5454
position.y = nextPosition;
5555
}
56-
draw :: (){
56+
draw:: (){
5757
sprite.position = vector2(position);
5858
sprite.rotation = rotation.z;
5959
sprite.draw();
6060
}
6161
}
6262

63-
ball :: gameObject :: struct{
63+
ball:: gameObject :: struct{
6464
moveSpeed = 1;
65-
vector2 minMax = vector2(0, screen_height);
66-
sprite2d sprite = sprite2d("./ball.png");
65+
minMax = vector2(0, screen_height);
66+
sprite = sprite2d("./ball.png");
6767

68-
move :: (float dT){
68+
move :: (dT : float){
6969
nextPosition = position.y + moveSpeed * dT;
7070
if((nextPosition > position.y && nextPosition<minMax.y) ||
7171
(nextPosition < position.y && nextPosition>minMax.x))
7272
position.y = nextPosition;
7373
}
7474
draw :: (){
75-
sprite.position = (vector2)position;
75+
sprite.position = vector2(position);
7676
sprite.rotation = rotation.z;
7777
sprite.draw();
7878
}
7979
}
8080

81-
list paddles = {paddle(), paddle()};
81+
paddles : paddle[] = {paddle(), paddle()};
8282
ball = ball();
8383

84-
main :: (){
84+
main:: (){
8585
w = window_create("Pong", 512, 512);
8686

8787
paddles[0].position = vector3(10, screen_height/2, 0);
@@ -91,7 +91,7 @@ main :: (){
9191
}
9292

9393
// Function called by draw_window method
94-
update :: (float dT){
94+
update:: (dT : float ){
9595
if(key_down("W"))
9696
paddles[0].move(dT);
9797
else if(key_down("S"))

examples/start/main.asa

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,24 @@ Or individual components:
2222
//string :: struct {
2323
// c : int;
2424
//}
25-
string::string(){
25+
create::string() #inline; #replaceable; {
2626
return *(#new string);
2727
}
28+
//cast::string(c : *char) #inline; {
29+
// s = string();
30+
//
31+
// len : uint32 = 0;
32+
// for(i : 0..4_294_967_296){
33+
// if(c[i] == '\0')
34+
// break;
35+
// len++;
36+
// }
37+
// s.address = malloc(len);
38+
// for(i : 0..len){
39+
// s.address[i] = c[i];
40+
// }
41+
// s.length = len;
42+
//}
2843

2944
operator|| :: bool(a : bool, b : bool) #inline {
3045
if(a){
@@ -62,7 +77,7 @@ operator[] :: (x : int, y : int){
6277
puts("Bracket overload works!\n");
6378
}
6479

65-
newline::(){
80+
newline::() #inline; {
6681
putchar(10);
6782
}
6883

@@ -76,13 +91,19 @@ main :: (){
7691
//y : uint16 = 4;
7792
f = float(1);
7893

94+
var : bool;
95+
7996
s : string = string();
97+
s = string("This works");
8098

81-
s.c = 8;
82-
printint(s.c);
99+
s.length = 8;
100+
printint(s.length);
101+
s.size();
83102

84103
newline();
85104

105+
puts(s.address);
106+
86107
//x_ptr : *int = &x;
87108
//begin : *int = x_ptr;
88109
//i = 0;

modules/Builtin/asa.asa

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,28 +121,14 @@ Strings :: module{
121121
//#import Builtin.Operators;
122122

123123
string :: struct {
124-
//address : *char;
124+
address : *char;
125125
length : uint32;
126126

127-
//size::uint32(){
128-
// return length;
129-
//}
127+
size::uint32(){
128+
return this.length;
129+
}
130130

131-
//cast::string(c : *char){
132-
// len = 0;
133-
// for(i : 0..4_294_967_296){
134-
// if(c[i] == '\0')
135-
// break;
136-
// len++;
137-
// }
138-
// address = malloc(len);
139-
// for(i : 0..len){
140-
// address[i] = c[i];
141-
// }
142-
// length = len;
143-
//}
144-
145-
//binary+ :: string(s : ref string, c : char) #inline {
131+
//operator+ :: string(s : ref string, c : char) #inline {
146132
// s.length += 1;
147133
// newAddress : *char = malloc(s.length);
148134
// for(i : 0..s.length-1){
@@ -154,7 +140,7 @@ Strings :: module{
154140
// return s;
155141
//}
156142

157-
//binary+ :: string(s : ref string, otherStr : string) #inline {
143+
//operator+ :: string(s : ref string, otherStr : string) #inline {
158144
// oldLength = s.length;
159145
// s.length += otherStr.length;
160146
// newAddress : *char = malloc(s.length);
@@ -169,8 +155,13 @@ Strings :: module{
169155
// return s;
170156
//}
171157

172-
//binary[] :: char(s : ref string, i : int) #inline {
158+
//operator[] :: char(s : ref string, i : int) #inline {
173159
// return s.address[i];
174160
//}
175161
}
162+
163+
//cast::string(c : *char){
164+
// return string(c);
165+
//}
166+
176167
}

0 commit comments

Comments
 (0)