Dark Bit Factory & Gravity
PROGRAMMING => Other languages => Yabasic => Topic started by: Clanky on April 04, 2007
-
Ok, I decided to make a new post, because I thought that this could be where I moan on about the progress of the program. I fixed the mini-map / location / perspective problem! Too easy!
The code is attatched. I think it's going pretty good. For the basis of the RTS, its' fairly under way!
Enjoy. I hope people like it!
-
SO I put your files in my flash memory USB then put on PS 2 and load yabasic in there. I will let u know if is work (but I already know you got the file working on your system)
Yep I am big fan of RST ;)
cheers
-
much easier to load the files in Jims emulator Hotshot theres a sticky topic on the Yabasic board you can download it there.
As for the minimap problem do you have the offset for one corner of the big map (relative to the screen) you can scale this value down and apply it to window that highlights the minimap (relative to the offset for the center of the minimap)
-
->Hotshot http://dbfinteractive.com/index.php?topic=758.0 (http://dbfinteractive.com/index.php?topic=758.0)
Jim
-
I think I have the mini-map sorted. It works on the emulator quite good. The perspective of the square in the map shows almost exactly (can't be too sure) where what you are scrolling over!
I applied the optimising technique Shockwave said, and I will now work on drawing the units... I want to see the little fellas so I get motivated to finish it!!!
@Hotshot: Any help and advise on making this RTS good would be great! I love RTS's too - just need to get my laptop and the Dawn of War / Dawn of War: Winter Assault Pack!!!
@Rain: I used window origin "cc" so that the starting position was the centre of the 1920x1536 map!
It uses three 640 screens and three 512 screens - effectively making a huge rectangle map area... (guess you already knew!) . The program scrolls the positions of all objects which are planted (or rather - suppose to be) on the screen (map). The positions of these objects is put onto the mini-map (as the origon is 0,0) and divided by 20 to get the relative positions correct.
You can only scroll through the terrain when your cursor reaches the boundries (-320, 320, -256 and 194)... I used 194 so that you scrolled when you reached the top of the task bar! Although you can go through the top of the map (an error which I think I may leave in... unless somone says it's not good)
@Jim: You said something about multiplying by 0.05... Just wondering what you were refering to? The units?
Well, hope everyone likes the start. I can hopefully get it done.
I only have 10 units of each, because the mini-map was way to over loaded when I had 100 of each... also, I need room for buildings and turrets / anti-air... if I get them in!
I think I might change the visuals of the units positions on the mini-map as dots if they aren't too small.
(wow, biiig post. sorry)
-
b = a / 20
b = a * 0.05
both give the same result (since 0.05 = 1/20), but the second one is far easier to compute. Division is generally (much) slower than multiplication in hardware. On the PS2 it can't even use the hardware division instruction so it does all the maths in software!
Jim
-
wow! Gee, that sped it up heaps!!! Thanks Jim.
-
I love RTS's its great to see one in the works for Yabasic :D
-
This is an interesting project! I have tried to create a turn-based strategy game myself, but didn't really see how to make AI work so I gave up.
Could you tell us more on what features you plan to add?
-
is that you toni? if it is then great to see your still around!
-
For this code, I am hoping for real-time battles, build and movement. I attempted a 640x512 turn-based before... but I wasn't motivated enough so I stopped.
The features I can hopefully put in:
AI - I have a friend who knows some programming... I can ask for help from him, and from you guys too.
There are only three units (soldiers, tanks and jets) but when you build you can build turrets and anti-air.
I have a fair idea on how to make resources (radomise the positions - easy!), so I might just do that... the resources being: gold for money and ore for materials.
Umm... other features? I don't know at the moment. Any suggestions (which are possible for yabasic) will be fantastic!!!
I will make it so that when a unit is destroyed, their STATUS turns OFF and their co-ordinates become off the screen and unselectable.
If anyone thinks there is a better way, then I will be open for suggestions!
@Shockie: If I have it so that all mini-map units (for one player) are the same colour, would it be a better option to put the mini-map unit FOR LOOP as one? Because I have eliminated changing colours between drawing a different unit??? Or should I still have them seperate because they are using different co-ordinates?
I have changed the mini-map position. Annoying that it was in the middle? Unless someone thinks it should stay in the middle? I am going to put a nice decal around it... haha!
-
It would certainly complicate things, especially AI, but have you thought of terrain? Say, you could add mountains or seas to restrict the movement of land units.
Nino: thanks, I am the very same toni from the old forums. Been visiting this forum rarely nowadays.
-
rivers and seas would definately make navigation AI a nightmare but maybe forrests/deserts would suffice for scenery you could simplify them as different coloured terrain tyles something along the lines of this but shaded -
____ ____
/ \__/ \
| _ |
\__/ \ ______ \
\__/
How about counting they total units killed compare it to the total that were alive and give a rating in percentage for performance
-
Yea I thought about the terrain. As rain said - it might be a bit difficult for the AI to get around unpassable terrain. I might make the terrain - may be hard... as it will have to span over a large area (for tiling)
I'll add the percentage feature! Sounds good. Maybe if you press SEL you can bring up statistics - Power, Percentage, Units, Kills, Score... etc. Might do that.
I also thought about Researching Exports to allow further income?
I might also make it so that you can only build one sort of unit construction building, instead of having air-ports academy's and stuff... but you have to invest and research the technologies. I guess the reasoning for this is that it's less things for yabasic to mess around with. But, if you guys think that having seperate buildings would make the game 'more fun' then, I guess I can put it in.
I also thought of having mints (or banks) and mines to produce more income and materials instead of collecting them all the time... easy?
-
Ok, I have tried doing the selection. But it seems that I don't know hoiw to keep the sel_x(1) and sel_y(1) co-ordinates stay at their first position?
I've tried:
'GET CO-ORDINATES
if sel = 1 then
sel_sel = sel_sel + 1
if sel_sel >= 5 then
if select = 0 select = 1
if select = 2 select = 0
sel = 0
sel_sel = 0
fi
fi
'DRAW SELECTION SQUARE
if select = 1 then
sel_x(1) = per_x
sel_y(1) = per_y
select = 2
elsif select = 2 then
setrgb 1, 0, 35, 40
fill rect sel_x(1), sel_y(1), per_x, per_y
setrgb 1, 120, 180, 250
rect sel_x(1), sel_y(1), per_x, per_y
fi
I thought that this would make the sel_x(1) and sel_y(1) co-ordinates stay where they were first made available?
I've attatched the updated code... not much done... but I have done some stuff.
--EDIT--
I have drawn the unit graphics.
One thing I am having trouble with is that I will need to rotate the graphics for their movement! Umm... serious problems lol. I tried to copy the way I did it in Pool, but it didn't rotate them.
Any help for this problem will be much appreciated!
Also, for future reference - when I code the "Unit To Here" bit, I will probably need some help to make it so that they move to the position where you select - rotating approporately in the drection from where they are to where they are going.
-
I will see about rolling up a subroutine that accepts the origin x,y and the destination x,y
the subroutine would ouput values in variables that you can make use of. Now which would you find more useful for the output a pair of angles or pairs of cos/sin? reason for pairing the output is that you need two angles one relative to direction of travel the other at right angles.
-
Alright here is the subroutine with an example of using the return values the routine can be called as follows - getang(posx,posy, tarx,tary)
the angles returned are in radians within the range of 0 - 2*pi
angy - direction of travel and it is linked to cosy,siny (cos is horizontal, sin is vertical)
angx - right angles and it is linked to cosx,sinx
Here it is
// This version returns two angles as well as the cos/sin for each
// angy is the actual direction and corrisponds to y axis for drawing
// angx is at right angles and corrisponds to x axis for drawing
// cosx is the cosine of angx
// sinx is the sine of angx
// cosy is the cosine of angy
// siny is the sine of angy
sub getang(x1,y1,x2,y2)
angx = atan(x2-x1,y2-y1)
angy = angx - pi/2
if (angx < 0) angx = angx + 2*pi
if (angy < 0) angy = angy + 2*pi
cosx = cos(-angx)
sinx = sin(-angx)
cosy = cos(-angy)
siny = sin(-angy)
end sub
And this is an example of how to use it
sub getang(x1,y1,x2,y2)
angx = atan(x2-x1,y2-y1)
angy = angx - pi/2
if (angx < 0) angx = angx + 2*pi
if (angy < 0) angy = angy + 2*pi
cosx = cos(-angx)
sinx = sin(-angx)
cosy = cos(-angy)
siny = sin(-angy)
end sub
open window 640,512
posx = 320
posy = 256
desx = 640
desy = 256
repeat
setdispbuf draw
draw = 1 - draw
setdrawbuf draw
clear window
desx = desx + and(peek("port1"),32)/32 - and(peek("port1"),128)/128
desy = desy + and(peek("port1"),64)/64 - and(peek("port1"),16)/16
line posx,posy to desx,desy
getang(posx,posy,desx,desy)
text 20,20,"Angle Y - " + str$(angy/pi*180) // x/pi*180 convert radians to degrees
text 20,40,"Angle X - " + str$(angx/pi*180) // x/pi*180 convert radians to degrees
// example of drawing something using the output values
cy = desx
sy = desy
for y = 0 to 32
cx = cy
sx = sy
for x = 0 to 32
dot cx,sx
cx = cx + cosx
sx = sx + sinx
next
cy = cy + cosy
sy = sy + siny
next
until (0=1)
-
Thanks rain!
So I use this for when I want to make the units go to a specific place? Nice!
If I get stuck with the implementation I'll ask lol.
-
Ok, I think I got the selection square done!!!
It works, but I'm not sure if it keeps the values properly? I am using sel_x(1):sel_y(1):sel_x(2):sel_y(2) and I am wondering whether, since they are arrays, if they keep their values after they have stopped being used? I did a check, by having text display their value, and they didn't appear until 'selection' was set above 1?
Should I just use sel_x1:sel_y1:sel_x2:sel_y2??? I normally do that, but it seems neater with the ()... not sure if that's bad programming - but I assume it is?
The way I fixed it was to have a selection scroll value... haha! Too easy!
Ohh - to use the selection square - press X and scroll around the screen... think I didn't say that before!
The way I am going to implement the selection is:
sel_x(1) >= sel_x(2)
sel_y(1) >= sel_y(2)
______sel_x(1), sel_y(2)
| x |
| |
|____x
sel_x(2), sel_y(1)
where the X represents a unit,
then you would say, IF:
unit_x >= sel_x(2) / unit_x <= sel_x(1)
unit_y >= sel_y(2) / unit_y <= sel_y(1)
the opposite method for:
sel_x(2) >= sel_x(1)
sel_y(2) >= sel_y(1)
I know what this means... I'm pretty sure some of you might have trouble understanding... the explaination is very brief and shotty!!! I will try and explain it when I get it working with the units?
-
Ok, here's the latest code. I noticed with the selection square, when I was just mucking around, that if you scroll away from the centre of the map, and make the screen scroll and then press X - it stuffs up and goes to a wierd location!!!
I've been trying to fix it, but I am unable to know why its doing it.
But... hope you enjoy the newest code.
--EDIT--
Fixed the Selection Square bit... ahh! Much better.
Attatched new code... deleted old.
Posted on: April 10, 2007, 02:09:16 PM
Ok, here's the newest code.
-> You can now select units... But not do anything atm.
-> The selection counts how any units have been selected. Nice touch!
-> I am going to change the Attack cursor and the Stop cursor. They look funny!
There is a problem with the selection visual - where it shows on the mini-map which units you have selected. Insteas of just the units you have selected, it picks funny ones... but some times it is properly visualised - the units you have selected are the only white ones on the mini-map.
Also, I think I will have to re-service the scrolling bit. It seems that it goes to far to the right. Doing that now.
Cheers. And I think I'll start with the unit movement next. I know I will need help with that! Looking at rain_storms example helped... but I still don't get it enough to do it without help.
--EDIT--
Press R1 (CAPS) to change menu right
Press L1 (Crtl) to change menu left
*NB// Must select a unit first*
Press X (Delete) to get selection tool
--When selecting, scroll around map - this increases/decreases the size of the selection square.
-Click the Double Post thing... and it merged the two! So, I deleted the older code.
-
coming along nicely the scrolling screen seems to be a nice choice even though it is more challenging to pull off
-
I dont know if this can be useful in any way but years ago I coded this up on the PS2 it runs at good speed on the old black box and is a fairly large terrain with trees and hills if you are interested in using this I can clean it up a whole lot and make it even faster with more trees etc. also I can understand if you aren't interested its probably not a large enough terrain for your RTS and the black background / end of the terrain makes it seem even smaller but fell free to use it if you like.
-
Thnaks, I'll see what it's like!
-
Thanks awesome!!!
:updance:
Truely amazing! Hmm... yea - bummer it only uses the one screen.
Just a thought - if I implement it - would it make the RTS really slow? like - mega slow down?
We'll see about it. If it can be made into a larger size - then it would be a great addition if it was to be put in!
K+
-
its gonna be slower then 2D you could reduce it to 16x16 but that would mean the map would be too small for a RTS but there is one trick that can speed it up that I learned much later than I coded this. This will be a top down game so you can rotate the terrain just once and store the coordinates then to move about the map all you have to do is add an offset for x & y (leave z alone) then apply perspective to the new co-ordinates and you have a 3D speeded up terrain this trick only works as long as the angles of rotation are fixed. moving the terrain like this is called translation. this may double the speed of the terrain but for large maps it will still be slow especially with the number of units moving around at once
-
Well, I think that I won't have the Options (Attack, Move, Stop)... I will just have it so that when you select a unit, it automatically has the Move function (press X and they move to that spot, press TRI and it de-selects)
If you want to attack you will have to scroll over the enemy and the attack cursor will appear (press X and you set the unit to attacking that enemy)
If you want to stop, select the unit and press CIRCLE.
I guess this will make it easier... (alot more like a real RTS).
I've mad a large map (press START to view, SEL to exit)
I'm wondering how I will be able to make AI!!! ??? kinda scarey thinking about it!
I don't want it so that you can pawn them all the time. That you will actually need to think a little before you build your units and just trounce the oppo!!!
hmmm... Well, I'll consintrate on getting the options done, then the movement. Then I'll think about the firing of your units!!!
... not sure how deep and fast flowing that river will be... but when it's done, I'll get cracking on some basic AI.
-
For AI think about state machines. Each 'thing' in your world has a state (or set of states) - what that thing is currently being or doing. When one thing interacts with another thing it will change one or more states of each thing.
A simple one might be a player paying a non-player character (npc or AI) for some information. cash for player goes down, cash for npc goes up, and player has information.
A more complicated one might be a npc on a quest - when he meets the thing he's questing for, they might compare states (good, evil, strength, army size) and then decide to make friends or have a battle. As players move through the landscape their state might change from 'go to land of other player' to 'go to city of other player' once they're inside the bounds of the land. Also, rand() is a VERY good piece of AI, it'll persuade most people.
Try to draw out the states for each thing on a piece of paper. How many things can each thing in your world do? How does it go from doing or being one thing to another thing? Writing it down will help you understand better what you're trying to do and to avoid deadlocks (cycles or stuck states where the thing can't stop doing what it's doing).
Jim
-
Nice. I'll see what I can get up too!
-
For the AI, is something like:
--
Statments and Commands
--
000 - OFF
:: No Signal, specifys that unit is dead.
001 - ON
:: Signal, specifys that unit is alive.
Specifys that the unit is on stand-by.
>> No movement, and no attacking.
002 - MOVE
:: Specifys that the unit is randomly moving.
>> Random movement.
003 - FIND
:: Specifys that the unit is searching for a unit to attack.
>> Normally finds closest if;
01: Number of units is proximity of other unit is low (~3)
02: Units health is higher than 75%
03: Other units health is lower than 85%
>> Errors;
01: If other unit is a jet, than a soldier will not seek
004 - CALL
:: Specifys that the unit is in trouble and needs assistance.
>> Normally because the units health is low.
01: Will call if the enemys health is low, and if no more than
3 enemy units are included in, or surrounding the battle
>> Errors;
01: A soldier will not be called
005 - RETREAT
:: Specifys that the unit is not capable of defeting the enemy, and will
try and evade all other attacks and return to base.
>> Retreat will occur when;
01: Units health is lower than 15%
02: Enemys health is higher than 70%
03: Enemy units in proximity is more than 2
That good for a basic start?
Attatched is the working demo of the states... not finished.
-
Here is a really good way to control the flow of the ai so that the correct actions are taken and only the correct actions are considered
// (must start with one not zero so correct this now)
jumppoint = ai_state + 1
// on goto will allow you to jump to different positions in the code which label the code will jump to
// is dependent on the value of the variable used to call on goto
on jumppoint goto dead, stand_by, random_movement, search_for_enemy, call_for_help, retreat
label dead
// dead routine
label stand_by
// stand by routine
label random_movement
// random movement routine
label search_for_enemy
// search for enemy routine
label call_for_help
// call for help routine
label retreat
// retreat routnine
the on goto command will prove invaluable in an ai routine those labels that are in the list can be laid out any way you want and given any functionality desired but can be optimised for dealing with a certain set of conditions in this case the current state of a particular unit. "on goto" can also be called as "on gosub" but on gosub cannot be used within a subroutine due to the fact that return will break out of the subroutine instead of returning to the calling point. There is another advantage in using on goto it helps to make your code more modular each label can be cut out and replaced without effecting the functionality of the other labels
-
That good for a basic start?
Yes, that's exactly the kind of thing you need to do.
Jim
-
Forgot to say thats really compact code for getting the units to move to destinations less than 100 lines of code thats real nice +K
-
Thanks :D
The random movement will be different... I wont use Up, Down, Left Right... but have angles so it looks sommother. Not sure whether or not this will make the code longer - or slower. But I'll see where it goes.
I still need to do the code for call and retreats, but it's all basically there.
I will also make it so that the FINDING unit will stop within a range around the enemy unit, attack until either the enemies death or retreat / call is satisfied - instead of having it so it's random selection and changes when ever.
Got class - so an update probably around 8.00 - 9.00 (my time)
--
EDIT
--
Cant do much more tonight - have to do other things. I added the range function.. and have made health for them. I am now working on the RETREAT and CALL commands.