Skip to content

Commit ac41e28

Browse files
authored
Add files via upload
1 parent 9722cfe commit ac41e28

13 files changed

+863
-808
lines changed

src/game.c

Lines changed: 30 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,49 @@
11
#include "game.h"
22

3-
#define NROFBLOCKS 600
3+
#define BRICKS 600
44

5-
Position stBallPos;
6-
Position stPadPos;
7-
Position stBlockPos[NROFBLOCKS];
5+
tStObject stFrame[4];
6+
tStObject stBall;
7+
tStObject stPaddle;
8+
tStObject stBrick[BRICKS];
89

9-
Velocity stBallVel;
10-
Velocity stPadVel;
10+
tEnumState ePrvGameState = MainMenu;
11+
bool xInit = true;
1112

12-
Characteristics stBallChar;
13-
Characteristics stPadChar;
14-
Characteristics stBlockChar[NROFBLOCKS];
15-
16-
Map stFrame;
17-
18-
unsigned short uiInit = 1;
19-
20-
bool xGameDone;
21-
bool xOldButtonState;
22-
bool xGamePaused;
23-
24-
int engine(/*GameState *eGame,*/ Console *stVita, unsigned short uiScreenWidth, unsigned short uiScreenHeight, unsigned short uiStartLevel) {
25-
26-
if (uiInit == 1)
13+
void gameLoop(tEnumState *eGameState, stGamePad *stMcd)
14+
{
15+
if (ePrvGameState != *eGameState)
2716
{
28-
frameConstructor(&stFrame, uiScreenWidth, uiScreenHeight);
29-
paddleConstructor(&stPadPos, &stPadVel, &stPadChar);
30-
ballConstructor(&stBallPos, &stBallVel, &stBallChar);
31-
levelConstructor(stBlockPos, stBlockChar, &stFrame, uiStartLevel, NROFBLOCKS);
32-
// blockConstructor(stBlockPos, stBlockChar, &stFrame, NROFBLOCKS);
33-
loadAudio();
34-
uiInit = 0;
17+
xInit = true;
3518
}
3619

37-
if (stVita->xStart && !xOldButtonState && !xGamePaused)
38-
{
39-
xGamePaused = true;
40-
}
41-
else if (stVita->xStart && !xOldButtonState && xGamePaused)
20+
if (xInit)
4221
{
43-
xGamePaused = false;
22+
if (*eGameState >= Playing)
23+
{
24+
frameConstructor(stFrame);
25+
ballConstructor(&stBall);
26+
paddleConstructor(&stPaddle);
27+
}
28+
levelConstructor(*eGameState - 10, stFrame, stBrick, BRICKS);
29+
xInit = false;
4430
}
4531

46-
xOldButtonState = stVita->xStart;
47-
48-
if(xGamePaused || stBallChar.uiLives == 0)
32+
if (*eGameState != Paused)
4933
{
50-
xGameDone = stVita->xCircle;
34+
paddleUpdate(stMcd, &stPaddle, stFrame);
35+
ballUpdate(stMcd, &stBall, &stPaddle, stFrame, stBrick, BRICKS);
36+
brickUpdate(stBrick, BRICKS);
5137
}
52-
else
53-
{
54-
paddleUpdate(&stPadPos, &stPadVel, &stPadChar, stVita, &stFrame);
55-
xGameDone = ballUpdate(&stBallPos, &stBallVel, &stBallChar, &stFrame, &stPadPos, &stPadVel, &stPadChar, stBlockPos, stBlockChar, stVita, NROFBLOCKS);
56-
}
57-
58-
frameVisualizer(&stFrame, stVita, uiScreenWidth, uiScreenHeight, xGamePaused);
59-
paddleVisualizer(&stPadPos, &stPadVel, &stPadChar);
60-
blockVisualizer(stBlockPos, stBlockChar, NROFBLOCKS);
61-
ballVisualizer(&stBallPos, &stBallVel, &stBallChar);
6238

63-
if(xGameDone)
39+
if (*eGameState >= Playing)
6440
{
65-
uiInit = 1;
66-
return 0;
41+
showPaddle(&stPaddle);
42+
showBall(&stBall);
43+
showFrame(stFrame);
6744
}
6845

69-
return 1;
46+
showBrick(stBrick, BRICKS);
7047

48+
ePrvGameState = *eGameState;
7149
}

src/game.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#ifndef _GAME_H_
22
#define _GAME_H_
33

4-
#include "menu.h"
54
#include "objectConstructor.h"
65
#include "objectUpdater.h"
76
#include "objectVisualizer.h"
87

9-
int engine(/*GameState *eGame,*/Console *stVita, unsigned short uiScreenWidth, unsigned short uiScreenHeight, unsigned short uiStartLevel);
8+
void gameLoop(tEnumState *eGameState, stGamePad *stMcd);
109

1110
#endif

src/inputHandler.c

Lines changed: 43 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -2,133 +2,63 @@
22
#include <psp2/touch.h>
33
#include "inputHandler.h"
44

5-
#define RELEASED 0
6-
#define TOUCHING 1
7-
#define TOUCHED 2
8-
#define RELEASING 3
9-
10-
unsigned short uiRearTouchReport;
11-
unsigned short uiFrontTouchReport;
12-
135
void startInput(){
14-
sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG_WIDE);
15-
sceTouchSetSamplingState(SCE_TOUCH_PORT_FRONT, SCE_TOUCH_SAMPLING_STATE_START);
16-
sceTouchSetSamplingState(SCE_TOUCH_PORT_BACK, SCE_TOUCH_SAMPLING_STATE_START);
6+
if (PLATFORM == Vita)
7+
sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG_WIDE);
8+
sceTouchSetSamplingState(SCE_TOUCH_PORT_FRONT, SCE_TOUCH_SAMPLING_STATE_START);
9+
sceTouchSetSamplingState(SCE_TOUCH_PORT_BACK, SCE_TOUCH_SAMPLING_STATE_START);
1710
}
1811

19-
void inputRead(Console *stVita) {
20-
SceCtrlData pad;
21-
SceTouchData touch;
22-
23-
sceCtrlPeekBufferPositive(0, &pad, 1);
24-
stVita->xCircle = (pad.buttons & SCE_CTRL_CIRCLE);
25-
stVita->xCross = (pad.buttons & SCE_CTRL_CROSS);
26-
stVita->xTriangle = (pad.buttons & SCE_CTRL_TRIANGLE);
27-
stVita->xSquare = (pad.buttons & SCE_CTRL_SQUARE);
28-
29-
stVita->xUp = (pad.buttons & SCE_CTRL_UP);
30-
stVita->xDown = (pad.buttons & SCE_CTRL_DOWN);
31-
stVita->xLeft = (pad.buttons & SCE_CTRL_LEFT);
32-
stVita->xRight = (pad.buttons & SCE_CTRL_RIGHT);
33-
34-
stVita->xLeftTrigger = (pad.buttons & SCE_CTRL_LTRIGGER);
35-
stVita->xRightTrigger = (pad.buttons & SCE_CTRL_RTRIGGER);
36-
37-
stVita->xStart = (pad.buttons & SCE_CTRL_START);
38-
stVita->xSelect = (pad.buttons & SCE_CTRL_SELECT);
12+
void inputRead(stGamePad *stMcd) {
13+
SceCtrlData stPad;
14+
SceTouchData stTouch; // TODO Not allowed here, must be in vita function
15+
if (PLATFORM == Vita) // Button layout borrowed from DS3 controller
16+
sceCtrlPeekBufferPositive(0, &stPad, 1);
3917

40-
stVita->stLeftJoy.siX = (signed char)pad.lx - 128;
41-
stVita->stLeftJoy.siY = (signed char)pad.ly - 128;
42-
stVita->stRightJoy.siX = (signed char)pad.rx - 128;
43-
stVita->stRightJoy.siY = (signed char)pad.ry - 128;
18+
stMcd->stButt[0].xTrigger = !stMcd->stButt[0].xHold && (stPad.buttons & SCE_CTRL_SQUARE);
19+
stMcd->stButt[0].xHold = (stPad.buttons & SCE_CTRL_SQUARE);
4420

45-
sceTouchPeek(SCE_TOUCH_PORT_BACK, &touch, 1);
46-
if (touch.reportNum > 0)
47-
{
48-
stVita->stRearTouch.uiX = touch.report[0].x / 2;
49-
stVita->stRearTouch.uiY = touch.report[0].y / 2;
50-
}
51-
else
52-
{
53-
stVita->stRearTouch.uiX = 0;
54-
stVita->stRearTouch.uiY = 0;
55-
}
21+
stMcd->stButt[1].xTrigger = !stMcd->stButt[1].xHold && (stPad.buttons & SCE_CTRL_CROSS);
22+
stMcd->stButt[1].xHold = (stPad.buttons & SCE_CTRL_CROSS);
5623

57-
stVita->stRearTouch.xFtrig = false;
58-
stVita->stRearTouch.xRtrig = false;
24+
stMcd->stButt[2].xTrigger = !stMcd->stButt[2].xHold && (stPad.buttons & SCE_CTRL_CIRCLE);
25+
stMcd->stButt[2].xHold = (stPad.buttons & SCE_CTRL_CIRCLE);
5926

60-
switch (uiRearTouchReport)
61-
{
62-
case RELEASED:
63-
if (stVita->stRearTouch.uiX > 0)
64-
{
65-
uiRearTouchReport = TOUCHING;
66-
}
67-
break;
27+
stMcd->stButt[3].xTrigger = !stMcd->stButt[3].xHold && (stPad.buttons & SCE_CTRL_TRIANGLE);
28+
stMcd->stButt[3].xHold = (stPad.buttons & SCE_CTRL_TRIANGLE);
6829

69-
case TOUCHING:
70-
stVita->stRearTouch.xRtrig = true;
71-
uiRearTouchReport = TOUCHED;
72-
break;
73-
74-
case TOUCHED:
75-
if (stVita->stRearTouch.uiX == 0)
76-
{
77-
uiRearTouchReport = RELEASING;
78-
}
79-
break;
30+
stMcd->stButt[4].xTrigger = !stMcd->stButt[4].xHold && (stPad.buttons & SCE_CTRL_LTRIGGER);
31+
stMcd->stButt[4].xHold = (stPad.buttons & SCE_CTRL_LTRIGGER);
8032

81-
case RELEASING:
82-
stVita->stRearTouch.xFtrig = true;
83-
uiRearTouchReport = RELEASED;
84-
break;
33+
stMcd->stButt[5].xTrigger = !stMcd->stButt[5].xHold && (stPad.buttons & SCE_CTRL_RTRIGGER);
34+
stMcd->stButt[5].xHold = (stPad.buttons & SCE_CTRL_RTRIGGER);
8535

86-
default:
87-
break;
88-
}
36+
stMcd->stButt[6].xTrigger = !stMcd->stButt[6].xHold && (stPad.buttons & SCE_CTRL_SELECT);
37+
stMcd->stButt[6].xHold = (stPad.buttons & SCE_CTRL_SELECT);
8938

90-
sceTouchPeek(SCE_TOUCH_PORT_FRONT, &touch, 1);
91-
if (touch.reportNum > 0)
92-
{
93-
stVita->stFrontTouch.uiX = touch.report[0].x / 2;
94-
stVita->stFrontTouch.uiY = touch.report[0].y / 2;
95-
}
96-
else
97-
{
98-
stVita->stFrontTouch.uiX = 0;
99-
stVita->stFrontTouch.uiY = 0;
100-
}
39+
stMcd->stButt[7].xTrigger = !stMcd->stButt[7].xHold && (stPad.buttons & SCE_CTRL_START);
40+
stMcd->stButt[7].xHold = (stPad.buttons & SCE_CTRL_START);
10141

102-
stVita->stFrontTouch.xFtrig = false;
103-
stVita->stFrontTouch.xRtrig = false;
42+
stMcd->stDpad[0].xTrigger = (!(stMcd->stDpad[0].xUp || stMcd->stDpad[0].xDown || stMcd->stDpad[0].xLeft || stMcd->stDpad[0].xRight) &&
43+
((stPad.buttons & SCE_CTRL_UP) || (stPad.buttons & SCE_CTRL_DOWN) || (stPad.buttons & SCE_CTRL_LEFT) || (stPad.buttons & SCE_CTRL_RIGHT)));
44+
stMcd->stDpad[0].xUp = (stPad.buttons & SCE_CTRL_UP);
45+
stMcd->stDpad[0].xDown = (stPad.buttons & SCE_CTRL_DOWN);
46+
stMcd->stDpad[0].xLeft = (stPad.buttons & SCE_CTRL_LEFT);
47+
stMcd->stDpad[0].xRight = (stPad.buttons & SCE_CTRL_RIGHT);
10448

105-
switch (uiFrontTouchReport)
106-
{
107-
case RELEASED:
108-
if (stVita->stFrontTouch.uiX > 0)
109-
{
110-
uiFrontTouchReport = TOUCHING;
111-
}
112-
break;
49+
stMcd->stJoy[0].siX = stPad.lx > 127 ? limit(100,0, stPad.lx-137) : limit(0,-100, stPad.lx-117);
50+
stMcd->stJoy[0].siY = stPad.ly > 127 ? limit(100,0, stPad.ly-137) : limit(0,-100, stPad.ly-117);
11351

114-
case TOUCHING:
115-
stVita->stFrontTouch.xRtrig = true;
116-
uiFrontTouchReport = TOUCHED;
117-
break;
118-
119-
case TOUCHED:
120-
if (stVita->stFrontTouch.uiX == 0)
121-
{
122-
uiFrontTouchReport = RELEASING;
123-
}
124-
break;
52+
stMcd->stJoy[1].siX = stPad.rx > 127 ? limit(100,0, stPad.rx-137) : limit(0,-100, stPad.rx-117);
53+
stMcd->stJoy[1].siY = stPad.ry > 127 ? limit(100,0, stPad.ry-137) : limit(0,-100, stPad.ry-117);
12554

126-
case RELEASING:
127-
stVita->stFrontTouch.xFtrig = true;
128-
uiFrontTouchReport = RELEASED;
129-
break;
55+
sceTouchPeek(SCE_TOUCH_PORT_FRONT, &stTouch, 1);
56+
stMcd->stTouch[0].xTrigger = (stMcd->stTouch[0].uiX == 0) && (stTouch.report[0].x > 0);
57+
stMcd->stTouch[0].uiX = (stTouch.reportNum > 0) ? stTouch.report[0].x/2 : 0;
58+
stMcd->stTouch[0].uiY = (stTouch.reportNum > 0) ? stTouch.report[0].y/2 : 0;
13059

131-
default:
132-
break;
133-
}
60+
sceTouchPeek(SCE_TOUCH_PORT_BACK, &stTouch, 1);
61+
stMcd->stTouch[1].xTrigger = (stMcd->stTouch[1].uiX == 0) && (stTouch.report[0].x > 0);
62+
stMcd->stTouch[1].uiX = (stTouch.reportNum > 0) ? stTouch.report[0].x/2 : 0;
63+
stMcd->stTouch[1].uiY = (stTouch.reportNum > 0) ? stTouch.report[0].y/2 : 0;
13464
}

0 commit comments

Comments
 (0)