Ayudar con la fisica

Started by MisterN, January 31, 2013, 03:50:55 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

MisterN

//Velocity And Movement Tester
//By: Nicholas Wolf
//Date: 1/29/2013
program velocity_test;

import "mod_proc"
import "mod_video"
import "mod_text"
import "mod_map"
import "mod_draw"
import "mod_math"
import "mod_grproc"
import "mod_key"
import "mod_wm"
import "mod_say"

global
ball_dim_x = 32;
ball_dim_y = 32;

begin
set_mode(320,240,16);
set_fps(60,0);

//spawn the ball
ball(320/2,240-(ball_dim_y/2));

    loop
        //press esc or click X to exit game
        if(key(_esc) or exit_status)
            exit("goodbye",0);
        end
    frame;end
end

process ball(x,y);
private
    //key presses
    bool key_right = false;
    bool key_left = false;
    bool key_jump = false;
    //status
    bool standing = false;
    bool walking = false;
    bool jumping = false;
    bool falling = true;
    //movements
    int v = 0; //velocity
    int v_min = -4; //the minimum a velocity can get
    int v_max = 4; //the maximum a velocity can get
    int v_timer = 0; //a counter that will steadily increase/decrease v
    int v_timer_max = 4; //the max time a v_timer will set itself to
    int dir = 0;
    int h_speed = 1.5;
begin
graph = load_png("velocity.png");
    loop
        write(0,0,0,0,"STATS:");
        write(0,0,8,0,"dir: "); write_var(0,56,8,0,dir);
        write(0,0,16,0,"v: ");  write_var(0,56,16,0,v);
        write(0,0,24,0,"v_timer: "); write_var(0,56,24,0,v_timer);
        //formula for moving
            x+=dir*h_speed;
        //move left and right
            if(key(_right))
                key_right=true;
            else
                key_right=false;
            end
            if(key(_left))
                key_left=true;
            else
                key_left=false;
            end
            //determine dir
                if(key_right) //because the right key, you are going right
                    dir = 1;
                end
                if(key_left) //because the left key, you are going left
                    dir = -1;
                end
                if((!key_right and !key_left) or (key_right and key_left)) //if neither keys or both keys, then stalemate
                    dir = 0;
                end
            //ensure you dont collide with wall
                if(dir==1)
                    if(x>320-16)
                        dir = 0;
                    end
                end
                if(dir==-1)
                    if(x<0+16)
                        dir = 0;
                    end
                end
        //formula for movement along the y axis
            y+=v;
        //jumping and falling
            //jumping
            if(key(_control))
                key_jump = true;
            else
                key_jump = false;
            end
            if(key_jump)
                if(standing and !jumping and !falling) //to ensure we can only jump once we are on a surface
                    jumping = true;
                    standing = false;
                end
            end
            if(jumping)
                if(v>v_min) //since you are jumping, you want v to reach v_max
                    if(v_timer>0)
                        v_timer--;
                    else
                        v--;
                        v_timer = v_timer_max;
                    end
                else
                    falling = true;
                    jumping = false;
                end
            end
            //falling
            if(falling)
                if(v<v_max) //since you are falling, you want v to reach v_min, which is -v_max
                    if(v_timer>0)
                        v_timer--;
                    else
                        v++;
                        v_timer = v_timer_max;
                    end
                end
                if(y>240-(ball_dim_y/2)) //getting onto the ground
                    falling = false;
                    v = 0;
                    standing = true;
                end
            end
    frame;end
end


Problemas:
* y=v^2
no funciona (line 97)

*
la bola será enterrado en el suelo

http://forum.bennugd.org/index.php?action=dlattach;topic=3436.0;attach=2849
werg

SplinterGU

que buscas hacer con v^2?

eso es operador bitwise XOR.

imagino que quieres hacer pow.
Download Lastest BennuGD Release: http://www.bennugd.org/node/2

MisterN

me gustaria saber la equivalente en grafica de y=x^2
werg

fulgorelizz

Quote from: DoctorN on January 31, 2013, 04:05:32 AM
me gustaria saber la equivalente en grafica de y=x^2

en esa expresion pretendes ejecutar una raiz cuadrada o una potencia??? pareciera mas una potencia , x con coheficiente 2. corrigeme si me equivoco   :)
Compiling code -- generating exe...

SplinterGU

Download Lastest BennuGD Release: http://www.bennugd.org/node/2