Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Challenges?

edited July 2012 in General Posts: 68

I'm new-ish to Codea and I've started about a million projects that start off with a certain goal (The one I've gone farthest in is having a virtual pet, where you name it and make sure it gets fed or it dies) but I always end up wondering what new additions to add to those projects and I work on the additions so much they become their own projects.

Basically an endless cycle of me never truly completeing anything. I really enjoyed learning with those little challenges that Simeon had written in a discussion ( this one: http://twolivesleft.com/Codea/Talk/discussion/comment/9791#Comment_9791) and I was wondering if you guys could kinda come up with a list of increasingly difficult little projects in order to go from noob to moderately well. Projects that teaches noobs new ways of doing things like using meshes instead of sprites, in order to use in future projects :)

Just being hopeful.

Comments

  • Posts: 179

    I had this idea to issue a weekly programming challenge, with a sort of deadline for entry. Everyone who was interested could complete it and help each other through the week. Then on the final day everyone could post their code and you could see how others tackled the same problem you did, and maybe it would teach you how to think like an advanced programmer.

    The reason I never have done so is that I've wondered if anyone would care or even want to. It's not like a programming contest where I could really offer a prize, and who would judge the entries? Maybe I will try sometime anyway and see if anyone tries it.

  • Posts: 68

    Sounds great! You don't need prizes, it sounds like it would be the perfect hands-on learning experience that some people need! I suggest you get a trial run working as soon as you can because I'm itiching to see this in action :)

  • edited July 2012 Posts: 68

    You know I'm kinda in a Codea coding mode so if you have a small challenge off the top of your head (keep in mind that I still sometimes struggle with basic stuff like multi-touch) that would be great for today XP

  • Posts: 179

    Alright, here are two challenge paths for people who are newer to Codea:

    Dice Roller-
    Challenge1: When the player touches the screen, make a random number between 1 and 6 and print it using the print function.
    Challenge 2: Now make it draw to the screen when the player touches the die, and update the die to the show the new face number. You can either use shapes like ellipse and rectangle to draw them, or import custom dice drawings using Dropbox.
    Challenge 3: Make that code into a dice CLASS, which will allow you to easily add as many dice as you want to your project (or any future project.). Make it so the dice only roll if you touch on the die.

    Whack-A-Mole (er bug):
    Challenge 1: Use sprite to draw a bug (you can use the enemy bug sprite) to the screen. When the screen is touched, make the bug disappear.
    Challenge 2: Now make it so that the bug appears in a random location on screen. Make it so that if you touch the screen the bug will move to a new random location.
    Challenge 3: Now make multiple bugs that move when you touch them (maybe 5 on screen a t once.) It may be a good idea to use a CLASS for bugs now to store their locations, but it can be done without classes. Program it so that the user has to touch directly on the bug to make it disappear and move.
    Challenge 4: Create a score variable, and add points to it every time a bug is touched. Display the score on screen.
    Challenge 5: Create a timer and make it count down, when 0 is reached, display a new screen with the score. If the user touches the screen from here it should start the game over. You may need to see the state machine tutorial by @Reefwing.
    Challenge 6: Add sounds. When the game starts, a bug is touched, or the game is over, make it play a sound.
    Challenge 7: make it so that the bugs move automatically if not touched with 1 or 2 seconds. This should make the game more fun and challenging.

    If you decide to try one of those, let me know how it goes. Good luck.

  • Posts: 68

    Just woke up. On it

  • Posts: 68

    Darn it I am so code challenged. I'm having trouble with Dice Roller's Challenge 3.
    To touch a certain part of the screen only I would always use this one code that I learned in another Discussion:

    //the position of my dice as defined in Dice:init() is a vec2 called SELF.POS so...
    function point(x,y)
        if x < (self.pos.x + self.width/2) and
        x > (self.pos.x - self.width/2) and
        y < (self.pos.y + self.height/2) and
        y > (self.pos.y - self.height/2) then
            return true
        end
        return false
    end
    
    function Dice:touched(touch)
        if point(touch.x, touch.y) and touch.state == ENDED then
            self.number = math.random(1,6)
            print(self.number)
        end
    end
    

    If there's something easier than that plz let me know.

    But this code only works with the most recent dice and when touched all the dice have the same number.

    So how do I go about doing Challenge 3? (God I suck at this >< )

  • Posts: 68

    How do I make multiple instances of a Class but give them different locations? Can it only be done using tables or something?

  • Posts: 176

    Tables are the best way to accomplish this. Look up ipairs to iterate through them.

  • Posts: 179

    Don't beat yourself up, that code looks correct and should work. Maybe the issue is with how you are storing / calling the dice. I would guess that your main setup has some code that looks like:

    dice = {}
    newDie = Dice(100,100) --Or however your init looks 
    table.insert(dice, newDie)
    newDie = Dice(300,100)
    table.insert(dice, newDie)
    -- Now we have a table of dice that contains 2 dice.
    

    And then in your main touched function you might have

    touched(touch)
        for _,die in pairs(dice) do
            die:touched(touch)
        --That calls the touched function of each die.
        end
    end
    
  • edited July 2012 Posts: 68

    What do I put in the draw function to get the table drawn?
    Because Dice:draw() only draws one dice


    function setup()     print("Hello World!")     dice = {}     newDie = Dice:init(math.random(1,WIDTH),math.random(1,HEIGHT))     table.insert(dice,newDie)     newDie = Dice:init(math.random(1,WIDTH),math.random(1,HEIGHT))     table.insert(dice,newDie) end -- This function gets called once every frame function draw()     -- This sets a dark background color      background(40, 40, 50)     -- This sets the line thickness     strokeWidth(5)     -- Do your drawing here for _,v in ipairs(dice) do v:draw() end end
  • Posts: 2,161
    for _,v in ipairs(dice) do
        v:draw()
    end
    
  • Posts: 68

    I did it exactly as you said and nothing's appearing on screen anymore :(

  • Posts: 179

    The issue is probably in your Dice:draw() function. You might need to post that code so we can see whats going on.

  • Posts: 68

    It shouldn't be :/ it's uber simple:


    Dice = class() function Dice:init(x,y)     -- you can accept and set parameters here     self.pos = vec2(x,y) end function Dice:draw()     -- Codea does not automatically call this method     stroke(0,0);strokeWidth(10)     fill(255);rectMode(CENTER)     rect(self.pos.x,self.pos.y,150,150) end function Dice:touched(touch)     -- Codea does not automatically call this method end
  • Posts: 179

    Okay, sorry, I see it now, small syntax error. In your main, you shouldn't call init directly, it is the constructor. All you have to do is delete

    :init
    

    Twice from the setup function. So the code should look like:

        print("Hello World!")
        dice = {}
        newDie = Dice(math.random(1,WIDTH),math.random(1,HEIGHT))
        table.insert(dice,newDie)
        newDie = Dice(math.random(1,WIDTH),math.random(1,HEIGHT))
        table.insert(dice,newDie)
    

    And voila.

  • Posts: 68

    It worked! I had added the ":init" because I thought you had simply forgotten to put it in :)
    I don't understand, though. If you don't tell the code to put the two math.randoms in the initiate then how does it know that's where the variables go?

  • Posts: 179

    Init is a special function called a "constructor." The constructor is automatically called when an object is created and receives the parameters that you pass in upon object creation.

  • Posts: 68

    Thanks! Now that i'm armed with this new piece of coding I can also tackle part 3 of the Whack-A-Mole (er, bug) challenge!

  • edited July 2012 Posts: 68

    @Vega Lol, can't get my High Score past 97 whacks :P
    Another challenge please :)

  • Posts: 179

    Nice, @RichGala1. Seems like you had a successful day of coding. This isn't really a challenge, but you might want to learn about 2d transformations (i.e. matrix transformations) which most of use use a lot for drawing in our games. A good way to learn is to do this tutorial written about 2d transforms in Processing (a different programming language), and translate the code to Codea code to test:

    http://processing.org/learning/transform2d/

    The Processing code is extremely similar to Codea, making it easy to translate. Be aware that all calls of the size() function can be ignored, and there is no triangle function in Codea, so you have to draw 3 lines instead.

    And if you would like to learn about meshes, which are very useful for making graphics intensive games, you may want to check out the Mesh tutorial on the Codea wiki, written by yours truly:

    https://bitbucket.org/TwoLivesLeft/codea/wiki/mesha

    Once you get all that down, you should be ready to handle about anything. Maybe I can think of something more intermediate level for you, or maybe someone else on here has some ideas.

  • edited July 2012 Posts: 68

    Good mesh tutorial. The matrix transformations was interesting but I can't think of why I would use it.

    EXCELLENT start-up challenges, by the way. Thanks to you I learned something valuable. I don't want to keep taking away ur time and challenge ideas so I guess I'll start a new project. Tnx!

Sign In or Register to comment.