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.