QJ.NET | Videos | Forums | iPhone | MMORPG | Nintendo DS | Wii | PlayStation 3 | PSP | Xbox 360 | PC | Downloads | Contact Us
Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact

QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides

Go Back   QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides > Developers Corner > PSP Development, Hacks, and Homebrew > PSP Development Forum
The above video goes away if you are a member and logged in, so log in now!

A Real Time Strategy Game: The Making Of

This is a discussion on A Real Time Strategy Game: The Making Of within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Hi all, Here is a new thread to share the work i'm currently making on a Lua Coded Real Time ...

Reply
 
LinkBack Thread Tools
Old 06-12-2009, 06:39 AM   #1

QJ Gamer Bronze
 
seanpaul223's Avatar
 
My Mood: Psychedelic
Join Date: Dec 2007
Location: B.F.
Posts: 309
Trader Feedback: 0
Default A Real Time Strategy Game: The Making Of

Hi all,
Here is a new thread to share the work i'm currently making on a Lua Coded Real Time Strategy Game.
I've been missing for long, because of studies, but now i have a break and i'm back for coding.
As far as i can i'll post here about what have been done, and techniques i've used to reach my goals.So anybody can learn, help, and those who're more experienced can discuss or propose better ways of dealing with the code.

I. The Map Engine
The Map is one of most important elements in a Real Time Strategy game.That's why i've started working on the map.
I've decided to use 60x68 sized tiles.The map engine generates a map using 7 different kind of tiles.
Here is what this engine can actually do:

Randomly generates a 1920-width 1632-height sized map.Of course, the entirely map cannot be seen on the PSP's screen.So i made a Camera System which supports horizontal and vertical scrolling.


Mini Map: A mini map can be displayed, so the player knows where he is exactly on the world map.This Mini Map is not dsplayed by defalut, but just as the player wishes, when pushing a button.

Teleportation:The player can instantaneously move to a far location on the world map instead of scrolling the map.This features works when displaying the minimap,as in any RTS game.

Now here is a summup of the main functions i've set in the map engine:

Sets map sizes and load tiles

Code:
--sets mapSize
map_h=480*4
map_v=272*6

--load tiles
tile={}
for i=1,7 do tile[i]=Image.load("map_tiles/"..i..".png") end
tileWidth=tile[1]:width()
tileHeight=tile[1]:height()
Generates randomly a map and collision grid for a next pathfinding code

Code:
function mapcreate()
    map={}
    i=9*4
    j=4*6
    math.randomseed(os.time())
    for x=1,j,1 do map[x]={} end
    for x=1,table.getn(map) do
        for n=1,i do
        map[x][n]=math.random(1,7)
        end
    end
end
function mapcol()
col={}
    for i=1,table.getn(map) do col[i]={} end
    for j=1,table.getn(map) do
        for i=1,table.getn(map[1]) do
        col[j][i]=0
        end
    end
end        
mapcreate()
mapcol()
This function is runned in the main loop and draws the map using tiles


Code:
function drawmap()
xint=-tileWidth
yint=0
    for i=1,table.getn(map) do    
        for j=1,table.getn(map[1]) do
        xint=xint+tileWidth
        screen:blit(xint-camX,yint-camY,tile[map[i][j]])
        end
    yint=yint+tileHeight
    xint=-tileWidth
    end
end
This functions enables scrolling
Code:
function browsemap()
scrollValue=2.5*3
key=Controls.read()
    if key:square() then
        if key:left() then 
            if camX > 0 then camX = camX-scrollValue else camX=0 end
        end
        if key:right() then
            if camX < map_h-480 then camX=camX+scrollValue else camX=map_h-480 end
        end
        if key:up() then
            if camY > 0 then camY=camY-scrollValue else camY=0 end
        end
        if key:down() then
            if camY < map_v-272 then camY=camY+scrollValue else camY=map_v-272 end
        end
    end
end
This creates an displays minimap

Code:
blit_mmap=false

--Sub function which draws a rectangle
function drawrect(x1,x2,y1,y2,color)
screen:drawLine(x1,y1,x2,y1,color)
screen:drawLine(x1,y1,x1,y2,color)
screen:drawLine(x1,y2,x2,y2,color)
screen:drawLine(x2,y1,x2,y2,color)
end

function setminimap()
    if key:select() and not oldkey:select() then 
        if blit_mmap == false then blit_mmap = true
        elseif blit_mmap == true then blit_mmap = false
        end
    end
    if blit_mmap then
    drawrect((480/4), (480*3/4),(272/4), (272*3/4), Color.new(255,255,0))    
    mmapX,mmapY =(480/4)+(camX/8), (272/4)+(camY/12)
    mmapXw,mmapYh= mmapX+(480/8), mmapY+(272/12)
    drawrect(mmapX,mmapXw,mmapY,mmapYh,Color.new(0,0,255))
        if cursor.x > (480/4) and cursor.x < (480*3/4) and cursor.y > (272/4) and cursor.y < 272*3/4 then        
            if key:cross() and not oldkey:cross() then
            camX=8*(cursor.x-(480/4)-((480/2)/8))
            camY=12*(cursor.y-(272/4)-((272/2)/12))
            end
        end            
    end
end
This a a simple debug function which returns a text file containing the map table

Code:
function debugf()
file=io.open("debug.txt","w")
file:write("map={")
file:write("\n")
    for i=1,table.getn(map) do
    file:write("{")
        for j=1,table.getn(map[1]) do
        file:write(map[i][j]..", ")
        end
    file:write("},")
    file:write("\n")
    end
file:write("\n".."}")
file:close()
end
Here is a example of map printed in the debug.txt file
Code:
map={
{1, 2, 5, 7, 2, 1, 1, 5, 7, 7, 1, 3, 1, 3, 2, 5, 7, 7, 6, 3, 2, 1, 3, 7, 2, 5, 5, 6, 1, 5, 4, 2, 3, 1, 4, 2, },
{1, 4, 1, 5, 1, 2, 4, 3, 5, 5, 7, 6, 3, 7, 5, 3, 2, 1, 2, 3, 1, 2, 6, 6, 6, 3, 1, 2, 5, 6, 4, 5, 3, 5, 1, 7, },
{3, 6, 2, 4, 1, 6, 2, 2, 3, 5, 4, 6, 3, 7, 2, 6, 4, 1, 4, 7, 4, 2, 4, 4, 2, 4, 7, 2, 5, 5, 5, 2, 7, 2, 2, 2, },
{3, 7, 4, 6, 6, 7, 2, 3, 1, 6, 5, 7, 2, 5, 4, 3, 6, 6, 6, 3, 4, 4, 7, 4, 5, 7, 3, 7, 1, 7, 4, 2, 5, 7, 7, 3, },
{1, 3, 3, 2, 4, 3, 6, 7, 2, 3, 6, 2, 5, 1, 6, 1, 7, 3, 6, 3, 2, 5, 6, 2, 7, 3, 5, 3, 3, 7, 7, 2, 3, 7, 5, 7, },
{3, 7, 6, 1, 4, 6, 7, 4, 5, 5, 3, 1, 3, 2, 5, 5, 4, 7, 1, 2, 1, 2, 3, 7, 6, 6, 2, 1, 2, 6, 5, 1, 7, 3, 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 3, 7, 4, 4, 5, 1, 5, 3, 5, 6, 6, 2, 5, 4, 4, 2, 6, 4, 7, 5, 2, 7, 1, 7, 7, 3, 7, },
{6, 2, 7, 5, 3, 1, 6, 6, 1, 1, 5, 3, 6, 1, 1, 6, 7, 7, 7, 1, 7, 1, 7, 1, 7, 4, 7, 4, 1, 7, 3, 2, 6, 7, 2, 7, },
{7, 4, 4, 6, 6, 4, 1, 3, 5, 2, 2, 4, 3, 1, 2, 7, 4, 2, 4, 7, 2, 6, 6, 4, 5, 4, 1, 7, 2, 6, 3, 2, 4, 1, 6, 3, },
{6, 7, 3, 1, 3, 3, 5, 7, 3, 2, 4, 5, 1, 3, 2, 3, 3, 2, 1, 3, 5, 4, 2, 3, 5, 3, 1, 5, 5, 6, 7, 4, 4, 3, 1, 6, },
{6, 4, 3, 4, 4, 7, 7, 1, 2, 4, 3, 6, 5, 7, 7, 6, 5, 5, 5, 2, 5, 6, 6, 7, 6, 3, 2, 4, 3, 6, 2, 3, 7, 5, 4, 4, },
{2, 4, 4, 4, 5, 7, 7, 5, 1, 5, 3, 5, 2, 6, 1, 4, 1, 5, 2, 7, 4, 6, 7, 6, 6, 3, 7, 6, 7, 7, 7, 1, 3, 4, 1, 2, },
{7, 4, 6, 2, 5, 5, 4, 2, 1, 7, 4, 4, 1, 2, 5, 5, 7, 5, 4, 3, 1, 1, 1, 3, 1, 4, 5, 1, 3, 3, 5, 2, 3, 4, 1, 4, },
{4, 1, 2, 6, 7, 5, 7, 5, 6, 3, 3, 4, 7, 2, 3, 1, 5, 2, 6, 6, 7, 3, 3, 2, 6, 4, 5, 3, 6, 7, 1, 7, 5, 1, 3, 2, },
{7, 2, 4, 7, 4, 2, 4, 3, 6, 1, 2, 4, 1, 5, 4, 7, 7, 7, 6, 7, 2, 5, 1, 1, 4, 2, 6, 3, 7, 5, 5, 3, 2, 2, 7, 1, },

}
Now, some screens:






That's all for now.Now waitings for suggestions and pieces of advise.
__________________
00:00: Windows is loading...Come back tomorrow.
01:00 : Booting done.Not yet errors encountered...
01:10: Fatal error.Windows has been detected on logical drive
01:22: Keyboard Locked, try everything.
01:42 : Mouse Device Pilot not found, or uninstalled.Press Left-Bouton to continue.
01:50 : Ending User session.Do you want to play another game ?
01:59: Not enough memory.Only 508'312'583 bytes available.
02:00 : System is shutting Down.
seanpaul223 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Best prices available for:
Price Range:
$13.00 - $25.00
at 10 Stores

Price Range:
$17.00 - $48.00
at 10 Stores

Old 06-12-2009, 07:26 AM   #2
QJ Gamer Green
 
_df_'s Avatar
 
Join Date: May 2007
Posts: 125
Trader Feedback: 0
Default

nice work mate, only things I see off the bat is everything is global everywhere, and at some point that is gonna bite you in the ass with subtle bugs.

also, you realise you can use '#' instead of table.getn all the time right?

so for eg;

Code:
function drawmap()
	local xint
	local yint
	local i
	local j
	
	xint = -tileWidth
	yint = 0
	
	for i=1, #map do
		for j=1, #map[i] do
			xint = xint + tileWidth
			screen:blit(xint - camX, yint - camY, tile[map[i][j]])
		end
		
		yint = yint + tileHeight
		xint = -tileWidth
	end
end
also, anywhere you have global variables that track game state, I'd create a table and put them in eg;

Code:
game_vars = {}
game_vars.camX = ...
game_vars.camY = ...
then you know where everything is for a savegame and you can serialise just one variable recursively like

Code:
-- modify for file io or whatever
function SaveGame()
	local function Serialise(name, vv)
		local k,v
		
		print(name .." = {}")
		for k,v in pairs(vv) do
			if type(v) == "string" then
				print(name .. "." .. k .." = " .. string.format("%q", v) .. "")
			elseif type(v) == "table" then
				Serialise(name .. "." .. k, v)
			else
				print(name .. "." .. k .." = " .. tostring(v) .. "")
			end
		end
	end
	
	Serialise("game.vars", game.vars)
end
that way you are not polluting the global namespace and doing things like 'new' games or restarts is as simple as game_vars = nil, or even easier if everything were a child of a table called game (ie: game.sprites, game.vars, game.whatever), game = nil....
__________________
-- Code Monkey : Sarien, Fishguts, Cracks and Crevices --

"Did IQ's just drop sharply while I was away?" (Ripley)
_df_ is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-12-2009, 07:53 AM   #3

QJ Gamer Bronze
 
seanpaul223's Avatar
 
My Mood: Psychedelic
Join Date: Dec 2007
Location: B.F.
Posts: 309
Trader Feedback: 0
Default

Nice, df.
Yeah, i know # operator.it did the same thing that table.getn().I'm used to the table.getn() to iterate all over tables.But anyway, # does the same work.
Right,then i'll make a clear difference between global and local variables so that they won't mess up.Thanks.
seanpaul223 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-12-2009, 08:00 AM   #4
Lua guy
 
dan369's Avatar
 
My Mood: Mellow
Join Date: Jan 2008
Real First Name: Dan
Location: Wales, cardiff
Just Played: MW2/Bioshock 2
Posts: 1,400
Blog Entries: 1
Trader Feedback: 0
Default

'tile[map[i][j]]'

but this in a variable.
e.g
local tile
tile = map[i][j]

Use it that way, it's better.
dan369 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-14-2009, 09:55 AM   #5
No longer a community member.
 
a_noob's Avatar
 
Join Date: Sep 2006
Location: Over there.
Posts: 666
Trader Feedback: 0
Default

for the rendering you need to redo it otherwise you will run into slowdowns in the future, only render the tiles that are on screen, no need to render all the tiles in the map, this can be done with a simple offset based on a % of the x,y position of the map.
a_noob is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-14-2009, 12:24 PM   #6
QJ Gamer Blue
 
Join Date: May 2007
Posts: 70
Trader Feedback: 0
Default

You should really use a tile-set as opposed to individual tile images. Doing what a_noob suggested will surely bump up the speed a lot as well.
__________________
[url="http://www.safarial.homebrewheaven.net"]Blog[/url]
SafariAl is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-17-2009, 09:29 AM   #7

QJ Gamer Bronze
 
seanpaul223's Avatar
 
My Mood: Psychedelic
Join Date: Dec 2007
Location: B.F.
Posts: 309
Trader Feedback: 0
Default

Hi all,
Great update for the map engine..

Now,Basically, there are no limit for the game field.I tried up to 480.000 width by 272.000 height for the map size, and it fully works without freezing.
The fact is that now, the map engine randomly generates a 2D map grid of numbers.All numbers corresponds to a special tile.
As a_Noob said, i've made it so that not all tiles are rendered at the same time, but just the tiles that are on the screen where the camera looks.
I've also added water, as many guys asked for.


Quick Video:
YouTube
seanpaul223 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-17-2009, 11:24 AM   #8
 
Join Date: Jul 2008
Posts: 170
Trader Feedback: 0
Default

whooo sweet, looks really nice for a lua game
SGT4EVA is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-18-2009, 04:30 AM   #9

QJ Gamer Bronze
 
seanpaul223's Avatar
 
My Mood: Psychedelic
Join Date: Dec 2007
Location: B.F.
Posts: 309
Trader Feedback: 0
Default

Thanks.

Well, i brought some modifications to the engine.

The Map Engine now contains only functions.So when the game scenario starts, it defines the map size, the amount of resources.Thus, the map engine now creates the map, deals with the tiles rendering, and creates the amount of natural resources according to the current game scenario.

Addedd to that, there are now two minimaps.The first one shows only units and buildings, and the other one shows natural resources.It is possible to disable Minimap view from screen.

I've also included the drag box selection.

Some screens:


The first minimap showing units/buildings (not done yet)


lthe second minimap showing resources


drag box selection


drag box selection
seanpaul223 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-26-2009, 02:26 AM   #10

QJ Gamer Bronze
 
seanpaul223's Avatar
 
My Mood: Psychedelic
Join Date: Dec 2007
Location: B.F.
Posts: 309
Trader Feedback: 0
Default

Hi all,
I've entierely ended with the implementation of A-Star Pathfinding Algorithm in the game.I must thanks Developer Yaustar for his piece of advise.

New possiblities are:
  • Move a Unit
  • Alternate unit control with another
  • Group Units
  • Move many units at the same time.
  • All moves on the map world uses pathfinding.

Video: Age of Nations Pathfinding Implementation
seanpaul223 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-26-2009, 04:13 AM   #11

QJ Gamer Silver
 
yaustar's Avatar
 
Join Date: Jun 2006
Location: UK
Posts: 2,322
Trader Feedback: 0
Default

Pretty good. One thing I would like to see is to be able to scroll the screen when the you push the cursor 'off' the screen rather then just only using a separate control.
yaustar is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-26-2009, 07:00 AM   #12
Lua guy
 
dan369's Avatar
 
My Mood: Mellow
Join Date: Jan 2008
Real First Name: Dan
Location: Wales, cardiff
Just Played: MW2/Bioshock 2
Posts: 1,400
Blog Entries: 1
Trader Feedback: 0
Default

Have you fixed that bug then? The one were if you clicked on a house it would just crash?
dan369 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-27-2009, 03:19 AM   #13

QJ Gamer Bronze
 
seanpaul223's Avatar
 
My Mood: Psychedelic
Join Date: Dec 2007
Location: B.F.
Posts: 309
Trader Feedback: 0
Default

Quote:
Originally Posted by yaustar View Post
Pretty good. One thing I would like to see is to be able to scroll the screen when the you push the cursor 'off' the screen rather then just only using a separate control.
I've already did it.I just forgot to show it in the demo video.

Quote:
Originally Posted by dan369
Have you fixed that bug then? The one were if you clicked on a house it would just crash?
Yes, this is now fixed.
seanpaul223 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-29-2009, 07:51 AM   #14
QJ Gamer Green
 
Join Date: Jul 2008
Location: Italy
Posts: 144
Trader Feedback: 0
Default

Uhm, congratulations, I guess you are doing a very good job. Can we know when the next release come out?
Gefa is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 06-29-2009, 09:13 AM   #15

QJ Gamer Bronze
 
seanpaul223's Avatar
 
My Mood: Psychedelic
Join Date: Dec 2007
Location: B.F.
Posts: 309
Trader Feedback: 0
Default

Quote:
Originally Posted by Gefa View Post
Uhm, congratulations, I guess you are doing a very good job. Can we know when the next release come out?
Well, i haven't planned this.No for tomorrow, of course...The fact is after i've end up with the game engine, i'll just have to create scenarios, and plug 'em into the game.
seanpaul223 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
game , making , real , strategy , time

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -8. The time now is 04:11 PM.



Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © 2010, QJ.NET. All Rights Reserved.
Contact Us | Free Flash Games