Skip to main content
gamedev.net
🔒 Locked

example code

Started by Sepier 4 replies 1.3k views
Original Post
Sepier
Sepier
watup. i in a class for highschool at a tech school in utah. im learning C#, and just starting in Java. i am trying to figure out how to code a simple rts game, (real time strategy), for those who dont know what that is its a game in the format similar to warcraft, age of empires, starcraft etc... can anyone please send me some example code? or a link to an open source rts? i dont want any realy complicated stuff, like 3d landscape, or animation coding. im looking for things like simple ai, creating structures, selection of units, makeing the units, and a map. thank you for your time, and if this sounds like im just some idiot kid, please dont flame me for it. im still learning.
Drew_Benton
Drew_Benton
Well let me tell you that there is nothing avaliable that is *simple*. You can take a look at Glest and machinations but those are both written in C++. I have yet to come across anything written in c# and Java, for those are not the ideal languages to write a RTS game in as of now. The best thing you can do is look at the Isometric Forum here in hopes of finding something really useful, but other than that, RTS game resources are rather lacking on the net. Best of luck!

- Drew
Sepier
Sepier
thank you much.
Kramy
Kramy
I wrote an 8-direction RTS a while ago in a scripting language, but(obviously) it was slow as hell. Tell a unit to move somewhere, and it freezes for 2 seconds while it thinks. [grin]

I don't have the source anymore, but if you want some advice, find a nice scripting language that takes care of classes, inheritance, variable types, etc. behind the scenes. After all, it's a lot easier to think up "RTS logic", and the best way to do something, if you don't have to worry about memory usage and all these darned deleted pointers that used to point to the same thing. [grin]

Example:
MapGrid[32,32] = 0;ScreenPosX = 320; // 10*32ScreenPosY = 240; // 24*32myTank = New Unit("tankimg.png",640,480);Function Unit(pUnitImage,XPos,YPos){// Unit ImageThis.mySurface = New Surface(pUnitImage);This.ImgSizeX = mySurface.GetPixelWidth();This.ImgSizeY = mySurface.GetPixelHeight();This.XPosition = XPos;This.YPosition = YPos;// Define FunctionsThis.DisplayUnit = Unit_DisplayUnit;}Function Unit_DisplayUnit(){// Copy To Window (Img, Copy PositionX, Copy PositionY, (4 parameters making a rectangle to copy))myWindow.Copy(mySurface,XPosition-ScreenPosX,YPosition-ScreenPosY,0,0,ImgSizeX,ImgSizeY);}


Now obviously the code I just wrote is complete crap, since it doesn't even perform any checks on if the coordinates to see if they are even in the window....not to mention not even initializing it, but hey, it gets the point across - LOTS simpler than C or Java. [smile]

Edit: Man that source box mutilated my code. [Lol]
-Kramy
Genjix
Genjix
try searching for battle of survival on google (BOS)
Sepier
Sepier
thanks kramy. ill mess with that example code, it gives me a kindof clear look on what will need to be done atleast to make a unit move.

and ill look up battle for survival now.

oh and i checked out glest, is there an open source file i can download somewhere to play with it? as for editing models and stuff, that they let you do, i already do too much of that with warcraft3.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.