Spawning enemies help. No idea what is wrong.
Author |
Message |
iRobsta
|
Posted: Tue May 18, 2010 9:29 pm Post subject: Spawning enemies help. No idea what is wrong. |
|
|
What is it you are trying to achieve?
I am trying to get enemies to spawn at the same time. So have my 'goomba' enemy flying around multiple places on the on screen.
What is the problem you are having?
I can't get the same enemy to spawn in a different location considering my variables.
Describe what you have tried to solve this problem
I have read tutorials but I couldn't find any that helped. . I have played around with the procedures, made new ones and such. Nothing worked. I don't know were to start.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Here it is:
Turing: |
% quick test to see if i can get the simple movment working. I failed D:!
import GUI %speaks for it's self
View.Set ("graphics:600,600,noecho,nobuttonbar,offscreenonly")
var koopa : int := Pic.FileNew ("koopa.jpg") % my enemy
var koopam : int := Pic.Mirror (koopa ) % my enemy mirrored
var rY := Rand.Int (100, 600) % random y variable
var rX := Rand.Int (2, 600) % random x variable
var rX2 := Rand.Int (2, 600) % second random x variable
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Procedure's %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
proc Koopas
var rY := Rand.Int (100, 600) % random y variable
var rX := Rand.Int (2, 600) % random x variable
var rX2 := Rand.Int (2, 600) % second random x variable
var temp : int % temp variable
if rX > rX2 then % makes sure smaller number goes forst
temp := rX % if the second is bigger then temp becomes the bigger
rX := rX2 % makes the second number the bigger number
rX2 := temp % makes the smaller number the new bigger number
end if
loop %Loops the momvent
for x : rX .. rX2 % the area
Pic.Draw (koopam, x, rY, picMerge) %draws the first movment going right
View.Update % update
delay (10) % delay
cls % close. blah blah blah
end for % exit's the movment to the right
for decreasing x : rX2 .. rX % movment to the left, same distance but backwords
Pic.Draw (koopa, x, rY, picMerge) % draws moving to the left
View.Update % look up 4 lines.
delay (10)
%Time.DelaySinceLast(5)
cls
end for
end loop
end Koopas % finish
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Game %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Koopas % draw the first one
%koopas % draw the second one
%koopas % draw the third one
|
Please specify what version of Turing you are using
Turing 4.1.1
Description: |
here is the game With the picture. |
|
Download |
Filename: |
RealGame.rar |
Filesize: |
10.49 KB |
Downloaded: |
92 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
iRobsta
|
Posted: Tue May 18, 2010 10:20 pm Post subject: Re: Spawning enemies help. No idea what is wrong. |
|
|
Anyone? D??
|
|
|
|
|
|
DemonWasp
|
Posted: Tue May 18, 2010 11:29 pm Post subject: RE:Spawning enemies help. No idea what is wrong. |
|
|
Look at the game programming tutorials either in the Turing Tutorials section or the one linked in my signature. There is a basic structure for game programming that makes it vastly easier to design the game, think of how things work, and get a working game. The main loop of your program looks like this:
Turing: |
loop
update ALL object locations
clear screen
redraw ALL objects
View.Update()
end loop
|
|
|
|
|
|
|
iRobsta
|
Posted: Wed May 19, 2010 7:26 am Post subject: Re: Spawning enemies help. No idea what is wrong. |
|
|
Sorry DemonWasp, I don't understand what you are trying to say.
|
|
|
|
|
|
DemonWasp
|
Posted: Wed May 19, 2010 8:45 am Post subject: RE:Spawning enemies help. No idea what is wrong. |
|
|
I'm saying that what you have right now is this:
code: |
loop
update location of ONE enemy
clear screen
redraw ONE enemy
end loop
|
What you should be doing is the following:
1. Have a main loop for your game. This is the ONLY loop in the program that runs forever (until someone closes the game). No other loop is allowed to continue indefinitely. Each time we go around this loop, we will call that one "tick". Preferably, you would have about 50 to 100 ticks per second of real time.
2. You should have two basic methods for each thing in your game (note that things might be koopas, players, whatever other enemies you have, objects in the game world, etc): move and draw. Each of these methods does exactly what it says on the label: either it moves the object an appropriate amount, or it draws the object. Hint: with a bit of thought, you should be able to get away with ONE draw method that works on every object in your game.
3. The move method does the following: determines exactly where that object should be going and moves very slightly in that direction. Your koopas, for example, would move at a fixed pace in whatever direction they're currently moving (you would need to store this in a variable). A player would determine where it's supposed to go based on what keys are pressed (Input.KeyDown).
The above is the easiest, fastest way to get a working game program with multiple concurrent objects.
|
|
|
|
|
|
iRobsta
|
Posted: Wed May 19, 2010 1:07 pm Post subject: Re: Spawning enemies help. No idea what is wrong. |
|
|
Okay I understand what your saying in a way. I just don't get how I could incorpiarate that into my game. I think I should tell you what my game is.
This is a general idea of what I want my game engine to work like:
http://www.flamehaus.com/bbs/flash-winterbells-vt115270.html
Take those bells in that game, and replace them with my 'koopas', a character from mario. Replace the bunny with mario and a diffrent backround and such.
The big diffrence is, the bells in winterbells get smaller as the game goes. What I would like, is have my koopas move back in forth.
The reason i have a random x is so thay they don't always go back and forth the same distance and it was working.
What I need to get the exact same thing, witha diffrent y variable. No matter what I do it does not work. but i'm going to see if i can try your method. Thank you for your time. (:
|
|
|
|
|
|
DemonWasp
|
Posted: Wed May 19, 2010 5:46 pm Post subject: RE:Spawning enemies help. No idea what is wrong. |
|
|
If you want to track multiple bells / koopas, you are going to need storage for each of them. You could do something like:
Turing: |
var bell_x : array 1..num_bells of int
var bell_y : array 1..num_bells of int
|
in which case each bell should be drawn at ( bell_x(i), bell_y(i) )
OR...
Turing: |
type bell :
record
x, y : int
end record
var bells : array 1..num_bells of bell
|
in which case each bell would be at ( bells(i).x, bells(i).y ).
I prefer the second approach because it makes it easier to avoid using the wrong subscript (i), for example.
When each one moves, you would just keep a direction and speed (or just a speed that can be either positive or negative). You can also randomize maximum_x and minimum_x, for example:
Turing: |
type bell :
record
x, y, maximum_x, minimum_x, speed : int
end record
proc move_bell ( var b : bell )
% Move based on speed...
b.x += b.speed
% Check for boundaries
if ( b.x < b.minimum_x ) then
b.x := b.minimum_x
b.speed = -b.speed % reverse direction
elsif ( b.x > b.maximum_x ) then
% similar to above, fill in yourself...
end if
end move_bell
|
Note that this move code will allow them to continue moving back and forth indefinitely, always in the same horizontal region, always at the same height (y).
I'll leave it to you to figure out how to generate the x, y, minimum_x, maximum_x and speed variables. You already have some randomization that would be useful for minimum_x and maximum_x, and you may as well randomize between the two for the current x value; speed should be something relatively small. If you have 60 ticks per second and they move 5 pixels per tick, that's about 300 pixels / second (pretty fast).
|
|
|
|
|
|
iRobsta
|
Posted: Wed May 19, 2010 9:27 pm Post subject: Re: Spawning enemies help. No idea what is wrong. |
|
|
OH MAN! Thank you, so much. This is pretty much the help i needed. Thank a bunch (:
I shall fill in the rest and do what I need to do. You are a very good programmer I must say (:
Ah, you've saved so much time for me. I don't know how to thank you (:
Sorry, but quick question. Me and my friend were discussing how to do this all day, to be honest, even my teacher couldn't figure out how to help me. If I were to use colour collision, and have it so my main character hits brown (the koopas) or whatever, and it 'kills' the koopa, wouldn't i need each individual koopa as a variable?
My map is 600 by 3000 pixels. My main character jumps at about 70 pixies (vertical indeed) so each of my koopas would need to be a minimum of 70 pixels appart. If I hit one and kill it and they each were not given a individual variable/memory/record etc wouldn't that delete all my koopas?
or does the method you have suggest for me to follow have a loop hole around that?
I don't need you to give me more coding, you've already done a whole bunch. I would just like advice of how to go on ahead on my project.
Sorry ahead of time if you find this a very dumb question, it's just this program has been a bit stressful for me with a lot of bug i had to debug. But I still love doing it (:
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
TheGuardian001
|
Posted: Wed May 19, 2010 9:51 pm Post subject: Re: Spawning enemies help. No idea what is wrong. |
|
|
You should be using multiple variables. If you only have one variable (or one set of variables), then you can only ever have 1 enemy (or multiple exact copies of that one enemy, which will all do the same thing, such as moving. Or dying.)
Use an array of enemies, then you can use a for loop to go through each element of the array and move/kill each of them individually.
|
|
|
|
|
|
iRobsta
|
Posted: Wed May 19, 2010 10:50 pm Post subject: Re: Spawning enemies help. No idea what is wrong. |
|
|
Okay. I understand what you are saying, but what if I have 42 enemies at the screen at once? Is array the only way? or is there a short cut?
|
|
|
|
|
|
DemonWasp
|
Posted: Wed May 19, 2010 11:14 pm Post subject: RE:Spawning enemies help. No idea what is wrong. |
|
|
Arrays are the shortcut. The array syntax makes things very simple and easy to use compared to using multiple variables.
|
|
|
|
|
|
iRobsta
|
Posted: Wed May 19, 2010 11:28 pm Post subject: Re: Spawning enemies help. No idea what is wrong. |
|
|
Thanks alot everyone.
I think i've got enough general information (:
array = shortcut.
|
|
|
|
|
|
Monduman11
|
Posted: Sat May 22, 2010 7:35 pm Post subject: Re: Spawning enemies help. No idea what is wrong. |
|
|
and remember Rob, happy b day by the way lol, that its easier to make your koopas be relocated somewhere of screen once they are hit instead of having them be erased.
|
|
|
|
|
|
|
|