Skip to content
This repository was archived by the owner on Feb 14, 2024. It is now read-only.

Commit b24b76d

Browse files
authored
Add files via upload
1 parent 0d5ff9a commit b24b76d

File tree

8 files changed

+165
-174
lines changed

8 files changed

+165
-174
lines changed

PouletAPlus.ino

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#include <Arduboy2.h>
2+
#include <Tinyfont.h>
3+
#include <math.h>
4+
25

36
Arduboy2 arduboy;
7+
Tinyfont tinyfont = Tinyfont(arduboy.sBuffer, Arduboy2::width(), Arduboy2::height());
48

59
#include "poulet.h"
610
#include "graphics.h"
@@ -9,6 +13,8 @@ Arduboy2 arduboy;
913
#include "entity.h"
1014
#include "physics.h"
1115
#include "numbers.h"
16+
#include "sprite.h"
17+
1218

1319

1420
// Forward declaration of essential types:
@@ -17,13 +23,7 @@ struct Game;
1723

1824
Entity player;
1925
Game game;
20-
21-
// later I'll init this as zero size
22-
Entity ents[4];
23-
24-
25-
// Init player
26-
26+
Entity ents[10];
2727

2828

2929
void setup() {
@@ -32,6 +32,18 @@ void setup() {
3232
player.walkSpeed = 1;
3333
player.walkAccel = 0.1;
3434
player.animSpeed = 4;
35+
player.image = poulet;
36+
37+
// Put a few test cats in
38+
39+
/*
40+
create(1, 30, 10, ents);
41+
create(1, 40, 20, ents);
42+
create(1, 50, 30, ents);
43+
create(1, 60, 40, ents);
44+
create(1, 70, 50, ents);
45+
create(1, 80, 60, ents);
46+
*/
3547

3648
game.mode = 1;
3749

@@ -56,7 +68,7 @@ void loop() {
5668
arduboy.clear();
5769

5870
if(game.mode == 0){
59-
play(&player, &game);
71+
play(&player, &game, ents);
6072
}
6173

6274
if(game.mode == 1){
@@ -72,15 +84,18 @@ void loop() {
7284

7385

7486
void title(Game *g){
87+
7588
Sprites::drawOverwrite(0, -10, titlescreen, 0);
7689
arduboy.setCursor(40, 40);
7790
arduboy.print("Start");
7891
arduboy.setCursor(40, 48);
92+
7993
if(g->debug == false){
8094
arduboy.print("Debug: Off");
8195
} else {
8296
arduboy.print("Debug: On");
8397
}
98+
8499
arduboy.setCursor(40, 56);
85100
arduboy.print("Sound: Off");
86101

@@ -97,7 +112,6 @@ void title(Game *g){
97112
arduboy.setCursor(30, (40 + (g->menuItem * 8)));
98113
arduboy.print(">");
99114

100-
101115
if(arduboy.justPressed(LEFT_BUTTON) || arduboy.justPressed(RIGHT_BUTTON)){
102116
if(g->menuItem == 1){
103117
if(g->debug){
@@ -111,7 +125,9 @@ void title(Game *g){
111125
}
112126

113127

114-
void play(Entity *p, Game *g){
128+
void play(Entity *p, Game *g, Entity *ents){
129+
130+
int i = 0;
115131

116132
if (arduboy.pressed(LEFT_BUTTON)){
117133
p->ax -= p->walkAccel;
@@ -125,15 +141,29 @@ void play(Entity *p, Game *g){
125141
}
126142
if (arduboy.justPressed(A_BUTTON)){
127143
// YOU WIN!
128-
g->score += 1000;
144+
g->score += 10;
145+
create(1, p->x, p->y - 10, ents);
146+
129147
}
130148

131-
physicsUpdate(&player);
149+
physicsUpdate(p);
150+
for(i = 0; i < sizeof(ents); i++){
151+
physicsUpdate(&ents[i]);
152+
}
153+
132154
camera(&player, &game);
133155
if(game.debug) debug(&player, &game);
134156
drawLevel(0, 0, &game);
135-
showHUD(&game);
157+
136158
animation(p, g);
159+
drawSprite(g, p);
160+
161+
for(i = 0; i < ENT_MAX; i++){
162+
animation (&ents[i], g);
163+
drawSprite(g, &ents[i]);
164+
}
165+
166+
showHUD(g);
137167

138168
}
139169

@@ -152,7 +182,8 @@ void gameInit(Entity *p, Game *g){
152182
}
153183

154184

155-
void animation(Entity *p, Game *game){
185+
void animation(Entity *p, Game *g){
186+
int i = 0;
156187

157188
p->ticker += abs(p->ax);
158189
if(p->ticker >= p->animSpeed){
@@ -165,7 +196,6 @@ void animation(Entity *p, Game *game){
165196

166197
if(p->ax > 0) p->flip = 0;
167198
if(p->ax < 0) p->flip = 8;
168-
169199
if(p->ax == 0) p->frame = 0;
170200

171201

@@ -174,8 +204,6 @@ void animation(Entity *p, Game *game){
174204
if(p->ay > 0) p->frame = 7;
175205
}
176206

177-
Sprites::drawPlusMask(p->x - game->camerax, p->y, poulet, p->frame + p->flip);
178-
179207
}
180208

181209

@@ -193,19 +221,19 @@ void camera(Entity *p, Game *game){
193221
}
194222

195223

196-
void debug(Entity *p, Game *game){
197-
arduboy.print("X: ");
198-
arduboy.print(p->x);
199-
arduboy.print(" Y: ");
200-
arduboy.print(p->y);
201-
arduboy.print("\nTX: ");
202-
arduboy.print(floor(p->x / 8));
203-
arduboy.print(" TY: ");
204-
arduboy.print(floor(p->y / 8));
205-
arduboy.print("\nAX: ");
206-
arduboy.print(p->ax);
207-
arduboy.print(" AY: ");
208-
arduboy.print(p->ay);
224+
void debug(Entity *p, Game *g){
225+
226+
tinyfont.setCursor(1, 0);
227+
tinyfont.print("Debug Mode");
228+
tinyfont.setCursor(1, 5);
229+
tinyfont.print("p.X:");
230+
tinyfont.print(int(p->x));
231+
tinyfont.print(" p.Y:");
232+
tinyfont.print(int(p->y));
233+
tinyfont.setCursor(1, 10);
234+
tinyfont.print("Score: ");
235+
tinyfont.print(g->score);
236+
209237
}
210238

211239

entity.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,39 @@
44
* Functions for adding, removing, and updating entities.
55
*/
66

7-
7+
#include "poulet.h"
8+
#include "entity.h"
9+
#include "graphics.h"
10+
#include "physics.h"
11+
12+
// create a new entity in the world.
13+
void create(int type, float x, float y, struct Entity e[]){
14+
15+
int newIndex = 0;
16+
int i = 0;
17+
int elementSize = 0;
18+
19+
// Iterate through what's still alive and active to not overwrite anything...
20+
for(i = 0; i < ENT_MAX; i++){
21+
if(e[i].alive = 0){
22+
break;
23+
}
24+
}
25+
26+
newIndex = i;
27+
e[i].alive = true;
28+
29+
// Now we assign values to the new index.
30+
e[newIndex].x = x;
31+
e[newIndex].y = y;
32+
33+
34+
// Catch default case:
35+
e[newIndex].image = cat;
36+
37+
// Cat
38+
if(type == 1){
39+
e[newIndex].image = cat;
40+
}
41+
}
42+

entity.h

Lines changed: 2 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,9 @@
11
#ifndef ENTITY_H
22
#define ENTITY_H
33

4+
#include "poulet.h"
45

5-
void entPhysicsUpdate(struct Entity *e){
6-
7-
// Process the entity physics.
8-
9-
int i; // iterator to check
10-
bool blocked; // State if a wall is found during a check.
11-
12-
// lock the velocity to the set walkspeed.
13-
if(e->ax > 0){
14-
if(e->ax > e->walkSpeed){
15-
e->ax = e->walkSpeed;
16-
}
17-
} else {
18-
if(e->ax < -e->walkSpeed){
19-
e->ax = -e->walkSpeed;
20-
}
21-
}
22-
23-
// Apply gravity:
24-
e->ay += gravity;
25-
26-
27-
// Collision checks:
28-
// Right
29-
blocked = false;
30-
if(e->ax > 0){
31-
for(i = floor(e->x); i <= floor(e->x + e->ax); i++){
32-
if((isSolid(i + 9, e->y)) || (isSolid(i + 9, floor(e->y + 7)))){
33-
e->x = i;
34-
blocked = true;
35-
e->ax = 0;
36-
break;
37-
}
38-
}
39-
if(!blocked) e->x += e->ax;
40-
}
41-
42-
// Left
43-
blocked = false;
44-
if(e->ax < 0){
45-
for(i = floor(e->x); i >= floor(e->x + e->ax); i--){
46-
if((isSolid(i-1, e->y)) || (isSolid(i-1, floor(e->y + 7)))){
47-
e->x = i;
48-
blocked = true;
49-
e->ax = 0;
50-
break;
51-
}
52-
}
53-
if(!blocked) e->x += e->ax;
54-
}
55-
56-
// Down
57-
blocked = false;
58-
if(e->ay > 0){
59-
for(i = floor(e->y); i <= floor(e->y + e->ay); i++){
60-
if((isSolid(e->x , i + 8)) || (isSolid(e->x + 8, i + 8))){
61-
e->y = i;
62-
blocked = true;
63-
e->grounded = true;
64-
e->ay = 0;
65-
break;
66-
} else {
67-
e->grounded = false;
68-
}
69-
}
70-
if(!blocked) e->y += e->ay;
71-
}
72-
73-
// Up
74-
blocked = false;
75-
if(e->ay < 0){
76-
for(i = floor(e->y); i >= floor(e->y + e->ay); i--){
77-
if((isSolid(e->x, i-1)) || (isSolid(e->x + 8, i-1))){
78-
e->y = i;
79-
blocked = true;
80-
e->ay = -e->ay;
81-
break;
82-
}
83-
}
84-
if(!blocked) e->y += e->ay;
85-
}
86-
87-
88-
// Handle falling out of world:
89-
if(e->y > 128) e->y = -8;
90-
91-
// Add friction:
92-
if(e->ax > 0){
93-
e->ax -= groundFriction;
94-
}
95-
if(e->ax < 0){
96-
e->ax += groundFriction;
97-
}
98-
if(abs(e->ax) < groundFriction){
99-
e->ax = 0;
100-
}
101-
}
102-
103-
6+
void create(int type, float x, float y, struct Entity e[]);
1047

1058

1069

numbers.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void drawScore(long score){
2727
// blit a number here...
2828
// This is a real-time string compare, for better or for worse...
2929

30-
/*
30+
/*
3131
if(charBuf[i] == '0')
3232
Sprites::drawOverwrite(50 + ((i + pad) * 4), 0, num0, 0);
3333
if(charBuf[i] == '1')
@@ -48,7 +48,8 @@ void drawScore(long score){
4848
Sprites::drawOverwrite(50 + ((i + pad) * 4), 0, num8, 0);
4949
if(charBuf[i] == '9')
5050
Sprites::drawOverwrite(50 + ((i + pad) * 4), 0, num9, 0);
51-
*/
51+
52+
*/
5253
}
5354
}
5455

0 commit comments

Comments
 (0)