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

Username:   Password: 
 RegisterRegister   
 starting my final project...
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: Fri Feb 27, 2004 6:51 pm   Post subject: starting my final project...

since i've been bored lately and havent thought of a cool program to make, i decided to start on my final project... im going to make a multiplayer capture the falg/2d shooter/tag type game.... heres what i have so far...

source

are there any bugs that need to be fixed???

- zylum
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Fri Feb 27, 2004 7:05 pm   Post subject: (No subject)

wow that's pretty good. as far as I can tell the collisions and everything are flawless. Nice, neat code too Smile
Tony




PostPosted: Fri Feb 27, 2004 8:33 pm   Post subject: (No subject)

looks like it will turn out to be an awesome game 8)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Andy




PostPosted: Fri Feb 27, 2004 8:43 pm   Post subject: (No subject)

nsns but y does it "lag" when i back up?
Tony




PostPosted: Fri Feb 27, 2004 11:23 pm   Post subject: (No subject)

i dont think it "lags"... you just move slowler when you run backwards then overwise... just makes the game that much more realistic Very Happy
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Paul




PostPosted: Fri Feb 27, 2004 11:42 pm   Post subject: (No subject)

Very nice, you might wanna make it a bit bigger though, some ppl would prolly not see it that well.
zylum




PostPosted: Sat Feb 28, 2004 1:38 am   Post subject: (No subject)

thanks for the comments... here is an updated version and a level editor....

map editor:

code:
setscreen ("graphics:593;593")

var cols, rows : int
put "how many columns?"
get cols
put "how many rows?"
get rows

cols := min (cols, 37)
rows := min (rows, 37)

cls

var clr : int
var tile : array 1 .. cols, 1 .. rows of int
for col : 1 .. cols
    for row : 1 .. rows
        if row = 1 or col = 1 or row = rows or col = cols then
            clr := 43
            tile (col, row) := 1
        else
            clr := 53
            tile (col, row) := 0
        end if
        drawfillbox ((col - 1) * 16, (row - 1) * 16, (col - 1) * 16 + 15, (row - 1) * 16 + 15, clr)
    end for
end for

var mx, my, md, x, y : int
loop
    mousewhere (mx, my, md)
    if md = 1 then
        x := mx div 16
        y := my div 16
        if tile (x + 1, y + 1) = 1 then
            tile (x + 1, y + 1) := 0
            drawfillbox ((x) * 16, (y) * 16, (x) * 16 + 15, (y) * 16 + 15, 53)
        else
            tile (x + 1, y + 1) := 1
            drawfillbox ((x) * 16, (y) * 16, (x) * 16 + 15, (y) * 16 + 15, 43)
        end if
        delay (200)
    end if
    exit when hasch
end loop

put "what is the name of the map???"
var mapName : string
get mapName
var mapFile : int

open : mapFile, mapName, put

put : mapFile, rows
put : mapFile, cols

cls
for col : 1 .. cols
    for row : 1 .. rows
        if row < rows then
            put : mapFile, tile (col, row) ..
            put : mapFile, " " ..
        else
            put : mapFile, tile (col, row)
        end if
    end for
end for

put "map saved"


updated version which works with user made maps:

code:

setscreen ("graphics:593;593")

var mapCols := 20
var mapRows := 20
var mapDensity := 2.7
var tileSize := 16

var players : int := 1
var playerSize : int := 3
var playerTurnSpeed : real := 2
var playerMaxSpeed : real := 0.5
var playerMinSpeed : real := -0.2
var playerMoveSpeed : array 1 .. players of real
var playerSpeeds : array 1 .. players, 1 .. 2 of real
var playerCoords : array 1 .. players, 1 .. 2 of real
playerCoords (1, 1) := tileSize + tileSize / 2
playerCoords (1, 2) := tileSize + tileSize / 2
var playerAng : array 1 .. players of real
for i : 1 .. players
    playerAng (i) := 0
end for

var mapPic : int

var map : array 1 .. 1000, 1 .. 1000 of int

procedure createMap (size : int, density : real, clr1, clr2 : int)
    var clr : real
    var mapType : string
    loop
        locate (1, 1)
        put "random or file?"
        get mapType
        exit when mapType = "random" or mapType = "file"
        cls
    end loop
    cls
    var cols : int := mapCols
    var rows : int := mapRows
    if mapType = "random" then
        for col : 1 .. cols
            for row : 1 .. rows
                if row = 1 or col = 1 or row = rows or col = cols then
                    clr := clr2
                elsif row = 2 or col = 2 or row = rows - 1 or col = cols - 1 then
                    clr := clr1
                else
                    clr := Rand.Real * density
                    if clr < density - 1 then
                        clr := clr1
                        map (col, row) := 0
                    else
                        clr := clr2
                        map (col, row) := 1
                    end if
                end if
                if clr = clr1 then
                    map (col, row) := 0
                else
                    map (col, row) := 1
                end if
                drawfillbox (col * size, row * size, col * size + size, row * size + size, round (clr))
            end for
        end for
    else
        var mapFile : int
        var mapFileName : string
        var tile : int
        var rows2, cols2 : int
        %load map here
        put "what is the map file name?"
        get mapFileName
        cls
        open : mapFile, mapFileName, get
        get : mapFile, mapRows
        get : mapFile, mapCols
        for col : 1 .. mapCols
            for row : 1 .. mapRows
                get : mapFile, tile
                if tile = 0 then
                    clr := clr1
                    map (col, row) := 0
                else
                    clr := clr2
                    map (col, row) := 1
                end if
                drawfillbox ((col - 1) * size, (row - 1) * size, (col - 1) * size + size, (row - 1) * size + size, round (clr))
            end for
        end for
    end if
    mapPic := Pic.New (0, 0, (mapCols - 1) * size + size, (mapRows - 1) * size + size)
    cls
end createMap

var move : array char of boolean
procedure getKeyStrokes (num : int)
    Input.KeyDown (move)
    if move (KEY_UP_ARROW) then
        playerMoveSpeed (num) := playerMaxSpeed
    elsif move (KEY_DOWN_ARROW) then
        playerMoveSpeed (num) := playerMinSpeed
    else
        playerMoveSpeed (num) := 0
    end if
    if move (KEY_RIGHT_ARROW) then
        playerAng (num) -= playerTurnSpeed
    elsif move (KEY_LEFT_ARROW) then
        playerAng (num) += playerTurnSpeed
    end if
    if playerAng (num) > 360 then
        playerAng (num) := 5
    elsif playerAng (num) < 0 then
        playerAng (num) := 355
    end if
end getKeyStrokes

procedure checkCollision (num : int)
    var x, y : real
    /***X AXIS***
     bottom left*/
    x := (playerCoords (num, 1) + tileSize + playerSpeeds (num, 1) - playerSize) div tileSize
    y := (playerCoords (num, 2) + tileSize - playerSize) div tileSize
    if map (round (x), round (y)) = 1 then
        playerSpeeds (num, 1) := 0
    end if
    %top left
    x := (playerCoords (num, 1) + tileSize + playerSpeeds (num, 1) - playerSize) div tileSize
    y := (playerCoords (num, 2) + tileSize + playerSize) div tileSize
    if map (round (x), round (y)) = 1 then
        playerSpeeds (num, 1) := 0
    end if
    %bottom right
    x := (playerCoords (num, 1) + tileSize + playerSpeeds (num, 1) + playerSize) div tileSize
    y := (playerCoords (num, 2) + tileSize - playerSize) div tileSize
    if map (round (x), round (y)) = 1 then
        playerSpeeds (num, 1) := 0
    end if
    %top right
    x := (playerCoords (num, 1) + tileSize + playerSpeeds (num, 1) + playerSize) div tileSize
    y := (playerCoords (num, 2) + tileSize + playerSize) div tileSize
    if map (round (x), round (y)) = 1 then
        playerSpeeds (num, 1) := 0
    end if

    /*Y AXIS
     bottom left*/
    x := (playerCoords (num, 1) + tileSize - playerSize) div tileSize
    y := (playerCoords (num, 2) + tileSize + playerSpeeds (num, 2) - playerSize) div tileSize
    if map (round (x), round (y)) = 1 then
        playerSpeeds (num, 2) := 0
    end if
    %top left
    x := (playerCoords (num, 1) + tileSize - playerSize) div tileSize
    y := (playerCoords (num, 2) + tileSize + playerSpeeds (num, 2) + playerSize) div tileSize
    if map (round (x), round (y)) = 1 then
        playerSpeeds (num, 2) := 0
    end if
    %bottom right
    x := (playerCoords (num, 1) + tileSize + playerSize) div tileSize
    y := (playerCoords (num, 2) + tileSize + playerSpeeds (num, 2) - playerSize) div tileSize
    if map (round (x), round (y)) = 1 then
        playerSpeeds (num, 2) := 0
    end if
    %top right
    x := (playerCoords (num, 1) + tileSize + playerSize) div tileSize
    y := (playerCoords (num, 2) + tileSize + playerSpeeds (num, 2) + playerSize) div tileSize
    if map (round (x), round (y)) = 1 then
        playerSpeeds (num, 2) := 0
    end if
end checkCollision

procedure movePlayer (num : int)
    playerSpeeds (num, 1) := cosd (playerAng (num)) * playerMoveSpeed (num)
    playerSpeeds (num, 2) := sind (playerAng (num)) * playerMoveSpeed (num)
    checkCollision (num)
    playerCoords (num, 1) += playerSpeeds (num, 1)
    playerCoords (num, 2) += playerSpeeds (num, 2)
    drawline (round (playerCoords (num, 1)), round (playerCoords (num, 2)), round (playerCoords (num, 1) + cosd (playerAng (num)) * (playerSize + 1.5)), round (playerCoords (num, 2) +
        sind (playerAng (num)) * (playerSize + 1.5)), 7)
    drawfilloval (round (playerCoords (num, 1)), round (playerCoords (num, 2)), playerSize, playerSize, grey)
    drawoval (round (playerCoords (num, 1)), round (playerCoords (num, 2)), playerSize, playerSize, 7)
end movePlayer

createMap (tileSize, mapDensity, 53, 43)

setscreen ("offscreenonly")

loop
    for plyr : 1 .. players
        getKeyStrokes (plyr)
        movePlayer (plyr)
    end for
    View.Update
    delay (5)
    Pic.Draw (mapPic, 0, 0, picCopy)
end loop


-zylum
recneps




PostPosted: Sat Feb 28, 2004 10:15 am   Post subject: (No subject)

The collision is a little messed :\ ( idid random)
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sat Feb 28, 2004 12:47 pm   Post subject: (No subject)

are you talking about collision in the first one he posted or this last one. I've only looked at the first one and the collision is flawless for me
recneps




PostPosted: Sat Feb 28, 2004 4:49 pm   Post subject: (No subject)

The second ones he posted Wink
Tony




PostPosted: Sat Feb 28, 2004 5:54 pm   Post subject: (No subject)

plz try to upload the code as an attachment if you have a lot of it Rolling Eyes thx
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
shorthair




PostPosted: Sat Feb 28, 2004 6:22 pm   Post subject: (No subject)

Well done , i like the effort you have put into this , that collision detection is way off in the second version , its almost as if it thinks its a different map , but great job anywhoo
poly




PostPosted: Sun Feb 29, 2004 10:17 am   Post subject: (No subject)

yes i agree with everybody here, its pretty good (cant wait to see the final outcome), but collision is a bit messed up on the second version you posted. I would be walking around the blue area and all of a sudden it would act like there is a wall infront of me
zylum




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

hmm... thats odd. i havnt changed the collision detection at all...
zylum




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

oops, looks like i messed up the random map generator... heres an update for those of you who are interested...

game engine

map editor

*sorry about posting that long source

-zylum
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  [ 17 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: