SimpleSnake small updates

- CodeCleanup
- MIT License file
- readme update
This commit is contained in:
aismann 2022-06-15 07:02:08 +02:00
parent 559bb6881e
commit 05f92e4208
3 changed files with 46 additions and 20 deletions

View File

@ -157,20 +157,16 @@ void SimpleSnake::onKeyPressed(EventKeyboard::KeyCode keyCode, Event* event)
switch (keyCode)
{
case cocos2d::EventKeyboard::KeyCode::KEY_LEFT_ARROW:
if (dir != 2)
dir = 1;
if (dir != 2) dir = 1;
break;
case cocos2d::EventKeyboard::KeyCode::KEY_RIGHT_ARROW:
if (dir != 1)
dir = 2;
if (dir != 1) dir = 2;
break;
case cocos2d::EventKeyboard::KeyCode::KEY_UP_ARROW:
if (dir != 3)
dir = 0;
if (dir != 3) dir = 0;
break;
case cocos2d::EventKeyboard::KeyCode::KEY_DOWN_ARROW:
if (dir != 0)
dir = 3;
if (dir != 0) dir = 3;
break;
default:
break;
@ -185,7 +181,7 @@ void SimpleSnake::menuCloseCallback(Ref* sender)
void SimpleSnake::update(float delta)
{
static float runTime = 0;
static bool finish = false;
static bool finish = false;
runTime += delta;
endLevelTime += delta;
@ -204,23 +200,19 @@ void SimpleSnake::update(float delta)
{
case 0:
s[0].y++;
if (s[0].y >= M)
s[0].y = 0;
if (s[0].y >= M) s[0].y = 0;
break;
case 1:
s[0].x--;
if (s[0].x < 0)
s[0].x = N;
if (s[0].x < 0) s[0].x = N;
break;
case 2:
s[0].x++;
if (s[0].x >= N)
s[0].x = 0;
if (s[0].x >= N) s[0].x = 0;
break;
case 3:
s[0].y--;
if (s[0].y < 0)
s[0].y = M;
if (s[0].y < 0) s[0].y = M;
break;
default:
break;
@ -249,7 +241,7 @@ void SimpleSnake::update(float delta)
myScore[num - StartBodies] = endLevelTime;
sprintf(buffer, "Level %i Time : %f", num - StartBodies + 1, myScore[num - StartBodies]);
myScoreLabel[num - StartBodies]->setString(buffer);
if (num >= (snakeBodies + StartBodies-1))
if (num >= (snakeBodies + StartBodies - 1))
{
myScoreLabel[num - StartBodies]->setString("FINISH");
finish = true;

View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) @aismann; Peter Eismann, Germany; dreifrankensoft
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,7 +1,20 @@
Simple Snake
adxe version of a "Simple Snake" game.
If you have any questions or want to continue this project feel free to do so.
Here are some ideas:
- Improve the "score optic"
- Save the "highsore times"
- Use sprites unstead of draw primitives
- Add some effects (sound, exploding stuff, traps, etc)
- or use it as startup
Idea from here:
https://www.youtube.com/channel/UCC7qpnId5RIQruKDJOt2exw
MIT License
# adxe Simple Snake Example
Easy adxe version of a "Simple Snake" game