[Need Help] How do I translate this out-of-bounds collider from my gamebuino game to pokitto?

  if(positionX < 0){
    speedX = 0;   
    positionX = positionX + 1;
  }
  

  if(positionX > gb.display.width() - ballSize){
    speedX = 0;
    positionX = positionX - 1;
  }

 if(positionY < 0){
    speedY = 0;
    positionY = positionY + 1;
  }


if(positionY > gb.display.height() - ballSize){
    speedY = 0;
    positionY = positionY - 1;
  }

How can this be made to work with pokitto?

Try this:

At the top of your class, add:

#include "Pokitto.h"

using PC = Pokitto::Core;
using PD = Pokitto::Display;

Then you can refer to the constants, width and height …

  if(positionX < 0){
    speedX = 0;   
    positionX = positionX + 1;
  }
  
  if(positionX > PD::width - ballSize){
    speedX = 0;
    positionX = positionX - 1;
  }

 if(positionY < 0){
    speedY = 0;
    positionY = positionY + 1;
 }

 if(positionY > PD::height - ballSize){
    speedY = 0;
    positionY = positionY - 1;
 }
2 Likes

Thank you!

how do i implement this into my prexisting code and edit the older way to change the top thingies

#include <Pokitto.h>

Pokitto::Display display;
Pokitto::Buttons;

int moveY = 0;
int moveX = 0;
int sizeX = 8;
int sizeY = 8;
float speedX;
float speedY;
float baseSpeed = 2.5;


void setup(){

}

void update(){
    bool verticalMove = false;
    bool horizontalMove = false;
    
    display.setColor(C_BROWN);
    display.fillRect(moveX, moveY, sizeX, sizeY);
    
    if (horizontalMove == true && verticalMove == true){
        speedX = baseSpeed * 0.7;
        speedY = baseSpeed * 0.7;
    }else {
        speedX = baseSpeed;
        speedY = baseSpeed;
    }
    
 
    if (buttons.repeat(BTN_UP,0)){
        moveY = moveY - speedY;
    }
    
    if (buttons.repeat(BTN_DOWN,0)){
        moveY = moveY + speedY;
    }
    
    if (buttons.repeat(BTN_LEFT,0)){
        moveX = moveX - speedX;
    }
    
    if (buttons.repeat(BTN_RIGHT,0)){
        moveX = moveX + speedX;
    }
    
    
}

Try this out:

2 Likes