Advertisement
xerpi

Ball

Apr 22nd, 2012
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2.  
  3. using Sce.Pss.HighLevel.UI;
  4.  
  5. namespace SuitePong
  6. {
  7.     public class Ball
  8.     {
  9.         float x, y, speed, angle, inc_x, inc_y;
  10.         int w, h;
  11.         int min_x, min_y, max_x, max_y;
  12.         public Ball (int min_x, int min_y, int max_x, int max_y){
  13.            
  14.             this.min_x = min_x;
  15.             this.max_x = max_x;
  16.            
  17.             this.min_y = min_y;
  18.             this.max_y = max_y;
  19.            
  20.             this.w = 24;
  21.             this.h = 24;
  22.            
  23.             reset();
  24.         }
  25.        
  26.         public void reset(){
  27.             this.x = 960/2 + this.w/2;
  28.             this.y = 544/2 + this.h/2;
  29.             this.speed = 1;
  30.             System.Random random = new System.Random();
  31.             this.angle = (float)(random.NextDouble() * 360);
  32.             this.inc_x = (float)Math.Cos(this.angle);
  33.             this.inc_y = (float)Math.Sin(this.angle);
  34.             //Wait a second?
  35.                 //sleep
  36.         }
  37.        
  38.         public void move(){
  39.             //Move
  40.                 this.x += this.inc_x * this.speed;
  41.                 this.y += this.inc_y * this.speed;
  42.             //Check limits
  43.                 if(this.x < this.min_x)
  44.                     this.x = this.min_x;
  45.                 if(this.x + this.w > this.max_x)
  46.                     this.x = this.max_x - this.w;
  47.                 if(this.y < this.min_y)
  48.                     this.y = this.min_y;
  49.                 if(this.y + this.h > this.max_y)
  50.                     this.y = this.max_y - this.h;
  51.         }
  52.         public void blit(ImageBox image){
  53.             image.X = this.x;
  54.             image.Y = this.y;
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement