Howdy, Stranger!

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

I've got a lot of questions but I can help in return

edited January 2017 in Questions Posts: 19

So I'm terrible at this. I tried plugging someone's clock into my game to start a varying sequence when after 225 overall clicks if there's been less then 15 seconds between clicks the player will go into a more captain falcon like punch sequence. I plan on making a cookie clicker wario ware hybrid. Cookie clicker to level up for a punch out like game that will both give you access to unlocking mini games I've been making to test mechanics. I've got much moreover want to do but I feel like this is a reasonable goal. This is my main chunk of code and I know I'm formatting it wrong to post but I'm not quite sure how to. The Sprite cycled fine before the clock. The reason for the break in the else if and the logical listing is to draw the hand behind the punching bag at times. I have animations I have in mind for the bag but I'm using a static until I work out animations and the track for the main Sprite the timer and counters.


-- Punchies_00.01 function draw() --supportedOrientations(LANDSCAPE_ANY) --displayMode(FULLSCREEN) noFill() noSmooth() noStroke() pushStyle() background(210, 146, 146, 255) if player == punch_a then sprite(nanner_pa,WIDTH/2,HEIGHT/2, 256, 256) elseif player == punch_b then sprite(nanner_pb,WIDTH/2,HEIGHT/2, 256, 256) end sprite(pbag_a, WIDTH/2,HEIGHT/2, 256,256) if player == idle_a then sprite(nanner_a,WIDTH/2,HEIGHT/2, 256, 256) elseif player == idle_b then sprite(nanner_b,WIDTH/2,HEIGHT/2, 256, 256) elseif player == punch_c then sprite(nanner_pc,WIDTH/2,HEIGHT/2, 256, 256) elseif player == punch_d then sprite(nanner_pd,WIDTH/2,HEIGHT/2, 256, 256) elseif player == punch_2a then sprite(nanner_p2a,WIDTH/2,HEIGHT/2, 256, 256) elseif player == punch_2b then sprite(nanner_p2b,WIDTH/2,HEIGHT/2, 256, 256) elseif player == punch_2c then sprite(nanner_p2c,WIDTH/2,HEIGHT/2, 256, 256) elseif player == punch_2d then sprite(nanner_p2d,WIDTH/2,HEIGHT/2, 256, 256) end end function timer(s) if s~=nil then et=ElapsedTime+s clock = true end if et-5<ElapsedTime then clock = false end end function touched(touch) --- score if punches == 15 then print ("1") end if punches > 15 then punches = punches - punches end --- input if touch.state == BEGAN and player == idle_a then player = punch_a end if touch.state == BEGAN and player == idle_b then player = punch_a end if touch.state == BEGAN and player == punch_d then player = punnch_a end if touch.state == ENDED and player == punch_a then player = punch_b end if touch.state == BEGAN and player == punch_b then player = punch_c end if touch.state == ENDED and player == punch_c then player = punch_d end if touch.state == ENDED then punches = punches + 1 focus = focus + 1 end if punches == 15 then powerlevel = powerlevel + 1 end if touch.state == BEGAN then timer(20) end end

Here's a quick snapshot of my sprites. I can art in exchange for some help.
http://tinypic.com/r/14uvx1t/9

Tagged:

Comments

  • dave1707dave1707 Mod
    Posts: 7,605

    @Dean To post code, put 3 ~'s on a line before and after the code. I added them to your code. I'll look at your code later when I have more time.

  • @Dean Just looking at your code, I can already see that there is no setup function, and the images will most likely produce an error because your giving a nil image, is there a setup function in your application so I can run it?

  • dave1707dave1707 Mod
    edited January 2017 Posts: 7,605

    @Dean You need to move the timer check outside of the touched function. See the example code where I have the comment check if timer has expired. You were checking if the time expired only if a touch began, which also started the timer again. So the timer would never expire. By moving the check into the draw function, it's being checked every draw cycle and will eventually expire if a touch wasn't detected.

    function setup()
        et=0
    end
    
    function draw()    
        background(0)
        fill(255)
        text("Tap screen to start timer.",WIDTH/2,HEIGHT-50)
    
        if et<ElapsedTime then  -- check if timer has expired
            clock = false
        end
    
        if clock then
            text("TIMER  "..math.floor(et-ElapsedTime+1),WIDTH/2,HEIGHT/2)
        end
    end
    
    function timer(s)
        if s~=nil then
            et=ElapsedTime+s
            clock = true
        end
    end
    
    function touched(touch)    
        if touch.state == BEGAN then
            timer(15)
        end
    end
    
  • Posts: 19

    I was trying to get the timer only to reset into the idle animation if it wasn't currently in the middle of a punch. It will loop the rest animation and take the sprite out of the attack sequence fine. I couldn't get the sprite to stay in windup punch_c/d though, so I swapped idle_b to go into punch_c to keep the Sprite from throwing one punch much more frequently than the other. I wanted the punch_2 sequence to last until the timer runs out. The timer resets every touch because it's meant to reflect exercising. I decided on 15 seconds between repitions to represent cooling down. Just like working out the more you stay at it the more you'll feel it and see results. I have the flashier attack sequence to encourage to just mindlessly click. I plan on using the power level to control the characters stats once I start figuring out a punch out like game. I'm thinking a bunch of areas that either calculate towards a win when touching happens and some that bring you closer to losing. The ai I just need to think of a way to react to the player or patterns that can have variables caused by the player. I've got some tilt and jab controls working, as well as swipe and tap, and a mixture of them. If you guys want I can get the sprite sheet loaded up so you can see what I'm doing.

    I'm a bit slow with everything. I'm still wanting to go back and fix the stepping pattern.

    I have a two player first to 15 version gets their finisher and resets both counters. The finishers all play the same frames as attacks for all the sprites like that so I could have them flow into the next round in the endlessly cycle. One has a magic tuba one has a barrage of flaming fist.

    I plan on adding things with buttons that can be bought with some form of currency. Things like free weights to give idle points and maybe have it load a new idle if it's idled for awhile. Upgrade paths for the punches or something like that, maybe a kick frame that will randomly play when you click for an extra punch. I feel like I can manage the upgrades bits. I plan on also animating a more punch out style sprite for the boxers. I have a comic I decided to turn into games so I've got a plethora of characters to animate once I get there.

    Sprite list

    nanner_a = "Project:nanner_a"
    nanner_b = "Project:nanner_b"
    nanner_pa = "Project:nanner_pa"
    nanner_pb = "Project:nanner_pb"
    nanner_pc = "Project:nanner_pc"
    nanner_pd = "Project:nanner_pd"
    nanner_p2a = nanner_pa
    nanner_p2b = "Project:nanner_p2b"
    nanner_p2c = "Project:nanner_p2c"
    nanner_p2d = "Project:nanner_p2d"
    
    pbag_a = "Project:pb_a"
    pbag_b = "Project:pb_b"
    level_1 = "Project:test room"
    

    What I sync the sprites to plus some things to hold values

    idle_a = 0
    idle_b = 2
    punch_a = 3
    punch_b = 4
    punch_c = 5
    punch_d = 6
    punch_2a = 7
    punch_2b = 8
    punch_2c = 9
    punch_2d = 10
    
    player = idle_a
    pbag = pbag_a
    

    All the rest of the junk

    -- Punchies_00.01
    function setup()
       delay = 0
       score = 0 
       punches = 0
    end
    
    function draw()
    
        --supportedOrientations(LANDSCAPE_ANY)
        --displayMode(FULLSCREEN) 
        noFill()
        noSmooth()
        noStroke()
        pushStyle()
    
       background(210, 146, 146, 255)
       sprite(level_1, WIDTH/2 - 44,HEIGHT/2, 256,256)
    
       addscore()
    
            if player == idle_a then
            sprite(nanner_a,WIDTH/2,HEIGHT/2, 256, 256)
            end
            if player == idle_b then
            sprite(nanner_b,WIDTH/2,HEIGHT/2, 256, 256)
            end
            if player == punch_a then
            sprite(nanner_pa,WIDTH/2,HEIGHT/2, 256, 256)
            end
            if player == punch_b then
            sprite(nanner_pb,WIDTH/2,HEIGHT/2, 256, 256)
            end
            if pbag == pbag_a then
            sprite("Project:pb_a", WIDTH/2,HEIGHT/2, 256,256)
            end
            if pbag == pbag_b then
            sprite("Project:pb_b", WIDTH/2,HEIGHT/2, 256, 256)
            end
            if player == punch_c then
            sprite(nanner_pc,WIDTH/2,HEIGHT/2, 256, 256)
            end
            if player == punch_d then
            sprite(nanner_pd,WIDTH/2,HEIGHT/2, 256, 256)
            end
            if player == punch_2a then
            sprite(nanner_p2a,WIDTH/2,HEIGHT/2, 256, 256)
            end
            if player == punch_2b then
            sprite(nanner_p2b,WIDTH/2,HEIGHT/2, 256, 256)
            end
            if player == punch_2c then
            sprite(nanner_p2c,WIDTH/2,HEIGHT/2, 256, 256) 
            end
            if player == punch_2d then
            sprite(nanner_p2d,WIDTH/2,HEIGHT/2, 256, 256)
            end
    
    
    
    function touched(touch)
    
    
            if touch.state == BEGAN and
            player == idle_a then
            player = punch_a 
            end
            if touch.state == BEGAN and
            player == idle_b then
            player = punch_c 
            end
            if touch.state == BEGAN and
            player == punch_d then
            player = punch_a
            end
            if touch.state == ENDED and
            player == punch_a then
            player = punch_b
            punches = punches +1
            end
            if touch.state == BEGAN and
            player == punch_b then
            player = punch_c
            end
            if touch.state == ENDED and
            player == punch_c then
            player = punch_d
            punches = punches + 1
            end
    
            if touch.state == BEGAN and
            player == punch_2d then
            player = punch_2a
            end
            if touch.state == ENDED and
            player == punch_2a then
            player = punch_2b
            punches = punches +3
            end
            if touch.state == BEGAN and
            player == punch_2b then
            player = punch_2c
            end
            if touch.state == ENDED and
            player == punch_2c then
            player = punch_2d
            punches = punches + 3
            end
    
            if punches == 15 then
            score = score + 1
            punches = 0 
            pbag = pbag_b
            player = punch_2a
            end
        end
    end
    
    function addscore() 
    
            delay = delay + 1
            if delay > 60 then
            delay = 0
            end
            if delay == 30 or
            delay == 60 then
            pbag = pbag_a
            end
            if delay == 0 or
            delay == 30 then
            player = idle_a
            end
            if delay == 15 or
            delay == 45 then
            player = idle_b
            end 
    
    end
    
  • Posts: 19

    This is week three for me. I've just been winging it so I know I'm doing a lot wrong more than likely.

  • dave1707dave1707 Mod
    Posts: 7,605

    @Dean In my example, I was just showing how the timer was supposed to work. I'm not sure what you're exactly doing in your code, but you would start the timer or timers with some type of event. In the draw function which runs at 60 times per second, you would check each timer or timers to see if they expire. If any timer expires you set a flag that you check elsewhere in your code to control what you're doing. Normally I don't bother to run someone else's code if I have to mess around with loading sprites. So I usually look thru the code to see if there's any obvious errors, in your case, you weren't checking properly if the timer expired. Once you understand how to control the timer, then you shouldn't have any trouble coding how you want to use it. You can have one or multiple timers to control whatever you want.

  • Posts: 19

    @dave1707 so I've been using a clock that runs off from giving a constant value between 0 and 60 I can call on. My issue I've ran into is my lack of knowledge like you've pointed out. I know I can shorten code I've written but I'm not sure if that helps with any issues I'm facing. Looking through here just about everyone animates sprites completely different than I have been and I can't seem to get those ways to work, because I don't know the entirety of the language. I can't seem to get the positioning to change in increments of 26 pixels without it randomly jumping around the screen sometimes. Do you know of any resources I could look up terms? I don't understand a lot and I'm not sure where to look for resources.

    The game cycles through left and right jabs and if you can maintain it without releasing on a reset trigger like keeping momentum in working out there's more of an effect. That's the punch_2 reason it animates differently as well. I have some stuff ripped out that animates lifting weights if weights are purchased and punching the punching bag. Once I get walking down I was going to have random chance off the clock to use the objects if the sprite x and y lines up with the object he'll go into a sequence and tapping at any point I feel I could simple have a touch state reset everything and begin sequences from each point to bring the character to the punching bag in two seconds ready to punch for the next ten seconds.

    Kinda like a tomagatchi/cookie clicker fighter I want to transition into a punch out game

    -- Punchies_00.01 (pocket boxers?)
    
    -- keeps tracks of my frames and animations
    function setup()
       delay = 0
       score = 0 
       punches = 0
       idle = 0
       wander = 0
       cycle = 0 --12
    end
    
    function draw()
    
        --supportedOrientations(LANDSCAPE_ANY)
        --displayMode(FULLSCREEN) 
        noFill()
        noSmooth()
        noStroke()
        pushStyle()
    
       background(210, 146, 146, 255)
       sprite(level_1, WIDTH/2 ,HEIGHT/2, 256,256)
    
       addscore()
    --- what determines wander animation placement
       c_pos = pos5
    ---cycles through wandering positions        
            if cycle == 1 then
            c_pos = pos5 elseif
            cycle == 2 then
            c_pos = pos4 elseif
            cycle == 3 then
            cpos = pos3 elseif
            cycle == 4 then
            cpos = pos2 elseif
            cycle == 5 then
            c_pos = pos5 elseif
            cycle == 6 then
            c_pos = pos4 elseif
            cycle == 7 then
            cpos = pos3 elseif
            cycle == 8 then
            cpos = pos2 elseif
            cycle == 9 then
            c_pos = pos1
            end
    
    ---punch/wander animations and sandbag  
            if player == idle_a then
            sprite(nanner_a,WIDTH/2,HEIGHT/2, 256, 256)
            end
            if player == idle_b then
            sprite(nanner_b,WIDTH/2,HEIGHT/2, 256, 256)
            end
            if player == punch_a then
            sprite(nanner_pa,WIDTH/2,HEIGHT/2, 256, 256)
            end
            if player == punch_b then
            sprite(nanner_pb,WIDTH/2,HEIGHT/2, 256, 256)
            end
            if pbag == pbag_a then
            sprite("Project:pb_a", WIDTH/2,HEIGHT/2, 256,256)
            end
            if pbag == pbag_b then
            sprite("Project:pb_b", WIDTH/2,HEIGHT/2, 256, 256)
            end
            if player == punch_c then
            sprite(nanner_pc,WIDTH/2,HEIGHT/2, 256, 256)
            end
            if player == punch_d then
            sprite(nanner_pd,WIDTH/2,HEIGHT/2, 256, 256)
            end
            if player == punch_2a then
            sprite(nanner_p2a,WIDTH/2,HEIGHT/2, 256, 256)
            end
            if player == punch_2b then
            sprite(nanner_p2b,WIDTH/2,HEIGHT/2, 256, 256)
            end
            if player == punch_2c then
            sprite(nanner_p2c,WIDTH/2,HEIGHT/2, 256, 256) 
            end
            if player == punch_2d then
            sprite(nanner_p2d,WIDTH/2,HEIGHT/2, 256, 256)
            end
            if player == left_a then
            sprite(nanner_la, c_pos.x, c_pos.y, 256, 256)
            end
            if player == left_b then
            sprite(nanner_lb, c_pos.x, c_pos.y, 256, 256)
            end
            if player == left_c then
            sprite(nanner_lc, c_pos.x, c_pos.y, 256, 256)
            end
            if player == right_a then
            sprite(nanner_ra, c_pos.x, c_pos.y, 256, 256)
            end
            if player == right_b then
            sprite(nanner_rb, c_pos.x, c_pos.y, 256, 256) 
            end
            if player == right_c then
            sprite(nanner_rc, c_pos.x, c_pos.y, 256, 256)
            end
    
    ---wander cycle
            if wander == 1 then
            player = left_a
            end
            if wander == 2 then
            player = left_b 
            end
            if wander == 3 then
            player = left_c 
            end
            if wander == 4 then
            player = left_b
            end
            if wander == 5 then 
            player = left_a
            end
            if wander == 6 then
            player = left_b
            end
            if wander == 7 then
            player = left_c
            end
            if wander == 8 then
            player =  left_b
            end
            if wander == 9 then
            player = left_a
            end
            if wander == 10 then 
            player = left_b
            end
            if wander == 11 then
            player = left_c
            end
            if wander > 11 then
            wander = 4
            end
    
    
    function touched(touch)
    
     ---check to see if youve been idling adds score and what determines the animation sequence       
    
            if touch.state == BEGAN then
            idle = 0
            wander = 0
            end
            if touch.state == BEGAN and
            player == idle_a then
            player = punch_a 
            end
            if touch.state == BEGAN and
            player == idle_b then
            player = punch_c 
            end
            if touch.state == BEGAN and
            player == punch_d then
            player = punch_a
            end
            if touch.state == ENDED and
            player == punch_a then
            player = punch_b
            punches = punches +1
            end
            if touch.state == BEGAN and
            player == punch_b then
            player = punch_c
            end
            if touch.state == ENDED and
            player == punch_c then
            player = punch_d
            punches = punches + 1
            end
    
            if touch.state == BEGAN and
            player == punch_2d then
            player = punch_2a
            end
    
    ---an animation that will be bought or trained into that will encourage rythm      
    
            if touch.state == ENDED and
            player == punch_2a then
            player = punch_2b
            punches = punches +3
            end
            if touch.state == BEGAN and
            player == punch_2b then
            player = punch_2c
            end
            if touch.state == ENDED and
            player == punch_2c then
            player = punch_2d
            punches = punches + 3
            end
    
    ---punching bag animations part one       
            if punches == 15 then
            score = score + 1
            punches = 0 
            pbag = pbag_b
            player = punch_2a
            end
        end
    end
    
    function addscore() 
    
    ---score, clocks, and junk
    
            delay = delay + 1
            if delay == 60 then --clock
            idle = idle + 1
            end
            if idle > 9 and
            delay == 20 then --what makes wandering animate
            wander = wander + 1
            end
            if idle > 9 and
            delay == 40 then
            wander = wander +1
            end
            if idle > 9 and
            delay == 60 then 
            wander = wander + 1
            end
            if wander > 0 and
            delay == 10 then --what cycles the sprite position
            cycle = cycle + 1
            end
            if wander > 0 and
            delay == 30 then
            cycle = cycle +1
            end
            if wander > 0 and
            delay == 50 then 
            cycle = cycle + 1
            end
            if delay > 60 then --resets clock
            delay = 0 
            end
            if delay == 30 or
            delay == 60 then ---punching bag animation to keep it randomish
            pbag = pbag_a
            end
            if player == punch_b and
            delay == 0 or
            player == punch_b and 
            delay == 30 or
            player == punch_d and. --- puts you into idle stand and cycles idle animations
            delay == 0 or
            player == punch_d and 
            delay == 30 then
            player = idle_a
            end 
            if player == punch_b and
            delay == 15 or
            player == punch_b and 
            delay == 45 or
            player == punch_d and
            delay == 15 or
            player == punch_d and 
            delay == 45 then
            player = idle_a
            end
            if player == punch_2b and
            delay == 0 or
            player == punch_2b and 
            delay == 30 or
            player == punch_2d and
            delay == 0 or
            player == punch_2d and 
            delay == 30 then
            player = idle_a
            end 
            if player == punch_2b and
            delay == 15 or
            player == punch_2b and 
            delay == 45 or
            player == punch_2d and
            delay == 15 or
            player == punch_2d and 
            delay == 45 then
            player = idle_a
            end  
            if player == idle_b and
            delay == 0 or
            player == idle_b and 
            delay == 30 then
            player = idle_a
            end 
            if player == idle_a and
            delay == 15 or
            player == idle_a and 
            delay == 45 then
            player = idle_b
            end
    end
    
  • dave1707dave1707 Mod
    Posts: 7,605

    @Dean One thing I noticed looking thru your code is that you have the function touched() within the function draw(). That's a no-no. You need an end statement to end the draw function before starting the touched function. They'll probably work the way you have it, but it shouldn't be done like that and may cause problems at some point. You say you have trouble positioning in 26 pixels without it jumping. You need to write a small routine using some Codea built in Sprites showing what you're trying to do with your 26 pixel positioning. Maybe then we can help because the code you've been posting is unusable. That's a suggestion I usually give. Write small programs that do things you want you're larger program to do. Once you get the small program to work, then you can move it into the larger one. That way you're working with small code doing one thing instead of a large program doing a lot of things that aren't working. It would also be easier for us to help if you have trouble with that small code.

  • Posts: 19

    @dave1707 My issue is when I try to tell it to change a value for the walk cycle position one out of ten times it works. Sometimes the sprite will jump out of frame, and other times it tends to play the walking animation in place, jump, take a step or two, and jump again.

    I use the cycle to swap these out every .33 seconds with a c_pos = in the setup assigned to the walk cycles sprites frames to move the sprite with each step. I feel like I'm going about it all wrong.

    I made a whack-a-mole game with my octopus sprites to try figure this out. I was able to get movement using what I've been trying for this.

    pos1 = vec2((WIDTH/2) - 112, HEIGHT/2)
    pos2 = vec2((WIDTH/2) - 78, HEIGHT/2)
    pos3 = vec2((WIDTH/2) - 56, HEIGHT/2)
    pos4 = vec2((WIDTH/2) - 28, HEIGHT/2)
    pos5 = vec2((WIDTH/2), HEIGHT/2)
    pos6 = vec2((WIDTH/2) + 28, HEIGHT/2)
    pos7 = vec2((WIDTH/2) + 56, HEIGHT/2)
    
  • dave1707dave1707 Mod
    Posts: 7,605

    @Dean From your code above, it looks like you want to move your Sprite in jumps of 28. I assume it's supposed to move back and forth in jumps of 28 pixels. Here's some code that moves two sprites. One moves the Sprite back and forth in jumps of 28, the other in jumps of 1. Not sure if this is what you're after.

    function setup()
        dir=1.3
        pos=0
        val=0
        cnt=0
        xx=1
    end
    
    function draw()
        background(0)
        calcPosition1()
        sprite("Planet Cute:Character Boy",WIDTH/2+pos,HEIGHT/2+100)
        calcPosition28()
        sprite("Planet Cute:Character Boy",WIDTH/2+28*val,HEIGHT/2-100)
    end
    
    function calcPosition28()
        cnt=cnt+1
        if cnt>20 then     -- every .33 seconds
            cnt=0
            val=val+xx
            if val<-3 or val>3 then
                xx=xx*-1
            end
        end
    end
    
    function calcPosition1()
        pos=pos+dir
        if pos<-112 or pos>112 then
            dir=dir*-1
        end    
    end
    
  • Posts: 19

    @dave1707 yes thank you so much. Little things like this help me so much, and I understand they take time. It saves me time, and jumps me to that ah I'm so stupid moment. You go about doing this for everyone here. If you need some art or animation for personal use or demonstrations let me know. A lot of my questions I found by looking at others asking the same, and so this isn't the first problem you've actually helped me with.

  • dave1707dave1707 Mod
    Posts: 7,605

    @Dean I'm here to help. Thanks for the offer for art work, but I don't do anything that involved.

  • Posts: 19

    @dave1707 trying to use your clock setup with it running on a touch that cancles if certain objects or active or the wander cycle when touched giving me a Sprite being told nothing to do. My issue seems to be I can't add anything else in the function setup. No matter what I try naming anything the game won't boot and highlight the end and draw function until I remove anything like this. I'm trying to get the characte to return to the punching bag in a second from object or the current val value in a loop that plays on a clock. I've got the idle ai interacting with things based on its position value and a math.random to start and stop randomly as he wanders. That works fine but nothing seems to work to get him out and I can only seem to pause all the clocks running him with a touch that cancles his next everything for 10 seconds. Sorry to bug this is just the last animation problem I couldn't work out on my own.

    function setup()
       idlelag = 0
       idlex = 0
       idleframe = 0
    end
    
       If idleframe == -3 
       idlelag == 20 then
       val = - 2
       player = right b  ---another function starts up the wanders coordinating part
       idleframe = -2
    end
    
    
            if touch.state == BEGAN and 
            curl == 1 then  ---would flag wander to go into the same cycle this way I plan
            curl = 0
            idleframe = -3 ---tried working with just positives too
            val = -3
            If idlex = 1
            player = right_a
         end
    
       If idlex == 1 then
       idlelag =  idlelag + 1
       end
       If idlelag > 20 then
       idlelag = 0
    end
    
    
  • Posts: 19

    Turned the tablet on again and off again and magic?

Sign In or Register to comment.