2022-06-17 22:16:55 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022 @aismann; Peter Eismann, Germany; dreifrankensoft
|
|
|
|
*
|
|
|
|
* This software is provided 'as-is', without any express or implied
|
|
|
|
* warranty. In no event will the authors be held liable for any damages
|
|
|
|
* arising from the use of this software.
|
|
|
|
* Permission is granted to anyone to use this software for any purpose,
|
|
|
|
* including commercial applications, and to alter it and redistribute it
|
|
|
|
* freely, subject to the following restrictions:
|
|
|
|
* 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
* claim that you wrote the original software. If you use this software
|
|
|
|
* in a product, an acknowledgment in the product documentation would be
|
|
|
|
* appreciated but is not required.
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
* misrepresented as being the original software.
|
|
|
|
* 3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __SIMPLE_SNAKE_SCENE_H__
|
|
|
|
#define __SIMPLE_SNAKE_SCENE_H__
|
|
|
|
|
|
|
|
#include "cocos2d.h"
|
|
|
|
|
2022-06-24 21:12:31 +08:00
|
|
|
const int snakeBodies = 9;
|
2022-06-17 22:16:55 +08:00
|
|
|
const int StartBodies = 4;
|
|
|
|
|
|
|
|
class SimpleSnake : public cocos2d::Scene
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual bool init() override;
|
|
|
|
|
|
|
|
// a selector callback
|
|
|
|
void menuCloseCallback(Ref* sender);
|
|
|
|
virtual void update(float delta) override;
|
2022-06-24 21:12:31 +08:00
|
|
|
void drawAll(bool finish);
|
2022-06-17 22:16:55 +08:00
|
|
|
void onKeyPressed(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event* event);
|
|
|
|
|
|
|
|
cocos2d::Vec2 offset;
|
|
|
|
cocos2d::DrawNode* mydraw;
|
|
|
|
|
|
|
|
// game stuff
|
2022-06-25 10:16:54 +08:00
|
|
|
int N = 36, M = 36;
|
2022-06-17 22:16:55 +08:00
|
|
|
int size = 20;
|
|
|
|
int w = size * N;
|
|
|
|
int h = size * M;
|
|
|
|
float level = 0.1;
|
|
|
|
float myScore[snakeBodies + StartBodies];
|
|
|
|
|
|
|
|
float startLevelTime = 0.0;
|
|
|
|
float endLevelTime = 0.0;
|
|
|
|
|
|
|
|
int dir, num = StartBodies;
|
2022-06-24 21:12:31 +08:00
|
|
|
cocos2d::Label* myScoreLabel[snakeBodies + 1];
|
2022-06-25 10:16:54 +08:00
|
|
|
cocos2d::Sprite* background;
|
2022-06-17 22:16:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __SIMPLE_SNAKE_SCENE_H__
|