convert 1 enemy into 5 enemies?
Blitz3D Forums/Blitz3D Programming/convert 1 enemy into 5 enemies?
| ||
i now this is a newbie question but i would like for you to help me please. i my rpg test everything os working as planned, now the second phase for me is to multiply the enemies that walks in the map. i know i have to convert my code from "1 enemy" to several enemies. i know i have to use types and this is my problem i dont understand them very good. acctually i have the following code for the enemy: Global imgEnemyV=LoadImage("walking.PNG") EnemyX=rand(0,640) EnemyY=rand(0,480) EnemySpd#=0.5 then to use this enemy i do a move the enemy and then draws it: drawimage imgEnemyV,EnemyX,EnemyY can somebody tell me how to covert this into a 'type' model to create 5 or more enemies? maybe it can be something like: type enemy x=rand(0,640) y=rand(0,480) spd#=0.5 but how to create more enemies in one shoot for the level? thanks a lot. matt. |
| ||
type enemy field x,y field speed# endtype for x = 1 to 5 enemy.enemy = new enemy enemy\x = rand(0,640) enemy\y = rand(0,480) enemy\speed# = 0.5 nextand then to move/edit/draw enemies use something like this in main loop: for enemy.enemy = each enemy enemy\x = enemy\x + (rand(-1,0) + enemy\speed#) enemy\y = enemy\y + (rand(-1,0) + enemy\speed#) drawimage enemyimg,enemy\x,enemy\y,0 nextseems right, i dont really know, slapped it together in about 15 seconds with out testing it |
| ||
Well, using terms like "enemy.enemy" is truely confusing IMHO. So when you don't understand types, you won't know what part is the instance and what's the type id. |
| ||
to better understand Types, i am going to look for a types tutorial :P thanks! |
| ||
Well, using terms like "enemy.enemy" is truely confusing IMHO. So when you don't understand types, you won't know what part is the instance and what's the type id. I always append the word 'Type' to the type definition to make things a little clearer so enemy becomes enemytype, player becomes playertype etc. |
| ||
or name the type with a "T" prefix ie enemy.TEnemy |
| ||
whats an 'instance', JFK? i dont fully understand types. Maybe i should learn somemore about them. I always avoided them until my latest project, which needs them |
| ||
The base Type, ie Type Person field age end type Is often called the definition of Person. Global eric:Person = new Person Here we have created a person (or an Instance of Person) So in your case we say definition of enemy to mean the type itself. And then each actual enemy is an instance of enemy. What the main advice you have been given is, the code you have already done is for the Type, then you create 5 instances of that type. |
| ||
is that bad? |