Advertisement
Guest User

main look

a guest
Jun 21st, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.88 KB | None | 0 0
  1. int main () {
  2.  
  3.     setup();
  4.  
  5.     p1.x = 32; p1.y = 64; // bottom of the screen... fixed point
  6.     p1.vy = 0; // not jumping
  7.     p1.flip = 0;
  8.  
  9.     uint32_t myDelay = 1000/47;
  10.     uint32_t tempTime  = mygame.getTime();
  11.  
  12.  
  13.     while (mygame.isRunning()) {
  14.  
  15.         // timing loop
  16.         if(mygame.getTime()-tempTime >= myDelay){
  17.             tempTime = mygame.getTime();
  18.  
  19.             // update buttons
  20.             myPad = updateButtons(myPad);
  21.             UpdatePad(myPad);
  22.             frameNumber++;
  23.  
  24.             p1.jumping = 0;
  25.             p1.falling = 0;
  26.             p1.y += p1.FallSpeed;
  27.             p1.FallSpeed += GRAVITY;
  28.             if (p1.FallSpeed > 5) {
  29.                 p1.FallSpeed = 5;
  30.             }
  31.  
  32.             if (getTile(p1.x +1, p1.y + 8) > SOLIDTILE  ||  getTile(p1.x +7, p1.y + 8) > SOLIDTILE) { // falling
  33.                 p1.FallSpeed = 0;
  34.                 p1.y = ((int)p1.y >> 3) << 3;
  35.             }
  36.             if ((getTile(p1.x +1, p1.y - 1) > SOLIDTILE  ||  getTile(p1.x +7, p1.y - 1) > SOLIDTILE) && p1.FallSpeed <= 0) { // jumping
  37.                 p1.FallSpeed = 0;
  38.                 int py = (int)p1.y;
  39.                 p1.y = ((py+4) >> 3) << 3;
  40.             }
  41.  
  42.             // jump
  43.             if (_A[NEW] && (getTile(p1.x+1, p1.y+8) > SOLIDTILE  ||  getTile(p1.x+7, p1.y+8) > SOLIDTILE)) {
  44.                 p1.FallSpeed = -p1.JumpHeight;
  45.             //    SFX = SFX_Jump;
  46.             //    playSfx = true;
  47.             }
  48.  
  49.             // Moving Code
  50.             if ((_Right[HELD]) && ((getTile(p1.x + 7 + p1.speed, p1.y + 4) <= SOLIDTILE ))) {
  51.                 p1.x += p1.speed;
  52.                 p1.step++;
  53.                 p1.direction=0;
  54.             }
  55.             if ((_Left[HELD]) && (getTile(p1.x - p1.speed, p1.y+4) <= SOLIDTILE )) {
  56.                 p1.x -= p1.speed;
  57.                 p1.step++;
  58.                 p1.direction=1;
  59.             }
  60.  
  61.             if (p1.step == p1.speed) {
  62.                 p1.frame++;
  63.                 p1.step = 0;
  64.             }
  65.             if (p1.frame >= 12) {
  66.                 p1.frame = 0;
  67.             }
  68.  
  69.             if (p1.FallSpeed > 0) {
  70.                 p1.falling = 1;
  71.             }
  72.             if (p1.FallSpeed < 0) {
  73.                 p1.jumping = 1;
  74.             }
  75.  
  76.             if (!_Up[HELD] && !_Down[HELD] && !_Left[HELD] && !_Right[HELD]) {
  77.                 p1.frame = 3;
  78.             }
  79.  
  80.             // falling == 0, jumping == 0
  81.             if (p1.jumping == 1) {
  82.                 p1.frame = 12;
  83.             }
  84.             if (p1.falling == 1) {
  85.                 p1.frame = 13;
  86.             }
  87.  
  88.             if ((getTile(p1.x +1, p1.y + 8) < SOLIDTILE  ||  getTile(p1.x +7, p1.y + 8) < SOLIDTILE) && p1.falling == 0 && p1.jumping == 0) { // jumping
  89.                 p1.frame = 3;
  90.             }
  91.  
  92.         }; // timer
  93.  
  94.  
  95.         if (mygame.update()) {
  96.             renderMap();
  97.         }
  98.  
  99.     }
  100.  
  101.     return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement