+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: [egp]Minesweeper-WIP

  1. #1
    Wire Sofaking feha's Avatar
    Join Date
    Sep 2009
    Location
    Here
    Posts
    1,156

    Default [egp]Minesweeper-WIP

    Ok, some of you have probably already seen me work on my minesweeper at unsmarts (ok srv, and one of the few that got egp). Some of you probably also got annoyed by me physgunning you to the ctrl chair.

    Anyway, I have got it to a phase where it is very playable, it got the "bg", mine count, timer, cell and mine placement and is interactive. I made it possible to create "flags" and a check for winning (and loosing on clicking a mine XD). Even the restart works XD.

    To do is fixing minor bugs, adding a menu for entering field size and number of mines, instead of doing that in code and maybe a high-score list.

    Code:
    @name EGP-Minesweeper
    @inputs EGP:wirelink
    @outputs Started Lost
    @persist UserAllow BoxSize Surround Size Mine Max StartTime Started Lost SafeCount
    @persist [Cell Safe Open Hover]:array [Screen Pod]:entity
    @persist FillCount
    
    #First stuff
    if (first()) {
        runOnTick(1)
        Size = 5
        Mine = 5
        Max = maxOfType("wire_egp_elements")
        Pod = entity():isWeldedTo()
        Screen = EGP:entity()
        EGP:egpClear()
        EGP:egpBox(1,0,0,512,10,200,200,200,255)
        EGP:egpBox(2,0,0,10,512,200,200,200,255)
        EGP:egpBox(3,0,502,512,10,200,200,200,255)
        EGP:egpBox(4,502,0,10,512,200,200,200,255)
        EGP:egpBox(5,10,10,492,75,150,150,150,255)
        EGP:egpBox(6,0,85,512,10,200,200,200,255)
        EGP:egpBox(7,10,95,492,407,150,150,150,255)
        EGP:egpBox(8,20,20,100,55,0,0,0,255)
        EGP:egpBox(9,392,20,100,55,0,0,0,255)
        EGP:egpBox(10,227.5,20,55,55,0,150,0,255)
        String = (Mine-SafeCount):toString()
        EGP:egpText(11,"0":repeat(3-String:length())+String,20,15,255,0,0,255)
        EGP:egpSetFont(11,"arial",70)
        EGP:egpText(12,"000",392,15,255,0,0,255)
        EGP:egpSetFont(12,"arial",70)
        EGP:egpCircle(Max+1,255,255,10,10,0,255,0,255)
        timer("new",10)
        timer("unglitch",1000)
    }
    
    #Get user
    User=Pod:driver()
    
    #Unglitch odd glitch tied to using
    if (clk("unglitch")) {
        UserAllow = 1
    }
    
    #Start a new game
    if (clk("new")) {
        Cell = array()
        Safe = array()
        Open = array()
        Hover = array()
        #fix arrays so I can loop using :count()
        for (I=0,Size^2-1) {
            Hover[I,number]=0
        }
        for (I=0,Size^2-1) {
            Open[I,number]=0
        }
        #end of fix
        I=1
        while (I <= Mine) {
            Pos = randint(1,Size^2-1)
            if (!Cell[Pos,number]) {
                Cell[Pos,number]=1
            } else {
                I--
            }
            I++
        }
        FillCount = 0
        RowCount = Size
        BoxY=0
        BoxX=0
        Lost = 0
        Started = 0
        timer("fill",10)
    }
    
    #fill the field with cells
    if (clk("fill") & FillCount < Size^2) {
        BoxSize = 397/Size
        BoxX = (492-BoxSize*Size)/2+(FillCount%Size)*BoxSize
        BoxY = floor(FillCount/Size)*BoxSize
        EGP:egpBox(15+FillCount,10+BoxX,100+BoxY,BoxSize-5,BoxSize-2,200,200,200,255)
        FillCount++
        timer("fill",0)
    }
    
    #Unhover cells
    for (I=0,Hover:count()) {
        if (Hover[I,number] & !Open[I,number]) {
            BoxX = (492-BoxSize*Size)/2+(I%Size)*BoxSize
            BoxY = floor(I/Size)*BoxSize
            if (!Safe[I,number]) {
                EGP:egpBox(15+I,10+BoxX,100+BoxY,BoxSize-5,BoxSize-2,200,200,200,255)
            } else {
                EGP:egpBox(15+I,10+BoxX,100+BoxY,BoxSize-5,BoxSize-2,0,0,255,255)
            }
        }
    }
    
    #mine count and time
    if (Started & !Lost & clk("on")) {
        if (SafeCount < Mine) {
                String = (Mine-SafeCount):toString()
        } else {
            String = "000"
        }
        EGP:egpText(11,"0":repeat(3-String:length())+String,20,15,255,0,0,255)
        EGP:egpSetFont(11,"arial",70)
        Time = floor(curtime()-StartTime):toString()
        EGP:egpText(12,"0":repeat(3-Time:length())+Time,392,15,255,0,0,255)
        EGP:egpSetFont(12,"arial",70)
        
        #Win!!!
        for (I=0,Open:count()) {
            if (!Open[I,number]) {
                if (!Cell[I,number]) {
                    break
                }
            } elseif (I == Open:count()) {
                print("blah")
                Started = 0
            }
        }
        
        timer("on",100)
    }
    
    #Interact
    if (UserAllow & User:aimEntity() == Screen) {
        Pos2=floor((vec2(Screen:toLocal(User:aimPos()))+vec2(29,37))*(1/0.1835))
        Pos = floor(Pos2:y()/BoxSize+1)+Size*floor(Pos2:x()/BoxSize)-1
        BoxX = (492-BoxSize*Size)/2+(Pos%Size)*BoxSize
        BoxY = floor(Pos/Size)*BoxSize
        CursorPos=floor((vec2(Screen:toLocal(User:aimPos()))+vec2(47,47))*(1/0.1835))
        EGP:egpCircle(13,CursorPos:y(),CursorPos:x(),10,10,0,255,0,255)
        if (Pos == -3 & changed(User:keyAttack1()) & User:keyAttack1()) {
            timer("new",10)
        }
        if (!Lost & inrange(Pos2,vec2(0,0),vec2(397,397))) {
            if (!Open[Pos,number] & inrange(Pos,0,Size^2-1)) {
                Hover[Pos,number]=1
                if (!Safe[Pos,number]) {
                    EGP:egpBox(15+Pos,10+BoxX,100+BoxY,BoxSize-5,BoxSize-2,225,225,225,255)
                } else {
                    EGP:egpBox(15+Pos,10+BoxX,100+BoxY,BoxSize-5,BoxSize-2,0,0,200,255)
                }
            }
            if (changed(User:keyAttack1()) & User:keyAttack1()) {
                if (!Started) {
                    Started = 1
                    StartTime = curtime()
                    timer("on",100)
                }
                if (inrange(Pos,0,Size^2-1) & !Safe[Pos,number]) {
                    Col = Pos%Size
                    Open[Pos,number]=1
                    if (Cell[Pos,number]) {
                        Lost = 1
                        EGP:egpBox(15+Pos,10+BoxX,100+BoxY,BoxSize-5,BoxSize-2,255,0,0,255)
                    } else {
                        I = -1
                        while (I<=1) {
                            if (Col == 0) {
                                Surround+=Cell[Pos+(I*Size),number]
                                Surround+=Cell[Pos+1+(I*Size),number]
                            } elseif (Col == Size-1) {
                                Surround+=Cell[Pos-1+(I*Size),number]
                                Surround+=Cell[Pos+(I*Size),number]
                            } else {
                                N = -1
                                while (N<=1) {
                                    Surround+=Cell[Pos+N+(I*Size),number]
                                    N++
                                }
                            }
                            I++
                        }
                        EGP:egpText(15+Pos,Surround:toString(),10+BoxX,100+BoxY,0,0,255,255)
                        EGP:egpSetFont(15+Pos,"arial",BoxSize)
                        Surround=0
                    }
                }
            } elseif (changed(User:keyAttack2()) & User:keyAttack2()) {
                if (inrange(Pos,0,Size^2-1)) {
                    if (!Open[Pos,number]) {
                        if (Safe[Pos,number]) {
                            EGP:egpBox(15+Pos,10+BoxX,100+BoxY,BoxSize-5,BoxSize-2,200,200,200,255)
                            Safe[Pos,number]=0
                            SafeCount--
                        } else {
                            EGP:egpBox(15+Pos,10+BoxX,100+BoxY,BoxSize-5,BoxSize-2,0,0,255,255)
                            Safe[Pos,number]=1
                            SafeCount++
                        }
                    }
                }
            }
        }
    }
    
    EGP:egpDraw()
    This is for the egp, so dont even try using it with console screens XD.

    EDIT: I was a bit tired yesterday, so I forgott to say how to make it work. Spawn the egp, a pod and slap the e2 on said pod. Then give egp a wirelink and wire the e2 to the egp. Profit!

    EDIT2:
    Due to popular demand I took some pictures of it. As you can see by hud it was on unsmarts, and due to ppl chattign and I wanting stuff away from chat, it took 100 seconds to take the last 2 pictures XD. I havent added a pause for stepping out, as then it would be easy :S.

    The holo is from my holo painter, so you wouldnt see disturbing stuff.
    Attached Thumbnails Attached Thumbnails [egp]Minesweeper-WIP-freespace_revolution0003.jpg   [egp]Minesweeper-WIP-freespace_revolution0004.jpg   [egp]Minesweeper-WIP-freespace_revolution0005.jpg   [egp]Minesweeper-WIP-freespace_revolution0006.jpg  
    Last edited by feha; 12-17-2009 at 09:26 AM.

  2. #2
    goluch
    Guest goluch's Avatar

    Default Re: [egp]Minesweeper-WIP

    Sweet!

  3. #3
    Wire Sofaking N00bDud3's Avatar
    Join Date
    Jul 2009
    Location
    Error: Unknown Location
    Posts
    1,252

    Default Re: [egp]Minesweeper-WIP

    No piccy no clicky



  4. #4
    Wire Sofaking SystemsLock's Avatar
    Join Date
    Mar 2009
    Posts
    474

    Default Re: [egp]Minesweeper-WIP

    Sounds cool, pics please?
    Make a Small Loan, Make a Big Difference - Check out Kiva.org to Learn How!

  5. #5
    hurrr physics Tolyzor's Avatar
    Join Date
    Aug 2008
    Location
    England
    Posts
    1,019

    Default Re: [egp]Minesweeper-WIP

    I had a go or two on this on unsmart's server, it is frikken awesome. Just call it a gmod port of minesweeper tbh.

  6. #6
    Wire Sofaking Rybec's Avatar
    Join Date
    Apr 2008
    Location
    Denver
    Posts
    648

    Default Re: [egp]Minesweeper-WIP

    Ahaha, nice. Should also make it auto-clear squares around 0s, like the real thing.

    A right-click to clear adjacent squares if the right number of them are flagged would be nice, too.

    Great job.

  7. #7
    Wire Sofaking ryland's Avatar
    Join Date
    Oct 2009
    Location
    Card bord box next to wal-mart.
    Posts
    594

    Default Re: [egp]Minesweeper-WIP

    I was just playing with this on NikoKun's server, it was freaking awesome.
    We finally beat it, but it was fun.
    Good job.
    "I like pie"-Jat Goodwin

    <Azrael-> ryland: LOL is such a noobish thing to say.
    <ryland> LOL
    <Fox682> LOLLOL
    <Fox682> LOL
    <ryland> LOL

  8. #8
    Wire Sofaking feha's Avatar
    Join Date
    Sep 2009
    Location
    Here
    Posts
    1,156

    Default Re: [egp]Minesweeper-WIP

    Ryland, dont tell me you find a 5*5 mine sweper game hard o_O...

    And I guess I should add pics.

    About opening around 0's, I will not do that, it is already quite ops heavy, as a 10*10 field likes to reach tick quota (prolly caused by hover code executing every tick, looping trough all not opened squares). Not to mention it would be quite much code for that (I am lazy XD).

    About pressign and opening adjecent squares, read above. Both things would require that I code a way to start going trough adjecent squares like I go trough the opened square right now. It takes both less ops and code if the player just click those squares fast (fyi you dont have to wait for graphics to catch up, the code can open one square each tick, the screen updates all the changes every egp-frame anyway).

  9. #9
    Wire Sofaking Unsmart's Avatar
    Join Date
    Dec 2008
    Location
    Belgium OR BANland
    Posts
    1,965

    Default Re: [egp]Minesweeper-WIP

    Its nice, but I hate minesweeper, i always loose
    New server IP: 89.238.160.17:27018
    Hologram contraptions 1 Holo contraptions 2 EGP stuff Holo minigun Holo javelin rocket launcher
    Unsmart: I doubt the intelligence of some people.
    Drunkie: Nobody could have said that any better than Unsmart.

    Unsmart: Solece, I totally did your mom yesterday
    Solece: Who hasnt

    Divran: there are more retarded people than there are clever people in this world

  10. #10
    Wire Sofaking ShadowBrain's Avatar
    Join Date
    Oct 2008
    Location
    Where you live.
    Posts
    910

    Default Re: [egp]Minesweeper-WIP

    Whats with all the people creating EGP stuff not putting up pics or a vid or anything?
    I maek 3D mdoels adn paly veido gaems!

+ Reply to Thread
Page 1 of 2 12 LastLast

LinkBacks (?)

  1. 01-27-2010, 03:13 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots