![]() |
| Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact |
| ||||||
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 ...
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 |
![]() ![]() QJ Gamer Bronze
|
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()
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()
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
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
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
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
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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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, },
}
![]() ![]() ![]() 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. |
|
|
|
|
|
#2 |
![]() QJ Gamer Green
|
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 Code:
game_vars = {}
game_vars.camX = ...
game_vars.camY = ...
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
__________________
-- Code Monkey : Sarien, Fishguts, Cracks and Crevices -- "Did IQ's just drop sharply while I was away?" (Ripley) |
|
|
|
|
|
#3 |
![]() ![]() QJ Gamer Bronze
|
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. |
|
|
|
|
|
#4 |
![]() Lua guy
|
'tile[map[i][j]]'
but this in a variable. e.g local tile tile = map[i][j] Use it that way, it's better.
__________________
https://sourceforge.net/projects/projectd2/ |
|
|
|
|
|
#5 |
![]() No longer a community member.
|
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.
|
|
|
|
|
|
#6 |
![]() QJ Gamer Blue
|
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] |
|
|
|
|
|
#7 |
![]() ![]() QJ Gamer Bronze
|
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 |
|
|
|
|
|
#9 |
![]() ![]() QJ Gamer Bronze
|
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 |
|
|
|
|
|
#10 |
![]() ![]() QJ Gamer Bronze
|
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:
Video: Age of Nations Pathfinding Implementation |
|
|
|
|
|
#11 |
![]() ![]() QJ Gamer Silver
|
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.
__________________
[Blog] [Portfolio] [Homebrew Illuminati - Serious Homebrew Development Forums] [I want to make Homebrew FAQ] [How I broke into the Games Industry] [Programming Book List] [Programming Article List] |
|
|
|
|
|
#13 | ||
![]() ![]() QJ Gamer Bronze
|
Quote:
Quote:
|
||
|
|
|
|
|
#15 |
![]() ![]() QJ Gamer Bronze
|
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.
|
|
|
|
![]() |
| Tags |
| game , making , real , strategy , time |
| Thread Tools | |
|
|