Posted: Thu Feb 09, 2012 7:19 pm Post subject: How do you get multiple enemies?
What is it you are trying to achieve?
I want to have multiple enemies when the score reaches 250 (So it's kind of like a difficulty)
Turing:
%Set the screen size setscreen("graphics:900;550,nobuttonbar,offscreenonly")
var chars :arraycharofboolean var enemy, player :array1.. 3ofint
enemy (1):=15
enemy (2):=15
enemy (3):=1
player (1):=450
player (2):=275
player (3):=1 var mx, my, b :int var shockwave :array1.. 4ofint
shockwave (3):=1
shockwave (4):=0 var space :int:=0 var count :int:=3 var health :int:=215 var Intro :int:=Pic.FileNew("Game-Intro.jpg") var Instructions :int:=Pic.FileNew("Game-Instructions.jpg") var Background :int:=Pic.FileNew("Game-Background.jpg") var Pause :int:=Pic.FileNew("Game-Pause.jpg") var End :int:=Pic.FileNew("Game-End.jpg") var font :int:=Font.New("DigifaceWide:46") var font1 :int:=Font.New("Ethnocentric:13") var score :int:=0 var s :string:="" var rectangle :int
%THE INTRO loop Pic.Draw(Intro, 0, 0, picMerge) mousewhere(mx, my, b) exitwhen mx > 288and mx < 634and my > 185and my < 234and b =1 View.Update endloop
%THE INSTRUCTIONS loop Pic.Draw(Instructions, 0, 0, picMerge) mousewhere(mx, my, b) exitwhen mx > 242and mx < 694and my > 104and my < 170and b =1 View.Update cls endloop
%THE GAME loop loop %Draw the Background for the game Pic.Draw(Background, 0, 0, picMerge)
Input.KeyDown(chars) %Player controls if chars ('a')and player (1) > 48then
player (1):= player (1) - 2 endif if chars ('d')and player (1) < 851then
player (1):= player (1) + 2 endif if chars ('w')and player (2) < 472then
player (2):= player (2) + 2 endif if chars ('s')and player (2) > 49then
player (2):= player (2) - 2 endif
% Attempt on enemy follow if player (1) > enemy (1)then
enemy (1):= enemy (1) + 1 endif if player (1) < enemy (1)then
enemy (1):= enemy (1) - 1 endif if player (2) > enemy (2)then
enemy (2):= enemy (2) + 1 endif if player (2) < enemy (2)then
enemy (2):= enemy (2) - 1 endif
%Shockwave if chars (' ')and count > 0and space =0then
shockwave (1):= player (1)
shockwave (2):= player (2)
shockwave (3):=1
shockwave (4):=1
count := count - 1
space :=1 endif ifnot chars (' ')then
space :=0 endif
%Restart the game if 'TRY AGAIN' is clicked if mx > 216and mx < 389and my > 183and my < 271and b =1then %Set the variables
enemy (1):=15
enemy (2):=15
enemy (3):=1
player (1):=450
player (2):=275
player (3):=1
count :=3
health :=215
score :=0 exit endif
%Close the game if 'EXIT' is clicked if mx > 522and mx < 692and my > 200and my < 257and b =1then Window.Close(defWinID) endif endloop endloop
Please specify what version of Turing you are using
Turing 1.4.1
Posted: Thu Feb 09, 2012 7:28 pm Post subject: RE:How do you get multiple enemies?
You would use flexible arrays I believe. Or just a regular array, but you keep track of the amount of enemies you have.
One thing I would change for sure is how you have youyr variables set up. The player, for instance, you have as player (1) = x and player (2) = y. Thats bad format; if someone was trying to figure out your code, it would be diffivult for someone to understand, especially if it becomes longer. If the reason you have this is to have less random variables, I would suggest looking into records:
Turing:
type shipSpecs : record
x, y :int endrecord
var player : shipSpecs
player.x :=50
player.y :=100
Aange10
Posted: Fri Feb 10, 2012 11:39 am Post subject: RE:How do you get multiple enemies?
Also, what is it you are having difficulty with?
mobin12
Posted: Fri Feb 10, 2012 4:16 pm Post subject: RE:How do you get multiple enemies?
i dont know how to make a lot of enemies spawn at a certain point.
I have never tried something like this before, it's very new for me.
Raknarg
Posted: Fri Feb 10, 2012 6:01 pm Post subject: RE:How do you get multiple enemies?
You can use an arrays to keep track of individual enemies.
For instance:
var enemyX, enemyY : array 1 .. 5 of int
var enemyLive : array 1 .. 5 of boolean
This is assuming there are 5 enemies. Enemy 1 would get the first element of all those arrays, enemy 2 would get element 2, etc.
You use the x and y to keep track of enemies. When you want to spawn an enemy, you set the x and y and set the Live variable to true. When they die, set that variable to false. Only draw them when they're live.
Thats the basic idea.
mobin12
Posted: Fri Feb 10, 2012 6:12 pm Post subject: RE:How do you get multiple enemies?
thanks very much i will try that
mobin12
Posted: Sat Feb 11, 2012 2:51 pm Post subject: Re: How do you get multiple enemies?
Alright i have tried that, but i ended up with a huge error: For the code of collision of the enemy
with the shockwave, player, and bullet. Does it have to be repeated for every single enemy.
Because if that's true then would i just copy and paste and change the numbers?
Raknarg
Posted: Sat Feb 11, 2012 4:20 pm Post subject: RE:How do you get multiple enemies?
What I would do is include a for loop for every object that needs to check for certain collisions.
For instance, when you calculate bullet conditions such as movement, you can calculate collisions as well. Lets say you had five bullets total and ten enemies:
Turing:
for i :1.. 5
calculate_bullet_stuff () for j :1.. 10 if bullet (i)and enemy (j) collide then
kill enemy (j)
kill bullet (i) endif endfor endfor
same thing goes for the shockwave. You would calulate everything for the shockwave, then you would check for collisions in the same loop.
If I got your question totally wrong, you should reword it.
Sponsor Sponsor
mobin12
Posted: Mon Feb 13, 2012 5:27 pm Post subject: Re: How do you get multiple enemies?
I found another way of doing it but i'm not sure if it is something one of you would do so...
Oh and it's actually pretty fun to play in my opinion.
Turing:
%Set the screen size setscreen("graphics:900;550,nobuttonbar,offscreenonly")
var chars :arraycharofboolean var player :array1.. 3ofint
player (1):=450
player (2):=275
player (3):=1 var enemy1, enemy2, enemy3 :array1.. 3ofint
enemy1 (1):=15
enemy1 (2):=15
enemy1 (3):=1
enemy2 (1):=15
enemy2 (2):=15
enemy2 (3):=1
enemy3 (1):=15
enemy3 (2):=15
enemy3 (3):=1 var mx, my, b :int var shockwave :array1.. 4ofint
shockwave (3):=1
shockwave (4):=0 var space :int:=0 var count :int:=3 var health :int:=215 var Intro :int:=Pic.FileNew("Game-Intro.jpg") var Instructions :int:=Pic.FileNew("Game-Instructions.jpg") var Background :int:=Pic.FileNew("Game-Background.jpg") var Pause :int:=Pic.FileNew("Game-Pause.jpg") var End :int:=Pic.FileNew("Game-End.jpg") var font :int:=Font.New("DigifaceWide:46") var font1 :int:=Font.New("Ethnocentric:13") var score :int:=0 var s :string:="" var rectangle :int
%THE INTRO loop Pic.Draw(Intro, 0, 0, picMerge) mousewhere(mx, my, b) exitwhen mx > 288and mx < 634and my > 185and my < 234and b =1 View.Update endloop
%THE INSTRUCTIONS loop Pic.Draw(Instructions, 0, 0, picMerge) mousewhere(mx, my, b) exitwhen mx > 242and mx < 694and my > 104and my < 170and b =1 View.Update cls endloop
%THE GAME loop loop %Draw the Background for the game Pic.Draw(Background, 0, 0, picMerge)
Input.KeyDown(chars) %Player controls if chars ('a')and player (1) > 48then
player (1):= player (1) - 2 endif if chars ('d')and player (1) < 851then
player (1):= player (1) + 2 endif if chars ('w')and player (2) < 472then
player (2):= player (2) + 2 endif if chars ('s')and player (2) > 49then
player (2):= player (2) - 2 endif
%Make the enemy follow the player's position %Enemy 1 if player (1) > enemy1 (1)then
enemy1 (1):= enemy1 (1) + 1 endif if player (1) < enemy1 (1)then
enemy1 (1):= enemy1 (1) - 1 endif if player (2) > enemy1 (2)then
enemy1 (2):= enemy1 (2) + 1 endif if player (2) < enemy1 (2)then
enemy1 (2):= enemy1 (2) - 1 endif %Enemy 2 if player (1) > enemy2 (1)then
enemy2 (1):= enemy2 (1) + 1 endif if player (1) < enemy2 (1)then
enemy2 (1):= enemy2 (1) - 1 endif if player (2) > enemy2 (2)then
enemy2 (2):= enemy2 (2) + 1 endif if player (2) < enemy2 (2)then
enemy2 (2):= enemy2 (2) - 1 endif %Enemy 3 if player (1) > enemy3 (1)then
enemy3 (1):= enemy3 (1) + 1 endif if player (1) < enemy3 (1)then
enemy3 (1):= enemy3 (1) - 1 endif if player (2) > enemy3 (2)then
enemy3 (2):= enemy3 (2) + 1 endif if player (2) < enemy3 (2)then
enemy3 (2):= enemy3 (2) - 1 endif
%Shockwave if chars (' ')and count > 0and space =0then
shockwave (1):= player (1)
shockwave (2):= player (2)
shockwave (3):=1
shockwave (4):=1
count := count - 1
space :=1 endif ifnot chars (' ')then
space :=0 endif
%Restart the game if 'TRY AGAIN' is clicked if mx > 216and mx < 389and my > 183and my < 271and b =1then %Set the variables %Enemy 1
enemy1 (1):=15
enemy1 (2):=15
enemy1 (3):=1 %Enemy 2
enemy2 (1):=15
enemy2 (2):=15
enemy2 (3):=1 %Enemy 3
enemy3 (1):=15
enemy3 (2):=15
enemy3 (3):=1 %Player
player (1):=450
player (2):=275
player (3):=1 %Shocwave count
count :=3 %Score
score :=0 %Health
health :=215 exit endif
%Close the game if 'EXIT' is clicked if mx > 522and mx < 692and my > 200and my < 257and b =1then Window.Close(defWinID) endif endloop endloop
mirhagk
Posted: Mon Feb 13, 2012 6:23 pm Post subject: RE:How do you get multiple enemies?
See this:
Turing:
%Make the enemy follow the player's position %Enemy 1 if player (1) > enemy1 (1)then
enemy1 (1):= enemy1 (1) + 1 endif if player (1) < enemy1 (1)then
enemy1 (1):= enemy1 (1) - 1 endif if player (2) > enemy1 (2)then
enemy1 (2):= enemy1 (2) + 1 endif if player (2) < enemy1 (2)then
enemy1 (2):= enemy1 (2) - 1 endif %Enemy 2 if player (1) > enemy2 (1)then
enemy2 (1):= enemy2 (1) + 1 endif if player (1) < enemy2 (1)then
enemy2 (1):= enemy2 (1) - 1 endif if player (2) > enemy2 (2)then
enemy2 (2):= enemy2 (2) + 1 endif if player (2) < enemy2 (2)then
enemy2 (2):= enemy2 (2) - 1 endif %Enemy 3 if player (1) > enemy3 (1)then
enemy3 (1):= enemy3 (1) + 1 endif if player (1) < enemy3 (1)then
enemy3 (1):= enemy3 (1) - 1 endif if player (2) > enemy3 (2)then
enemy3 (2):= enemy3 (2) + 1 endif if player (2) < enemy3 (2)then
enemy3 (2):= enemy3 (2) - 1 endif
Don't do that. For loops and arrays would turn this into like 4 lines.
Raknarg
Posted: Mon Feb 13, 2012 6:40 pm Post subject: RE:How do you get multiple enemies?
See, the problem is that you're using separate arrays for each enemy. At least if you are going to do that, you should save your time by putting them all in one array:
var enemy1 : array 1 .. 3 of int
var enemy2 : array 1 .. 3 of int
var enemy3 : array 1 .. 3 of int
can be shortened into
var enemy : arrat 1 .. 3, 1.. 3 of int
mobin12
Posted: Wed Feb 15, 2012 5:47 pm Post subject: RE:How do you get multiple enemies?
is anyone familiar with 'realstr'?
Raknarg
Posted: Thu Feb 16, 2012 11:33 am Post subject: RE:How do you get multiple enemies?
lol I tried figuring it out a while ago, but gave up.
mobin12
Posted: Thu Feb 16, 2012 3:52 pm Post subject: RE:How do you get multiple enemies?
what i dont understand is what you have to put after the comma.
in the help section it says something about width?...
Dreadnought
Posted: Thu Feb 16, 2012 4:16 pm Post subject: Re: How do you get multiple enemies?
realstr basically converts a real number to a string with at least the length (width) specified (the length is increased if the number is larger). You should perhaps know that real numbers (sometimes called floating point numbers) hold 16 digits along with an exponent (in scientific notation form [digits]e[exponent] where e is 10 to the power of exponent). The largest value for the exponent seems to be 309 (from my tests). Note that around 1e308 you might get infinity (yes Turing can sometimes return infinity).
It should be noted that realstr will round to 6 digits after the decimal point. If you want more you'll have to use frealstr or erealstr.
as an example:
Turing:
putrealstr(3.141593, 2)%-> "3.141593" (width was increased to 8) putrealstr(3.141593, 8)%-> "3.141593" (width of 8) putrealstr(3.14159265358, 12)%-> " 3.141593" (padded with 4 spaces to get a width of 12)
% With exponents we get a slightly longer string putrealstr(6.626069e-34, 2)% -> "6.626069e-34" (width was increased to 11) putrealstr(6.626069e-34, 11)% -> "6.626069e-34" (width of 11) putrealstr(6.62606957e-34, 12)% -> " 6.626069e-34" (padded with 1 space to get a width of 12)
Basically, the width controls the minimum length of the string that is created (it will be increased if the number contains more digits).
If you really want more control over the conversion I suggest looking into erealstr and frealstr.