haxegon / zeedonk

Haxegon + Puzzlescript = Zeedonk!
http://www.zeedonk.net
12 stars 2 forks source link

outsidebounds error #298

Closed increpare closed 9 years ago

increpare commented 9 years ago

this code spits out a billion outsidebounds errors - I don't think it did that earlier on today?

var player = {
  x:Gfx.screenwidthmid,
  y:Gfx.screenheightmid,
  v:0,
  dir:0
};

var turnspeed=0.1;
var acceleration=0.01;
var maxspeed=1.0;

function new() {
}

function tickShip(e){
  var dx = Math.sin(e.dir)+Math.cos(e.dir);
  var dy = Math.cos(e.dir)-Math.sin(e.dir);
  var cx=e.x;
  var cy=e.y;
  cx += dx*e.v;
  cy += dy*e.v;

  if (cx<0) {
    cx+=Gfx.screenheight;
  }    
  if (cx>=Gfx.screenheight){
    cx-=Gfx.screenheight;
  }

  if (cy<0) {
    cy+=Gfx.screenheight;
  }    
  if (cy>=Gfx.screenheight){
    cy-=Gfx.screenheight;

  e.x=cx;
  e.y=cy;
  var d = e.dir;
  var p1x = cx+(dx)*5;
  var p2x = cx+(Math.sin(e.dir-2)+Math.cos(e.dir-2))*3;
  var p3x = cx+(Math.sin(e.dir+2)+Math.cos(e.dir+2))*3;
  var p1y = cy+(dy)*5;
  var p2y = cy+(Math.cos(e.dir-2)-Math.sin(e.dir-2))*3;
  var p3y = cy+(Math.cos(e.dir+2)-Math.sin(e.dir+2))*3;
  Gfx.drawtri(p1x,p1y,p2x,p2y,p3x,p3y,Col.WHITE);
}

function update() {
  if (Input.pressed(Key.LEFT)){
    player.dir+=turnspeed;
  }
  if (Input.pressed(Key.RIGHT)){
    player.dir-=turnspeed;
  }
  if (Input.pressed(Key.UP)){
    player.v = Math.min(player.v+acceleration,maxspeed);
  }

  if (Input.pressed(Key.DOWN)){
    player.v = Math.max(player.v-acceleration,0);
  }

  tickShip(player);
}