About types.... to...
Blitz3D Forums/Blitz3D Beginners Area/About types.... to...
| ||
Well example my type is:type Player_typ field X field Y field JumpHeight field Visible end type I wonder how to get a value and put a value in thoses field??? ;need to add something like to set Player_typ Visible field to false, and do like this ;if player_typ's field Visible is true then If KeyDown(200) ; up y=y-4 EndIf If KeyDown(208) ; down y=y+4 EndIf If KeyDown(203) ; left x=x-4 EndIf If KeyDown(205) ; right x=x+4 EndIf DrawImage image,x,y until Visible ... What would be the correct way to do this.. add value to a field and retrieve the value from that type...??????? |
| ||
player.player_typ = new player_typ If KeyDown(200) ; up player\y = player\y - 4 EndIf If KeyDown(208) ; down player\y = player\y + 4 EndIf If KeyDown(203) ; left player\x = player\x - 4 EndIf If KeyDown(205) ; right player\x = player\x + 4 EndIf DrawImage image, player\x, player\y until player\visibleNot sure what you're getting at with the "visible" thing though... |
| ||
if the player Object is on the screen, then the player can move it if its not visible then he cant? Aint that logic? I dont get player.player_typ = new player_typ Why use that? whats the player. come from? why use player\x why not player_typ.x or player_typ\x ?? Good explications for the newbie please ^___^ |
| ||
A type is a structure from which you derive instances. This is the structure: type Player_typ field X% field Y% field JumpHeight# field Visible end type and this is an "instance" of the type, that you use in your game: Global Player.Player_typ = New Player_typ Player\X = 20 Player\Y = 20 Player\JumpHeight = 5.5 Player\Visible = false The beauty of it is, you can make one or 1000's of instances from the same structure. so: for count = 1 to 1000 Player.Player_typ = New Player_typ Player\X = 20 Player\Y = 20 Player\JumpHeight# = 5.5 Player\Visible = false next and you have 1000 instances of "Player" of type "Player_typ" |
| ||
I would suggest you read these through. If they don't make sense the first time, read them again. They're great tutorials. http://www.blitzcoder.com/cgi-bin/articles/show_article.pl?f=gamekrylar10192000.html http://www.blitzcoder.com/cgi-bin/articles/show_article.pl?f=mutteringgoblin09232002232208.html Apologies for the BlitzCoder links but I'm one of the "scags" who likes it over there. It's true that the discussions are not always as advanced as they are over here, but I find the atmosphere much nicer, and there's a lot less namecalling, bitching and jealousy. You'll find some other great tutorials over there which might be of interest to you as a newcomer to Blitz. I highly recommend Krylar's tutorials, as his writing style is clear and precise without being patronising. |
| ||
I think what confused me first was the similar name calling. Player_typ and Player sound similar and at first sound like the same thing. Kaisuo you could name the new instance of Player_typ anything you want such as Player, Person, Sprite, Thing-a-ma-jig. I tend to use something like thisPlayer to define the current instance because I think it makes more sense. Global thisPlayer.Player_typ = New Player_typ thisPlayer\X = 20 thisPlayer\Y = 20 thisPlayer\JumpHeight = 5.5 thisPlayer\Visible = false so if your types were dogs it could look like: Global thisDog.Player_typ = New Player_typ thisDog\X = 20 thisDog\Y = 20 thisDog\JumpHeight = 5.5 thisDog\Visible = false so: for count = 1 to 1000 Player.Player_typ = New Player_typ Player\X = 20 Player\Y = 20 Player\JumpHeight# = 5.5 Player\Visible = false next and you have 1000 instances of "Player" of type "Player_typ" ACTUALLY, you have ONE instance of Player (the last one that was created) and 1000 instances of Player_typ's. In other words, the Player variable only points to the last instance that was created because you reused it over and over. If you wanted to have a seperate variable for each instance of Player_typ then you would have use an array (i.e. Player(1) or Player(284)) to keep track of each one. |
| ||
so Player(1)... like if i wanted to change values of a specific one? |
| ||
ACTUALLY, you have ONE instance of Player (the last one that was created) and 1000 instances of Player_typ's aah!Well, if they were created with a For/Next loop, they can be accessed and changed with a For/Next loop as well. That sounds more complex than it is, check out the links Sybixsus has provided, it is explained much better than I could. Especially, note that there is a special For/Next loop for running through the instances of a type, a For/Each loop. check the link :) |
| ||
Um I would do this, this looks better, I think.p.player=new player If KeyDown(200) p\y = p\y - 4;Up If KeyDown(208) p\y = p\y + 4;down If KeyDown(203) p\x = p\x - 4;Left If KeyDown(205) p\x = p\x + 4;Right DrawImage image, p\x, p\y type player field x field y field Jumphieght field visible end type Hrrm what type of game program are you working on? 2d works, but to be honest I think 3d programming is much easier then 2d. The only part thats harder in 3d, is to make the 3d models. But use Milkshape. its the better then anything I've seen for under 100 bucks(milkshape is 30 btw still i think). |
| ||
2D is harder then 3D are you sure? |
| ||
No its not. Just depends on the application... Use what you think works best. Although Tetris could be written in 3D, it's not really necessary and is probably easier in 2D. |
| ||
Ive thought sometimes of making a tetris game but I just have no clue where to start and how to make the game work. |
| ||
im blitz3d 3d is much easier than the 2d aspect. With coding a 2d and 3d engine from scratch though, 3d is insanely harder. |
| ||
Ive thought sometimes of making a tetris game but I just have no clue where to start and how to make the game work. pop over to www.Blitzcoder.com go to the showcase, enter the search term "tetris" and when the results come up, look in the column for "source included" should get ya started :) |
| ||
Kaisuo: Types are one thing which baffled me initially. Try to think of them as a list of objects. So when you create a player Type you are really creating a list of players. So when you use the line p.player = New player you are really adding something to the list. Once an item is added to the list you can fill in it's variables. Like so:Type player Field X, Y ; You can also place multiple fields on the same line! Field Jumpheight Field visible End Type p1.player = New player ; Add player 1 to the list p2.player = New player ; Add player 2 to the list p1\X = player1_startX : p1\Y = player1_startY p2\X = player2_startX : p2\Y = player2_startYNote that like all variables, p1 and p2 (as per my example) are not global, therefore cannot be used in functions (it will return a Null value). If you want to be able to refer to it at any time, add Global to the declaration (ie. Global p1.player = New player). The items in a type list, however, are ALWAYS global. If you havent specified a global variable you can still get the information in the list by doing the following. upkey = KeyHit(200) For my.player = Each player If upkey my\Y = my\Y - 8 EndIf Next |