Thread: Help creating a random point that moves

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    4

    Help creating a random point that moves

    I have an assignment that involves creating a simple game. My game is sort of similar to the game snake, in that the purpose is to collect objects, in this case that moves in a random direction.

    using: K.I.S.S programming

    My issue and what I need help with is creating the array, filling it with random points, and then implementing a way to make it move (I think)

    What it does now is create a point that moves crazy fast and without a pattern.

    Line 33-45 is the function I need help with.

    My code:
    insert
    Code:
    #include <stdio.h>
    #include <kiss-graphics.h>
    #include <kiss-compat.h>
    #include <kiss-input.h>
    
    void drawRobot(int x0, int y0,float a, float s);
    void drawbackground();
    void drawtarget();
    
    int main() 
    {
        int x=400,y=400,i,a,size;//start in middle
        graphics_init(800,800);
        
        graphics_update();
        while((x <= 800)&&(y > 0)&&(x > 0)&&(y <= 800)){// loop until Q key is pressed
            drawbackground();
            if(left_button()!=0){x=x- 4;} // if left is pressed move left a pixel
            if(right_button()!=0){x=x+4;}// if right, move to the right
            if(up_button()!=0){y=y-4;}// if up is pressed move up (smaller Y)
            if(down_button()!=0){y=y+4;}// if down is pressed move down
            drawRobot(x,y,0,0);
            drawtarget();
            graphics_update();// update the screen
        }
        
        
        
        sleep(5);
        return 0;
    }
    //This is the function
    void drawtarget(double xA[], double yA[], int aSize)
    {
        int x,y;
        int a[1000],b[1000],size=1000,i;// create an array and other int variables
        //for(i=0;i<10;i++){
            a[i]=rand()%700;
            b[i]=rand()%700;
            x=a[3];
            y=a[4];
            graphics_circle_fill(x,y,10,5,5,5);
            graphics_update();    
            }
        
    void drawbackground()
    {
        
        
        graphics_fill(0,180,0);// fill in background
        graphics_update();
    }
    
    
    void drawRobot(int x, int y,float a, float s)
    {
        graphics_circle_fill(x+5,y+10,10,5,5,5);//Robot
        graphics_line(x+50, y+50, x-5, y-5, 0, 0, 0);
    }
    Thank you guys, in advance for helping. Any pointers and advice would be great.
    Last edited by Human107; 12-10-2012 at 03:08 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Random Floating Point Numbers
    By Khadafi in forum C++ Programming
    Replies: 16
    Last Post: 02-27-2011, 06:43 AM
  2. Random exclamation point at end of strings
    By -world in forum C Programming
    Replies: 8
    Last Post: 07-09-2010, 11:37 PM
  3. Replies: 2
    Last Post: 08-13-2008, 08:02 AM
  4. Creating a point
    By histevenk in forum C++ Programming
    Replies: 4
    Last Post: 10-07-2007, 02:05 AM
  5. random moves
    By Neoground1 in forum C++ Programming
    Replies: 8
    Last Post: 10-15-2002, 02:21 AM