Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 the start of an isometric game
Index -> Programming, Turing -> Turing Submissions
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
zylum




PostPosted: Sun Feb 15, 2004 10:01 pm   Post subject: the start of an isometric game

here's the code for an isometric game i was trying to make a few weeks ago but i ended up giving up after much frustration... the depth sorting ended up complicating things. i might end up rewriting it but this is it for now... i don't mind if anyone uses it but good luck understanding it as i've been too lazy to comment it Laughing

code:

setscreen ("graphics:780;450")
setscreen ("offscreenonly")

const PI := 3.14159
function isoTox (xpp, ypp, zpp : int) : int
    result ceil (xpp * cos (45 * PI / 180) + zpp * sin (45 * PI / 180))
end isoTox
function isoToy (xpp, ypp, zpp : int) : int
    result floor (ypp * cos (30 * PI / 180) - (zpp * cos (45 * PI / 180) - xpp * sin (45 * PI / 180)) * sin (30 * PI / 180))
end isoToy

var tempX : array 1 .. 4 of int
var tempY : array 1 .. 4 of int
procedure drawTile (size, height, c1, c2, c3 : int)
    tempX (1) := isoTox (0, height, 0) + maxx div 2
    tempY (1) := isoToy (0, height, 0) + maxy div 2
    tempX (2) := isoTox (size, height, 0) + maxx div 2
    tempY (2) := isoToy (size, height, 0) + maxy div 2
    tempX (3) := isoTox (size, height, size) + maxx div 2
    tempY (3) := isoToy (size, height, size) + maxy div 2
    tempX (4) := isoTox (0, height, size) + maxx div 2
    tempY (4) := isoToy (0, height, size) + maxy div 2
    drawfillpolygon (tempX, tempY, 4, c1)
    drawpolygon (tempX, tempY, 4, c3)
    tempX (1) := isoTox (0, height, 0) + maxx div 2
    tempY (1) := isoToy (0, height, 0) + maxy div 2
    tempX (2) := isoTox (0, 0, 0) + maxx div 2
    tempY (2) := isoToy (0, 0, 0) + maxy div 2
    tempX (3) := isoTox (0, 0, size) + maxx div 2
    tempY (3) := isoToy (0, 0, size) + maxy div 2
    tempX (4) := isoTox (0, height, size) + maxx div 2
    tempY (4) := isoToy (0, height, size) + maxy div 2
    drawfillpolygon (tempX, tempY, 4, c2)
    drawpolygon (tempX, tempY, 4, c3)
    tempX (4) := isoTox (size, height, size) + maxx div 2
    tempY (4) := isoToy (size, height, size) + maxy div 2
    tempX (3) := isoTox (size, 0, size) + maxx div 2
    tempY (3) := isoToy (size, 0, size) + maxy div 2
    tempX (2) := isoTox (0, 0, size) + maxx div 2
    tempY (2) := isoToy (0, 0, size) + maxy div 2
    tempX (1) := isoTox (0, height, size) + maxx div 2
    tempY (1) := isoToy (0, height, size) + maxy div 2
    drawfillpolygon (tempX, tempY, 4, c3)
    drawpolygon (tempX, tempY, 4, c3)
end drawTile



locatexy (maxx div 2 - 20, maxy div 2)
put "LOADING..."
View.Update
cls

var bw, bh, w : int
var h : array 1 .. * of int := init (5, 13, 21)

bw := 10
bh := 20
drawTile (bw, bh, 29, 28, 27)
var box := Pic.New (isoTox (0, bh, 0) + maxx div 2, isoToy (bw, bh, 0) + maxy div 2, isoTox (bw, bh, bw) + maxx div 2, isoToy (0, 0, bw) + maxy div 2)
cls

var tile : array 1 .. 5 of int

w := 30
drawTile (w, h (1), 43, 42, 41)
tile (1) := Pic.New (isoTox (0, h (1), 0) + maxx div 2, isoToy (w, h (1), 0) + maxy div 2, isoTox (w, h (1), w) + maxx div 2, isoToy (0, 0, w) + maxy div 2)

cls

drawTile (w, h (2), 53, 54, 55)
tile (2) := Pic.New (isoTox (0, h (2), 0) + maxx div 2, isoToy (w, h (2), 0) + maxy div 2, isoTox (w, h (2), w) + maxx div 2, isoToy (0, 0, w) + maxy div 2)

cls

drawTile (w, h (3), 45, 10, 2)
tile (3) := Pic.New (isoTox (0, h (3), 0) + maxx div 2, isoToy (w, h (3), 0) + maxy div 2, isoTox (w, h (3), w) + maxx div 2, isoToy (0, 0, w) + maxy div 2)

cls

const worldSize := 15

var tx : int := worldSize
var tz : int := 0
var tnz : int := 1
var tnx : int := worldSize
var tn : int := 1

var x : array 1 .. worldSize ** 2 of int
var z : array 1 .. worldSize ** 2 of int

var i : int := 1

loop
    exit when tx = 1 and tz = worldSize
    if tz < tnz then
        tz += 1
    end if
    x (i) := tx
    z (i) := tz
    if tz = tnz then
        if tx not= 1 and tnx not= 1 then
            tnx -= 1
            tx := tnx
        else
            tx := 1
        end if
        tz := 0
        if tnz < worldSize then
            tnz += 1
        else
            tz := tn
            tn += 1
        end if
    else
        tx += 1
    end if
    i += 1
end loop

i := 0
var randNum : int
const T2odds := 20
const T3odds := 5
var randMapTiles : array 1 .. worldSize ** 2 of int
procedure randMap
    for cols : 1 .. worldSize
        for rows : 1 .. worldSize
            i += 1
            if x (i) = 1 or z (i) = 1 or x (i) = worldSize or z (i) = worldSize then
                randMapTiles (i) := 2
            elsif x (i) = 2 or z (i) = 2 or x (i) = worldSize - 1 or z (i) = worldSize - 1 then
                randMapTiles (i) := 1
            else
                randint (randNum, 1, 100)
                if randNum < T3odds then
                    randMapTiles (i) := 3
                elsif randNum > T3odds and randNum < T3odds + T2odds then
                    randMapTiles (i) := 2
                else
                    randMapTiles (i) := 1
                end if
            end if
        end for
    end for
end randMap
randMap

const worldCX := 30
const worldCY := 190

var d : int := 1
var cd : int := 1
var depth : array 1 .. worldSize * 2 of int
var tnl : int
var direction : int
var draw : int := 0

for : 1 .. worldSize * 2 - 1
    tn := 1
    tnl := 1
    i := 0
    d := 1
    direction := 1
    for col : 1 .. worldSize
        for row : 1 .. worldSize
            if tn = worldSize then
                direction := -1
            end if
            i += 1
            if d = worldSize * 2 - (cd) then
                draw := 1
            end if
            if draw = 1 then
                Pic.Draw (tile (randMapTiles (i)), isoTox (x (i) * w, 0, z (i) * w) + worldCX, isoToy (x (i) * w, 0, z (i) * w) + worldCY, picMerge)
            end if
            if d = worldSize * 2 - (cd) - 1 then
                cls
            end if
            if tn = tnl then
                tn := 0
                tnl += direction
                if d = worldSize * 2 - 1 then
                    depth (cd) := Pic.New (0, 0, maxx, maxy)
                end if
                d += 1
            end if
            tn += 1
        end for
    end for
    cd += 1
    draw := 0
end for

cls

var bx, bz : int := w * 2
var bSpd : int := 6
var boxMove : array char of boolean
var boxDepth : int := worldSize - 1
var boxTX, boxTZ : int

function getTileNum (fx, fz : int) : int
    i := 0
    for col : 1 .. worldSize
        for row : 1 .. worldSize
            i += 1
            exit when col = fx and row = fz
        end for
    end for
    result i
end getTileNum

procedure moveUp
    if randMapTiles (getTileNum (round (((bx + bSpd) - w / 2) / w), boxTZ)) = 1 then
        bx += bSpd
    end if
end moveUp

loop
    Input.KeyDown (boxMove)
    if boxMove (KEY_UP_ARROW) then
        moveUp
    elsif boxMove (KEY_DOWN_ARROW) then
        bx += -bSpd
    elsif boxMove (KEY_RIGHT_ARROW) then
        bz += bSpd
    elsif boxMove (KEY_LEFT_ARROW) then
        bz += -bSpd
    end if
    boxTX := round ((bx - w / 2) / w)
    boxTZ := round (((bz + 10) - w / 2) / w)
    locate (1, 1)
    boxDepth := boxTX + (worldSize - boxTZ - 1)
    Pic.Draw (depth (worldSize * 2 - 1), 0, 0, picCopy)
    Pic.Draw (box, isoTox (bx, h (2), bz) + worldCX, isoToy (bx, h (2), bz) + worldCY, picMerge)
    Pic.Draw (depth (boxDepth), 0, 0, picMerge)
    put boxTX, ", ", boxTZ
    put randMapTiles (getTileNum (boxTX, boxTZ))
    View.Update
    cls
end loop

Sponsor
Sponsor
Sponsor
sponsor
shorthair




PostPosted: Sun Feb 15, 2004 10:05 pm   Post subject: (No subject)

Looks like someone knows what there doing , i like hte code its well written , good luck wiht your game
AsianSensation




PostPosted: Sun Feb 15, 2004 10:06 pm   Post subject: (No subject)

very nice, too bad the collision detection is a bit off, very good for a starting isometric game.

too only a puzzle game could be made out of this, it's too slow for a fast paced game.

oh yeah, btw, bitsness

+25 bits
jonos




PostPosted: Sun Feb 15, 2004 10:09 pm   Post subject: (No subject)

nice!!! good, smooth graphics, and really clean looking. collision detection is nonexistant though, and as someone said before, its really slow, but you could probably speed it up. first and best isometric engine i have seen.
zylum




PostPosted: Sun Feb 15, 2004 10:17 pm   Post subject: (No subject)

Quote:
i like hte code its well written


lol, i thought it was poorly written. it's hard to follow and to get the depth sorting to work required me to store the values of the map unconventionally which made it hard to make collision detection that's why i gave up on it Sad
shorthair




PostPosted: Sun Feb 15, 2004 10:20 pm   Post subject: (No subject)

thast what makes it well written , its sloppy and uniqe , and probably un upgradeable , i like when code is unique to the user , not conventional and perfect , when its uniqe no one can steal it cause it will be noting like the code they usually hand it , i understood it and folowod it , you just have to know what your reading , i mean if your an english scholar trying to decipher german ,you may get the odd line but you aint going anywhere fast,
rizzix




PostPosted: Sun Feb 15, 2004 10:29 pm   Post subject: (No subject)

ingnore the comments of the dude above me.. hey if ur code is not maintainable, extensible, is undocumented or is cryptic.. its bad code.

no company wants such progrmmers.. they are just havoc. but nice coding so far. can always improve. try OOP, helps alot
shorthair




PostPosted: Sun Feb 15, 2004 10:32 pm   Post subject: (No subject)

hey , all people have a unique writing stly , were not talking about writing for a ompany heree , when yur working for a company you write how they want , but as a new programmer ,you always develop a uniqe aspect , i think what he calls messy and unorganized code is good code, i see no problem with it * sure it may not the be the most efficiant ) but he has a good sense of what he is doing , look through it and tell me if you thik its messey or not
Sponsor
Sponsor
Sponsor
sponsor
rizzix




PostPosted: Sun Feb 15, 2004 10:33 pm   Post subject: (No subject)

well i dun think his code is newbie-ish.. and its always a good idea to get your style of programming right the first try.
shorthair




PostPosted: Sun Feb 15, 2004 10:36 pm   Post subject: (No subject)

That it is , and you will find not many people comment heir code ,thats the one thing i dont like , i like commented code ,that way if people want ot learn its better , but i find it alot harder to make a program that i am going to understand and also someone else, most people get lost in my code and its jsut because of the way i write it
zylum




PostPosted: Sun Feb 15, 2004 10:37 pm   Post subject: (No subject)

after this semester i will know how to use classes so i might make an attempt at V2 : OOPized...

man, look at all the those variables all over the place!!! lol
Dan




PostPosted: Sun Feb 15, 2004 11:44 pm   Post subject: (No subject)

wow, it is shure nice looking for not ushing any pic's. i am starting to realy like this hole isometric thing...

have some bits++
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Catalyst




PostPosted: Mon Feb 16, 2004 12:02 am   Post subject: (No subject)

Very nice looking Very Happy

have 20 bits

edit: the donate code seems to be messed up right now Sad
recneps




PostPosted: Mon Feb 16, 2004 4:23 pm   Post subject: (No subject)

That is nice. very nice.
Mazer




PostPosted: Mon Feb 16, 2004 8:36 pm   Post subject: (No subject)

Nice signature pic, nice programs, I see good things coming from you in the future zylum.

I'd give you all my bits but I'm fighting that addiction, so here's a nice non-sarcastic clap (I say that because I like to clap sarcastically from time to time) Claping

Just one thing I'd like to mention, it lags just a little bit... when you have a loop like that, it helps to have a delay (even a small one, like 20ms) in it right before the cls.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 16 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: