Author Topic: RTS  (Read 15085 times)

0 Members and 1 Guest are viewing this topic.

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 340
  • Karma: 16
  • kiss that sound that pounds your senses
    • View Profile
RTS
« 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!
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Offline Hotshot

  • DBF Aficionado
  • ******
  • Posts: 2114
  • Karma: 91
    • View Profile
Re: RTS
« Reply #1 on: April 04, 2007 »
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

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: RTS
« Reply #2 on: April 04, 2007 »
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)

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: RTS
« Reply #3 on: April 04, 2007 »
Challenge Trophies Won:

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 340
  • Karma: 16
  • kiss that sound that pounds your senses
    • View Profile
Re: RTS
« Reply #4 on: April 05, 2007 »
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)
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: RTS
« Reply #5 on: April 05, 2007 »
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
Challenge Trophies Won:

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 340
  • Karma: 16
  • kiss that sound that pounds your senses
    • View Profile
Re: RTS
« Reply #6 on: April 05, 2007 »
wow! Gee, that sped it up heaps!!! Thanks Jim.
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: RTS
« Reply #7 on: April 05, 2007 »
I love RTS's its great to see one in the works for Yabasic :D

Challenge Trophies Won:

Offline tronkko

  • ZX 81
  • *
  • Posts: 13
  • Karma: 23
    • View Profile
    • Softagalleria.net
Re: RTS
« Reply #8 on: April 05, 2007 »
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?

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: RTS
« Reply #9 on: April 05, 2007 »
is that you toni? if it is then great to see your still around!
Challenge Trophies Won:

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 340
  • Karma: 16
  • kiss that sound that pounds your senses
    • View Profile
Re: RTS
« Reply #10 on: April 07, 2007 »
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!
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Offline tronkko

  • ZX 81
  • *
  • Posts: 13
  • Karma: 23
    • View Profile
    • Softagalleria.net
Re: RTS
« Reply #11 on: April 07, 2007 »
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.

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: RTS
« Reply #12 on: April 07, 2007 »
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

Challenge Trophies Won:

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 340
  • Karma: 16
  • kiss that sound that pounds your senses
    • View Profile
Re: RTS
« Reply #13 on: April 08, 2007 »
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?
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 340
  • Karma: 16
  • kiss that sound that pounds your senses
    • View Profile
Re: RTS
« Reply #14 on: April 08, 2007 »
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:
Code: [Select]
'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.
« Last Edit: April 08, 2007 by CLANKY »
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: RTS
« Reply #15 on: April 08, 2007 »
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.

Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: RTS
« Reply #16 on: April 08, 2007 »
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
Code: [Select]
// 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
Code: [Select]
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)

Challenge Trophies Won:

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 340
  • Karma: 16
  • kiss that sound that pounds your senses
    • View Profile
Re: RTS
« Reply #17 on: April 09, 2007 »
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.
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 340
  • Karma: 16
  • kiss that sound that pounds your senses
    • View Profile
Re: RTS
« Reply #18 on: April 09, 2007 »
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:
Code: [Select]
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?
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..

Offline Clanky

  • Laser Guided Memories
  • Amiga 1200
  • ****
  • Posts: 340
  • Karma: 16
  • kiss that sound that pounds your senses
    • View Profile
Re: RTS
« Reply #19 on: April 14, 2007 »
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.
« Last Edit: April 14, 2007 by CLANKY »
He tilts, and his eyes are focused on the ground far below.. Wind? Angels? Men..