This month author Steve Vink takes us on a spring cleaning tour and talks about Asset Management. This is a shorter version of the tutorial, the full length verison can be downloaded - details at the end.

Last week, I cleared out the wardrobe and threw out some old clothes. Checking the pockets of a jacket I haven't worn for three years, I found a ten pound note (18.7 USD, 14.6 EUR). I don't know when I put there; I don't know why I put it there. In fact, due to the lack of a wallet, I couldn't tell you what was in my pocket now, which pockets have cash in, or if I have any money at all. Thankfully, my program code is a great deal more organised. Everything has it's place, and I can find it in an instant.

Assets cover a multitude of "things". An asset could be a character, a place, a planet or a wallet. Assets have many characteristics, which you might define like so:

AlienName$ = "Vinste Hudke"
AlienLegs = 1
AlienArms = 3
...

Full feature in the newsletter:

http://www.thegamecreators.com/data/newsletter/newsletter_issue_28.html#9

Language: 
Dark Basic Pro
Code: 
remstart
 Asset Management example
 by Steve Vink
 
 This example illustrates how to manage game assets.
 It utilises Types, and Arrays.
 It demonstrates how assets based on the same Type can have 
 significantly different characteristics
 It also demonstrates how assets can be processed efficiently
 when managed in Arrays
remend 
 
` Firstly, describe the attributes of an alien in a TYPE.
` These are the attributes that will determine what you can build later...
	type tAlien
		name$ as string
		legs as integer
		arms as integer
		mass# as float
		strength# as float
		health# as float
	endtype

` Basic Setup
`******************************************************
	set display mode 800,600,16
	sync on: sync rate 20
` Set up some data for the text display...
	LeftColX = 10
	RightColX = 410
	VertSpace = 50
	
	load image "backdrop.jpg",1,1
	

` Next, create 2 arrays to hold 2 alien tribes...
`******************************************************
	Dim Gahulu(10) as tAlien
	Dim Fragnog(10) as tAlien


` In a loop, the Gahulus are assigned the characteristics of their race...
`******************************************************
	Randomize Timer()
	For n = 1 to 10
		Gahulu(n).name$ = "Gahulu " + str$(n)
		Gahulu(n).legs = 4
		Gahulu(n).arms = 2
		` Each Gahulu will have a different mass, strength and health.
		Gahulu(n).mass# = 120 + rnd(20)
		Gahulu(n).strength# = 120 + rnd(60)
		Gahulu(n).health# = 120 - rnd(10)
	next	  n

` In a loop, the Fragnogs are assigned the characteristics of their race...
` They are very different to Gahulus, but can be described in terms of
` the same attributes...
`******************************************************
	For n = 1 to 10
		Fragnog(n).name$ = "Fragnog " + str$(n)
		Fragnog(n).legs = 2
		Fragnog(n).arms = 3
		` Each Fragnog will have a different mass, strength and health.
		Fragnog(n).mass# = 60 + rnd(20)
		Fragnog(n).strength# = 50 + rnd(70)
		Fragnog(n).health# = 150 - rnd(30)
	next	  n

`******************************************************
`******************************************************
` Let the battle commence!
`******************************************************

	do

	`******************************************************
	
	` Pick a random alien from each tribe, and belt each other...
	`******************************************************
		do
			Alien1 = rnd(9) + 1
			Alien2 = rnd(9) + 1
			if Gahulu(Alien1).health# > 0 and Fragnog(alien2).health# > 0
				exit
			endif
		loop
		
		` Calculation based on strength, arms, and mass
		
		Alien2Hit# = (((Fragnog(alien2).mass# / 200.00) +  (Fragnog(alien2).strength# / 200.00)) * Fragnog(alien2).arms )
		Alien1Hit# = (((Gahulu(alien1).mass# / 200.00) +  (Gahulu(alien1).strength# / 200.00)) * Gahulu(alien1).arms )
		dec Gahulu(Alien1).health#, Alien2Hit# : if Gahulu(Alien1).health# < 0 then Gahulu(Alien1).health# = 0
		dec Fragnog(Alien2).health#, Alien1Hit# : if Fragnog(Alien2).health# < 0 then Fragnog(Alien2).health# = 0
	
	` Print the details to screen...
	`******************************************************
		cls
		paste image 1,1,1,0
		
		` Display each alien and current health.
		for n = 1 to 10
			ink rgb(150 - Gahulu(n).health#, (Gahulu(n).health# * 1.6),0),0
			text LeftColX, (VertSpace * (n-1) + 100), Gahulu(n).name$
			box leftColX, (VertSpace * (n-1) + 120), leftColX + (Gahulu(n).health# * 2), (VertSpace * (n-1) + 140)
			
			ink rgb(150 - Fragnog(n).health#, (Fragnog(n).health# * 1.6),0),0
			text RightColX, (VertSpace * (n-1) + 100), Fragnog(n).name$
			box RightColX, (VertSpace * (n-1) + 120), RightColX + (Fragnog(n).health# * 2), (VertSpace * (n-1) + 140)
		next n

		ink rgb(255,255,255),0	
		` Check if either side has been defeated...
		`******************************************************
		FragnogCount = 0
		GahuluCount = 0
	
		for n = 1 to 10
			if Fragnog(n).health# > 0 then inc FragnogCount
			if Gahulu(n).health# > 0 then inc GahuluCount
		next n
	
		if FragnogCount = 0
			center text 400,80, "***** Gahulus Win with " + str$(GahuluCount) + " Warriors still standing! *****"
			sync
			wait key
			end
		endif		
				
		if GahuluCount = 0
			center text 400,80, "***** Fragnogs Win with " + str$(FragnogCount) + " Warriors still standing! *****"
			sync
			wait key
			end
		endif		
			
		sync
		
	loop
 
0
No votes yet