View Single Post
  #4  
Old 01-02-2012, 10:15 PM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is just really niceTricxta is just really nice
Quote:
Originally Posted by Gunderak View Post
PHP Code:
      this.sx2 this.sx;
      
this.sy2 this.sy;
      if (
this.dir == && !onwall(this.sxthis.sy 0.5)) {
        
this.sy -= 0.5;
      }
      if (
this.dir == && !onwall(this.sx 0.5this.sy)) {
        
this.sx -= 0.5;
      }
      if (
this.dir == && !onwall(this.sxthis.sy 0.5)) {
        
this.sy += 0.5;
      }
      if (
this.dir == && !onwall(this.sx 0.5this.sy)) {
        
this.sx += 0.5;
      }
...
    if (
this.dir == && player.this.sy) {
      
player.-= 0.5;
    }
    if (
this.dir == && player.this.sy) {
      
player.+= 0.5;
    }
    if (
this.dir == && player.this.sx) {
      
player.-= 0.5;
    }
    if (
this.dir == && player.this.sx) {
      
player.+= 0.5;
    } 
I always criticise people for this so don't worry you're not alone.
Instead of writing all these seperate statement it's possible to compact them
PHP Code:
for (temp.04i++){
  if (
this.dir == temp.&& !onwall(this.sx vecx(this.dir) * 0.5this.sy vecy(this.dir) * 0.5)){
    
this.sx += vecx(this.dir) * 0.5;
    
this.sy += vecy(this.dir) * 0.5;
  }

Another good trick to remember is if you want to invert your direction instead of touching the direction you can just do vecx(dir)*-1 since I figured you're not so hot with math.

Also callimuc is correct in advising you to use updateboard although in my past the respawn method for those tiles becomes a bit messy which is something to keep in mind. None the less... you're on the right track so far, keep at it
Reply With Quote