openframeworks/ofBook

Game Design - mid-chapter crisis

tremblap opened this issue · 8 comments

When we reach the sentence:

You should have a player who moves around on-screen. Sweet! ###Player bullets

I find 2 errors:

  • we don't have a Player.cpp code yet - so nothing will compile. (there is a short section missing here?)
  • I presume ### is to declare a new section?

p

There was also nowhere that told us where to get the icons from, and where to put them for them to load. (I'm also told by the compiler that loadImage is deprecated)

width = player_image->width;
gives the error
'width' is a protected member of 'ofImage_'
in Bullet::setup (and in my own Player::setup which I tried to code from the text)


needs replacing by
width = img->getWidth();

ok at this stage, my Player.cpp looks like this (with some executive decisions on about everything)

#include "Player.h"

void Player::setup(ofImage* player_image) {
    pos.set((ofGetWidth() / 2),(ofGetHeight() - 50),0);
    speed = 0;
    img = player_image;
    width = player_image->getWidth();          //gets an error saying that width is a protected member of 'ofImage_<unsigned char>'
    height = player_image->getHeight();
    lives = 3;

    is_left_pressed = false;
    is_right_pressed = false;
    is_down_pressed = false;
    is_up_pressed = false;
}

void Player::update() {
    calculate_movement();
}

void Player::shoot() {
    //could be commented as it is unused for now
}

void Player::draw() {
    img->draw(pos.x - width/2, pos.y - width/2);
}


void Player::calculate_movement() {
    //update speed according to current key press
    if (is_left_pressed) {
        speed -= 0.5;
    } else if (is_right_pressed)  {
        speed += 0.5;
    }

    //update position according to current speed
    pos.x += speed;
    if (pos.x < (width / 2)) {
        pos.x = (width / 2);
        speed = 0;
    } else if (pos.x > (ofGetWidth() - (width / 2))){
        pos.x = (ofGetWidth() - (width / 2));
        speed = 0;
    }
}

bool Player::check_can_shoot() {
    //could be commented as it is unused for now
}

@tremblap thanks for looking into this chapter! Pinging the author: @phoenixperry

Two quick things:

  • @firmread was putting together a repository that has code put together from each chapter. It's here: https://github.com/firmread/ofBookExamples. I haven't looked through the code on this chapter, but it might be helpful to check that out.
  • To make it easy for the author to see all your feedback at once, it would be good to group all your feedback for one chapter under one issue. That also helps make the email notifications from this repository more focused/targeted as well. When you create an issue on GitHub, you can always edit the post and add more issues/questions to it as you go.

ok sorry for the mess - and I have to say that I did not know there was this repository! The errors I'm pointing at are still valid, but the answers are much more elegant in the official code repos!

another error/omission in the chapter: at the end there is no instance of LiveTesting - I can see it in the code repos but it would be good to add a paragraph at the end on it.

It was a fun chapter to play with, and with the tweaks I flagged will be very much self-sufficient and useful in a lot of different skills to acquire.

thanks again for doing this.

p

final comment: the OSC modified instance variables are never passed to the game engine. I get the updatedVals back, so I know OSC is modifying them, but they are not passed to the engine.

@tremblap the errors definitely seem like important ones - hope I didn't imply otherwise. And with respect to the ofBookExamples repository, it's hasn't become official yet, so it's not linked anywhere. Hopefully it'll get integrated into the book in the future.

no offence taken: don't forget I'm second language English (native French).

Another bug:
int i = bonuses.size()-1; i > 0; i--
should read
int i = bonuses.size()-1; i >= 0; i--

(I don't understand why iteration is done downwards in that example but good to show the hurdles of conditional ending)