Message Board


Message Board > C/C++ > get distance from process

October 19, 2012, 06:59
DoctorN
Whiskered
91 posts
Lately ive been using this code since I havent had a floor
Code:
//Handle the players gravity
    if( y + PLAYER_HEIGHT > SCREEN_HEIGHT - PLAYER_HEIGHT ) //If the player is on the ground
    {
        //only if falling is true (landing on the ground)
        if( falling == true && ( in_air == false && on_ground == false) )
        {
            y -= yVel;
            yVel = 0;
            on_ground = true;
            falling = false;
        }
    }
    else //If you are not on the ground
    {
        if( on_ground == false )
        {
            if( in_air == false )
            {
                falling = true;
            }
        }
    } 

and

Code:
//When landing on the ground, make sure you are right above the surface
    if( on_ground == true )
    {
        y=SCREEN_HEIGHT - (PLAYER_HEIGHT+16);
    } 


but then I created tiles, here is level.h
Code:
 
#ifndef LEVEL_H_INCLUDED__
#define LEVEL_H_INCLUDED__

class Tile
{
private:
    //The dimmensions
    int tile_dimx;
    int tile_dimy;

    //The offset
    int x;
    int y;

public:
    Tile();
   
    void show(int x, int y);
};

#endif  // LEVEL_H_INCLUDED__

and level.cpp
Code:
#include "constants.h"
#include "globals.h"
#include "level.h"
#include <iostream>
#include <cstdlib>

Tile::Tile()
{
    tile_dimx = tile_dimy = 16; //saves lines, since the dimmensions will be the same on both sides
    //x = 0; y = SCREEN_HEIGHT - tile_dimy;
}

void Tile::show(int x ,int y)
{
    //Show the animation
    apply_surface( x, y, tiles, screen, &screen->clip_rect);


In main.cpp, I have
Code:
 Tile tiles;

and they are spawned as so
Code:
tiles.show(0,SCREEN_HEIGHT-16);

for example, 0 being x and SCREEN_HEIGHT-16 being y. Now, how can I change the code around so that the player checks if it is on top of the tile? That is all the collision code there is to my program. Also, I would like to know if I can do arrays and structs like I can in Bennu. By that, I mean can I load a file that has the x and y coordinates saved for that specific array, and and the the tiles are placed by the array coutning up or whatever? here is some bennu code:
Code:
// put the blocks
    FOR (tile_count_x=0; tile_count_x<TILE_DIMX; tile_count_x+=1)
           
        FOR (tile_count_y=0; tile_count_y<TILE_DIMY; tile_count_y+=1)
   
            IF (level.tile[tile_count_x][tile_count_y].used==TRUE)
           
                // make sure that the tiles are put on the right place
                temp_x=(tile_count_x*block_size)+8;
                temp_y=(tile_count_y*block_size)+8;
                   
                block_graph=level.tile[tile_count_x][tile_count_y].kind;
       
                //map_xputnp ( <INT destinationFileID> , <INT destinationGraphID> , <INT originFileID> , <INT originGraphID> , <INT x> , <INT y> , <INT angle> , <INT scale_x> , <INT scale_y> , <INT blitflags> ) 
               
                // put a block into the scroll
                map_xputnp(0,scroll_map,block_fpg,block_graph,temp_x,temp_y,0,100,100,0);
                say("plotting tile: "+tile_count_x+" , "+tile_count_y);
            END
        END
    END 


thanks!
____________
#

Message Board > C/C++ > get distance from process

Quick reply


You must log in or register to post.
Copyright © 2005 Booleansoup.com
Questions? Comments? Bug reports? Contact us!