NILS

Good tunes to listen to while programming

Posted on Updated on

I love programming. Especially as a job, i mean it’s like playing with computers all day and get paid for it!

But while coding all day is fun .. it’s not as fun to be in the zone without some good tunes pumping into your ears. So I decided to share some of my favourites!



Happy coding!

‘ReceiveActorBeginOverlap’ marked ‘override’ but does not override any member functions – (Unreal Engine 4 with C++, Mac OSX)

Posted on Updated on

スクリーンショット 2015-09-20 21.15.00

After playing with Cocos2dx and Unity 5, I decided to challenge myself even further by working on a test project (FPS, 3rd person shooter etc) using Unreal Engine 4 with C++.

While working on a first person shooter project, I was in the middle of creating power up / health pick up items. All was going well until I ran into this error message:

‘ReceiveActorBeginOverlap’ marked ‘override’ but does not override any member functions

My source code below:

.h header file

    #pragma once
     #include "GameFramework/Actor.h"
     #include "HealthPack.generated.h"

    UCLASS()
    class TESTFPS_API AHealthPack : public AActor
    {
	    GENERATED_BODY()
	
    public:	
    	AHealthPack();	
	    AHealthPack(const FObjectInitializer& ObjectInitializer);	

	    virtual void 	BeginPlay()  override;
	    virtual void 	Tick( float DeltaSeconds ) override;
	    virtual void 	ReceiveActorBeginOverlap(class AActor* Other)	override;	

And in my .cpp implementation file l declare this method like this:

    void AHealthPack::ReceiveActorBeginOverlap(class AActor* Other)	
    {
     	if (Other != NULL)
	    {
	    	if (CanBePickedUp(Cast<ATestFPSCharacter>(Other)))
	    	{
	    		HandlePickUp(Cast<ATestFPSCharacter>(Other));
	    		HandleEffects();
	    		removeFromWorld();
	    	}
	    }
    }

Turns out that “ReceiveActorBeginOverlap” is not virtual so you cannot override this method (anymore). So to solve this you need to override <strong"NotifyActorBeginOverlap" and then call Super inside this function. Modifying the lines above to below resolves my error:

.h header file:

virtual void 	NotifyActorBeginOverlap(class AActor* Other)	override;

.cpp implementation file:

/**
 *	Check if we can pick up a health pack
 */
void AHealthPack::NotifyActorBeginOverlap(class AActor* Other)	
{
	Super::NotifyActorBeginOverlap(Other);

	if (Other != NULL)
	{
		if (CanBePickedUp(Cast< ATestFPSCharacter >(Other)))
		{
			HandlePickUp(Cast< ATestFPSCharacter >(Other));
			HandleEffects();
			removeFromWorld();
		}
	}
}

Samurai Gunship – A retro flavour 2D casual shooter game!

Posted on Updated on

At long last I am ready to unveil a game I have been developing with Pamprepps Games in Japan for a few months. Thanks to my friend Lee Adams (a good friend from all the way back in the day when we used to play Beyblade and talk about Sonic the hedgehog) for composing the BGM!

An iOS is being released soon. Till then stay tuned!

DL link:
https://play.google.com/store/apps/details?id=com.pamprepps.samuraigames

スクリーンショット 2015-09-02 14.17.38

◆◇◆Samurai Gunship◆◇◆
A simple retro flavour shooter game.
Destroy incoming enemy aliens to score points.

◆◇◆How to play◆◇◆
To destroy enemy targets, set your gunship into position by holding down the left or right arrow buttons. The fuel you carry doesn’t last forever, however you can extend the time you have left by collecting points and by moving through each wave.

How to traverse through a 2D CCArray – Cocos2dx, C++ on Android (and 5 month workout progress)

Posted on Updated on

Couldn’t find anything on making a multidimensonal CCArray anywhere so I’m leaving this here so I don’t forget later.

Objective:
Generate an array which holds an array that holds a sprite.

Adding into our 2D CCArray:
Lets open our text editor and write some code!

Somewhere in our header file

	// ... 
    Sprite*                     _spriteImage;
    CCArray*                    _arr_x;
    CCArray*                    _arr_y;
	// ...

Now in our implementation file:
cpp file:

/**
 * add sprites into a 2D CCArray
 */
void Hoge::addIntoMultiCCArray() {
    _arr_x = CCArray::create();

    for (int i = 0; i < ARRAY_SIZE; i++) {
        for (int j = 0; j < ARRAY_SIZE; j++) {
            _arr_y = CCArray::create();

				int randomized_tag  = rand();                                  // generate a random tag to identify which element
				int pos_x           = i * 100 / 1.5f;                          
				int pos_y           = j * 100 / 1.5f;                          
  
                _spriteImage   	   = MySprite::create();
                _spriteImage        -> setPosition(Point(visibleSize.width / 4 + pos_x, visibleSize.height / 2 + pos_y));
                _spriteImage   	  -> setTag(randomized_tag);
                _arr_y         	  -> addObject(_spriteImage);
                this           	  -> addChild(_spriteImage);

                _arr_x   -> addObject(_arr_y);            //  Where the magic happens
        }
    }
    _arr_x -> retain();
    _arr_y -> retain();
}

Adding into a multi CCArray is quite straight forward. For each element in the first CCArray you just need to create another CCArray to produce that multidimensional array.

Now we want to do something else besides adding.

Why the traditional way is a bad idea:
The traditional way of traversing through a 2D array is with for loops:

for (int x = 0; x < ARRAY_SIZE; x++) {
	for (int y = 0; y < ARRAY_SIZE; y++) {
		// do something
	}
}

Lets say we want to edit or delete something. We can’t just do the traditional way like above.

Compiling the code using this method is okay, but at runtime this will produce unexpected behavior and our app will crash due to memory leaks. So to counter this, we need to use CCArrays CCCARRAY_FOREACH method.

Solution:

// ... somewhere below our implementation file

    // traverse through our multi CCArray
    CCObject*   obj_x = NULL;
    CCObject*   obj_y = NULL;

    CCARRAY_FOREACH(_arr_x, obj_x) {
        CCArray* _obj_x_arr = (static_cast<CCArray*>(obj_x));

        CCARRAY_FOREACH(_obj_x_arr, obj_y) {
            Sprite* _spriteImage_y  = (static_cast<Sprite*>(obj_y));
            Rect rect_a         = IntersectionPoint_A -> getBoundingBox();
            Rect rect_b               = _spriteImage_y  -> getBoundingBox();

            if (rect_b.intersectsRect(rect_a)) {                
                // maybe delete this element from _arr_y?
                _obj_x_arr -> removeObject(_spriteImage_y);
                this       -> removeChildByTag(_spriteImage_y -> getTag());	
            }
        }

    }

Hopefully this will help someone out there. Maybe my coding still is weird (and if it is I would love some feedback on how to write better code^^)

Oh yeah before I forget, here is a recent picture of my arm after 5 months of workout!

Not bad eh? Gotta keep eating and working!
Happy coding!

Generate array of sprites (Cocos2dx, C++, Android)

Posted on Updated on

alright before i forget i better write this down (being an idiot that i am i’ll forget this later)

i have this image:

which when fired at, a single block explodes gracefully like a new born baby taking its first breath outside of a womans-anyway having 1 massive image like the one above to hold several dozen block images isn’t a good idea.

A better way to do this is to have each block:
block

stored in an array or vector, loop over then before the loop is finished, add each element into our layer.

In code this would look something like this:

Block header file .h

#ifndef __BLOCK_H__
#define __BLOCK_H__
 
#include "cocos2d.h"
 
class Block : public cocos2d::Sprite
{
 
// ....
 
protected:
    Sprite*                 block;
 
public:
    Block();                                                    //  constructor
    Sprite*                 generateBlock(int pos);             //  generate a block
};
 
 
#endif // __BLOCK_H__

Block Implementation file.cpp

// ... 
Sprite* Block::generateBlock(int pos) {
    Block        _block_obj;            // instantiate our block class
// ...
    block      = Sprite::create("block.png");
    block     -> setPosition(Vec2(visibleSize.width/2 + pos, visibleSize.height));
    return block;
}
 
// ...

Now in our game scene we can do something like this:

Game scene header file.h

// ...
std::array<cocos2d::Sprite*, 10> _blockArray;
void    generateBlocksThenAddToArray();                              // generate a block then add into our array
// ...

implementation file .cpp

/**
 *  generate a block then add into our array
 */
void Hoge::generateBlocksThenAddToArray() {
 
    for (int i = 0; i < 10; i++) {
        Sprite* _generatedBlock  = _block_obj.generateBlock((i * 100) / 2);
        _blockArray[i]        = _generatedBlock;
        this                 -> addChild(_generatedBlock);
    }
}

The magic happens in the for loop in Hoge::generateBlocksThenAddToArray() method.
We loop to a suitable range (10 in this case),generate a block from the block class, set its x position by multiplying it by 100 per iteration using i, then add the instantiated block object into our _blockArray with the loop count as its address, then finally add the generated block into our game scene.

There’s probably another (better) way to do this, and I’d love some input from other talented programmers out there so, please give me a shout in the comment section below!

BBQ & Japan updates

Video Posted on Updated on

It’s been another month since I last updated and as expected a lot of things have happened.

I used to work at a chinese restaurant the school got me. And while I am grateful for their efforts I didnt like it very much. It was good to work with Japanese chefs but there was absolutely no time to talk freely since it was always busy. But other than that I was just washing dishes and maybe cooking a little but not much. Carrying hot plates straight out of the machine did some damage to my hands so part of my skin in my fingers kinda melted off a bit and now i have to moisturize it like crazy.

Good news is though I quit that job over a week ago and I now work for Seven Eleven, which is a 24 hours convenience store all over Japan … kinda as popular as Starbucks now that I think about it. Seriously, theyre everywhere. I found the job and applied by myself and got it within that week. So now I have more chances to work with Japanese people and talk to them freely and theyre all extremely nice people too!

School was on a 1 1/2 month Summer break and 2-3 weeks later we’re now in Autumn break for a week. It’s … well I haven’t got any complaints because I still study but its nice to have someone help me in a while.

 

1267766_448923848555585_2031425408_o

A few days ago me and some friends went to a BBQ with the owner of the Japanese bar Rough Times. They don’t have a website but they are mentioned here in a food blog site:

http://tabelog.com/fukuoka/A4008/A400802/40025518/

Just to better explain what sort of life I have in Japan I made a video and decided to upload it here! So without rambling on, please check it out in HD

Laters!

《The Last Samurai 翻訳》 + small update

Posted on Updated on

Hi, Sorry I haven’t updated in a very long time. But to make it brief on the last one:

1) I’m finally leaving my part time job in that chinese restaurant because I got hired at an even better place to work, closer, better environment and better experience. Pay wise, not so much different. Still, good.

 

2) Studying has been on and off, but made up a lot in a lot of non english leisure time (films, books & friends etc)

3) It’s been pretty hot. Sweating like crazy.

 

Anyway I few weeks ago or two I watched The Last Samurai and one part of the movie got me thinking on how to translate it in my own words. So I finally got to it and here it is:

 

“From the moment they wake they devote themselves to the perfection of whatever they pursue. I have never seen such discipline. I am surprised to learn that the word ‘Samurai’ means‘to serve’…” 

「起きる瞬間から目的まで一部たりともミスのないように、彼らはそれなりに前進する。私はこれ程の自制心そのものを見たことがない。侍というのは誰かのためにこうするわけだとはね」

 

また更新するからお楽しみ

Ben