Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main () {
- setup();
- p1.x = 32; p1.y = 64; // bottom of the screen... fixed point
- p1.vy = 0; // not jumping
- p1.flip = 0;
- uint32_t myDelay = 1000/47;
- uint32_t tempTime = mygame.getTime();
- while (mygame.isRunning()) {
- // timing loop
- if(mygame.getTime()-tempTime >= myDelay){
- tempTime = mygame.getTime();
- // update buttons
- myPad = updateButtons(myPad);
- UpdatePad(myPad);
- frameNumber++;
- p1.jumping = 0;
- p1.falling = 0;
- p1.y += p1.FallSpeed;
- p1.FallSpeed += GRAVITY;
- if (p1.FallSpeed > 5) {
- p1.FallSpeed = 5;
- }
- if (getTile(p1.x +1, p1.y + 8) > SOLIDTILE || getTile(p1.x +7, p1.y + 8) > SOLIDTILE) { // falling
- p1.FallSpeed = 0;
- p1.y = ((int)p1.y >> 3) << 3;
- }
- if ((getTile(p1.x +1, p1.y - 1) > SOLIDTILE || getTile(p1.x +7, p1.y - 1) > SOLIDTILE) && p1.FallSpeed <= 0) { // jumping
- p1.FallSpeed = 0;
- int py = (int)p1.y;
- p1.y = ((py+4) >> 3) << 3;
- }
- // jump
- if (_A[NEW] && (getTile(p1.x+1, p1.y+8) > SOLIDTILE || getTile(p1.x+7, p1.y+8) > SOLIDTILE)) {
- p1.FallSpeed = -p1.JumpHeight;
- // SFX = SFX_Jump;
- // playSfx = true;
- }
- // Moving Code
- if ((_Right[HELD]) && ((getTile(p1.x + 7 + p1.speed, p1.y + 4) <= SOLIDTILE ))) {
- p1.x += p1.speed;
- p1.step++;
- p1.direction=0;
- }
- if ((_Left[HELD]) && (getTile(p1.x - p1.speed, p1.y+4) <= SOLIDTILE )) {
- p1.x -= p1.speed;
- p1.step++;
- p1.direction=1;
- }
- if (p1.step == p1.speed) {
- p1.frame++;
- p1.step = 0;
- }
- if (p1.frame >= 12) {
- p1.frame = 0;
- }
- if (p1.FallSpeed > 0) {
- p1.falling = 1;
- }
- if (p1.FallSpeed < 0) {
- p1.jumping = 1;
- }
- if (!_Up[HELD] && !_Down[HELD] && !_Left[HELD] && !_Right[HELD]) {
- p1.frame = 3;
- }
- // falling == 0, jumping == 0
- if (p1.jumping == 1) {
- p1.frame = 12;
- }
- if (p1.falling == 1) {
- p1.frame = 13;
- }
- if ((getTile(p1.x +1, p1.y + 8) < SOLIDTILE || getTile(p1.x +7, p1.y + 8) < SOLIDTILE) && p1.falling == 0 && p1.jumping == 0) { // jumping
- p1.frame = 3;
- }
- }; // timer
- if (mygame.update()) {
- renderMap();
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement