convert 1 enemy into 5 enemies?

Blitz3D Forums/Blitz3D Programming/convert 1 enemy into 5 enemies?

matthews_30(Posted 2006) [#1]
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.


n8r2k(Posted 2006) [#2]
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
next 
and 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
next
seems right, i dont really know, slapped it together in about 15 seconds with out testing it


jfk EO-11110(Posted 2006) [#3]
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.


matthews_30(Posted 2006) [#4]
to better understand Types, i am going to look for a types tutorial :P

thanks!


Shambler(Posted 2006) [#5]

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.


(tu) sinu(Posted 2006) [#6]
or name the type with a "T" prefix ie enemy.TEnemy


n8r2k(Posted 2006) [#7]
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


H&K(Posted 2006) [#8]
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.


n8r2k(Posted 2006) [#9]
is that bad?