<commit_before>#include <SDL.h>
#include <stdio.h>
#include "world.h"
#include "actor.h"
#include "map.h"
#include "font.h"
#include "sound.h"

Actor::Actor()
{
    sprite=NULL;
    x=128;
    y=160;
    jump=false;
    // Animation state
    frame=0;
    frameTimer=150;
    // Power up
    powerup=0;
    timer=0;
    // physics
    ay=0;
    vy=0;
    score=0;
    physicsTimer=0;
}

Actor::~Actor()
{

}

void Actor::init()

{
    if(!sprite) {
        sprite=new Image(World::getRenderer(),"Trump.png");
        sprite->setCellSize(32);
    }
    x=128;
    y=160;
    jump=false;
    // Animation state
    frame=0;
    frameTimer=150;
    // Power up
    powerup=0;
    timer=0;
    // physics
    ay=0;
    vy=0;
    score=0;
    physicsTimer=0;
}

void Actor::update(int elapsed, Map *map)
{
    // Update the animation frame
    if (jump==true){
        frame=8;
    }else{
        frameTimer-=elapsed;
        if (frameTimer<=0){
            if (frame==8){
                frame=0;
            }else{
                frame++;
            }
            if(frame==5){
                frame=0;
            }
            frameTimer+=150;
        }
    }
    // Apply the physics.
    physicsTimer+=elapsed;
    while(physicsTimer>16) {
        physicsTimer-=16;
        updateGravity(map);
    }
}

void Actor::updateGravity(Map *map)
{
        if( ay!=0) {
                printf("y=%.2f; vy=%.2f; ay=%.2f\n",y,vy,ay);
        }
        vy=vy+ay;
        vy=vy+GRAVITY;   // earth gravity is 9.8 m/s^2, or whatever it works out to in your units.
        // apply terminal velocity
        if( vy<MINVEL) {
                vy=MINVEL;
                ay=0;  // hit minimum negative velocity so stop jumping.
        }
        if( vy>MAXVEL) {
                vy=MAXVEL;
                ay=0;  // hit maximum velocity so stop jumping.
        }
        // propose new position, and test for collision:
        float newy=y+vy;
        int i;
        for( i=0; i<8; i++) {
                int item=map->collide(x, newy+32, 32, 32 );
                int item2=map->collide(x+16, newy, 32, 32 );
                bool barrier1= (item!=MAP_BARRIER_A && item!=MAP_BARRIER_B);
                bool barrier2 = (item2!=MAP_BARRIER_A && item2!=MAP_BARRIER_B);
                if( item==MAP_SKY ) break; // a safe place to move the item to.
                if (barrier1 || barrier2) {
                    if (barrier1) {
                        item=map->collect(x,newy+32, 32, 32);
                    }
                    if (barrier2) {
                        item2=map->collect(x+16,newy, 32, 32);
                    }
                    collectedItem(item);
                    break;
                }
                if( item==MAP_BARRIER_A || item==MAP_BARRIER_B) {
                    if(vy<0) break;     // Jump up through walls!
                }
                // we don't want to be inside the object, so guess we can move half the distance.
                vy/=2.0f;
                newy=y+vy;
        }
        if( i==8) {
                newy=y; // we can't find a place closer to the ground/ceiling so we need to stop moving.
                vy=0;
                ay=0;
        }
        y=newy; // our new vertical position with gravity and jumping factored in!
}

void Actor::handle(bool down)
{
    ay=down?JUMP:0;
    if(down && !jump) {
        Sound::playSfx(SFX_JUMP);
    }

    jump=down;
}<commit_msg>fixes errors of last commit<commit_after>#include <SDL.h>
#include <stdio.h>
#include "world.h"
#include "actor.h"
#include "map.h"
#include "font.h"
#include "sound.h"

Actor::Actor()
{
    sprite=NULL;
    x=128;
    y=160;
    jump=false;
    // Animation state
    frame=0;
    frameTimer=150;
    // Power up
    powerup=0;
    timer=0;
    // physics
    ay=0;
    vy=0;
    score=0;
    physicsTimer=0;
}

Actor::~Actor()
{

}

void Actor::init()

{
    if(!sprite) {
        sprite=new Image(World::getRenderer(),"Trump.png");
        sprite->setCellSize(32);
    }
    x=128;
    y=160;
    jump=false;
    // Animation state
    frame=0;
    frameTimer=150;
    // Power up
    powerup=0;
    timer=0;
    // physics
    ay=0;
    vy=0;
    score=0;
    physicsTimer=0;
}

void Actor::update(int elapsed, Map *map)
{
    // Update the animation frame
    if (jump==true){
        frame=8;
    }else{
        frameTimer-=elapsed;
        if (frameTimer<=0){
            if (frame==8){
                frame=0;
            }else{
                frame++;
            }
            if(frame==5){
                frame=0;
            }
            frameTimer+=150;
        }
    }
    // Apply the physics.
    physicsTimer+=elapsed;
    while(physicsTimer>16) {
        physicsTimer-=16;
        updateGravity(map);
    }
}

void Actor::updateGravity(Map *map)
{
        if( ay!=0) {
                printf("y=%.2f; vy=%.2f; ay=%.2f\n",y,vy,ay);
        }
        vy=vy+ay;
        vy=vy+GRAVITY;   // earth gravity is 9.8 m/s^2, or whatever it works out to in your units.
        // apply terminal velocity
        if( vy<MINVEL) {
                vy=MINVEL;
                ay=0;  // hit minimum negative velocity so stop jumping.
        }
        if( vy>MAXVEL) {
                vy=MAXVEL;
                ay=0;  // hit maximum velocity so stop jumping.
        }
        // propose new position, and test for collision:
        float newy=y+vy;
        int i;
        for( i=0; i<8; i++) {
                int item=map->collide(x, newy+32, 32, 32 );
                if( item==MAP_SKY ) break; // a safe place to move the item to.
                if( (item!=MAP_BARRIER_A && item!=MAP_BARRIER_B)) {
                    item=map->collect(x,newy+32, 32, 32);
                    collectedItem(item);
                    break;
                }
                if( item==MAP_BARRIER_A || item==MAP_BARRIER_B) {
                    if(vy<0) break;     // Jump up through walls!
                }
                // we don't want to be inside the object, so guess we can move half the distance.
                vy/=2.0f;
                newy=y+vy;
        }
        if( i==8) {
                newy=y; // we can't find a place closer to the ground/ceiling so we need to stop moving.
                vy=0;
                ay=0;
        }
        y=newy; // our new vertical position with gravity and jumping factored in!
}

void Actor::handle(bool down)
{
    ay=down?JUMP:0;
    if(down && !jump) {
        Sound::playSfx(SFX_JUMP);
    }

    jump=down;
}
{'fraction_non_alphanumeric': 0.13249114158065012, 'fraction_numerical': 0.027114466183947004, 'mean_word_length': 1.447041085563513, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5471584', 'n_tokens_mistral': 2312, 'n_tokens_neox': 2162, 'n_words': 502}