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

Username:   Password: 
 RegisterRegister   
 A Map Maker
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
darkangel




PostPosted: Thu Feb 28, 2008 5:12 pm   Post subject: A Map Maker

Because no one has posted in the Turing board for several days now i figured, why not?

This is a basic map creation program i made, it has:
-Snap to grid
-Helpful Undo Command
-If wanted, a guideline to show you your partialy made polygon.
-Saves to a file, EFFICIENTLY

Instructions:
    Left Click: Makes a point on the grid
    Right Click (HOLD): draws the partially drawn polygon
    Middle Click: Saves and Exits.
    Ctrl Z: Undo


PS: You can change the amount of points in each polygon in the variable "poly" and changing the upper of the variable in record "coo"

code:

Mouse.ButtonChoose ("multibutton")
View.Set ("offscreenonly,nobuttonbar")
colorback (black)
cls
var mx, my, mz, b : int
var c := 1
var ch : array char of boolean
var poly : int := 4                                   %<-- Change this
type coo :
    record
        x, y : array 1 .. 4 /*                          <--- and this!     */of int
    end record

var Line : flexible array 1 .. 1 of coo

proc click
    for yy : 0 .. maxy by 10
        Draw.Line (0, yy, maxx, yy, 19)
    end for
    for xx : 0 .. maxx by 10
        Draw.Line (xx, 0, xx, maxy, 19)
    end for
    if upper (Line) > 1 then
        for i : 1 .. upper (Line) - 1
            Draw.FillPolygon (Line (i).x, Line (i).y, upper (Line (i).x), grey)
        end for
    end if
    View.Update
end click
click
loop
    Mouse.Where (mx, my, mz)
    Input.KeyDown (ch)
    if mz = 1 then
        Line (upper (Line)).x (c) := (round (mx / 10)) * 10
        Line (upper (Line)).y (c) := (round (my / 10)) * 10
        Draw.FillOval (Line (upper (Line)).x (c), Line (upper (Line)).y (c), 3, 3, black)
        delay (200)
        View.Update
        c += 1
    elsif mz = 10 and c = 1 then
        exit
    end if
    if c > 1 and c < poly+1 and mz = 100 then
        cls
        click
        Draw.FillOval (Line (upper (Line)).x (1), Line (upper (Line)).y (1), 3, 3, black)
        if c > 2 then
            for i : 2 .. c - 1
                Draw.Line (Line (upper (Line)).x (i),
                    Line (upper (Line)).y (i),
                    Line (upper (Line)).x (i - 1),
                    Line (upper (Line)).y (i - 1), black)
                Draw.FillOval (Line (upper (Line)).x (i), Line (upper (Line)).y (i), 3, 3, black)
            end for
        end if
        Draw.Line (Line (upper (Line)).x (c - 1), Line (upper (Line)).y (c - 1), mx, my, black)
        View.Update
        delay (50)
    end if
    if c = poly+1 then
        cls
        new Line, upper (Line) + 1
        click
        Draw.FillPolygon (Line (upper (Line)).x, Line (upper (Line)).y, upper (Line (upper (Line)).x), grey)
        c := 1
        %new Line, upper (Line) + 1
    end if
    if ch (KEY_CTRL) and ch ('z') and upper (Line) > 1 and c = 1 then
        new Line, upper (Line) - 1
        c := 1
        cls
        click
        delay (500)
        Input.Flush
    end if
    /* REDO COMMAND It works but its dangerous.
     if ch (KEY_CTRL) and ch ('y') and upper (Line) > 1 and c = 1 then
     new Line, upper (Line) + 1

     c := 1
     cls
     locate (1, 1)
     put upper (Line)
     click
     delay (500)
     Input.Flush
     end if
     */
end loop
cls

var f : int
open : f, "Coor.txt", put
for i : 1 .. upper (Line) - 1
    Draw.FillPolygon (Line (i).x, Line (i).y, upper (Line (i).x), grey)
    View.Update
    %Input.Pause
    for ii : 1 .. 4
        put : f, Line (i).x (ii), " ", Line (i).y (ii), " | " ..
    end for
    put : f, ""
end for
close : f
Sponsor
Sponsor
Sponsor
sponsor
that-guy




PostPosted: Thu Apr 03, 2008 5:13 pm   Post subject: Re: A Map Maker

I don't mean to be mean here or anything but there are a lot of things in this code that I know a more efficient way of doing. Also, when you save to file, use the write command. Writing works much faster than putting. (Use an array with it).

good job though i guess.
Tony




PostPosted: Thu Apr 03, 2008 7:02 pm   Post subject: Re: A Map Maker

that-guy @ Thu Apr 03, 2008 5:13 pm wrote:
there are a lot of things in this code that I know a more efficient way of doing.

This is where you list what those things are...
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Tallguy




PostPosted: Tue Apr 15, 2008 9:50 am   Post subject: RE:A Map Maker

thats a cool idea, good job, i can several ways u can apply this to different programs
r.m_spy




PostPosted: Sat Apr 19, 2008 7:45 pm   Post subject: RE:A Map Maker

I don't understand what this is for?
darkangel




PostPosted: Sun Apr 20, 2008 5:03 pm   Post subject: Re: A Map Maker

Basically lets say you wanted to make a overhead shooter game.

Instead of making a picture and doing the very inefficient whatdotcolor() method of collision, you are able to do Math() functions because you know the corners (points) of your obstacles.

plus if you want to make lots of maps for your overhead shooter, whats going to be easier to distribute? A 5-10 kb file? or a 5-10mb BMP?
(my overhead shooter uses big maps too)
Nick




PostPosted: Sun Apr 20, 2008 5:08 pm   Post subject: RE:A Map Maker

maybe I'll put my map maker on soon
darkangel




PostPosted: Sun Apr 20, 2008 5:09 pm   Post subject: Re: RE:A Map Maker

nick @ Sun Apr 20, 2008 5:08 pm wrote:
maybe I'll put my map maker on soon

maybe you should.
Sponsor
Sponsor
Sponsor
sponsor
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 1  [ 8 Posts ]
Jump to:   


Style:  
Search: