3 Different Sprites on Screen using Type?

Blitz3D Forums/Blitz3D Beginners Area/3 Different Sprites on Screen using Type?

Hotshot2005(Posted 2009) [#1]
I am trying to create 3 Different Enemys on screen at the same time by using Type but I am suck at it for some reason.


Pongo(Posted 2009) [#2]
here is a simple example. I'll expand on this in a bit and add more comments. It would also help if your question was a bit more specific,... types can be a large topic.

I've also used types within types in this example to show how that can be done.




A few notes:
This has been written for easy reading, not efficiency. For example, if you bump up the enemy count, things will slow down quickly. This is because of the slow Oval command I am using to draw them. Changing them to a regular bitmap will speed things up tremendously.


_PJ_(Posted 2009) [#3]
How about you post something of your code, Hotshot, so we can see where the problems are?


WERDNA(Posted 2009) [#4]
Here is my favoriote way to set up enemy types.
I just create ONE type, called Enemy, and using its Typ field, I can
make it act in different ways.


This is basically an easy way to make a single Type, act like several.
Instead of creating a seperate Type for each and every enemy, which
can get annoying especially if each and every one of them has its own
seperate For Loop, I simply create ONE Type, and ONE For Loop to
control them all, and depending on their Typ Value, They will act
differently.
In the section where it checks their Typ value and then colors them
accordingly, you could put in code to make them move differently
depending on their typ, to make them attack differently, basically
whatever you wanted.

Hope this helps you out,

WERDNA


Hotshot2005(Posted 2009) [#5]
it is interesting to learn from type from pongo and Werdna.

If I going to used 3 different enemys sprites or images, would be better if I did this than using dim arrays?

Type Enemys
     field images[3] ; 3 different enemys images or sprites]
     field X,Y
     field Health
     field Hit
end type


how i used images arrays when using types to show 3 different enemys on the screen?


_PJ_(Posted 2009) [#6]
The whole purpose of using Custom Types is that you can create many instances of the same type, so if I am understanding what you want correctly, then you shouldn't need any form of array.

Just create a new instance for each enemy:

Type Enemies
Field Image
Field X,Y
Field Health
Field Hit

Enemy_1.Enemies = New Enemies
Enemy_1\Image=LoadImage("Enemy1.bmp")

Enemy_2.Enemies = New Enemies
Enemy_2\Image=LoadImage("Enemy2.bmp")

Enemy_3.Enemies = New Enemies
Enemy_3\Image=LoadImage("Enemy3.bmp")



Hotshot2005(Posted 2009) [#7]
ahhh right....that is much better than I thought.

what happen if I have images of punch and kick for each enemys?

would I do this

Type Enemies
     field images
     field X,Y
     field Walk  ???
     field Punch
     field Kick
     field Health
     field hit
end type

Enemy_1.Enemies = New Enemies
; For enemies standing still
Enemy_1\Image=LoadImage("Enemy1.bmp")
; for enemies to walk
Enemy_1\Image\walk=LoadImage("Enemy1.bmp")
; for enemies punch
Enemy_1\Image\punch=LoadImage("Enemy1.bmp")
; for enemies kick
Enemy_1\Image\kick=LoadImage("Enemy1.bmp")


Do you think it would be better if i did that above?


_PJ_(Posted 2009) [#8]
Well, if the images are separate and not frames of animation, then yes, you were nearly there. Remember the filename must be accurate to the right image file.
You can assign the handle of the images to any field of your type.

Type Enemies
     field images
     field X,Y
     field Walk  ???
     field Punch
     field Kick
     field Health
     field hit
end type

Enemy_1.Enemies = New Enemies
; For enemies standing still
Enemy_1\Image=LoadImage("Enemy1.bmp")
; for enemies to walk
Enemy_1\walk=LoadImage("Enemy1walk.bmp")
; for enemies punch
Enemy_1\punch=LoadImage("Enemy1punch.bmp")
; for enemies kick
Enemy_1\kick=LoadImage("Enemy1kick.bmp")



Have a good read up of Custom Types and try out the examples to get a feel of how they work.
http://www.blitzbasic.com/b3ddocs/command.php?name=Type&ref=2d_a-z


Hotshot2005(Posted 2009) [#9]
thank you very much malice and everyone too :)