Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Chapter 05] KamaKazi Base code
#13
Ok I get what you are saying, but again...you're building up from the Invaders code,  which shows the process, and while the code is a little different it does have the same principles, re-read page 123, where I say:

"Download the Kamikazi base project from the support site, you will see its essentially still the InvaderStart project we achieved before adding gameplay, but I’ve renamed a few things, this is going to be our base line project for the next few games."

So that for me was making it clear things were basically the same, but we've shuffled things about a bit.  But I take it on board that you were confused so I'm adding something to the base Kamikazi code to make that clearer.

You indeed must use the previous code for reference, (that will be a recurring theme) and as you say its good exercise for you to recognise patterns in the code even if the names and order get altered.

Page 124, lays out a list of the things we have to do and some reference to what we already know what to do.  The Rand should indeed be taken from the Invaders so I will add that as a macro to game.h

Page 128 shows the creation of 2 shooter constructors, but I don't list the code for Shooter::Shooter(char*, MyFiles*) as you note, but, there's a good reason for that. Its actually defined in the header itself and you have the code listed there.
Shooter(char* filename, MyFiles* filehander)
: GameObject(filename, filehander) {};
Which indicates that if you try to create a shooter and pass a char* filename, and a MyFiles* pointer, it will in fact call the GameObject constructor which is a base class Big Grin
Now, I don't think I've explained that at all well here, so am adding these files to the Kamakazi code with comments to clear that up.

We now have this code for shooter.h and cpp files 
Code:
#pragma once
//I'll start you off with this, as there is something here not well reviewed in the book, thanks to reader Jon Morrs for pointing this out
#pragma once
#include "GameObject.h"


class Shooter :
    public GameObject
{
public:
    Shooter();
    ~Shooter();

    Shooter(char* filename, MyFiles* filehander)
        : GameObject(filename, filehander) {}; // <<<< Look here, we provide the constructor with info to use a GameObject constuctor, and {} indicates that this shooter part does nothing.
    
    // these replace the pure virtuals    
    bool Update(Surface* s, Input* InputHandler);
    bool Update(Game* g);
    void Draw(Surface* TheScreen);
    
// feel free to add more methods and variables

};
and shooter.cpp

Code:
#include "Shooter.h"
#include "Game.h"

// we are using an overloaded constructor so we must give it a default constructor
Shooter::Shooter()
{
}

Shooter::~Shooter()
{
}
// now its important to note, we don't need to define this because we already did in the header file, if we add more code here we get errors..but if you feel
// you want to expand on this constructor, you can remove the {} from the end of the definition in the h file, and uncomment this code to add what you want.
// Thanks for Jon Morss for his help in identifying and clearing up confusion here.
//Shooter::Shooter(char*, MyFiles*)
//{
//    
//}

//
bool Shooter::Update(Surface* s, Input* a_Input)
{
    // this is up to you
}

bool Shooter::Update(Game* g)
{
// fill this in yourself
}


void Shooter::Draw(Surface* TheScreen)
{
    Image->CopyAlphaPlot(TheScreen, Xpos, Ypos);
    
}
Brian Beuken
Lecturer in Game Programming at Breda University of Applied Sciences.
Author of The Fundamentals of C/C++ Game Programming: Using Target-based Development on SBC's 



Reply


Messages In This Thread
[Chapter 05] KamaKazi Base code - by jomoengineer - 11-13-2018, 07:57 AM
RE: [Chapter 05] KamaKazi Base code - by Brian Beuken - 11-19-2018, 08:15 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)