# Horse racing

**URL:** https://forum.kirupa.com/t/horse-racing/8873
**Category:** programming
**Created:** [November 30, 2002, 12:41am UTC](https://forum.kirupa.com/t/horse-racing/8873 "2002-11-30T00:41:47Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![luksy](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@luksy](https://forum.kirupa.com/u/luksy)
#### Post date: [November 30, 2002, 12:41am UTC](https://forum.kirupa.com/t/horse-racing/8873/1 "2002-11-30T00:41:47Z")

</div>

ok, so there is an MC on the stage. He is going straight but with different speed. Slow, then fast then slow…randomly.

Thanx.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 30, 2002, 5:47am UTC](https://forum.kirupa.com/t/horse-racing/8873/2 "2002-11-30T05:47:06Z")

</div>

```php

createHorse = function () {
	var horse = this.attachMovie("linkage name to horse library symbol", "horse", 10);
	horse.onEnterFrame = horse.xmove;
};
this.onEnterFrame = function() {
	horse.rate = (Math.random()*10)-3;
};
MovieClip.prototype.xmove = function() {
	this._x += this.rate;
};
createHorse();

```

That should do it. Play around with the numbers in the horse.rate function until you’re happy with it.

Cheers! 🙂

- wobbly

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 30, 2002, 12:49pm UTC](https://forum.kirupa.com/t/horse-racing/8873/3 "2002-11-30T12:49:42Z")

</div>

This code will do basically the same thing as the the other code…it just smooths the movement of the “horse”.

```php

targetPos=50;
createEmptyMovieClip("line",1);
line.lineStyle(50);
line.moveTo(0,200);
line.lineTo(0,200+.15);
onEnterFrame=function(){
	targetPos+=Math.random()*10;
	line._x+=(targetPos-line._x)*.09;
}
	

```

If you want to try it out with your horse symbol you could just do this…

```php

targetPos=50;
onEnterFrame=function(){
	targetPos+=Math.random()*10;
	horseInstance._x+=(targetPos-horseInstance._x)*.09;
}

```

🙂

Replace the smiley image thingys with 0…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 30, 2002, 5:20pm UTC](https://forum.kirupa.com/t/horse-racing/8873/4 "2002-11-30T17:20:53Z")

</div>

thank you all. Really…thanx. But i’ll be back! 😉

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 30, 2002, 7:22pm UTC](https://forum.kirupa.com/t/horse-racing/8873/5 "2002-11-30T19:22:55Z")

</div>

Well, yes…like i thought…it works and it works awesome!! Just like I wanted!! Thanksssss! This will be an awesome game! 😉  
But there is just one more thing i want to add to the game. The betting system. (huh 🙂

So, it’s like this. You have…like…500$ at the begginning. You have a choice to bet on the horse with x amount of money. If he wins you get a random number of money from 50 to 200.

Huh…i got a bit carried on but I think this could be a very original game don’t you think? I never saw this kind of game on flash. And there is no doubt that you guys will be in the credits 😉  
Tell me what do you think?

Oh yeah, to ease the things for the betting system…Every horse has a number. From 1 to 5. Then you can type 400 for the amount of money and in the horse field you type from 1 to 5.

Jeez. Well…huh…

-luksy
