[SOLVED] Collision Between Bitmaps

Understanding the language, error messages, etc.

[SOLVED] Collision Between Bitmaps

Postby Reocha » Wed Oct 28, 2015 8:25 pm

Please help I am making a game but I'm kind of a noob so I have no idea what I am doing so PLEASE help, I'm trying to make collision between the man and the tree bitmaps and when the man hits the tree he stops. I've tried everything I know (not much) to get this to work but it wont work :(
Code: Select all
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;
#define MENULENGTH 2
const char strHS[] PROGMEM = "Resume";
const char strGM[] PROGMEM = "Boot Loder";
const char* const menu[MENULENGTH] PROGMEM = {
  strHS,
  strGM,
};
const byte Man[] PROGMEM = {16,12,
0x3F,0x0,
0x4C,0x80,
0xFF,0xC0,
0x52,0x80,
0x40,0x80,
0x7F,0x80,
0x3F,0x0,
0x3F,0x0,
0x3F,0x0,
0x3F,0x0,
0x21,0x0,
0x21,0x0,
};
const byte tree[] PROGMEM = {16,16,
0x3,0xC0,
0x7,0xE0,
0xF,0xF0,
0x1F,0xF8,
0x3F,0xFC,
0x3F,0xFC,
0x1F,0xF8,
0xF,0xF0,
0x7,0xE0,
0x3,0xC0,
0x3,0xC0,
0x3,0xC0,
0x3,0xC0,
0x3,0xC0,
0x3,0xC0,
0x3,0xC0,
};

int man_x = LCDWIDTH/2;
int man_y = LCDHEIGHT/2;
int man_vx = 3;
int man_vy = 3;
int man_size = 8;
int game_level = 1;


void setup(){
  gb.begin();
}
void loop(){
  gb.collideBitmapBitmap(3, 3,Man, 0, 0, tree);
  if(gb.update()){
     gb.display.println((man_x));
     gb.display.println((man_y));
    gb.display.drawBitmap((man_x),(man_y),Man,NOROT,NOFLIP);
    gb.display.drawBitmap(57,18,tree,NOROT,NOFLIP);

    if(gb.buttons.repeat(BTN_RIGHT,2)){
      man_x = man_x + man_vx;
      gb.sound.playTick();
    }
    if(gb.buttons.repeat(BTN_LEFT,2)){
      man_x = man_x - man_vx;
      gb.sound.playTick();
    }
    if(gb.buttons.repeat(BTN_DOWN,2)){
      man_y = man_y + man_vy;
      gb.sound.playTick();
    }
    if(gb.buttons.repeat(BTN_UP,2)){
      man_y = man_y - man_vy;
      gb.sound.playTick();
    }
    if(gb.buttons.pressed(BTN_A)){
      gb.popup(F("THIS IS A TEST!"), 200);
 
    if(gb.buttons.pressed(BTN_C)){
     switch(gb.menu(menu, MENULENGTH)){
    case -1: //nothing selected
      gb.titleScreen(F("Reocha's EPIC Game... hopefully"));
      break;
    case 0: //display system info

      break;
    case 1:
      gb.changeGame();
      break;
    default:
      break;
  }
}
    }
   
   
    if(man_x < 0){
      man_x = 0;
    }
    if((man_x + man_size) > LCDWIDTH){
      man_x = LCDWIDTH - man_size;
    }
    if(man_y < 0){
      man_y = 0;
    }
    if((man_y + man_size) > LCDHEIGHT){
      game_level = LCDHEIGHT - man_size;
    }
}

Thanks :D
Last edited by Reocha on Thu Nov 12, 2015 9:47 pm, edited 1 time in total.
User avatar
Reocha
 
Posts: 2
Joined: Tue Oct 27, 2015 9:03 am

Re: [HELP] Collision Between Bitmaps

Postby Risike » Tue Nov 03, 2015 11:26 am

The collideBitmapBitmap methods returns a boolean. True if it collides, False if not.

You must use :
if(gb.collideBitmapBitmap(..............){
// Do something
}
Risike
 
Posts: 24
Joined: Mon Sep 14, 2015 5:25 pm

Re: [HELP] Collision Between Bitmaps

Postby Reocha » Thu Nov 12, 2015 9:48 pm

Risike wrote:The collideBitmapBitmap methods returns a boolean. True if it collides, False if not.

You must use :
if(gb.collideBitmapBitmap(..............){
// Do something
}

thank you!!
User avatar
Reocha
 
Posts: 2
Joined: Tue Oct 27, 2015 9:03 am


Return to Programming Questions

Who is online

Users browsing this forum: No registered users and 2 guests