Inertia/Gravity/Type/Method/Function/Strict Sample
BlitzMax Forums/BlitzMax Beginners Area/Inertia/Gravity/Type/Method/Function/Strict Sample
| ||
I am trying to make a simple game by myself by using as little sample code as I can to learn how to do this. I am trying to draw a oval on the screen, then have little rectangles circle around the oval. Once I figure that out I would like some kind of inertia effect (the rectangles will go faster when they are going straight than when they are turning). After I get that I would like to have a black-hole effect. The rectangles will be pulled (clockwise) in towards the oval. When the rectangles collide with the oval they will be deleted. [The rectangles will be an array]. So here's what I have so far:Strict AppTitle="Game" Graphics 600,600 SeedRnd MilliSecs() AutoMidHandle False Type TStar Field x:Int Field y:Int Field dx:Int Field dy:Int Field inertia:Int Method create() DrawRect 20,20,20,20 End Method 'Global star:TStar = New TStar End Type While Not KeyHit(KEY_ESCAPE) Cls TStar.create() drawcircle() drawmouse() Flip Wend Function drawcircle() DrawOval 270,254,90,90 End Function Function drawmouse() DrawText"Mouse X",0,10 DrawText MouseX(),0,20 DrawText"Mouse Y",0,30 DrawText MouseY(),0,40 End Function Now I don't know what to do with the "star:TStar = New TStar". I want the compiler to go into the type of TStar then go to method create() to make the rectangle. So when I run it I get Identifier 'star' not found from the compiler. My first instinct is to put it before the While...wend loop but when I do that I get an error Identifier 'create' not found which doesn't make sense because I declare the type before the main loop.So do I change Method to Function? Which could work since Im known for having more luck with functions than methods. |
| ||
with "SuperStrict" to create an object of type "Int" you do this:local n:int and to crate an object of type "Float" you do this: local r:Float To crate an object of type "Tstar" you do this: local comet:TStar before you can use it, you need to create an instance of the object "Tstar" like this: comet = new TStar to use your newly created object of type "Tstar" you do it like this: comet.draw() |
| ||
One issue though, if it is local then will it work if I put it out of the type? Like before or in the main loop? |
| ||
No. |
| ||
So,...I would create it in the type and make it Global, right? |
| ||
Take a look at this: |
| ||
you must put the types in a tlist that is global or just make them global themselves like you said earlier |
| ||
lemme see how this works for me then ill post my results @Plash- how hard was it to make the code for me? Im curious |
| ||
Strict AppTitle="Game" Graphics 600,600 SeedRnd MilliSecs() AutoMidHandle False Local star:TStar = TStar.Create(Rnd(0,600),Rnd(0,600),40,40) Type TStar Global starList:TList = New TList Field x:Int Field y:Int Field dx:Int Field dy:Int Field inertia:Int Method New() starList.AddLast(Self) End Method Function Create:TStar(_x,_y,_w,_h) Local star:TStar star = New TStar star.SetPosition(_x,_y) star.SetSize(_w,_h) Return star End Function Method SetPosition(_x,_y) _x = x _y = y End Method Method SetSize(_w,_h) _w = w _h = h End Method Method Draw() DrawRect(x, y, w, h) End Method Function DrawStars() Local star:TStar For star = EachIn starList DrawStars() Next End Function End Type While Not KeyHit(KEY_ESCAPE) Cls TStar.Create() drawcircle() drawmouse() Flip Wend Function drawcircle() DrawOval 270,254,90,90 End Function Function drawmouse() DrawText"Mouse X",0,10 DrawText MouseX(),0,20 DrawText"Mouse Y",0,30 DrawText MouseY(),0,40 End Function |
| ||
Method SetPosition(_x,_y) _x = x _y = y End Method Re-read that code carefully, then answer the following questions : 1) What do you *think* it is supposed to be doing? 2) What is it actually doing? |
| ||
@Plash- how hard was it to make the code for me? Im curious Sorry, what? |
| ||
how long did it take you to make the code? |
| ||
how long did it take you to make the code? About 10 minutes (mostly testing and going against my coding standards to not confuse you too much). |
| ||
Ok, see that is how I want to program. I want my games to only limit my imagination, not my skill level. That is my goal that I want to get out of all this help. @Brucey- 1) _x is supposed to equal x _y is supposed to equal y 2) I think I mixed up the two variables and should flip them. Right? |
| ||
1) _x is supposed to equal x Incorrect._y is supposed to equal y 2) I think I mixed up the two variables and should flip them. Right? Yep.' field = parameter, not parameter = field x = _x y = _y Ok, see that is how I want to program. I want my games to only limit my imagination, not my skill level. That is my goal that I want to get out of all this help. You need to start small, go through the tutorials and you'd of learned all of this by now.Try this, and take a scroll through the BlitzMax Tutorials section. |
| ||
I've looked @ the link before, just so you are aware...:) |