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

Username:   Password: 
 RegisterRegister   
 Huge project, few questions
Index -> Programming, Turing -> Turing Help
Goto page Previous  1, 2, 3, 4  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Nathan4102




PostPosted: Sun Jul 28, 2013 11:02 am   Post subject: Re: Huge project, few questions

Raknarg @ Sun Jul 28, 2013 12:35 am wrote:
I was busy making this space shooting game, but if I remember correctly 1200 lines are dedicating to all the enemy drawings... I hard coded them so I could manipulate them.

It's also written like garbage haha I've rewritten it a couple times in the past

You wont be able to run it without removing all the picture stuff in the program though.


Wow... xD

And thanks for the suggestions Dread! That's probably actually a good idea, since I'll have 4 or 5 characters per 20x20 tile, the text file could get pretty big if I used binary.

Edit: Now I gotta figure out how to do decimal to hex... :/
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Sun Jul 28, 2013 12:06 pm   Post subject: RE:Huge project, few questions

If you want to use dreadnaughts solution, you just replace the 2's with 16's and it then works in hex
jr5000pwp




PostPosted: Mon Jul 29, 2013 9:54 am   Post subject: Re: RE:Huge project, few questions

Nathan4102 @ Sat Jul 27, 2013 11:20 pm wrote:
Jesus, a 2000 line project in grade 10? What on earth were you making? xD My summative was 400 lines, and I got 105%. This game will be around 3-5k lines when I'm done, I'm assuming, so HOPEFULLY I don't run into too many problems. If I do, at least its just a project for fun, and not a final!
My grade 10 project was 5726 lines. My case really highlighted the necessity of well thought out code. I had the idea to make a minecraft 2D clone early in the semester, maybe a month or two in. I started it one way, refactored it to work another way, added features, and refactored some times. My issue was that I would refactor one file down from 800 lines to 150 but became too lazy to do the second file. Another issue was that I was too lazy to refactor my main segments of code to a better design, take for example, a segment of my collision code:
Turing:
% If the character is moving right
if chars (rightkey) then
        % If the block at the players feet after moving is air, torch, or open door then continue
        if getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony)).blockid = 0
                or getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony)).blockid = 15
                or ((getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony)).blockid = 18
                and getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony)).dooropen = 0) = true
                or (getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony)).blockid = 19
                and getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony)).dooropen = 0) = true)
        then
                % If the block at the players torso after moving is air, torch, or open door then continue
                if getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 15).blockid = 0
                        or getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 15).blockid = 15
                        or ((getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 15).blockid = 18
                        and getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 15).dooropen = 0) = true
                        or (getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 15).blockid = 19
                        and getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 15).dooropen = 0) = true)
                then
                        % If the block at the players head after moving is air, torch, or open door then continue
                        if getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 29).blockid = 0
                                or getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 29).blockid = 15
                                or ((getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 29).blockid = 18
                                and getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 29).dooropen = 0) = true
                                or (getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 29).blockid = 19
                                and getblockfloor (round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 29).dooropen = 0) = true)
                        then
That's obviously not very friendly to change, if I wanted to add additional functionality, change current functionality, or track down a bug I'd be in for a word of pain.
My recommendation would be to think before you program. It's very easy to just hardcode stuff or use tons of if statements etc. but it will bite you in the end. Take a few minutes, think about what you need to do, think about how you can do it, and find the best solution for it. Had I done that when making my game I would have thought of a 1 minute solution to improve the code
Turing:
function CheckCollision(x, y : int) : boolean
        if getblockfloor (x, y).blockid = 0
                or getblockfloor (x, y).blockid = 15
                or ((getblockfloor (x, y).blockid = 18
                and getblockfloor (x, y).dooropen = 0) = true
                or (getblockfloor (x, y).blockid = 19
                and getblockfloor (x, y).dooropen = 0) = true)
        then
                result false
        else
                result true
        end
end CheckCollision

if chars(rightkey)
        and CheckCollision(round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony)) = false
        and CheckCollision(round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 15) = false
        and CheckCollision(round (positionxreal + movespeed * (timeframe / 1000)) + 7, round (positiony) + 29) = false
then
This code is no where near perfect either, but it's better.
Raknarg




PostPosted: Mon Jul 29, 2013 6:25 pm   Post subject: RE:Huge project, few questions

My friend made a program well over 10000 lines because noone had introduced him to arrays.
Nathan4102




PostPosted: Mon Jul 29, 2013 8:39 pm   Post subject: RE:Huge project, few questions

10 thousand lines... I imagine that was fun to write... and fun to read for the teacher xD

I might end up plannign out all the programming for this thing after all. When I go to work on it, I end up only getting 20-30 lines down, because I spend the whole time trying to figure out the best way to do what I want to do. We'll see how it goes
Raknarg




PostPosted: Mon Jul 29, 2013 10:00 pm   Post subject: RE:Huge project, few questions

Thinking is half the process.

Maybe getting you ideas down here might help.
Nathan4102




PostPosted: Tue Jul 30, 2013 2:47 pm   Post subject: RE:Huge project, few questions

I would put my ideas here, but I kind of wanted to try to do this with as little help as possible. I could do some sort of development progress thread or something, you think I should?
Raknarg




PostPosted: Tue Jul 30, 2013 5:45 pm   Post subject: RE:Huge project, few questions

Whatever you want, it's your progress. Either you want to tell people what you've accomplished or you want help from outside sources, if you don't care about either, then dont. Otherwise, go crazy.

I don't know if it's against posting rules or whatever, but you can probably post it under submissions, or at least off topic.
Sponsor
Sponsor
Sponsor
sponsor
Nathan4102




PostPosted: Thu Aug 08, 2013 9:49 pm   Post subject: RE:Huge project, few questions

Man...

Ignoring your guy's' suggestions to think out my code before I go was a bad idea. Now I'm getting into this, and my code is A MESS. Look at this crap!

Turing:
for i : 1 .. llength
        for ii : 1 .. height
            case text (ii) (i) of
                label "R" :
                    Pic.Draw (pic (1), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "G" :
                    Pic.Draw (pic (2), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "B" :
                    Pic.Draw (pic (3), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "V" :
                    Pic.Draw (pic (4), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "H" :
                    Pic.Draw (pic (5), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "1" :
                    Pic.Draw (pic (6), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "2" :
                    Pic.Draw (pic (7), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "3" :
                    Pic.Draw (pic (8), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "4" :
                    Pic.Draw (pic (9), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "q" :
                    Pic.Draw (pic (14), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "w" :
                    Pic.Draw (pic (15), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "e" :
                    Pic.Draw (pic (16), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "r" :
                    Pic.Draw (pic (17), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "a" :
                    Pic.Draw (pic (18), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "s" :
                    Pic.Draw (pic (19), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "d" :
                    Pic.Draw (pic (20), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

                label "f" :
                    Pic.Draw (pic (21), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)

            end case
        end for
    end for


I think I'm going to end up having to redo some of this, there's no way I'm going to be able to troubleshoot or modify my game with this kind of code.

Next time I'll listen to you guys :p
Raknarg




PostPosted: Thu Aug 08, 2013 9:59 pm   Post subject: RE:Huge project, few questions

Here, lets fix that for you.

Turing:

const Char : array 1 .. 21 of string := init ("R", "G", "B", "V", "H", "1", "2", "3", "4", " ", " ", " ", " ", "q", "w", "e", "r", "a", "s", "d", "f")

fcn indexArray (s : string) : int
    for i : 1 .. 21
        if Char (i) = s then
            result i
        end if
    end for
    result 0
end indexArray

for i : 1 .. llength
    for ii : 1 .. height
        Pic.Draw (pic (indexArray (text (ii)(i)), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)
    end for
end for


always look for ways to condense.

Also, everyones got to learn at some point. At least now you know fairly early on and you can change it.
chrisbrown




PostPosted: Thu Aug 08, 2013 10:29 pm   Post subject: Re: Huge project, few questions

One step further?

Turing:
const pic : array char of int := init ( 0 );
pic('R') := Pic.New(...)
pic('G') := Pic.New(...)
...

for i : 1 .. llength
    for ii : 1 .. height
        Pic.Draw (pic (text (ii) (i)), i * 40 + 240 - (40 * charx), height * 40 - (ii * 40) - (40 * chary) + 280 - ((height - 15) * 40), picMerge)
    end for
end for
Raknarg




PostPosted: Thu Aug 08, 2013 10:33 pm   Post subject: RE:Huge project, few questions

Good call, I forgot you could have an array of chars.
Nathan4102




PostPosted: Fri Aug 09, 2013 11:44 am   Post subject: Re: RE:Huge project, few questions

Nathan4102 @ Tue Jul 30, 2013 3:47 pm wrote:
I would put my ideas here, but I kind of wanted to try to do this with as little help as possible. I could do some sort of development progress thread or something, you think I should?


This is why I didn't want to put my code on here xD

Thanks for the help, I'll use your code just this one time, but the rest of it I want to do myself. :p
Raknarg




PostPosted: Fri Aug 09, 2013 8:52 pm   Post subject: RE:Huge project, few questions

then dont post specifics :p

And you shouldn't get the notion that using others' code = bad programming. A lot of times, programming is just taking stuff that other people have made and figuring out how it goes together. There's lots to be learned on your own, but theres lots you can be taught as well.

In any case, carry on.
Nathan4102




PostPosted: Fri Aug 09, 2013 9:44 pm   Post subject: Re: RE:Huge project, few questions

Raknarg @ Fri Aug 09, 2013 9:52 pm wrote:
then dont post specifics :p

And you shouldn't get the notion that using others' code = bad programming. A lot of times, programming is just taking stuff that other people have made and figuring out how it goes together. There's lots to be learned on your own, but theres lots you can be taught as well.

In any case, carry on.


The reason I wanted to try to do this all on my own was to see if I could finish a large project like this by myself, but I understand what you mean. Just reading those few code snippets in the last couple posts gave me some ideas on how to improve quite a few parts of my program. And now in the future, I'll be able to solve similar problems using methods I've learned from you guys.

I think I am going to create a project progress thread for this, because of what you said. I enjoy learning by myself, but there's only so much I can learn this way, and I might grow some bad habits along the way.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 4  [ 46 Posts ]
Goto page Previous  1, 2, 3, 4  Next
Jump to:   


Style:  
Search: