Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // v1.3 - Normal version
- // Task 1: Reach a certain speed; Task 2: Bounce off walls
- var task1 = 145, task1_submitted;
- var task2 = 1000, task2_submitted;
- // Variables
- var power, xspeed, yspeed, friction, gravity, thrust, update_timer, speed, bounces;
- var velocity_start = 1;
- // Initialization
- function onLoad() {
- // Textfield
- _root.speed_textfield.textColor = 0xFFFFFF;
- _root.speed_textfield._x = 15;
- _root.speed_textfield._y = 15;
- // Physic engine
- friction = 0.9685;
- gravity = 0.1155;
- thrust = 0.7395;
- power = 0.3285;
- xspeed = 0;
- yspeed = 15;
- circle._x = 300;
- circle._y = 100;
- }
- function submitTask1() {
- // Submit
- task1_submitted = true;
- }
- function submitTask2() {
- // Submit
- task2_submitted = true;
- }
- function updateSpeed() {
- speed = Math.sqrt((yspeed * yspeed) + (xspeed * xspeed));
- speed = int((speed * 100) / 100);
- if ((speed >= task1) && (not task1_submitted)) {
- submitTask1();
- }
- }
- function updateBounces() {
- if ((not task2_submitted) && (bounces >= task2)) {
- submitTask2();
- }
- }
- circle.onEnterFrame = function() {
- // Increase speed
- if (Key.isDown(Key.RIGHT)) {
- xspeed += power;
- }
- if (Key.isDown(Key.LEFT)) {
- xspeed -= power;
- }
- if (Key.isDown(Key.UP)) {
- yspeed -= power * thrust;
- }
- if (Key.isDown(Key.DOWN)) {
- yspeed += power / thrust;
- }
- // Decrease speed
- if ((not Key.isDown(Key.RIGHT)) && (not Key.isDown(Key.LEFT))) {
- xspeed *= friction;
- }
- if ((not Key.isDown(Key.UP)) && (not Key.isDown(Key.DOWN))) {
- yspeed *= friction;
- }
- // Movement
- circle._rotation += xspeed;
- circle._x += xspeed;
- circle._y += yspeed;
- circle._y += gravity;
- // Gravity
- yspeed += gravity;
- // Timer
- update_timer += 1;
- // Wall collisions
- if (circle._x > 600) {
- circle._x = 600;
- xspeed = -xspeed;
- bounces++;
- }
- if (circle._x < 0) {
- circle._x = 0;
- xspeed = -xspeed;
- bounces++;
- }
- if (circle._y > 600) {
- circle._y = 600;
- yspeed = -yspeed;
- bounces++;
- }
- if (circle._y < 0) {
- circle._y = 0;
- yspeed = -yspeed;
- bounces++;
- }
- // Check for API events
- updateBounces();
- updateSpeed();
- // Display
- _root.speed_textfield.text = speed + " km/h";
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement