2006-03-31 12:00:26 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 by Mat Holton
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-03-31 12:00:26 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "plugin.h"
|
2009-07-21 17:29:46 +00:00
|
|
|
#include "lib/display_text.h"
|
2008-11-20 11:27:31 +00:00
|
|
|
#include "lib/helper.h"
|
2009-07-21 17:29:46 +00:00
|
|
|
#include "lib/highscore.h"
|
|
|
|
#include "lib/playback_control.h"
|
2007-08-15 12:42:09 +00:00
|
|
|
|
2010-08-24 14:30:46 +00:00
|
|
|
|
2006-03-31 12:00:26 +00:00
|
|
|
|
|
|
|
/* variable button definitions */
|
|
|
|
#if CONFIG_KEYPAD == RECORDER_PAD
|
|
|
|
#define AST_PAUSE BUTTON_ON
|
|
|
|
#define AST_QUIT BUTTON_OFF
|
|
|
|
#define AST_THRUST BUTTON_UP
|
|
|
|
#define AST_HYPERSPACE BUTTON_DOWN
|
2009-12-05 14:08:09 +00:00
|
|
|
#define AST_LEFT BUTTON_LEFT
|
2006-03-31 12:00:26 +00:00
|
|
|
#define AST_RIGHT BUTTON_RIGHT
|
|
|
|
#define AST_FIRE BUTTON_PLAY
|
|
|
|
|
2007-01-14 13:48:09 +00:00
|
|
|
#elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
|
|
|
|
#define AST_PAUSE BUTTON_ON
|
|
|
|
#define AST_QUIT BUTTON_OFF
|
|
|
|
#define AST_THRUST BUTTON_UP
|
|
|
|
#define AST_HYPERSPACE BUTTON_DOWN
|
2009-12-05 14:08:09 +00:00
|
|
|
#define AST_LEFT BUTTON_LEFT
|
2007-01-14 13:48:09 +00:00
|
|
|
#define AST_RIGHT BUTTON_RIGHT
|
|
|
|
#define AST_FIRE BUTTON_SELECT
|
|
|
|
|
2006-03-31 12:00:26 +00:00
|
|
|
#elif CONFIG_KEYPAD == ONDIO_PAD
|
2006-03-31 12:39:32 +00:00
|
|
|
#define AST_PAUSE (BUTTON_MENU | BUTTON_OFF)
|
2006-03-31 12:00:26 +00:00
|
|
|
#define AST_QUIT BUTTON_OFF
|
|
|
|
#define AST_THRUST BUTTON_UP
|
|
|
|
#define AST_HYPERSPACE BUTTON_DOWN
|
|
|
|
#define AST_LEFT BUTTON_LEFT
|
|
|
|
#define AST_RIGHT BUTTON_RIGHT
|
|
|
|
#define AST_FIRE BUTTON_MENU
|
|
|
|
|
|
|
|
#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == IRIVER_H300_PAD)
|
|
|
|
#define AST_PAUSE BUTTON_REC
|
|
|
|
#define AST_QUIT BUTTON_OFF
|
|
|
|
#define AST_THRUST BUTTON_UP
|
|
|
|
#define AST_HYPERSPACE BUTTON_DOWN
|
2009-12-05 14:08:09 +00:00
|
|
|
#define AST_LEFT BUTTON_LEFT
|
2006-03-31 12:00:26 +00:00
|
|
|
#define AST_RIGHT BUTTON_RIGHT
|
|
|
|
#define AST_FIRE BUTTON_SELECT
|
|
|
|
|
2006-06-30 16:43:47 +00:00
|
|
|
#define AST_RC_QUIT BUTTON_RC_STOP
|
|
|
|
|
2007-03-16 23:02:39 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
|
2006-03-31 12:00:26 +00:00
|
|
|
#define AST_PAUSE BUTTON_PLAY
|
|
|
|
#define AST_QUIT BUTTON_POWER
|
|
|
|
#define AST_THRUST BUTTON_UP
|
|
|
|
#define AST_HYPERSPACE BUTTON_DOWN
|
2009-12-05 14:08:09 +00:00
|
|
|
#define AST_LEFT BUTTON_LEFT
|
2006-03-31 12:00:26 +00:00
|
|
|
#define AST_RIGHT BUTTON_RIGHT
|
|
|
|
#define AST_FIRE BUTTON_SELECT
|
|
|
|
|
2007-07-27 09:57:27 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == IPOD_1G2G_PAD)
|
2006-03-31 12:00:26 +00:00
|
|
|
#define AST_PAUSE (BUTTON_SELECT | BUTTON_PLAY)
|
|
|
|
#define AST_QUIT (BUTTON_SELECT | BUTTON_MENU)
|
|
|
|
#define AST_THRUST BUTTON_MENU
|
|
|
|
#define AST_HYPERSPACE BUTTON_PLAY
|
|
|
|
#define AST_LEFT BUTTON_SCROLL_BACK
|
|
|
|
#define AST_RIGHT BUTTON_SCROLL_FWD
|
|
|
|
#define AST_FIRE BUTTON_SELECT
|
2006-05-22 16:28:19 +00:00
|
|
|
|
|
|
|
#elif (CONFIG_KEYPAD == GIGABEAT_PAD)
|
2007-05-19 23:38:09 +00:00
|
|
|
#define AST_PAUSE BUTTON_A
|
|
|
|
#define AST_QUIT BUTTON_POWER
|
2006-05-22 16:28:19 +00:00
|
|
|
#define AST_THRUST BUTTON_UP
|
|
|
|
#define AST_HYPERSPACE BUTTON_DOWN
|
2009-12-05 14:08:09 +00:00
|
|
|
#define AST_LEFT BUTTON_LEFT
|
2006-05-22 16:28:19 +00:00
|
|
|
#define AST_RIGHT BUTTON_RIGHT
|
|
|
|
#define AST_FIRE BUTTON_SELECT
|
2006-08-03 20:17:25 +00:00
|
|
|
|
2006-10-26 13:38:09 +00:00
|
|
|
#elif (CONFIG_KEYPAD == SANSA_E200_PAD)
|
2007-01-15 20:40:48 +00:00
|
|
|
#define AST_PAUSE BUTTON_REC
|
2006-10-26 13:38:09 +00:00
|
|
|
#define AST_QUIT BUTTON_POWER
|
2009-01-04 23:33:15 +00:00
|
|
|
#define AST_THRUST BUTTON_UP
|
|
|
|
#define AST_HYPERSPACE BUTTON_DOWN
|
|
|
|
#define AST_LEFT BUTTON_SCROLL_BACK
|
|
|
|
#define AST_RIGHT BUTTON_SCROLL_FWD
|
|
|
|
#define AST_FIRE BUTTON_SELECT
|
|
|
|
|
|
|
|
#elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
|
2009-04-10 17:28:26 +00:00
|
|
|
#define AST_PAUSE (BUTTON_SELECT | BUTTON_UP)
|
|
|
|
#define AST_QUIT (BUTTON_HOME|BUTTON_REPEAT)
|
2006-10-26 13:38:09 +00:00
|
|
|
#define AST_THRUST BUTTON_UP
|
|
|
|
#define AST_HYPERSPACE BUTTON_DOWN
|
2008-01-10 08:08:31 +00:00
|
|
|
#define AST_LEFT BUTTON_SCROLL_BACK
|
|
|
|
#define AST_RIGHT BUTTON_SCROLL_FWD
|
2006-10-26 13:38:09 +00:00
|
|
|
#define AST_FIRE BUTTON_SELECT
|
|
|
|
|
2007-09-20 10:49:48 +00:00
|
|
|
#elif (CONFIG_KEYPAD == SANSA_C200_PAD)
|
|
|
|
#define AST_PAUSE BUTTON_REC
|
|
|
|
#define AST_QUIT BUTTON_POWER
|
|
|
|
#define AST_THRUST BUTTON_UP
|
|
|
|
#define AST_HYPERSPACE BUTTON_DOWN
|
|
|
|
#define AST_LEFT BUTTON_LEFT
|
2008-11-28 00:37:28 +00:00
|
|
|
#define AST_RIGHT BUTTON_RIGHT
|
|
|
|
#define AST_FIRE BUTTON_SELECT
|
|
|
|
|
|
|
|
#elif (CONFIG_KEYPAD == SANSA_CLIP_PAD)
|
|
|
|
#define AST_PAUSE BUTTON_HOME
|
|
|
|
#define AST_QUIT BUTTON_POWER
|
|
|
|
#define AST_THRUST BUTTON_UP
|
|
|
|
#define AST_HYPERSPACE BUTTON_DOWN
|
|
|
|
#define AST_LEFT BUTTON_LEFT
|
2007-09-20 10:49:48 +00:00
|
|
|
#define AST_RIGHT BUTTON_RIGHT
|
|
|
|
#define AST_FIRE BUTTON_SELECT
|
|
|
|
|
2008-12-12 19:50:49 +00:00
|
|
|
#elif (CONFIG_KEYPAD == SANSA_M200_PAD)
|
|
|
|
#define AST_PAUSE (BUTTON_SELECT | BUTTON_UP)
|
|
|
|
#define AST_QUIT BUTTON_POWER
|
|
|
|
#define AST_THRUST BUTTON_UP
|
|
|
|
#define AST_HYPERSPACE BUTTON_DOWN
|
|
|
|
#define AST_LEFT BUTTON_LEFT
|
|
|
|
#define AST_RIGHT BUTTON_RIGHT
|
|
|
|
#define AST_FIRE (BUTTON_SELECT | BUTTON_REL)
|
|
|
|
|
2006-08-03 20:17:25 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
|
|
|
|
#define AST_PAUSE BUTTON_PLAY
|
|
|
|
#define AST_QUIT BUTTON_POWER
|
|
|
|
#define AST_THRUST BUTTON_SCROLL_UP
|
|
|
|
#define AST_HYPERSPACE BUTTON_SCROLL_DOWN
|
2009-12-05 14:08:09 +00:00
|
|
|
#define AST_LEFT BUTTON_LEFT
|
2006-08-03 20:17:25 +00:00
|
|
|
#define AST_RIGHT BUTTON_RIGHT
|
|
|
|
#define AST_FIRE BUTTON_REW
|
|
|
|
|
2008-02-17 12:23:02 +00:00
|
|
|
#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
|
|
|
|
#define AST_PAUSE BUTTON_PLAY
|
|
|
|
#define AST_QUIT BUTTON_BACK
|
|
|
|
#define AST_THRUST BUTTON_UP
|
|
|
|
#define AST_HYPERSPACE BUTTON_DOWN
|
2009-12-05 14:08:09 +00:00
|
|
|
#define AST_LEFT BUTTON_LEFT
|
2008-02-17 12:23:02 +00:00
|
|
|
#define AST_RIGHT BUTTON_RIGHT
|
|
|
|
#define AST_FIRE BUTTON_SELECT
|
|
|
|
|
2008-03-01 22:55:09 +00:00
|
|
|
#elif (CONFIG_KEYPAD == MROBE100_PAD)
|
|
|
|
#define AST_PAUSE BUTTON_DISPLAY
|
|
|
|
#define AST_QUIT BUTTON_POWER
|
|
|
|
#define AST_THRUST BUTTON_UP
|
|
|
|
#define AST_HYPERSPACE BUTTON_DOWN
|
2009-12-05 14:08:09 +00:00
|
|
|
#define AST_LEFT BUTTON_LEFT
|
2008-03-01 22:55:09 +00:00
|
|
|
#define AST_RIGHT BUTTON_RIGHT
|
|
|
|
#define AST_FIRE BUTTON_SELECT
|
|
|
|
|
2008-03-22 10:24:28 +00:00
|
|
|
#elif CONFIG_KEYPAD == IAUDIO_M3_PAD
|
|
|
|
#define AST_PAUSE BUTTON_RC_PLAY
|
|
|
|
#define AST_QUIT BUTTON_RC_REC
|
|
|
|
#define AST_THRUST BUTTON_RC_VOL_UP
|
|
|
|
#define AST_HYPERSPACE BUTTON_RC_VOL_DOWN
|
2009-12-05 14:08:09 +00:00
|
|
|
#define AST_LEFT BUTTON_RC_REW
|
2008-03-22 10:24:28 +00:00
|
|
|
#define AST_RIGHT BUTTON_RC_FF
|
|
|
|
#define AST_FIRE BUTTON_RC_MODE
|
|
|
|
|
2009-12-15 20:51:41 +00:00
|
|
|
#elif (CONFIG_KEYPAD == COWON_D2_PAD)
|
2008-03-22 22:03:34 +00:00
|
|
|
#define AST_QUIT BUTTON_POWER
|
|
|
|
|
2008-12-04 21:28:56 +00:00
|
|
|
#elif CONFIG_KEYPAD == CREATIVEZVM_PAD
|
2008-12-08 09:51:42 +00:00
|
|
|
#define AST_PAUSE BUTTON_PLAY
|
2008-12-04 21:28:56 +00:00
|
|
|
#define AST_QUIT BUTTON_BACK
|
|
|
|
#define AST_THRUST BUTTON_UP
|
|
|
|
#define AST_HYPERSPACE BUTTON_DOWN
|
2009-12-05 14:08:09 +00:00
|
|
|
#define AST_LEFT BUTTON_LEFT
|
2008-12-04 21:28:56 +00:00
|
|
|
#define AST_RIGHT BUTTON_RIGHT
|
2008-12-08 09:51:42 +00:00
|
|
|
#define AST_FIRE BUTTON_SELECT
|
2008-12-04 21:28:56 +00:00
|
|
|
|
2009-01-24 22:41:55 +00:00
|
|
|
#elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
|
|
|
|
#define AST_PAUSE BUTTON_VIEW
|
|
|
|
#define AST_QUIT BUTTON_POWER
|
|
|
|
#define AST_THRUST BUTTON_UP
|
|
|
|
#define AST_HYPERSPACE BUTTON_DOWN
|
|
|
|
#define AST_LEFT BUTTON_LEFT
|
|
|
|
#define AST_RIGHT BUTTON_RIGHT
|
|
|
|
#define AST_FIRE BUTTON_PLAYLIST
|
|
|
|
|
2010-11-03 02:45:53 +00:00
|
|
|
#elif CONFIG_KEYPAD == PHILIPS_HDD6330_PAD
|
|
|
|
#define AST_PAUSE BUTTON_PLAY
|
|
|
|
#define AST_QUIT BUTTON_POWER
|
|
|
|
#define AST_THRUST BUTTON_UP
|
|
|
|
#define AST_HYPERSPACE BUTTON_DOWN
|
|
|
|
#define AST_LEFT BUTTON_LEFT
|
|
|
|
#define AST_RIGHT BUTTON_RIGHT
|
|
|
|
#define AST_FIRE BUTTON_VOL_DOWN
|
|
|
|
|
2009-12-05 14:34:47 +00:00
|
|
|
#elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
|
|
|
|
#define AST_PAUSE BUTTON_RIGHT
|
|
|
|
#define AST_QUIT BUTTON_POWER
|
|
|
|
#define AST_THRUST BUTTON_UP
|
|
|
|
#define AST_HYPERSPACE BUTTON_DOWN
|
|
|
|
#define AST_LEFT BUTTON_PREV
|
|
|
|
#define AST_RIGHT BUTTON_NEXT
|
|
|
|
#define AST_FIRE BUTTON_LEFT
|
|
|
|
|
2009-08-31 21:11:32 +00:00
|
|
|
#elif (CONFIG_KEYPAD == ONDAVX747_PAD) || \
|
2009-12-12 14:05:03 +00:00
|
|
|
(CONFIG_KEYPAD == ONDAVX777_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == MROBE500_PAD)
|
2009-04-07 23:41:44 +00:00
|
|
|
#define AST_QUIT BUTTON_POWER
|
|
|
|
|
2009-08-04 03:08:32 +00:00
|
|
|
#elif (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
|
|
|
|
#define AST_PAUSE BUTTON_FFWD
|
|
|
|
#define AST_QUIT BUTTON_REC
|
|
|
|
#define AST_THRUST BUTTON_UP
|
|
|
|
#define AST_HYPERSPACE BUTTON_DOWN
|
2009-12-05 14:08:09 +00:00
|
|
|
#define AST_LEFT BUTTON_LEFT
|
2009-08-04 03:08:32 +00:00
|
|
|
#define AST_RIGHT BUTTON_RIGHT
|
|
|
|
#define AST_FIRE BUTTON_PLAY
|
|
|
|
|
2010-02-13 15:46:34 +00:00
|
|
|
#elif (CONFIG_KEYPAD == PBELL_VIBE500_PAD)
|
|
|
|
#define AST_PAUSE BUTTON_PLAY
|
|
|
|
#define AST_QUIT BUTTON_REC
|
|
|
|
#define AST_THRUST BUTTON_UP
|
|
|
|
#define AST_HYPERSPACE BUTTON_DOWN
|
|
|
|
#define AST_LEFT BUTTON_PREV
|
|
|
|
#define AST_RIGHT BUTTON_NEXT
|
|
|
|
#define AST_FIRE BUTTON_OK
|
|
|
|
|
2010-04-26 21:40:00 +00:00
|
|
|
#elif (CONFIG_KEYPAD == MPIO_HD200_PAD)
|
|
|
|
|
2010-11-02 10:44:34 +00:00
|
|
|
#define AST_PAUSE (BUTTON_PLAY|BUTTON_FUNC)
|
2010-04-26 21:40:00 +00:00
|
|
|
#define AST_QUIT (BUTTON_REC|BUTTON_PLAY)
|
|
|
|
#define AST_THRUST BUTTON_REC
|
|
|
|
#define AST_HYPERSPACE BUTTON_PLAY
|
2010-11-02 10:44:34 +00:00
|
|
|
#define AST_LEFT BUTTON_REW
|
|
|
|
#define AST_RIGHT BUTTON_FF
|
|
|
|
#define AST_FIRE BUTTON_FUNC
|
2010-04-26 21:40:00 +00:00
|
|
|
|
2010-11-30 10:52:14 +00:00
|
|
|
#elif (CONFIG_KEYPAD == MPIO_HD300_PAD)
|
|
|
|
|
|
|
|
#define AST_PAUSE BUTTON_PLAY
|
|
|
|
#define AST_QUIT (BUTTON_REC|BUTTON_REPEAT)
|
|
|
|
#define AST_THRUST BUTTON_MENU
|
|
|
|
#define AST_HYPERSPACE (BUTTON_PLAY|BUTTON_REPEAT)
|
|
|
|
#define AST_LEFT BUTTON_REW
|
|
|
|
#define AST_RIGHT BUTTON_FF
|
|
|
|
#define AST_FIRE BUTTON_ENTER
|
|
|
|
|
2008-03-01 22:55:09 +00:00
|
|
|
#else
|
|
|
|
#error No keymap defined!
|
2006-03-31 12:00:26 +00:00
|
|
|
#endif
|
2008-04-27 15:30:19 +00:00
|
|
|
|
2008-08-23 09:46:38 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
2008-04-27 15:30:19 +00:00
|
|
|
#ifndef AST_PAUSE
|
|
|
|
#define AST_PAUSE BUTTON_CENTER
|
|
|
|
#endif
|
|
|
|
#ifndef AST_QUIT
|
|
|
|
#define AST_QUIT BUTTON_TOPLEFT
|
|
|
|
#endif
|
|
|
|
#ifndef AST_THRUST
|
|
|
|
#define AST_THRUST BUTTON_TOPMIDDLE
|
|
|
|
#endif
|
|
|
|
#ifndef AST_HYPERSPACE
|
|
|
|
#define AST_HYPERSPACE BUTTON_TOPRIGHT
|
|
|
|
#endif
|
|
|
|
#ifndef AST_LEFT
|
2009-12-05 14:08:09 +00:00
|
|
|
#define AST_LEFT BUTTON_MIDLEFT
|
2008-04-27 15:30:19 +00:00
|
|
|
#endif
|
|
|
|
#ifndef AST_RIGHT
|
|
|
|
#define AST_RIGHT BUTTON_MIDRIGHT
|
|
|
|
#endif
|
|
|
|
#ifndef AST_FIRE
|
|
|
|
#define AST_FIRE BUTTON_BOTTOMMIDDLE
|
|
|
|
#endif
|
|
|
|
#endif
|
2006-03-31 12:00:26 +00:00
|
|
|
|
2009-12-05 14:08:09 +00:00
|
|
|
#define RES MAX(LCD_WIDTH, LCD_HEIGHT)
|
|
|
|
#define LARGE_LCD (RES >= 200)
|
2007-01-01 23:31:53 +00:00
|
|
|
|
2009-12-05 14:08:09 +00:00
|
|
|
#define CYCLETIME 30
|
2009-07-21 17:29:46 +00:00
|
|
|
|
2009-12-05 14:08:09 +00:00
|
|
|
#define SHOW_COL 0
|
|
|
|
#define SCALE 5000
|
2009-12-10 12:53:47 +00:00
|
|
|
#define WRAP_GAP (LARGE*SCALE*3)
|
2009-12-05 14:08:09 +00:00
|
|
|
#define POINT_SIZE 2
|
2009-12-09 13:17:21 +00:00
|
|
|
#define START_LEVEL 1
|
2006-03-31 12:00:26 +00:00
|
|
|
#define SHOW_LEVEL_TIME 50
|
2009-12-05 14:08:09 +00:00
|
|
|
#define EXPLOSION_LENGTH 20
|
|
|
|
|
|
|
|
#define MAX_NUM_ASTEROIDS 25
|
|
|
|
#define MAX_NUM_MISSILES 6
|
|
|
|
#define NUM_STARS 50
|
|
|
|
#define NUM_TRAIL_POINTS 70
|
2009-12-09 13:17:21 +00:00
|
|
|
#define MAX_LEVEL MAX_NUM_ASTEROIDS
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2006-03-31 12:00:26 +00:00
|
|
|
#define NUM_ASTEROID_VERTICES 10
|
|
|
|
#define NUM_SHIP_VERTICES 4
|
2009-12-09 13:17:21 +00:00
|
|
|
#define NUM_ENEMY_VERTICES 8
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-10 12:53:47 +00:00
|
|
|
#define INVULNERABLE_TIME 30
|
2009-12-05 14:08:09 +00:00
|
|
|
#define BLINK_TIME 10
|
|
|
|
#define EXTRA_LIFE 250
|
|
|
|
#define START_LIVES 3
|
2009-12-10 12:53:47 +00:00
|
|
|
#define MISSILE_LIFE_LENGTH 40
|
2009-12-05 14:08:09 +00:00
|
|
|
|
|
|
|
#define ASTEROID_SPEED (RES/20)
|
|
|
|
#define SPACE_CHECK_SIZE 30*SCALE
|
|
|
|
|
2009-12-10 12:53:47 +00:00
|
|
|
#if (LARGE_LCD)
|
|
|
|
#define SIZE_SHIP_COLLISION 8*SCALE
|
|
|
|
#else
|
|
|
|
#define SIZE_SHIP_COLLISION 6*SCALE
|
|
|
|
#endif
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
#define LITTLE_SHIP 1
|
|
|
|
#define BIG_SHIP 2
|
2009-12-05 14:08:09 +00:00
|
|
|
#define ENEMY_BIG_PROBABILITY_START 10
|
|
|
|
#define ENEMY_APPEAR_PROBABILITY_START 35
|
2009-12-09 13:17:21 +00:00
|
|
|
#define ENEMY_APPEAR_TIMING_START 600
|
2006-03-31 12:00:26 +00:00
|
|
|
#define ENEMY_SPEED 4
|
2009-12-10 12:53:47 +00:00
|
|
|
#define ENEMY_MISSILE_LIFE_LENGTH (RES/2)
|
2009-12-09 13:17:21 +00:00
|
|
|
#if (LARGE_LCD)
|
|
|
|
#define SIZE_ENEMY_COLLISION 7*SCALE
|
|
|
|
#else
|
2006-03-31 12:00:26 +00:00
|
|
|
#define SIZE_ENEMY_COLLISION 5*SCALE
|
2009-12-09 13:17:21 +00:00
|
|
|
#endif
|
2006-03-31 12:00:26 +00:00
|
|
|
|
|
|
|
#define SIN_COS_SCALE 10000
|
|
|
|
|
|
|
|
#define FAST_ROT_CW_SIN 873
|
|
|
|
#define FAST_ROT_CW_COS 9963
|
|
|
|
#define FAST_ROT_ACW_SIN -873
|
|
|
|
#define FAST_ROT_ACW_COS 9963
|
|
|
|
|
|
|
|
#define MEDIUM_ROT_CW_SIN 350
|
|
|
|
#define MEDIUM_ROT_CW_COS 9994
|
|
|
|
#define MEDIUM_ROT_ACW_SIN -350
|
|
|
|
#define MEDIUM_ROT_ACW_COS 9994
|
|
|
|
|
|
|
|
#define SLOW_ROT_CW_SIN 350
|
|
|
|
#define SLOW_ROT_CW_COS 9994
|
2009-12-05 14:08:09 +00:00
|
|
|
#define SLOW_ROT_ACW_SIN -350
|
2006-03-31 12:00:26 +00:00
|
|
|
#define SLOW_ROT_ACW_COS 9994
|
|
|
|
|
2007-01-01 23:31:53 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
#define SHIP_ROT_CW_SIN 2419
|
|
|
|
#define SHIP_ROT_CW_COS 9702
|
2009-12-05 14:08:09 +00:00
|
|
|
#define SHIP_ROT_ACW_SIN -2419
|
2007-01-01 23:31:53 +00:00
|
|
|
#define SHIP_ROT_ACW_COS 9702
|
|
|
|
#else
|
|
|
|
#define SHIP_ROT_CW_SIN 3827
|
|
|
|
#define SHIP_ROT_CW_COS 9239
|
2009-12-05 14:08:09 +00:00
|
|
|
#define SHIP_ROT_ACW_SIN -3827
|
|
|
|
#define SHIP_ROT_ACW_COS 9239
|
2007-01-01 23:31:53 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
#define SCALED_WIDTH (LCD_WIDTH*SCALE)
|
|
|
|
#define SCALED_HEIGHT (LCD_HEIGHT*SCALE)
|
|
|
|
#define CENTER_LCD_X (LCD_WIDTH/2)
|
|
|
|
#define CENTER_LCD_Y (LCD_HEIGHT/2)
|
2007-01-01 23:31:53 +00:00
|
|
|
|
2006-03-31 14:38:15 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
2009-12-05 14:08:09 +00:00
|
|
|
#define ASTEROID_R 230
|
|
|
|
#define ASTEROID_G 200
|
|
|
|
#define ASTEROID_B 100
|
|
|
|
#define SHIP_R 255
|
|
|
|
#define SHIP_G 255
|
|
|
|
#define SHIP_B 255
|
|
|
|
#define ENEMY_R 50
|
|
|
|
#define ENEMY_G 220
|
|
|
|
#define ENEMY_B 50
|
|
|
|
#define THRUST_R 200
|
|
|
|
#define THRUST_G 200
|
|
|
|
#define THRUST_B 0
|
|
|
|
|
2006-03-31 14:38:15 +00:00
|
|
|
#define COL_MISSILE LCD_RGBPACK(200,0,0)
|
|
|
|
#define COL_PLAYER LCD_RGBPACK(200,200,200)
|
2009-05-24 23:42:32 +00:00
|
|
|
#define COL_INVULN LCD_RGBPACK(100,100,200)
|
2006-03-31 14:38:15 +00:00
|
|
|
#define COL_STARS LCD_WHITE
|
2007-01-01 23:31:53 +00:00
|
|
|
#define COL_ASTEROID LCD_RGBPACK(ASTEROID_R,ASTEROID_G,ASTEROID_B)
|
2006-03-31 14:38:15 +00:00
|
|
|
#define COL_TEXT LCD_RGBPACK(200,200,255)
|
2007-01-01 23:31:53 +00:00
|
|
|
#define COL_ENEMY LCD_RGBPACK(ENEMY_R,ENEMY_G,ENEMY_B)
|
2006-03-31 14:38:15 +00:00
|
|
|
#define SET_FG rb->lcd_set_foreground
|
|
|
|
#define SET_BG rb->lcd_set_background
|
|
|
|
#else
|
|
|
|
#define SET_FG(x)
|
|
|
|
#define SET_BG(x)
|
|
|
|
#endif
|
|
|
|
|
2010-02-27 14:45:37 +00:00
|
|
|
#define SCORE_FILE PLUGIN_GAMES_DIR "/spacerocks.score"
|
2009-07-21 17:29:46 +00:00
|
|
|
#define NUM_SCORES 5
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
static struct highscore highscores[NUM_SCORES];
|
2009-07-21 17:29:46 +00:00
|
|
|
|
2007-01-01 23:31:53 +00:00
|
|
|
/* The array of points that make up an asteroid */
|
|
|
|
static const short asteroid_one[NUM_ASTEROID_VERTICES*2] =
|
2009-12-05 14:08:09 +00:00
|
|
|
{
|
|
|
|
-2, -12,
|
|
|
|
4, -8,
|
|
|
|
8, -14,
|
|
|
|
16, -5,
|
|
|
|
14, 0,
|
|
|
|
20, 2,
|
|
|
|
12, 14,
|
|
|
|
-4, 14,
|
|
|
|
-10, 6,
|
|
|
|
-10, -8,
|
2007-01-01 23:31:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* The array of points that make up an asteroid */
|
|
|
|
static const short asteroid_two[NUM_ASTEROID_VERTICES*2] =
|
2009-12-05 14:08:09 +00:00
|
|
|
{
|
|
|
|
-2, -12,
|
|
|
|
4, -16,
|
|
|
|
6, -14,
|
|
|
|
16, -8,
|
|
|
|
14, 0,
|
|
|
|
20, 2,
|
2007-01-01 23:31:53 +00:00
|
|
|
12, 14,
|
|
|
|
-4, 14,
|
2009-12-05 14:08:09 +00:00
|
|
|
-10, 6,
|
|
|
|
-10, -8,
|
2007-01-01 23:31:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* The array of points that make up an asteroid */
|
|
|
|
static const short asteroid_three[NUM_ASTEROID_VERTICES*2] =
|
2009-12-05 14:08:09 +00:00
|
|
|
{
|
|
|
|
-2, -12,
|
|
|
|
4, -16,
|
|
|
|
6, -14,
|
|
|
|
2, -8,
|
|
|
|
14, 0,
|
|
|
|
20, 2,
|
2007-01-01 23:31:53 +00:00
|
|
|
12, 14,
|
|
|
|
-4, 14,
|
2009-12-05 14:08:09 +00:00
|
|
|
-16, 6,
|
|
|
|
-10, -8,
|
2007-01-01 23:31:53 +00:00
|
|
|
};
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* The array of points the make up the ship */
|
2007-01-01 23:31:53 +00:00
|
|
|
static const short ship_vertices[NUM_SHIP_VERTICES*2] =
|
2009-12-05 14:08:09 +00:00
|
|
|
{
|
|
|
|
#if (LARGE_LCD)
|
|
|
|
0, -6,
|
|
|
|
4, 6,
|
|
|
|
0, 2,
|
|
|
|
-4, 6,
|
|
|
|
#else
|
|
|
|
0, -4,
|
|
|
|
3, 4,
|
|
|
|
0, 1,
|
|
|
|
-3, 4,
|
|
|
|
#endif
|
2007-01-01 23:31:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* The array of points the make up the bad spaceship */
|
|
|
|
static const short enemy_vertices[NUM_ENEMY_VERTICES*2] =
|
2009-12-05 14:08:09 +00:00
|
|
|
{
|
|
|
|
#if (LARGE_LCD)
|
|
|
|
-8, 0,
|
|
|
|
-4, 4,
|
2007-01-01 23:31:53 +00:00
|
|
|
4, 4,
|
|
|
|
8, 0,
|
2009-12-09 13:17:21 +00:00
|
|
|
-8, 0,
|
|
|
|
8, 0,
|
2007-01-01 23:31:53 +00:00
|
|
|
4, -4,
|
2009-12-05 14:08:09 +00:00
|
|
|
-4, -4,
|
|
|
|
#else
|
|
|
|
-5, 0,
|
|
|
|
-2, 2,
|
2007-01-01 23:31:53 +00:00
|
|
|
2, 2,
|
|
|
|
5, 0,
|
2009-12-09 13:17:21 +00:00
|
|
|
-5, 0,
|
|
|
|
5, 0,
|
2007-01-01 23:31:53 +00:00
|
|
|
2, -2,
|
2009-12-05 14:08:09 +00:00
|
|
|
-2, -2,
|
|
|
|
#endif
|
2007-01-01 23:31:53 +00:00
|
|
|
};
|
|
|
|
|
2006-03-31 12:00:26 +00:00
|
|
|
enum asteroid_type
|
|
|
|
{
|
2009-12-05 14:08:09 +00:00
|
|
|
#if (LARGE_LCD)
|
2009-12-09 13:17:21 +00:00
|
|
|
SMALL = 2,
|
2007-01-01 23:31:53 +00:00
|
|
|
MEDIUM = 4,
|
2009-12-09 13:17:21 +00:00
|
|
|
LARGE = 6,
|
2009-12-05 14:08:09 +00:00
|
|
|
#else
|
2009-12-09 13:17:21 +00:00
|
|
|
SMALL = 1,
|
2006-03-31 12:00:26 +00:00
|
|
|
MEDIUM = 2,
|
2009-12-09 13:17:21 +00:00
|
|
|
LARGE = 3,
|
2009-12-05 14:08:09 +00:00
|
|
|
#endif
|
2006-03-31 12:00:26 +00:00
|
|
|
};
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
enum explosion_type
|
|
|
|
{
|
|
|
|
EXPLOSION_SHIP,
|
|
|
|
EXPLOSION_ASTEROID,
|
|
|
|
EXPLOSION_ENEMY,
|
|
|
|
EXPLOSION_THRUST,
|
|
|
|
};
|
|
|
|
|
2006-03-31 12:00:26 +00:00
|
|
|
enum game_state
|
|
|
|
{
|
|
|
|
GAME_OVER,
|
|
|
|
SHOW_LEVEL,
|
2009-12-05 14:08:09 +00:00
|
|
|
PLAY_MODE,
|
|
|
|
PAUSE_MODE,
|
2006-03-31 12:00:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Point
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int dx;
|
|
|
|
int dy;
|
|
|
|
};
|
|
|
|
|
2007-01-01 23:31:53 +00:00
|
|
|
struct TrailPoint
|
|
|
|
{
|
2009-12-05 14:08:09 +00:00
|
|
|
struct Point position;
|
2009-12-10 12:53:47 +00:00
|
|
|
int alive;
|
2009-12-05 14:08:09 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
short r;
|
|
|
|
short g;
|
|
|
|
short b;
|
|
|
|
short dec;
|
|
|
|
#endif
|
2007-01-01 23:31:53 +00:00
|
|
|
};
|
|
|
|
|
2006-03-31 12:00:26 +00:00
|
|
|
/* Asteroid structure, contains an array of points */
|
|
|
|
struct Asteroid
|
|
|
|
{
|
2009-12-05 14:08:09 +00:00
|
|
|
struct Point position;
|
2009-12-12 14:05:03 +00:00
|
|
|
struct Point rotation;
|
2009-12-05 14:08:09 +00:00
|
|
|
struct Point vertices[NUM_ASTEROID_VERTICES];
|
|
|
|
bool exists;
|
|
|
|
int explode_countdown;
|
|
|
|
enum asteroid_type type;
|
2006-03-31 12:00:26 +00:00
|
|
|
int radius;
|
|
|
|
long speed_cos;
|
|
|
|
long speed_sin;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Ship
|
|
|
|
{
|
|
|
|
struct Point position;
|
2009-12-12 14:05:03 +00:00
|
|
|
struct Point rotation;
|
2009-12-10 12:53:47 +00:00
|
|
|
struct Point vertices[NUM_SHIP_VERTICES];
|
|
|
|
bool exists;
|
2009-12-05 14:08:09 +00:00
|
|
|
int explode_countdown;
|
2009-12-10 12:53:47 +00:00
|
|
|
int invulnerable_time;
|
2006-03-31 12:00:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Enemy
|
|
|
|
{
|
|
|
|
struct Point position;
|
2009-12-10 12:53:47 +00:00
|
|
|
struct Point vertices[NUM_ENEMY_VERTICES];
|
2009-12-05 14:08:09 +00:00
|
|
|
bool exists;
|
2006-03-31 12:00:26 +00:00
|
|
|
int explode_countdown;
|
2009-12-09 13:17:21 +00:00
|
|
|
int appear_countdown;
|
2007-01-01 23:31:53 +00:00
|
|
|
short size_probability;
|
2009-12-05 14:08:09 +00:00
|
|
|
short appear_probability;
|
2007-01-01 23:31:53 +00:00
|
|
|
short appear_timing;
|
2006-03-31 12:00:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Missile
|
|
|
|
{
|
|
|
|
struct Point position;
|
|
|
|
struct Point oldpoint;
|
2009-12-10 12:53:47 +00:00
|
|
|
int alive;
|
2006-03-31 12:00:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static enum game_state game_state;
|
|
|
|
static int asteroid_count;
|
|
|
|
static int next_missile_count;
|
|
|
|
static int next_thrust_count;
|
|
|
|
static int num_lives;
|
2007-01-01 23:31:53 +00:00
|
|
|
static int extra_life;
|
2006-03-31 12:00:26 +00:00
|
|
|
static int show_level_timeout;
|
|
|
|
static int current_level;
|
|
|
|
static int current_score;
|
|
|
|
|
|
|
|
static struct Ship ship;
|
|
|
|
static struct Point stars[NUM_STARS];
|
|
|
|
static struct Asteroid asteroids_array[MAX_NUM_ASTEROIDS];
|
|
|
|
static struct Missile missiles_array[MAX_NUM_MISSILES];
|
|
|
|
static struct Missile enemy_missile;
|
|
|
|
static struct Enemy enemy;
|
|
|
|
static struct Point lives_points[NUM_SHIP_VERTICES];
|
2009-12-05 14:08:09 +00:00
|
|
|
static struct TrailPoint trail_points[NUM_TRAIL_POINTS];
|
2006-03-31 12:00:26 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/*************************************************
|
|
|
|
** Handle polygon and point
|
|
|
|
*************************************************/
|
2006-03-31 12:00:26 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* Check if point is in a polygon */
|
|
|
|
static bool is_point_in_polygon(struct Point* vertices, int num_vertices,
|
|
|
|
int x, int y)
|
|
|
|
{
|
|
|
|
struct Point* pi;
|
|
|
|
struct Point* pj;
|
|
|
|
int n;
|
|
|
|
bool c = false;
|
2006-03-31 12:00:26 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
if (x < -SCALED_WIDTH/2) x += SCALED_WIDTH;
|
|
|
|
else if (x > SCALED_WIDTH/2) x -= SCALED_WIDTH;
|
|
|
|
if (y < -SCALED_HEIGHT/2) y += SCALED_HEIGHT;
|
|
|
|
else if (y > SCALED_HEIGHT/2) y -= SCALED_HEIGHT;
|
2006-03-31 12:00:26 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
pi = vertices;
|
|
|
|
pj = vertices + num_vertices-1;
|
2006-03-31 12:00:26 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
n = num_vertices;
|
|
|
|
while (n--)
|
|
|
|
{
|
|
|
|
if ((((pi->y <= y) && (y < pj->y)) || ((pj->y <= y) && (y < pi->y))) &&
|
|
|
|
(x < (pj->x - pi->x) * (y - pi->y) / (pj->y - pi->y) + pi->x))
|
|
|
|
c = !c;
|
2006-03-31 12:00:26 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
pj = pi;
|
|
|
|
pi++;
|
|
|
|
}
|
2006-03-31 12:00:26 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
return c;
|
2009-07-21 17:29:46 +00:00
|
|
|
}
|
2006-03-31 12:00:26 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* Check if point is within a rectangle */
|
|
|
|
static bool is_point_within_rectangle(struct Point* rect, struct Point* p,
|
|
|
|
int size)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
int dx = p->x - rect->x;
|
|
|
|
int dy = p->y - rect->y;
|
|
|
|
#if SHOW_COL
|
|
|
|
rb->lcd_drawrect((rect->x - size)/SCALE, (rect->y - size)/SCALE,
|
2009-12-10 12:53:47 +00:00
|
|
|
(size*2+1)/SCALE, (size*2+1)/SCALE);
|
2009-07-23 17:45:33 +00:00
|
|
|
#endif
|
2009-12-09 13:17:21 +00:00
|
|
|
if (dx < -SCALED_WIDTH/2) dx += SCALED_WIDTH;
|
|
|
|
else if (dx > SCALED_WIDTH/2) dx -= SCALED_WIDTH;
|
|
|
|
if (dy < -SCALED_HEIGHT/2) dy += SCALED_HEIGHT;
|
|
|
|
else if (dy > SCALED_HEIGHT/2) dy -= SCALED_HEIGHT;
|
|
|
|
return (dx > -size && dx < size && dy > -size && dy < size);
|
2009-07-21 17:29:46 +00:00
|
|
|
}
|
2006-03-31 12:00:26 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* Rotate polygon */
|
|
|
|
static void rotate_polygon(struct Point* vertices, int num_vertices,
|
2009-12-12 14:05:03 +00:00
|
|
|
struct Point* rotation, int cos, int sin)
|
2009-07-21 17:29:46 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
struct Point* point;
|
|
|
|
int n;
|
|
|
|
long temp_x, temp_y;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-12 14:05:03 +00:00
|
|
|
temp_x = rotation->x;
|
|
|
|
temp_y = rotation->y;
|
|
|
|
rotation->x = (temp_x*cos - temp_y*sin)/SIN_COS_SCALE;
|
|
|
|
rotation->y = (temp_y*cos + temp_x*sin)/SIN_COS_SCALE;
|
|
|
|
#define MIN_SCALE (SIN_COS_SCALE-10)
|
|
|
|
#define MAX_SCALE (SIN_COS_SCALE+10)
|
|
|
|
/* normalize vector. this is not accurate but would be enough. */
|
|
|
|
temp_x = rotation->x*rotation->x + rotation->y*rotation->y;
|
|
|
|
if (temp_x <= MIN_SCALE*MIN_SCALE)
|
|
|
|
{
|
|
|
|
rotation->x = rotation->x*SIN_COS_SCALE/MIN_SCALE;
|
|
|
|
rotation->y = rotation->y*SIN_COS_SCALE/MIN_SCALE;
|
|
|
|
}
|
|
|
|
else if (temp_x >= MAX_SCALE*MAX_SCALE)
|
|
|
|
{
|
|
|
|
rotation->x = rotation->x*SIN_COS_SCALE/MAX_SCALE;
|
|
|
|
rotation->y = rotation->y*SIN_COS_SCALE/MAX_SCALE;
|
|
|
|
}
|
|
|
|
#undef MIN_SCALE
|
|
|
|
#undef MAX_SCALE
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
point = vertices;
|
|
|
|
n = num_vertices;
|
|
|
|
while (n--)
|
2009-12-05 14:08:09 +00:00
|
|
|
{
|
2009-12-12 14:05:03 +00:00
|
|
|
point->x = (point->dx*rotation->x - point->dy*rotation->y)/SIN_COS_SCALE;
|
|
|
|
point->y = (point->dy*rotation->x + point->dx*rotation->y)/SIN_COS_SCALE;
|
2009-12-09 13:17:21 +00:00
|
|
|
point++;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* Draw polygon */
|
|
|
|
static void draw_polygon(struct Point* vertices, int num_vertices,
|
|
|
|
int px, int py)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
int n, new_x, new_y, old_x, old_y;
|
|
|
|
struct Point *p;
|
2009-12-10 12:53:47 +00:00
|
|
|
bool draw_wrap;
|
|
|
|
|
|
|
|
if (px > SCALED_WIDTH - WRAP_GAP)
|
|
|
|
px -= SCALED_WIDTH;
|
|
|
|
if (py > SCALED_HEIGHT - WRAP_GAP)
|
|
|
|
py -= SCALED_HEIGHT;
|
|
|
|
|
|
|
|
draw_wrap = (px < WRAP_GAP || py < WRAP_GAP);
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
p = vertices + num_vertices - 1;
|
|
|
|
old_x = (p->x + px)/SCALE;
|
|
|
|
old_y = (p->y + py)/SCALE;
|
|
|
|
p = vertices;
|
2006-03-31 12:00:26 +00:00
|
|
|
n = num_vertices;
|
2009-12-10 12:53:47 +00:00
|
|
|
while (n--)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
new_x = (p->x + px)/SCALE;
|
|
|
|
new_y = (p->y + py)/SCALE;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
rb->lcd_drawline(old_x, old_y, new_x, new_y);
|
2009-12-10 12:53:47 +00:00
|
|
|
if (draw_wrap)
|
2009-12-09 13:17:21 +00:00
|
|
|
{
|
|
|
|
rb->lcd_drawline(old_x + LCD_WIDTH, old_y, new_x + LCD_WIDTH, new_y);
|
2009-12-10 12:53:47 +00:00
|
|
|
rb->lcd_drawline(old_x, old_y + LCD_HEIGHT, new_x, new_y + LCD_HEIGHT);
|
2009-12-09 13:17:21 +00:00
|
|
|
rb->lcd_drawline(old_x + LCD_WIDTH, old_y + LCD_HEIGHT,
|
|
|
|
new_x + LCD_WIDTH, new_y + LCD_HEIGHT);
|
|
|
|
}
|
|
|
|
old_x = new_x;
|
|
|
|
old_y = new_y;
|
|
|
|
p++;
|
|
|
|
}
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
static void move_point(struct Point* point)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
|
|
|
point->x += point->dx;
|
|
|
|
point->y += point->dy;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* Check bounds on the x-axis: */
|
2009-12-05 14:08:09 +00:00
|
|
|
point->x %= SCALED_WIDTH;
|
2009-12-09 13:17:21 +00:00
|
|
|
if (point->x < 0)
|
2009-12-05 14:08:09 +00:00
|
|
|
point->x += SCALED_WIDTH;
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* Check bounds on the y-axis: */
|
2009-12-05 14:08:09 +00:00
|
|
|
point->y %= SCALED_HEIGHT;
|
2009-12-09 13:17:21 +00:00
|
|
|
if (point->y < 0)
|
2009-12-05 14:08:09 +00:00
|
|
|
point->y += SCALED_HEIGHT;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/*************************************************
|
|
|
|
** Handle trail blaiz.
|
|
|
|
*************************************************/
|
|
|
|
|
|
|
|
static void create_ship_trail(struct TrailPoint* tpoint)
|
2007-01-01 23:31:53 +00:00
|
|
|
{
|
2009-12-12 14:05:03 +00:00
|
|
|
tpoint->position.x += ship.vertices[2].x;
|
|
|
|
tpoint->position.y += ship.vertices[2].y;
|
2009-12-05 14:08:09 +00:00
|
|
|
tpoint->position.dx = -( ship.vertices[0].x - ship.vertices[2].x )/10;
|
|
|
|
tpoint->position.dy = -( ship.vertices[0].y - ship.vertices[2].y )/10;
|
2007-01-01 23:31:53 +00:00
|
|
|
}
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
static void create_explosion_trail(struct TrailPoint* tpoint)
|
2007-01-01 23:31:53 +00:00
|
|
|
{
|
2009-12-05 14:08:09 +00:00
|
|
|
tpoint->position.dx = (rb->rand()%5001)-2500;
|
|
|
|
tpoint->position.dy = (rb->rand()%5001)-2500;
|
2007-01-01 23:31:53 +00:00
|
|
|
}
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
static void create_trail_blaze(int colour, struct Point* position)
|
2007-01-01 23:31:53 +00:00
|
|
|
{
|
2009-12-05 14:08:09 +00:00
|
|
|
int numtoadd;
|
|
|
|
struct TrailPoint* tpoint;
|
|
|
|
int n;
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
if (colour != EXPLOSION_SHIP)
|
2009-12-05 14:08:09 +00:00
|
|
|
{
|
|
|
|
numtoadd = NUM_TRAIL_POINTS/5;
|
|
|
|
}
|
|
|
|
else
|
2007-01-01 23:31:53 +00:00
|
|
|
{
|
2009-12-05 14:08:09 +00:00
|
|
|
numtoadd = NUM_TRAIL_POINTS/8;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* give the point a random countdown timer, so they dissapears at different
|
|
|
|
times */
|
|
|
|
tpoint = trail_points;
|
|
|
|
n = NUM_TRAIL_POINTS;
|
2009-12-12 14:05:03 +00:00
|
|
|
while (n--)
|
2009-12-05 14:08:09 +00:00
|
|
|
{
|
|
|
|
/* find a space in the array of trail_points that is NULL or DEAD or
|
|
|
|
whatever and place this one here. */
|
2009-12-10 12:53:47 +00:00
|
|
|
if (tpoint->alive <= 0)
|
2009-12-05 14:08:09 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
/* take a random point near the position. */
|
|
|
|
tpoint->position.x = (rb->rand()%18000)-9000 + position->x;
|
|
|
|
tpoint->position.y = (rb->rand()%18000)-9000 + position->y;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
|
|
|
switch(colour)
|
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
case EXPLOSION_SHIP:
|
2009-12-05 14:08:09 +00:00
|
|
|
create_explosion_trail(tpoint);
|
2009-12-09 13:17:21 +00:00
|
|
|
tpoint->alive = 51;
|
2009-12-05 14:08:09 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
tpoint->r = SHIP_R;
|
|
|
|
tpoint->g = SHIP_G;
|
|
|
|
tpoint->b = SHIP_B;
|
|
|
|
tpoint->dec = 2;
|
|
|
|
#endif
|
|
|
|
break;
|
2009-12-09 13:17:21 +00:00
|
|
|
case EXPLOSION_ASTEROID:
|
2009-12-05 14:08:09 +00:00
|
|
|
create_explosion_trail(tpoint);
|
2009-12-09 13:17:21 +00:00
|
|
|
tpoint->alive = 51;
|
2009-12-05 14:08:09 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
tpoint->r = ASTEROID_R;
|
|
|
|
tpoint->g = ASTEROID_G;
|
|
|
|
tpoint->b = ASTEROID_B;
|
|
|
|
tpoint->dec = 2;
|
|
|
|
#endif
|
|
|
|
break;
|
2009-12-09 13:17:21 +00:00
|
|
|
case EXPLOSION_ENEMY:
|
2009-12-05 14:08:09 +00:00
|
|
|
create_explosion_trail(tpoint);
|
2009-12-09 13:17:21 +00:00
|
|
|
tpoint->alive = 51;
|
2009-12-05 14:08:09 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
tpoint->r = ENEMY_R;
|
|
|
|
tpoint->g = ENEMY_G;
|
|
|
|
tpoint->b = ENEMY_B;
|
|
|
|
tpoint->dec = 2;
|
|
|
|
#endif
|
|
|
|
break;
|
2009-12-09 13:17:21 +00:00
|
|
|
case EXPLOSION_THRUST:
|
2009-12-05 14:08:09 +00:00
|
|
|
create_ship_trail(tpoint);
|
2009-12-09 13:17:21 +00:00
|
|
|
tpoint->alive = 17;
|
2009-12-05 14:08:09 +00:00
|
|
|
#ifdef HAVE_LCD_COLOR
|
|
|
|
tpoint->r = THRUST_R;
|
|
|
|
tpoint->g = THRUST_G;
|
|
|
|
tpoint->b = THRUST_B;
|
|
|
|
tpoint->dec = 4;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* give the points a speed based on direction of travel
|
|
|
|
- i.e. opposite */
|
|
|
|
tpoint->position.dx += position->dx;
|
|
|
|
tpoint->position.dy += position->dy;
|
2009-12-12 14:05:03 +00:00
|
|
|
|
|
|
|
numtoadd--;
|
|
|
|
if (numtoadd <= 0)
|
|
|
|
break;
|
2009-12-05 14:08:09 +00:00
|
|
|
}
|
|
|
|
tpoint++;
|
2007-01-01 23:31:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
static void draw_and_move_trail_blaze(void)
|
2007-01-01 23:31:53 +00:00
|
|
|
{
|
2009-12-05 14:08:09 +00:00
|
|
|
struct TrailPoint* tpoint;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
/* loop through, if alive then move and draw.
|
|
|
|
when drawn, countdown it's timer.
|
|
|
|
if zero kill it! */
|
|
|
|
|
|
|
|
tpoint = trail_points;
|
|
|
|
n = NUM_TRAIL_POINTS;
|
2009-12-09 13:17:21 +00:00
|
|
|
while (n--)
|
2007-01-01 23:31:53 +00:00
|
|
|
{
|
2009-12-10 12:53:47 +00:00
|
|
|
if (tpoint->alive > 0)
|
2009-12-05 14:08:09 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
if (game_state != PAUSE_MODE)
|
2009-12-05 14:08:09 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
tpoint->alive--;
|
2009-12-05 14:08:09 +00:00
|
|
|
move_point(&(tpoint->position));
|
|
|
|
#ifdef HAVE_LCD_COLOR
|
2009-12-09 13:17:21 +00:00
|
|
|
/* intensity = tpoint->alive/2; */
|
|
|
|
if (tpoint->r >= tpoint->dec) tpoint->r -= tpoint->dec;
|
|
|
|
if (tpoint->g >= tpoint->dec) tpoint->g -= tpoint->dec;
|
|
|
|
if (tpoint->b >= tpoint->dec) tpoint->b -= tpoint->dec;
|
2009-12-05 14:08:09 +00:00
|
|
|
#endif
|
2009-12-09 13:17:21 +00:00
|
|
|
}
|
|
|
|
SET_FG(LCD_RGBPACK(tpoint->r, tpoint->g, tpoint->b));
|
2009-12-05 14:08:09 +00:00
|
|
|
rb->lcd_drawpixel(tpoint->position.x/SCALE, tpoint->position.y/SCALE);
|
|
|
|
}
|
|
|
|
tpoint++;
|
2007-01-01 23:31:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/*************************************************
|
|
|
|
** Handle asteroid.
|
|
|
|
*************************************************/
|
|
|
|
|
|
|
|
static void rotate_asteroid(struct Asteroid* asteroid)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
rotate_polygon(asteroid->vertices, NUM_ASTEROID_VERTICES,
|
2009-12-12 14:05:03 +00:00
|
|
|
&asteroid->rotation,
|
2009-12-09 13:17:21 +00:00
|
|
|
asteroid->speed_cos, asteroid->speed_sin);
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* Initialise the passed Asteroid.
|
|
|
|
* if position is NULL, place it at the random loacation
|
|
|
|
* where ship doesn't exist
|
|
|
|
*/
|
|
|
|
static void initialise_asteroid(struct Asteroid* asteroid,
|
|
|
|
enum asteroid_type type, struct Point *position)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
const short *asteroid_vertices;
|
|
|
|
struct Point* point;
|
|
|
|
int n;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
asteroid->exists = true;
|
|
|
|
asteroid->explode_countdown = 0;
|
2009-12-10 12:53:47 +00:00
|
|
|
asteroid->type = type;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* Set the radius of the asteroid: */
|
|
|
|
asteroid->radius = (int)type*SCALE*3;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* shall we move Clockwise and Fast */
|
|
|
|
n = rb->rand()%100;
|
|
|
|
if (n < 25)
|
|
|
|
{
|
|
|
|
asteroid->speed_cos = FAST_ROT_CW_COS;
|
|
|
|
asteroid->speed_sin = FAST_ROT_CW_SIN;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
2009-12-09 13:17:21 +00:00
|
|
|
else if (n < 50)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
asteroid->speed_cos = FAST_ROT_ACW_COS;
|
|
|
|
asteroid->speed_sin = FAST_ROT_ACW_SIN;
|
2009-12-05 14:08:09 +00:00
|
|
|
}
|
2009-12-09 13:17:21 +00:00
|
|
|
else if (n < 75)
|
2007-01-01 23:31:53 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
asteroid->speed_cos = SLOW_ROT_ACW_COS;
|
|
|
|
asteroid->speed_sin = SLOW_ROT_ACW_SIN;
|
2007-01-01 23:31:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
asteroid->speed_cos = SLOW_ROT_CW_COS;
|
|
|
|
asteroid->speed_sin = SLOW_ROT_CW_SIN;
|
2009-12-05 14:08:09 +00:00
|
|
|
}
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
n = rb->rand()%99;
|
|
|
|
if (n < 33)
|
|
|
|
asteroid_vertices = asteroid_one;
|
|
|
|
else if (n < 66)
|
|
|
|
asteroid_vertices = asteroid_two;
|
|
|
|
else
|
|
|
|
asteroid_vertices = asteroid_three;
|
|
|
|
|
|
|
|
point = asteroid->vertices;
|
|
|
|
for(n = 0; n < NUM_ASTEROID_VERTICES*2; n += 2)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
point->x = asteroid_vertices[n];
|
|
|
|
point->y = asteroid_vertices[n+1];
|
|
|
|
point->x *= asteroid->radius/20;
|
|
|
|
point->y *= asteroid->radius/20;
|
2009-12-12 14:05:03 +00:00
|
|
|
/* dx and dy are used when rotate polygon */
|
|
|
|
point->dx = point->x;
|
|
|
|
point->dy = point->y;
|
2006-03-31 12:00:26 +00:00
|
|
|
point++;
|
|
|
|
}
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
if (!position)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
do {
|
|
|
|
/* Set the position randomly: */
|
|
|
|
asteroid->position.x = (rb->rand()%SCALED_WIDTH);
|
|
|
|
asteroid->position.y = (rb->rand()%SCALED_HEIGHT);
|
|
|
|
} while (is_point_within_rectangle(&ship.position, &asteroid->position,
|
|
|
|
SPACE_CHECK_SIZE));
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
asteroid->position.x = position->x;
|
|
|
|
asteroid->position.y = position->y;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
do {
|
|
|
|
asteroid->position.dx = (rb->rand()%ASTEROID_SPEED)-ASTEROID_SPEED/2;
|
|
|
|
} while (asteroid->position.dx == 0);
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
do {
|
|
|
|
asteroid->position.dy = (rb->rand()%ASTEROID_SPEED)-ASTEROID_SPEED/2;
|
|
|
|
} while (asteroid->position.dy == 0);
|
|
|
|
|
|
|
|
asteroid->position.dx *= SCALE/10;
|
|
|
|
asteroid->position.dy *= SCALE/10;
|
|
|
|
|
2009-12-12 14:05:03 +00:00
|
|
|
asteroid->rotation.x = SIN_COS_SCALE;
|
|
|
|
asteroid->rotation.y = 0;
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* Now rotate the asteroid a bit, so they all look a bit different */
|
|
|
|
for(n = (rb->rand()%30)+2; n--; )
|
|
|
|
rotate_asteroid(asteroid);
|
|
|
|
|
|
|
|
/* great, we've created an asteroid, don't forget to increment the total: */
|
|
|
|
asteroid_count++;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/*
|
|
|
|
* Creates a new asteroid of the given 4type (size) and at the given location.
|
|
|
|
*/
|
|
|
|
static void create_asteroid(enum asteroid_type type, struct Point *position)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
struct Asteroid* asteroid;
|
|
|
|
int n;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
asteroid = asteroids_array;
|
|
|
|
n = MAX_NUM_ASTEROIDS;
|
|
|
|
while (n--)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-10 12:53:47 +00:00
|
|
|
if (!asteroid->exists && asteroid->explode_countdown <= 0)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
initialise_asteroid(asteroid, type, position);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
asteroid++;
|
|
|
|
}
|
|
|
|
}
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* Draw and move all asteroids */
|
|
|
|
static void draw_and_move_asteroids(void)
|
|
|
|
{
|
|
|
|
struct Asteroid* asteroid;
|
|
|
|
int n;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
SET_FG(COL_ASTEROID);
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
asteroid = asteroids_array;
|
|
|
|
n = MAX_NUM_ASTEROIDS;
|
|
|
|
while (n--)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-10 12:53:47 +00:00
|
|
|
if (asteroid->exists)
|
|
|
|
{
|
|
|
|
draw_polygon(asteroid->vertices, NUM_ASTEROID_VERTICES,
|
|
|
|
asteroid->position.x, asteroid->position.y);
|
|
|
|
}
|
2009-12-09 13:17:21 +00:00
|
|
|
if (game_state != PAUSE_MODE)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
if (asteroid->exists)
|
2009-12-05 14:08:09 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
move_point(&asteroid->position);
|
|
|
|
rotate_asteroid(asteroid);
|
|
|
|
}
|
2009-12-10 12:53:47 +00:00
|
|
|
else if (asteroid->explode_countdown > 0)
|
2009-12-09 13:17:21 +00:00
|
|
|
{
|
|
|
|
asteroid->explode_countdown--;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-09 13:17:21 +00:00
|
|
|
asteroid++;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-10 12:53:47 +00:00
|
|
|
static void explode_asteroid(struct Asteroid* asteroid)
|
|
|
|
{
|
|
|
|
struct Point p;
|
|
|
|
p.dx = asteroid->position.dx;
|
|
|
|
p.dy = asteroid->position.dy;
|
|
|
|
p.x = asteroid->position.x;
|
|
|
|
p.y = asteroid->position.y;
|
|
|
|
|
|
|
|
asteroid_count--;
|
|
|
|
asteroid->exists = false;
|
|
|
|
|
|
|
|
switch(asteroid->type)
|
|
|
|
{
|
|
|
|
case SMALL:
|
|
|
|
asteroid->explode_countdown = EXPLOSION_LENGTH;
|
|
|
|
create_trail_blaze(EXPLOSION_ASTEROID, &p);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MEDIUM:
|
|
|
|
create_asteroid(SMALL, &p);
|
|
|
|
create_asteroid(SMALL, &p);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LARGE:
|
|
|
|
create_asteroid(MEDIUM, &p);
|
|
|
|
create_asteroid(MEDIUM, &p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/*************************************************
|
|
|
|
** Handle ship.
|
|
|
|
*************************************************/
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* Initialise the ship */
|
|
|
|
static void initialise_ship(void)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
struct Point* point;
|
|
|
|
struct Point* lives_point;
|
|
|
|
int n;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
ship.position.x = CENTER_LCD_X * SCALE;
|
|
|
|
ship.position.y = CENTER_LCD_Y * SCALE;
|
|
|
|
ship.position.dx = 0;
|
|
|
|
ship.position.dy = 0;
|
2009-12-12 14:05:03 +00:00
|
|
|
ship.rotation.x = SIN_COS_SCALE;
|
|
|
|
ship.rotation.y = 0;
|
2009-12-10 12:53:47 +00:00
|
|
|
ship.exists = true;
|
|
|
|
ship.explode_countdown = 0;
|
|
|
|
ship.invulnerable_time = INVULNERABLE_TIME;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
point = ship.vertices;
|
|
|
|
lives_point = lives_points;
|
|
|
|
for(n = 0; n < NUM_SHIP_VERTICES*2; n += 2)
|
|
|
|
{
|
|
|
|
point->x = ship_vertices[n];
|
|
|
|
point->y = ship_vertices[n+1];
|
|
|
|
point->x *= SCALE;
|
|
|
|
point->y *= SCALE;
|
2009-12-12 14:05:03 +00:00
|
|
|
/* dx and dy are used when rotate polygon */
|
|
|
|
point->dx = point->x;
|
|
|
|
point->dy = point->y;
|
2009-12-09 13:17:21 +00:00
|
|
|
/* grab a copy of the ships points for the lives display: */
|
|
|
|
lives_point->x = point->x;
|
|
|
|
lives_point->y = point->y;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
point++;
|
|
|
|
lives_point++;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/*
|
|
|
|
* Draws the ship, moves the ship and creates a new
|
|
|
|
* one if it's finished exploding.
|
|
|
|
*/
|
|
|
|
static void draw_and_move_ship(void)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-10 12:53:47 +00:00
|
|
|
if (ship.invulnerable_time > BLINK_TIME || ship.invulnerable_time % 2 != 0)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
SET_FG(COL_INVULN);
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
SET_FG(COL_PLAYER);
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-10 12:53:47 +00:00
|
|
|
if (ship.exists)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-10 12:53:47 +00:00
|
|
|
draw_polygon(ship.vertices, NUM_SHIP_VERTICES,
|
|
|
|
ship.position.x, ship.position.y);
|
2009-12-09 13:17:21 +00:00
|
|
|
}
|
2009-12-10 12:53:47 +00:00
|
|
|
|
|
|
|
if (game_state != PAUSE_MODE)
|
2009-12-09 13:17:21 +00:00
|
|
|
{
|
2009-12-10 12:53:47 +00:00
|
|
|
if (ship.exists)
|
|
|
|
{
|
|
|
|
if (ship.invulnerable_time > 0)
|
|
|
|
ship.invulnerable_time--;
|
|
|
|
move_point(&ship.position);
|
|
|
|
}
|
|
|
|
else if (ship.explode_countdown > 0)
|
2009-12-09 13:17:21 +00:00
|
|
|
{
|
|
|
|
ship.explode_countdown--;
|
2009-12-10 12:53:47 +00:00
|
|
|
if (ship.explode_countdown <= 0)
|
2009-12-09 13:17:21 +00:00
|
|
|
{
|
|
|
|
num_lives--;
|
2009-12-12 14:05:03 +00:00
|
|
|
if (num_lives <= 0)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
game_state = GAME_OVER;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
2009-12-09 13:17:21 +00:00
|
|
|
else
|
2009-12-05 14:08:09 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
initialise_ship();
|
2009-12-05 14:08:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-12-09 13:17:21 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-10 12:53:47 +00:00
|
|
|
static void explode_ship(void)
|
|
|
|
{
|
|
|
|
if (!ship.invulnerable_time)
|
|
|
|
{
|
|
|
|
/* if not invulnerable, blow up ship */
|
|
|
|
ship.explode_countdown = EXPLOSION_LENGTH;
|
|
|
|
ship.exists = false;
|
|
|
|
create_trail_blaze(EXPLOSION_SHIP, &ship.position);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* Rotate the ship using the passed sin & cos values */
|
|
|
|
static void rotate_ship(int cos, int sin)
|
|
|
|
{
|
2009-12-10 12:53:47 +00:00
|
|
|
if (ship.exists)
|
2009-12-09 13:17:21 +00:00
|
|
|
{
|
2009-12-12 14:05:03 +00:00
|
|
|
rotate_polygon(ship.vertices, NUM_SHIP_VERTICES,
|
|
|
|
&ship.rotation, cos, sin);
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
2009-12-09 13:17:21 +00:00
|
|
|
}
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
static void thrust_ship(void)
|
|
|
|
{
|
2009-12-10 12:53:47 +00:00
|
|
|
if (ship.exists)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
ship.position.dx += ( ship.vertices[0].x - ship.vertices[2].x )/20;
|
|
|
|
ship.position.dy += ( ship.vertices[0].y - ship.vertices[2].y )/20;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* if dx and dy are below a certain threshold, then set 'em to 0
|
|
|
|
but to do this we need to ascertain if the spacehip as moved on
|
|
|
|
screen for more than a certain amount. */
|
|
|
|
|
|
|
|
create_trail_blaze(EXPLOSION_THRUST, &ship.position);
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
2009-12-09 13:17:21 +00:00
|
|
|
}
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* stop movement of ship, 'cos that's what happens when you go into hyperspace. */
|
|
|
|
static void hyperspace(void)
|
|
|
|
{
|
2009-12-10 12:53:47 +00:00
|
|
|
if (ship.exists)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
ship.position.dx = ship.position.dy = 0;
|
|
|
|
ship.position.x = (rb->rand()%SCALED_WIDTH);
|
|
|
|
ship.position.y = (rb->rand()%SCALED_HEIGHT);
|
2009-12-05 14:08:09 +00:00
|
|
|
}
|
2009-12-09 13:17:21 +00:00
|
|
|
}
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
static void draw_lives(void)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
#if (LARGE_LCD)
|
|
|
|
int px = (LCD_WIDTH-1 - 4)*SCALE;
|
|
|
|
int py = (LCD_HEIGHT-1 - 6)*SCALE;
|
|
|
|
#else
|
|
|
|
int px = (LCD_WIDTH-1 - 3)*SCALE;
|
|
|
|
int py = (LCD_HEIGHT-1 - 4)*SCALE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
SET_FG(COL_PLAYER);
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
n = num_lives-1;
|
|
|
|
while (n--)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
draw_polygon(lives_points, NUM_SHIP_VERTICES, px, py);
|
|
|
|
#if (LARGE_LCD)
|
|
|
|
px -= 8*SCALE;
|
|
|
|
#else
|
|
|
|
px -= 6*SCALE;
|
|
|
|
#endif
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/*
|
|
|
|
* missile
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Initialise a missile */
|
|
|
|
static void initialise_missile(struct Missile* missile)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
missile->position.x = ship.position.x + ship.vertices[0].x;
|
|
|
|
missile->position.y = ship.position.y + ship.vertices[0].y;
|
|
|
|
missile->position.dx = (ship.vertices[0].x - ship.vertices[2].x)/2;
|
|
|
|
missile->position.dy = (ship.vertices[0].y - ship.vertices[2].y)/2;
|
2009-12-10 12:53:47 +00:00
|
|
|
missile->alive = MISSILE_LIFE_LENGTH;
|
2009-12-09 13:17:21 +00:00
|
|
|
missile->oldpoint.x = missile->position.x;
|
|
|
|
missile->oldpoint.y = missile->position.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fire the next missile */
|
|
|
|
static void fire_missile(void)
|
|
|
|
{
|
|
|
|
struct Missile* missile;
|
2006-03-31 12:00:26 +00:00
|
|
|
int n;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-10 12:53:47 +00:00
|
|
|
if (ship.exists)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
missile = missiles_array;
|
|
|
|
n = MAX_NUM_MISSILES;
|
|
|
|
while (n--)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-10 12:53:47 +00:00
|
|
|
if (missile->alive <= 0)
|
2009-12-09 13:17:21 +00:00
|
|
|
{
|
|
|
|
initialise_missile(missile);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
missile++;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw and Move all the missiles */
|
2009-12-09 13:17:21 +00:00
|
|
|
static void draw_and_move_missiles(void)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
|
|
|
struct Missile* missile;
|
2009-12-05 14:08:09 +00:00
|
|
|
struct Point vertices[2];
|
|
|
|
int n;
|
2006-03-31 14:38:15 +00:00
|
|
|
|
|
|
|
SET_FG(COL_MISSILE);
|
2009-12-05 14:08:09 +00:00
|
|
|
|
|
|
|
missile = missiles_array;
|
2006-03-31 12:00:26 +00:00
|
|
|
n = MAX_NUM_MISSILES;
|
2009-12-09 13:17:21 +00:00
|
|
|
while (n--)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-10 12:53:47 +00:00
|
|
|
if (missile->alive > 0)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-05 14:08:09 +00:00
|
|
|
vertices[0].x = 0;
|
|
|
|
vertices[0].y = 0;
|
|
|
|
vertices[1].x = -missile->position.dx;
|
|
|
|
vertices[1].y = -missile->position.dy;
|
2009-12-09 13:17:21 +00:00
|
|
|
draw_polygon(vertices, 2, missile->position.x, missile->position.y);
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
if (game_state != PAUSE_MODE)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
|
|
|
missile->oldpoint.x = missile->position.x;
|
|
|
|
missile->oldpoint.y = missile->position.y;
|
|
|
|
move_point(&missile->position);
|
2009-12-10 12:53:47 +00:00
|
|
|
missile->alive--;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
missile++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/*************************************************
|
|
|
|
** Handle enemy.
|
|
|
|
*************************************************/
|
2006-03-31 12:00:26 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
static void initialise_enemy(void)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
struct Point* point;
|
2009-12-05 14:08:09 +00:00
|
|
|
int n;
|
2009-12-09 13:17:21 +00:00
|
|
|
int size;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
if (rb->rand()%100 > enemy.size_probability)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
size = BIG_SHIP;
|
|
|
|
enemy.size_probability++;
|
|
|
|
if (enemy.size_probability > 90)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
enemy.size_probability = ENEMY_BIG_PROBABILITY_START;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-09 13:17:21 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
size = LITTLE_SHIP;
|
|
|
|
enemy.size_probability = ENEMY_BIG_PROBABILITY_START;
|
|
|
|
}
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
enemy.exists = true;
|
|
|
|
enemy.explode_countdown = 0;
|
|
|
|
enemy.appear_countdown = enemy.appear_timing;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
point = enemy.vertices;
|
|
|
|
for(n = 0; n < NUM_ENEMY_VERTICES*2; n += 2)
|
|
|
|
{
|
|
|
|
point->x = enemy_vertices[n];
|
|
|
|
point->y = enemy_vertices[n+1];
|
|
|
|
point->x *= size*SCALE/2;
|
|
|
|
point->y *= size*SCALE/2;
|
|
|
|
point++;
|
|
|
|
}
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
if (ship.position.x >= SCALED_WIDTH/2)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
enemy.position.dx = ENEMY_SPEED;
|
|
|
|
enemy.position.x = 0;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
2009-12-09 13:17:21 +00:00
|
|
|
else
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
enemy.position.dx = -ENEMY_SPEED;
|
|
|
|
enemy.position.x = SCALED_WIDTH;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
2009-12-09 13:17:21 +00:00
|
|
|
|
|
|
|
if (ship.position.y >= SCALED_HEIGHT/2)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
enemy.position.dy = ENEMY_SPEED;
|
|
|
|
enemy.position.y = 0;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
enemy.position.dy = -ENEMY_SPEED;
|
|
|
|
enemy.position.y = SCALED_HEIGHT;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
enemy.position.dx *= SCALE/10;
|
|
|
|
enemy.position.dy *= SCALE/10;
|
|
|
|
}
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
static void draw_and_move_enemy(void)
|
|
|
|
{
|
|
|
|
SET_FG(COL_ENEMY);
|
|
|
|
|
|
|
|
if (enemy.exists)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-10 12:53:47 +00:00
|
|
|
draw_polygon(enemy.vertices, NUM_ENEMY_VERTICES,
|
|
|
|
enemy.position.x, enemy.position.y);
|
|
|
|
}
|
2009-12-09 13:17:21 +00:00
|
|
|
|
2009-12-10 12:53:47 +00:00
|
|
|
if (game_state != PAUSE_MODE)
|
|
|
|
{
|
|
|
|
if (enemy.exists)
|
|
|
|
{
|
|
|
|
enemy.position.x += enemy.position.dx;
|
|
|
|
enemy.position.y += enemy.position.dy;
|
2009-12-09 13:17:21 +00:00
|
|
|
|
2009-12-10 12:53:47 +00:00
|
|
|
if (enemy.position.x > SCALED_WIDTH || enemy.position.x < 0)
|
|
|
|
enemy.exists = false;
|
2009-12-09 13:17:21 +00:00
|
|
|
|
2009-12-10 12:53:47 +00:00
|
|
|
enemy.position.y %= SCALED_HEIGHT;
|
|
|
|
if (enemy.position.y < 0)
|
|
|
|
enemy.position.y += SCALED_HEIGHT;
|
2009-12-09 13:17:21 +00:00
|
|
|
|
2009-12-10 12:53:47 +00:00
|
|
|
if ((rb->rand()%1000) < 10)
|
|
|
|
enemy.position.dy = -enemy.position.dy;
|
2009-12-09 13:17:21 +00:00
|
|
|
}
|
2009-12-10 12:53:47 +00:00
|
|
|
else if (enemy.explode_countdown > 0)
|
2009-12-09 13:17:21 +00:00
|
|
|
{
|
2009-12-10 12:53:47 +00:00
|
|
|
enemy.explode_countdown--;
|
2009-12-09 13:17:21 +00:00
|
|
|
}
|
2009-12-10 12:53:47 +00:00
|
|
|
else
|
2009-12-09 13:17:21 +00:00
|
|
|
{
|
2009-12-10 12:53:47 +00:00
|
|
|
if (enemy.appear_countdown > 0)
|
2009-12-09 13:17:21 +00:00
|
|
|
enemy.appear_countdown--;
|
|
|
|
else if (rb->rand()%100 >= enemy.appear_probability)
|
|
|
|
initialise_enemy();
|
|
|
|
}
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-10 12:53:47 +00:00
|
|
|
if (enemy_missile.alive <= 0)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
/* if no missile and the enemy is here and not exploding..
|
|
|
|
then shoot baby! */
|
2009-12-10 12:53:47 +00:00
|
|
|
if (enemy.exists && ship.exists &&
|
|
|
|
game_state == PLAY_MODE && (rb->rand()%10) >= 5 )
|
2009-12-09 13:17:21 +00:00
|
|
|
{
|
|
|
|
int dx = ship.position.x - enemy.position.x;
|
|
|
|
int dy = ship.position.y - enemy.position.y;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
if (dx < -SCALED_WIDTH/2) dx += SCALED_WIDTH;
|
|
|
|
else if (dx > SCALED_WIDTH/2) dx -= SCALED_WIDTH;
|
|
|
|
if (dy < -SCALED_HEIGHT/2) dy += SCALED_HEIGHT;
|
|
|
|
else if (dy > SCALED_HEIGHT/2) dy -= SCALED_HEIGHT;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
enemy_missile.position.x = enemy.position.x;
|
|
|
|
enemy_missile.position.y = enemy.position.y;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* lame, needs to be sorted - it's trying to shoot at the ship */
|
|
|
|
if (dx < -5*SCALE)
|
|
|
|
enemy_missile.position.dx = -1;
|
|
|
|
else if (dx > 5*SCALE)
|
|
|
|
enemy_missile.position.dx = 1;
|
|
|
|
else
|
|
|
|
enemy_missile.position.dx = 0;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
if (dy < -5*SCALE)
|
|
|
|
enemy_missile.position.dy = -1;
|
|
|
|
else if (dy > 5*SCALE)
|
|
|
|
enemy_missile.position.dy = 1;
|
|
|
|
else
|
|
|
|
enemy_missile.position.dy = 0;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
while (enemy_missile.position.dx == 0 &&
|
|
|
|
enemy_missile.position.dy == 0)
|
|
|
|
{
|
|
|
|
enemy_missile.position.dx = rb->rand()%2-1;
|
|
|
|
enemy_missile.position.dy = rb->rand()%2-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
enemy_missile.position.dx *= SCALE;
|
|
|
|
enemy_missile.position.dy *= SCALE;
|
2009-12-10 12:53:47 +00:00
|
|
|
enemy_missile.alive = ENEMY_MISSILE_LIFE_LENGTH;
|
2009-12-09 13:17:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rb->lcd_fillrect( enemy_missile.position.x/SCALE,
|
|
|
|
enemy_missile.position.y/SCALE,
|
|
|
|
POINT_SIZE, POINT_SIZE );
|
|
|
|
if (game_state != PAUSE_MODE)
|
|
|
|
{
|
|
|
|
move_point(&enemy_missile.position);
|
2009-12-10 12:53:47 +00:00
|
|
|
enemy_missile.alive--;
|
2009-12-09 13:17:21 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/*************************************************
|
|
|
|
** Check collisions.
|
|
|
|
*************************************************/
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* Add score if missile hit asteroid or enemy */
|
|
|
|
static void add_score(int val)
|
|
|
|
{
|
|
|
|
current_score += val;
|
|
|
|
if (current_score >= extra_life)
|
|
|
|
{
|
|
|
|
num_lives++;
|
|
|
|
extra_life += EXTRA_LIFE;
|
|
|
|
}
|
|
|
|
}
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
static bool is_point_within_asteroid(struct Asteroid* asteroid,
|
|
|
|
struct Point* point)
|
|
|
|
{
|
|
|
|
if (is_point_within_rectangle(&asteroid->position, point, asteroid->radius)
|
|
|
|
&& is_point_in_polygon(asteroid->vertices, NUM_ASTEROID_VERTICES,
|
|
|
|
point->x - asteroid->position.x,
|
|
|
|
point->y - asteroid->position.y))
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-10 12:53:47 +00:00
|
|
|
explode_asteroid(asteroid);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
2009-12-09 13:17:21 +00:00
|
|
|
|
2009-12-10 12:53:47 +00:00
|
|
|
static bool is_point_within_ship(struct Point* point)
|
|
|
|
{
|
|
|
|
if (is_point_within_rectangle(&ship.position, point, SIZE_SHIP_COLLISION)
|
|
|
|
&& is_point_in_polygon(ship.vertices, NUM_SHIP_VERTICES,
|
|
|
|
point->x - ship.position.x,
|
|
|
|
point->y - ship.position.y))
|
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
return true;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
2009-12-09 13:17:21 +00:00
|
|
|
else
|
|
|
|
return false;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
static bool is_point_within_enemy(struct Point* point)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
if (is_point_within_rectangle(&enemy.position, point, SIZE_ENEMY_COLLISION))
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
add_score(5);
|
|
|
|
enemy.explode_countdown = EXPLOSION_LENGTH;
|
2009-12-10 12:53:47 +00:00
|
|
|
enemy.exists = false;
|
2009-12-09 13:17:21 +00:00
|
|
|
create_trail_blaze(EXPLOSION_ENEMY, &enemy.position);
|
|
|
|
return true;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
2009-12-09 13:17:21 +00:00
|
|
|
else
|
|
|
|
return false;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
static bool is_ship_within_asteroid(struct Asteroid* asteroid)
|
|
|
|
{
|
|
|
|
struct Point p;
|
|
|
|
|
2009-12-10 12:53:47 +00:00
|
|
|
if (!is_point_within_rectangle(&asteroid->position, &ship.position,
|
|
|
|
asteroid->radius+SIZE_SHIP_COLLISION))
|
|
|
|
return false;
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
p.x = ship.position.x + ship.vertices[0].x;
|
|
|
|
p.y = ship.position.y + ship.vertices[0].y;
|
|
|
|
if (is_point_within_asteroid(asteroid, &p))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
p.x = ship.position.x + ship.vertices[1].x;
|
|
|
|
p.y = ship.position.y + ship.vertices[1].y;
|
|
|
|
if (is_point_within_asteroid(asteroid, &p))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
p.x = ship.position.x + ship.vertices[3].x;
|
|
|
|
p.y = ship.position.y + ship.vertices[3].y;
|
|
|
|
if (is_point_within_asteroid(asteroid, &p))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for collsions between the missiles and the asteroids and the ship */
|
|
|
|
static void check_collisions(void)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
struct Missile* missile;
|
|
|
|
struct Asteroid* asteroid;
|
|
|
|
int m, n;
|
|
|
|
bool asteroids_onscreen = false;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
asteroid = asteroids_array;
|
|
|
|
m = MAX_NUM_ASTEROIDS;
|
|
|
|
while (m--)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
/* if the asteroids exists then test missile collision: */
|
|
|
|
if (asteroid->exists)
|
2009-12-05 14:08:09 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
missile = missiles_array;
|
|
|
|
n = MAX_NUM_MISSILES;
|
|
|
|
while (n--)
|
2009-12-05 14:08:09 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
/* if the missiles exists: */
|
2009-12-10 12:53:47 +00:00
|
|
|
if (missile->alive > 0)
|
2009-12-09 13:17:21 +00:00
|
|
|
{
|
|
|
|
/* has the missile hit the asteroid? */
|
|
|
|
if (is_point_within_asteroid(asteroid, &missile->position) ||
|
|
|
|
is_point_within_asteroid(asteroid, &missile->oldpoint))
|
|
|
|
{
|
|
|
|
add_score(1);
|
2009-12-10 12:53:47 +00:00
|
|
|
missile->alive = 0;
|
2009-12-09 13:17:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
missile++;
|
2009-12-05 14:08:09 +00:00
|
|
|
}
|
2009-12-09 13:17:21 +00:00
|
|
|
|
|
|
|
/* now check collision with ship: */
|
2009-12-10 12:53:47 +00:00
|
|
|
if (asteroid->exists && ship.exists)
|
2009-12-05 14:08:09 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
if (is_ship_within_asteroid(asteroid))
|
|
|
|
{
|
|
|
|
add_score(1);
|
2009-12-10 12:53:47 +00:00
|
|
|
explode_ship();
|
2009-12-09 13:17:21 +00:00
|
|
|
}
|
2009-12-10 12:53:47 +00:00
|
|
|
}
|
2009-12-09 13:17:21 +00:00
|
|
|
|
2009-12-10 12:53:47 +00:00
|
|
|
/* has the enemy missile blown something up? */
|
|
|
|
if (asteroid->exists && enemy_missile.alive > 0)
|
|
|
|
{
|
|
|
|
if (is_point_within_asteroid(asteroid, &enemy_missile.position))
|
2009-12-09 13:17:21 +00:00
|
|
|
{
|
2009-12-10 12:53:47 +00:00
|
|
|
enemy_missile.alive = 0;
|
2009-12-09 13:17:21 +00:00
|
|
|
}
|
2009-12-05 14:08:09 +00:00
|
|
|
}
|
2007-01-01 23:31:53 +00:00
|
|
|
}
|
2009-12-09 13:17:21 +00:00
|
|
|
|
|
|
|
/* is an asteroid still exploding? */
|
2009-12-10 12:53:47 +00:00
|
|
|
if (asteroid->explode_countdown > 0)
|
2009-12-09 13:17:21 +00:00
|
|
|
asteroids_onscreen = true;
|
|
|
|
|
|
|
|
asteroid++;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
2009-12-09 13:17:21 +00:00
|
|
|
|
|
|
|
/* now check collision between ship and enemy */
|
2009-12-10 12:53:47 +00:00
|
|
|
if (enemy.exists && ship.exists)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
/* has the enemy collided with the ship? */
|
|
|
|
if (is_point_within_enemy(&ship.position))
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-10 12:53:47 +00:00
|
|
|
explode_ship();
|
2009-12-09 13:17:21 +00:00
|
|
|
create_trail_blaze(EXPLOSION_ENEMY, &enemy.position);
|
|
|
|
}
|
|
|
|
|
2009-12-10 12:53:47 +00:00
|
|
|
if (enemy.exists)
|
2009-12-09 13:17:21 +00:00
|
|
|
{
|
|
|
|
/* Now see if the enemy has been shot at by the ships missiles: */
|
|
|
|
missile = missiles_array;
|
|
|
|
n = MAX_NUM_MISSILES;
|
|
|
|
while (n--)
|
|
|
|
{
|
2009-12-10 12:53:47 +00:00
|
|
|
if (missile->alive > 0 &&
|
2009-12-09 13:17:21 +00:00
|
|
|
is_point_within_enemy(&missile->position))
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-10 12:53:47 +00:00
|
|
|
missile->alive = 0;
|
2009-12-09 13:17:21 +00:00
|
|
|
break;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
2009-12-09 13:17:21 +00:00
|
|
|
missile++;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* test collision with enemy missile and ship: */
|
2009-12-10 12:53:47 +00:00
|
|
|
if (enemy_missile.alive > 0 && is_point_within_ship(&enemy_missile.position))
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-10 12:53:47 +00:00
|
|
|
explode_ship();
|
|
|
|
enemy_missile.alive = 0;
|
2009-12-09 13:17:21 +00:00
|
|
|
enemy_missile.position.x = enemy_missile.position.y = 0;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* if all asteroids cleared then start again: */
|
2009-12-10 12:53:47 +00:00
|
|
|
if (asteroid_count == 0 && !asteroids_onscreen
|
|
|
|
&& !enemy.exists && enemy.explode_countdown <= 0)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
current_level++;
|
2009-12-12 14:05:03 +00:00
|
|
|
if (current_level > MAX_LEVEL)
|
|
|
|
current_level = START_LEVEL;
|
2009-12-09 13:17:21 +00:00
|
|
|
enemy.appear_probability += 5;
|
|
|
|
if (enemy.appear_probability >= 100)
|
|
|
|
enemy.appear_probability = ENEMY_APPEAR_PROBABILITY_START;
|
|
|
|
enemy.appear_timing -= 30;
|
|
|
|
if (enemy.appear_timing < 30)
|
|
|
|
enemy.appear_timing = 30;
|
|
|
|
game_state = SHOW_LEVEL;
|
|
|
|
show_level_timeout = SHOW_LEVEL_TIME;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/*
|
|
|
|
* stars
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void create_stars(void)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
|
|
|
struct Point* p;
|
2009-12-05 14:08:09 +00:00
|
|
|
int n;
|
|
|
|
|
|
|
|
p = stars;
|
|
|
|
n = NUM_STARS;
|
2009-12-09 13:17:21 +00:00
|
|
|
while (n--)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
p->x = (rb->rand()%LCD_WIDTH);
|
|
|
|
p->y = (rb->rand()%LCD_HEIGHT);
|
2006-03-31 12:00:26 +00:00
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
static void drawstars(void)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-05 14:08:09 +00:00
|
|
|
struct Point* p;
|
|
|
|
int n;
|
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
SET_FG(COL_STARS);
|
|
|
|
|
2006-03-31 12:00:26 +00:00
|
|
|
p = stars;
|
|
|
|
n = NUM_STARS;
|
2009-12-09 13:17:21 +00:00
|
|
|
while (n--)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
rb->lcd_drawpixel(p->x , p->y);
|
2006-03-31 12:00:26 +00:00
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************
|
2009-12-05 14:08:09 +00:00
|
|
|
** Creates start_num number of new asteroids of
|
2006-03-31 12:00:26 +00:00
|
|
|
** full size.
|
|
|
|
**************************************************/
|
2009-12-09 13:17:21 +00:00
|
|
|
static void initialise_level(int start_num)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-05 14:08:09 +00:00
|
|
|
struct Asteroid* asteroid;
|
|
|
|
struct Missile* missile;
|
2009-12-09 13:17:21 +00:00
|
|
|
struct TrailPoint* tpoint;
|
2006-03-31 12:00:26 +00:00
|
|
|
int n;
|
|
|
|
asteroid_count = next_missile_count = next_thrust_count = 0;
|
2007-01-01 23:31:53 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* no enemy */
|
2009-12-05 14:08:09 +00:00
|
|
|
enemy.exists = 0;
|
2009-12-10 12:53:47 +00:00
|
|
|
enemy.explode_countdown = 0;
|
|
|
|
enemy_missile.alive = 0;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* clear asteroids */
|
2009-12-05 14:08:09 +00:00
|
|
|
asteroid = asteroids_array;
|
2006-03-31 12:00:26 +00:00
|
|
|
n = MAX_NUM_ASTEROIDS;
|
2009-12-09 13:17:21 +00:00
|
|
|
while (n--)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
|
|
|
asteroid->exists = false;
|
|
|
|
asteroid++;
|
|
|
|
}
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* make some LARGE asteroids */
|
2006-03-31 12:00:26 +00:00
|
|
|
for(n = 0; n < start_num; n++)
|
2009-12-09 13:17:21 +00:00
|
|
|
initialise_asteroid(&asteroids_array[n], LARGE, NULL);
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* ensure all missiles are out of action: */
|
2006-03-31 12:00:26 +00:00
|
|
|
missile = missiles_array;
|
|
|
|
n = MAX_NUM_MISSILES;
|
2009-12-09 13:17:21 +00:00
|
|
|
while (n--)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-12-10 12:53:47 +00:00
|
|
|
missile->alive = 0;
|
2006-03-31 12:00:26 +00:00
|
|
|
missile++;
|
|
|
|
}
|
2009-12-09 13:17:21 +00:00
|
|
|
|
|
|
|
tpoint = trail_points;
|
|
|
|
n = NUM_TRAIL_POINTS;
|
|
|
|
while (n--)
|
|
|
|
{
|
|
|
|
tpoint->alive = 0;
|
|
|
|
tpoint++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void initialise_game(void)
|
|
|
|
{
|
|
|
|
enemy.appear_probability = ENEMY_APPEAR_PROBABILITY_START;
|
|
|
|
enemy.appear_timing = ENEMY_APPEAR_TIMING_START;
|
|
|
|
enemy.appear_countdown = enemy.appear_timing;
|
|
|
|
enemy.size_probability = ENEMY_BIG_PROBABILITY_START;
|
|
|
|
current_level = START_LEVEL;
|
|
|
|
num_lives = START_LIVES;
|
|
|
|
extra_life = EXTRA_LIFE;
|
|
|
|
current_score = 0;
|
|
|
|
initialise_ship();
|
|
|
|
initialise_level(0);
|
|
|
|
game_state = SHOW_LEVEL;
|
|
|
|
show_level_timeout = SHOW_LEVEL_TIME;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* menu stuff */
|
|
|
|
static bool spacerocks_help(void)
|
|
|
|
{
|
|
|
|
static char *help_text[] = {
|
2010-02-22 07:17:15 +00:00
|
|
|
"Spacerocks", "", "Aim", "",
|
|
|
|
"The", "goal", "of", "the", "game", "is", "to", "blow", "up",
|
|
|
|
"the", "asteroids", "and", "avoid", "being", "hit", "by", "them.",
|
|
|
|
"Also", "you'd", "better", "watch", "out", "for", "the", "UFOs!"
|
2009-12-09 13:17:21 +00:00
|
|
|
};
|
|
|
|
static struct style_text formation[]={
|
|
|
|
{ 0, TEXT_CENTER|TEXT_UNDERLINE },
|
|
|
|
{ 2, C_RED },
|
2010-02-22 07:17:15 +00:00
|
|
|
LAST_STYLE_ITEM
|
2009-12-09 13:17:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
rb->lcd_setfont(FONT_UI);
|
2010-02-22 07:17:15 +00:00
|
|
|
SET_BG(LCD_BLACK);
|
|
|
|
SET_FG(LCD_WHITE);
|
|
|
|
if (display_text(ARRAYLEN(help_text), help_text, formation, NULL, true))
|
2009-12-09 13:17:21 +00:00
|
|
|
return true;
|
|
|
|
rb->lcd_setfont(FONT_SYSFIXED);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PLUGIN_OTHER 10
|
|
|
|
static bool ingame;
|
|
|
|
static int spacerocks_menu_cb(int action, const struct menu_item_ex *this_item)
|
|
|
|
{
|
|
|
|
if (action == ACTION_REQUEST_MENUITEM
|
|
|
|
&& !ingame && ((intptr_t)this_item)==0)
|
|
|
|
return ACTION_EXIT_MENUITEM;
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int spacerocks_menu(void)
|
|
|
|
{
|
|
|
|
int selection = 0;
|
|
|
|
MENUITEM_STRINGLIST(main_menu, "Spacerocks Menu", spacerocks_menu_cb,
|
|
|
|
"Resume Game", "Start New Game",
|
|
|
|
"Help", "High Scores",
|
|
|
|
"Playback Control", "Quit");
|
|
|
|
rb->button_clear_queue();
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
switch (rb->do_menu(&main_menu, &selection, NULL, false))
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return PLUGIN_OTHER;
|
|
|
|
case 1:
|
|
|
|
initialise_game();
|
|
|
|
return PLUGIN_OTHER;
|
|
|
|
case 2:
|
|
|
|
if (spacerocks_help())
|
|
|
|
return PLUGIN_USB_CONNECTED;
|
|
|
|
break;
|
|
|
|
case 3:
|
2010-02-27 14:45:37 +00:00
|
|
|
highscore_show(-1, highscores, NUM_SCORES, true);
|
2009-12-09 13:17:21 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
playback_control(NULL);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
return PLUGIN_OK;
|
|
|
|
case MENU_ATTACHED_USB:
|
|
|
|
return PLUGIN_USB_CONNECTED;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
|
|
|
|
2009-07-21 17:29:46 +00:00
|
|
|
static int spacerocks_game_loop(void)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
|
|
|
int button;
|
|
|
|
int end;
|
2009-07-21 17:29:46 +00:00
|
|
|
int position;
|
2009-12-09 13:17:21 +00:00
|
|
|
int ret;
|
2009-07-21 17:29:46 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
if ((ret = spacerocks_menu()) != PLUGIN_OTHER)
|
|
|
|
return ret;
|
2006-03-31 14:38:15 +00:00
|
|
|
|
|
|
|
SET_BG(LCD_BLACK);
|
2009-07-21 17:29:46 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
ingame = true;
|
|
|
|
while (true)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-07-21 17:29:46 +00:00
|
|
|
end = *rb->current_tick + (CYCLETIME * HZ) / 1000;
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
SET_FG(COL_TEXT);
|
2009-12-05 14:08:09 +00:00
|
|
|
switch(game_state)
|
|
|
|
{
|
|
|
|
case GAME_OVER:
|
2009-12-09 13:17:21 +00:00
|
|
|
ingame = false;
|
2009-12-05 14:08:09 +00:00
|
|
|
rb->splash (HZ * 2, "Game Over");
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
position = highscore_update(current_score, current_level, "",
|
|
|
|
highscores, NUM_SCORES);
|
|
|
|
if (position != -1)
|
|
|
|
{
|
|
|
|
if (position == 0)
|
|
|
|
rb->splash(HZ*2, "New High Score");
|
|
|
|
highscore_show(position, highscores, NUM_SCORES, true);
|
|
|
|
}
|
2009-12-09 13:17:21 +00:00
|
|
|
return PLUGIN_OTHER;
|
2009-12-05 14:08:09 +00:00
|
|
|
break;
|
2009-07-21 17:29:46 +00:00
|
|
|
|
2009-12-05 14:08:09 +00:00
|
|
|
case PAUSE_MODE:
|
2010-08-28 21:46:45 +00:00
|
|
|
rb->lcd_putsxyf(1,LCD_HEIGHT-8, "score %d ", current_score);
|
2009-12-05 14:08:09 +00:00
|
|
|
rb->lcd_putsxy(CENTER_LCD_X - 15,
|
|
|
|
CENTER_LCD_Y + CENTER_LCD_Y/2 - 4, "pause");
|
|
|
|
draw_and_move_missiles();
|
2006-03-31 12:00:26 +00:00
|
|
|
draw_lives();
|
2009-12-05 14:08:09 +00:00
|
|
|
draw_and_move_ship();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLAY_MODE:
|
2010-08-28 21:46:45 +00:00
|
|
|
rb->lcd_putsxyf(1, LCD_HEIGHT-8, "score %d ", current_score);
|
2009-12-05 14:08:09 +00:00
|
|
|
draw_and_move_missiles();
|
|
|
|
draw_lives();
|
|
|
|
check_collisions();
|
|
|
|
draw_and_move_ship();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHOW_LEVEL:
|
2010-08-28 21:46:45 +00:00
|
|
|
rb->lcd_putsxyf(1, LCD_HEIGHT-8, "score %d ", current_score);
|
|
|
|
rb->lcd_putsxyf(CENTER_LCD_X - 20,
|
|
|
|
CENTER_LCD_Y + CENTER_LCD_Y/2 - 4,
|
|
|
|
"stage %d ", current_level);
|
2009-12-05 14:08:09 +00:00
|
|
|
draw_lives();
|
2009-12-09 13:17:21 +00:00
|
|
|
draw_and_move_ship();
|
2009-12-05 14:08:09 +00:00
|
|
|
show_level_timeout--;
|
2009-12-12 14:05:03 +00:00
|
|
|
if (show_level_timeout <= 0)
|
2009-12-05 14:08:09 +00:00
|
|
|
{
|
2009-12-09 13:17:21 +00:00
|
|
|
initialise_level(current_level);
|
2009-12-05 14:08:09 +00:00
|
|
|
game_state = PLAY_MODE;
|
|
|
|
}
|
|
|
|
break;
|
2009-07-21 17:29:46 +00:00
|
|
|
}
|
2009-12-09 13:17:21 +00:00
|
|
|
draw_and_move_trail_blaze();
|
2009-12-05 14:08:09 +00:00
|
|
|
drawstars();
|
2009-07-21 17:29:46 +00:00
|
|
|
draw_and_move_asteroids();
|
|
|
|
draw_and_move_enemy();
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-07-21 17:29:46 +00:00
|
|
|
rb->lcd_update();
|
2006-06-30 16:43:47 +00:00
|
|
|
|
2009-12-05 14:08:09 +00:00
|
|
|
#ifdef HAS_BUTTON_HOLD
|
|
|
|
if (rb->button_hold() && game_state == PLAY_MODE)
|
|
|
|
game_state = PAUSE_MODE;
|
2006-06-30 16:43:47 +00:00
|
|
|
#endif
|
2009-07-21 17:29:46 +00:00
|
|
|
button = rb->button_get(false);
|
2009-12-05 14:08:09 +00:00
|
|
|
switch(button)
|
|
|
|
{
|
2006-03-31 12:00:26 +00:00
|
|
|
case(AST_QUIT):
|
2009-12-09 13:17:21 +00:00
|
|
|
return PLUGIN_OTHER;
|
2006-03-31 12:00:26 +00:00
|
|
|
break;
|
2009-12-05 14:08:09 +00:00
|
|
|
#ifdef AST_PAUSE
|
|
|
|
case(AST_PAUSE):
|
|
|
|
if (game_state == PAUSE_MODE)
|
2009-07-21 17:29:46 +00:00
|
|
|
game_state = PLAY_MODE;
|
2009-12-05 14:08:09 +00:00
|
|
|
else if (game_state == PLAY_MODE)
|
|
|
|
game_state = PAUSE_MODE;
|
|
|
|
break;
|
|
|
|
#endif
|
2006-03-31 12:00:26 +00:00
|
|
|
case (AST_LEFT):
|
2009-07-21 17:29:46 +00:00
|
|
|
case (AST_LEFT | BUTTON_REPEAT):
|
2009-12-09 13:17:21 +00:00
|
|
|
if (game_state == PLAY_MODE || game_state == SHOW_LEVEL)
|
2006-03-31 12:00:26 +00:00
|
|
|
rotate_ship(SHIP_ROT_ACW_COS, SHIP_ROT_ACW_SIN);
|
|
|
|
break;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2006-03-31 12:00:26 +00:00
|
|
|
case (AST_RIGHT):
|
2009-07-21 17:29:46 +00:00
|
|
|
case (AST_RIGHT | BUTTON_REPEAT):
|
2009-12-09 13:17:21 +00:00
|
|
|
if (game_state == PLAY_MODE || game_state == SHOW_LEVEL)
|
2006-03-31 12:00:26 +00:00
|
|
|
rotate_ship(SHIP_ROT_CW_COS, SHIP_ROT_CW_SIN);
|
2009-12-05 14:08:09 +00:00
|
|
|
break;
|
|
|
|
|
2006-03-31 12:00:26 +00:00
|
|
|
case (AST_THRUST):
|
2009-07-21 17:29:46 +00:00
|
|
|
case (AST_THRUST | BUTTON_REPEAT):
|
2009-12-09 13:17:21 +00:00
|
|
|
if (game_state == PLAY_MODE || game_state == SHOW_LEVEL)
|
2009-12-05 14:08:09 +00:00
|
|
|
{
|
2009-12-12 14:05:03 +00:00
|
|
|
if (next_thrust_count <= 0)
|
2009-12-05 14:08:09 +00:00
|
|
|
{
|
|
|
|
next_thrust_count = 5;
|
|
|
|
thrust_ship();
|
|
|
|
}
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
2009-12-05 14:08:09 +00:00
|
|
|
break;
|
|
|
|
|
2006-03-31 12:00:26 +00:00
|
|
|
case (AST_HYPERSPACE):
|
2009-12-09 13:17:21 +00:00
|
|
|
if (game_state == PLAY_MODE)
|
2006-03-31 12:00:26 +00:00
|
|
|
hyperspace();
|
2009-12-09 13:17:21 +00:00
|
|
|
/* maybe shield if it gets too hard */
|
2009-12-05 14:08:09 +00:00
|
|
|
break;
|
|
|
|
|
2006-03-31 12:00:26 +00:00
|
|
|
case (AST_FIRE):
|
2009-07-21 17:29:46 +00:00
|
|
|
case (AST_FIRE | BUTTON_REPEAT):
|
2009-12-12 14:05:03 +00:00
|
|
|
if (game_state == PLAY_MODE)
|
2009-12-05 14:08:09 +00:00
|
|
|
{
|
2009-12-12 14:05:03 +00:00
|
|
|
if (next_missile_count <= 0)
|
2009-12-05 14:08:09 +00:00
|
|
|
{
|
2006-03-31 12:00:26 +00:00
|
|
|
fire_missile();
|
|
|
|
next_missile_count = 10;
|
|
|
|
}
|
|
|
|
}
|
2009-12-05 14:08:09 +00:00
|
|
|
else if(game_state == PAUSE_MODE)
|
2006-03-31 12:00:26 +00:00
|
|
|
game_state = PLAY_MODE;
|
|
|
|
break;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2006-03-31 12:00:26 +00:00
|
|
|
default:
|
2009-12-05 14:08:09 +00:00
|
|
|
if (rb->default_event_handler(button)==SYS_USB_CONNECTED)
|
2006-03-31 12:00:26 +00:00
|
|
|
return PLUGIN_USB_CONNECTED;
|
|
|
|
break;
|
|
|
|
}
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-12 14:05:03 +00:00
|
|
|
if (next_missile_count > 0)
|
2009-07-21 17:29:46 +00:00
|
|
|
next_missile_count--;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-12 14:05:03 +00:00
|
|
|
if (next_thrust_count > 0)
|
2009-07-21 17:29:46 +00:00
|
|
|
next_thrust_count--;
|
|
|
|
|
2009-10-18 15:50:30 +00:00
|
|
|
if (TIME_BEFORE(*rb->current_tick, end))
|
2009-07-21 17:29:46 +00:00
|
|
|
rb->sleep(end-*rb->current_tick);
|
|
|
|
else
|
|
|
|
rb->yield();
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-16 10:34:40 +00:00
|
|
|
enum plugin_status plugin_start(const void* parameter)
|
2006-03-31 12:00:26 +00:00
|
|
|
{
|
2009-07-21 17:29:46 +00:00
|
|
|
(void)parameter;
|
2009-12-09 13:17:21 +00:00
|
|
|
int ret = PLUGIN_OTHER;
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2006-11-15 06:46:35 +00:00
|
|
|
#if LCD_DEPTH > 1
|
2006-11-15 06:14:27 +00:00
|
|
|
rb->lcd_set_backdrop(NULL);
|
2006-11-15 06:46:35 +00:00
|
|
|
#endif
|
2007-08-16 23:01:18 +00:00
|
|
|
/* universal font */
|
2006-03-31 12:00:26 +00:00
|
|
|
rb->lcd_setfont(FONT_SYSFIXED);
|
2007-08-15 12:42:09 +00:00
|
|
|
/* Turn off backlight timeout */
|
2011-01-24 12:29:16 +00:00
|
|
|
backlight_ignore_timeout();
|
2010-02-27 14:45:37 +00:00
|
|
|
highscore_load(SCORE_FILE, highscores, NUM_SCORES);
|
2009-12-12 14:05:03 +00:00
|
|
|
rb->srand(*rb->current_tick);
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
/* create stars once, and once only: */
|
|
|
|
create_stars();
|
|
|
|
|
|
|
|
while (ret == PLUGIN_OTHER)
|
|
|
|
ret = spacerocks_game_loop();
|
2009-12-05 14:08:09 +00:00
|
|
|
|
2006-03-31 12:00:26 +00:00
|
|
|
rb->lcd_setfont(FONT_UI);
|
2010-02-27 14:45:37 +00:00
|
|
|
highscore_save(SCORE_FILE, highscores, NUM_SCORES);
|
2007-08-15 12:42:09 +00:00
|
|
|
/* Turn on backlight timeout (revert to settings) */
|
2011-01-24 12:29:16 +00:00
|
|
|
backlight_use_settings();
|
2009-07-21 17:29:46 +00:00
|
|
|
|
2009-12-09 13:17:21 +00:00
|
|
|
return ret;
|
2006-03-31 12:00:26 +00:00
|
|
|
}
|