'Custom delay'
Blitz3D Forums/Blitz3D Beginners Area/'Custom delay'
| ||
I'm making this small game where you are in control of a small 2d pixely world, where people need to grow and survive, in order to survive. What I'm asking is, it it possible to make an adjustable delay? If you don't know what I mean, here's some code from the game: .LIFEloop LIFE = LIFE + 1 Locate (0,0) Print "LIFE counter: "+LIFE+" Print "CO2: "+CO2+"%" Print "Oxygen: "+Oxygen+"%" Delay 10000 Cls Goto LIFEloop this is a part of my code which creates the 'LIFE', or 'humans' or 'living organisms' or whatever. As you can see, whenever 10 seconds pass, a new LIFE (human) is born. But when, let's say... 5 humans are born, I want it so that the population increases faster when a certain amount of humans are alive. Eventually, the population will reach a point where some will die, and then more will appear, so that the population stays at around certain number. If your following along, great job :P But the part I'm stuck on is the 'adjustable delay'. I want it so that whenever a certain amount of humans are alive, the delay is lowered, causing more humans to be born in a shorter amount of time. Is that even possible? If so, an example would be great. |
| ||
The time it takes to create one more organism decreases depending on the count of organisms able to reproduceGraphics(640,480,32,2) OrganismsCount% = 0 Repeat OrganismsCount = OrganismsCount + 1 ClsColor(000,000,000) Cls() Locate (0,0) Color(255,255,255) Print("OrganismsCount = "+OrganismsCount) Delay(10000.0/OrganismsCount) Until(OrganismsCount => 10000) WaitKey() End() If you want to see how the population increases/decreases depending on others factors (birthtime, necessary growthtime to become an adult able to reproduce, reproduction time, repairtime, deathtime), you want to store the properties of each organism in a list and update the population depending on the state of each organism... To store the properties of each organism, you can use a list : with arrays : OrganismsCount% Dim OrganismProperty1(1000) Dim OrganismProperty2(1000) Dim OrganismProperty3(1000) with types : Type Organism Field Property1 Field Property2 Field Property3 End type |
| ||
Ok, thanks for the reply. The first piece of code really helped. But I'm not that confident on data, arrays and types, so could you explain the code you gave to me? Also, is it possible to make each organism die at a random age when they are fully grown and nearing their death? A piece of text showing the 'average death' counter would also be really good. Also, is it possible to shorten the life span of the organisms depending on how much co2 is in the air/how little oxygen? It would be a great help for me if you were to make some code on these things, but it would be awesome if you could explain the code that I need to add, and I could then add my own code to my game, because as a beginner, I'd rather make my own code instead of copy/paste someone else's. I know I'm asking heaps, just do what you know :) thanks. |
| ||
Also, is it possible to make each organism die at a random age when they are fully grown and nearing their death? Yes Also, is it possible to shorten the life span of the organisms depending on how much co2 is in the air/how little oxygen? Yes an array list or a "type list" allows you to create/store instances of a thing which have the same properties/subthings but not the same values. with this you can create hundreds or thousands or millions of humans with random properties/subthings, and then you can search in the list and read/write/modify each instance in the list. then you can update your population by updating the environment and each human. For examples on how to use an array list or a type list, read the doc, search in the forum and in the codes archives, there are many examples of that. http://www.blitzbasic.com/b3ddocs/command.php?name=Dim&ref=2d_a-z http://www.blitzbasic.com/b3ddocs/command.php?name=Type&ref=2d_a-z |
| ||
One more thing, instead of using Delay(), i suggest to use Millisecs(). Millisecs() can give you a millisecond value that you can store for the different times you need. |
| ||
Also, when you did this: Delay(10000.0/OrganismsCount) Until(OrganismsCount => 10000) what does the arrow and the greater sign together mean? And how are you decreasing the delay? Are you making it shorter by the amount of organisms? Also, what was the purpose of changing the colour from black to white and so on? |
| ||
what does the arrow and the greater sign together mean? to prevent errors in others languages, i should have written >= > means superior to < means inferior to = means equal to >= means superior or equal to <= means inferior or equal to And how are you decreasing the delay? Are you making it shorter by the amount of organisms? Yes what was the purpose of changing the colour from black to white and so on? notice the first function is clscolor() the second function is color() read the doc : http://www.blitzbasic.com/b3ddocs/command.php?name=ClsColor http://www.blitzbasic.com/b3ddocs/command.php?name=Cls http://www.blitzbasic.com/b3ddocs/command.php?name=Color |
| ||
I know how colour commands work, but what was the point of using them? |
| ||
If the commands are not used elsewhere in the code, by default the clscolor seems to be 0,0,0 and by default the color seems to be 255,255,255 so you don't need to use them in this case. This was just an example... |
| ||
Another question: Whenever the numbers are being added faster, the text flickers. Is there a way I can fix this? |
| ||
Maybe try to replace Print() by Text() and Flip() |
| ||
replacing print with text and adding flip doesn't work. Any other suggestions? |
| ||
replacing print with text and adding flip doesn't work. On my computer, it works... |
| ||
Thanks, I replaced everything and it works. Thanks for all your help! But I have yet another problem. I want it so that when you hold 'e', the text on the screen goes away, and 'advanced stats' comes up, like the percentages of all the resources in the world, etc. I tried that using If KeyHit(18) Then cls but for some readon it won't work. Where do I put it so that it works? thanks again. |
| ||
And is there a way to independently fill a pixel on the screen with a certain colour? It would be helpful to make the terrain. Thanks. |
| ||
Yes, see the description of these functions: Keydown() Plot() |
| ||
Is there a way to plot multiple pixels using one command? It would take a lot of time to do it individually. |
| ||
See : Line() Rect() Oval() |
| ||
I'm using oval() with this code, but for some reason it won't draw it to my screen SetBuffer BackBuffer() humans = 0 oxygen = 21 co2$ = "200 ppm" Type human Field health Field death End Type Repeat humans = humans + 1 Cls Locate (0,0) Print "Humans Alive = "+humans Print "Co2 = "+co2 Print "Oxygen = "+oxygen+"%" Flip Delay 10000/humans Color 255,255,255 Oval 320,240,100,50,1 Until humans => 10000 End I'm pretty sure I put everything the correct order, but obviously I didn't. Also, the flickering of the text is coming back again. But not so often that it's annoying the crap out of me like before. Any suggestions? |
| ||
take the flip out and put in front of oval commands(between oval and until Humans=>10000 and it should draw the screen :) |
| ||
I am not sure if some functions set the buffer to backbuffer() each time they are used, but if not, in theory you should have a structure like this :repeat setbuffer(backbuffer()) clearscreen() render3d() draw2d() flip() until(condition) |
| ||
the oval draws only when the loop restarts. How can I make it so that It permanently stays on the screen, and the humans loop go on at the same time? Also, I'me imported an image onto the screen here: ;Graphics Graphics 640,480,32,2 SetBuffer BackBuffer() ;Variables humans = 0 terrain = LoadImage("life_terrain.png") tree = LoadImage("life_tree.png") ;Types Type human Field health Field death End Type ;Errors ;Main loop While Not KeyDown(1) DrawImage terrain,300,300 Wend ;Humans loop Repeat SetBuffer BackBuffer() Cls humans = humans + 1 Text 0,0, "Humans Alive = "+humans Delay 10000/humans Flip Until humans = 10000 ;End of program End It gives a white box at the bottom right of the screen. Why? |
| ||
I'm not sure you fully understand how the basics of a game programming loop works yet. Have you had a look through any of the tutorials and reference material that comes with your blitz help files? They are a good place to start as they take you through some of the basic steps. I could simply point out the mistake in your code, but I don't feel that it will help long term. I'd suggest playing around with the sample code that comes with blitz and the help files - the examples. You will learn a lot from them. |