Jetpack Impossible
Re: Jetpack Impossible
Mais c'est déjà ce que je fais, regarde dans mon code, j'écris le nombre en noir pour l'effacer et en blanc pour l'écrire.
![]() Pokemon Topaze (Axe) discussion and download links here | (19:29:36) noelnadal: plus sérieusement, j'ai très peu de problèmes (22:45:44) Clifward: J'aime rire du malheur des autres ![]() (2017.11.18 - 17:07:12) Fireworks: Hayleia !!!!! (2017.11.18 - 17:07:19) TI-Bot: Fireworks has been logged out (Kicked). (2017.11.18 - 17:07:22) TI-Bot: Ban of user Fireworks revoked. (2017.11.18 - 17:07:25) TI-Bot: Fireworks logs into the Chat. (2017.11.18 - 17:07:28) Fireworks: <3 (2017.11.18 - 17:07:31) Fireworks: 208 |
-
HayleiaGénéreux
Niveau 17: GM (Grand Maître des calculatrices)- Posts: 2509
- Images: 2
- Joined: 30 Aug 2011, 08:22
- Gender:
- Calculator(s):→ MyCalcs profile
- Class: Templar
Re: Jetpack Impossible
Il doit y avoir un problème de couleur dans la définition de la police, mais je ne vois pas trop lequel.
Les non-cx sont beaucoup moins puissantes, et du coup tous les programmes SDL laggent. Je sais pas si ça vaut le coup de porter ce jeu sur non-CX.
Les non-cx sont beaucoup moins puissantes, et du coup tous les programmes SDL laggent. Je sais pas si ça vaut le coup de porter ce jeu sur non-CX.
-
Lepzulnag
Niveau 9: IC (Compteur Infatigable)- Posts: 151
- Joined: 02 Aug 2012, 21:15
- Location: Bretagne
- Gender:
- Calculator(s):→ MyCalcs profile
- Class: M2 Maths
Re: Jetpack Impossible
Le truc c'est que les non-CX ont un ARM9 deux fois moins puissants que celui des CX, et un écran 3.141592 fois plus merdique, donc c'est sûr ça aide pas.
Pour elles, il faut vraiment éviter la SDL. Les conversions entre les formats sont vraiiiiiiiment trop lentes. Ou alors il faudrait essayer de mettre l'écran en mode 16-bits, je suis en train d'essayer ça avec la SDL sur TI-Nspire CAS. Résultats bientôt.
Pour elles, il faut vraiment éviter la SDL. Les conversions entre les formats sont vraiiiiiiiment trop lentes. Ou alors il faudrait essayer de mettre l'écran en mode 16-bits, je suis en train d'essayer ça avec la SDL sur TI-Nspire CAS. Résultats bientôt.
-
matref
Niveau 15: CC (Chevalier des Calculatrices)- Posts: 506
- Joined: 11 Dec 2011, 03:08
- Location: France, Châteaurenard
- Gender:
- Calculator(s):→ MyCalcs profile
- Class: Prépa MPSI
Re: Jetpack Impossible
J'avais une autre question d'ailleurs. Y a-t-il un moyen (simple
) de lancer valgrinder (ou similaire) le programme ? Parce que j'ai eu quelques problèmes de fuites de mémoire, mais je ne sais pas si je les ai tous réglés.

![]() Pokemon Topaze (Axe) discussion and download links here | (19:29:36) noelnadal: plus sérieusement, j'ai très peu de problèmes (22:45:44) Clifward: J'aime rire du malheur des autres ![]() (2017.11.18 - 17:07:12) Fireworks: Hayleia !!!!! (2017.11.18 - 17:07:19) TI-Bot: Fireworks has been logged out (Kicked). (2017.11.18 - 17:07:22) TI-Bot: Ban of user Fireworks revoked. (2017.11.18 - 17:07:25) TI-Bot: Fireworks logs into the Chat. (2017.11.18 - 17:07:28) Fireworks: <3 (2017.11.18 - 17:07:31) Fireworks: 208 |
-
HayleiaGénéreux
Niveau 17: GM (Grand Maître des calculatrices)- Posts: 2509
- Images: 2
- Joined: 30 Aug 2011, 08:22
- Gender:
- Calculator(s):→ MyCalcs profile
- Class: Templar
Re: Jetpack Impossible
Va ... quoi ?
C'est à toi de savoir ce que tu dois libérer ou pas. Règle universelle : tous les nSDL_LoadImage() doivent être libérés avec SDL_FreeSurface, tous les malloc() avec free().
Ce que je fais en général, c'est mettre un gros fatty commentaire avec // TO FREE ou // TO SDL_FREESURFACE à côté du truc en question.
C'est à toi de savoir ce que tu dois libérer ou pas. Règle universelle : tous les nSDL_LoadImage() doivent être libérés avec SDL_FreeSurface, tous les malloc() avec free().
Ce que je fais en général, c'est mettre un gros fatty commentaire avec // TO FREE ou // TO SDL_FREESURFACE à côté du truc en question.
-
matref
Niveau 15: CC (Chevalier des Calculatrices)- Posts: 506
- Joined: 11 Dec 2011, 03:08
- Location: France, Châteaurenard
- Gender:
- Calculator(s):→ MyCalcs profile
- Class: Prépa MPSI
Re: Jetpack Impossible
Le problème avec le lag sur non-CX est sûrement car nSDL_LoadImage retourne une surface de 16 bits (https://github.com/Hoffa/nSDL/wiki/TI-Nspire-specific-functions-and-macros). Du coup quand tu blitte des surfaces 16 bits sur l'écran non-CX (8 bits sur SDL), SDL va convertir la surface à chaque fois que tu blitte.
Crée un fonction qui charge une image et convertit la surface avant de la retourner (en utilisant SDL_DisplayFormat: http://sdl.beuc.net/sdl.wiki/SDL_DisplayFormat). Un jeu comme ça proprement optimisé devrait facilement tourner à 60+ FPS sur non-CX. Un look-up table pour sin et cos serait aussi utile.
Crée un fonction qui charge une image et convertit la surface avant de la retourner (en utilisant SDL_DisplayFormat: http://sdl.beuc.net/sdl.wiki/SDL_DisplayFormat). Un jeu comme ça proprement optimisé devrait facilement tourner à 60+ FPS sur non-CX. Un look-up table pour sin et cos serait aussi utile.
-
hoffa
Niveau 3: MH (Membre Habitué)- Posts: 4
- Joined: 29 May 2011, 00:00
- Gender:
- Calculator(s):→ MyCalcs profile
Re: Jetpack Impossible
Code source mis à jour (flemme de faire une archive
)
(de toute façon il ne compile pas, je règle un problème avec le score)
(fixed)
Je mets déjà des SDL_DisplayFormat (pas dans l'archive sur TI Planet mais dans le code posté ci-dessus), et je n'ai pas vu de différences avec le lag.
Pour le sin et le cos, pas besoin de LUT, ils sont juste dans l'initialisation (qui n'est pas time critical).
C'est ce que je fais pour l'instant mais justement, je n'ai pas un moyen de vérifier que je n'en ai pas oublié ?

(de toute façon il ne compile pas, je règle un problème avec le score)
(fixed)
Show/Hide spoilerAfficher/Masquer le spoiler
- Code: Select all
#include <nspireio.h>
#include <stdio.h>
#include <os.h>
#include <libndls.h>
#include <stdlib.h>
#include <SDL/SDL_config.h>
#include <SDL/SDL.h>
#include <time.h>
#include <math.h>
#include "nSDL_CustomFonts.h"
#include "fonts.h"
#define K_ESC isKeyPressed(KEY_NSPIRE_ESC)
#define K_ENTER isKeyPressed(KEY_NSPIRE_ENTER)
#define K_TAB isKeyPressed(KEY_NSPIRE_TAB)
#define K_A isKeyPressed(KEY_NSPIRE_A)
#define K_7 isKeyPressed(KEY_NSPIRE_7)
#define K_9 isKeyPressed(KEY_NSPIRE_9)
#define K_8 isKeyPressed(KEY_NSPIRE_8)
#define K_5 isKeyPressed(KEY_NSPIRE_5)
#define K_4 isKeyPressed(KEY_NSPIRE_4)
#define K_6 isKeyPressed(KEY_NSPIRE_6)
#define COLOR_BPP 16
#define COLOR_STORAGE_SIZE 2
#define BMPWIDTH 17;
#define BMPHEIGHT 12;
#define shift_y 8
#define shift_x 8
#define vy_limit 256
#define vx_limit 256
static unsigned short JillD_sprite[] = {
0x2a01,0x0011,0x000C,0x0000,0x001f,0x001f,0x001f,0x001f,0xb5b6,0xffff,
0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0x001f,0x001f,0x001f,
0x001f,0xb5b6,0xffff,0x001f,0xb5b6,0xffff,0xffff,0xffff,0xffff,0xffff,
0xffff,0xffff,0xffff,0xffff,0xffff,0x001f,0x001f,0x001f,0xb5b6,0xffff,
0xffff,0xffff,0xffff,0xffff,0xdc2b,0xdc2b,0xdc2b,0xdc2b,0xdc2b,0xdc2b,
0xdc2b,0xffff,0xffff,0x001f,0x001f,0xb5b6,0xffff,0xffff,0xffff,0xffff,
0xdc2b,0xfced,0xfced,0xfced,0xfced,0xfced,0xfced,0xfced,0xdc2b,0xffff,
0x001f,0x001f,0xb5b6,0xffff,0xffff,0xffff,0xffff,0xfced,0xfced,0x0000,
0xfced,0xfced,0xfced,0xfced,0x0000,0xfced,0xffff,0x001f,0x001f,0xb5b6,
0xffff,0xffff,0xffff,0xffff,0xfced,0xfced,0x0000,0xfced,0xfbad,0xfbad,
0xfced,0x0000,0xfced,0xffff,0xffff,0x001f,0xb5b6,0xffff,0xffff,0xffff,
0xffff,0xfced,0xfced,0xfced,0xfced,0xfced,0xfced,0xfced,0xfced,0xfced,
0xffff,0x001f,0xffff,0xb5b6,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0x001f,0x001f,
0xb5b6,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
0xffff,0xffff,0xffff,0xffff,0xffff,0x001f,0x001f,0xb5b6,0xffff,0x001f,
0xb5b6,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
0xffff,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,
0xb5b6,0x001f,0x001f,0x001f,0x001f,0x001f,0xb5b6,0x001f,0x001f,0x001f,
0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0xb5b6,0x001f,0x001f,
0x001f,0x001f,0x001f,0xb5b6,0x001f,0x001f,0x001f,0x001f
};
static unsigned short JillD_shadow_sprite[] = {
0x2a01,0x0011,0x000C,0x0000,0x001f,0x001f,0x001f,0x001f,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x001f,0x001f,0x001f,
0x001f,0x0000,0x0000,0x001f,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x001f,0x001f,0x001f,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x001f,0x001f,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x001f,0x001f,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x001f,0x001f,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x001f,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x001f,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x001f,0x001f,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x001f,0x001f,0x0000,0x0000,0x001f,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,
0x0000,0x001f,0x001f,0x001f,0x001f,0x001f,0x0000,0x001f,0x001f,0x001f,
0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f,0x0000,0x001f,0x001f,
0x001f,0x001f,0x001f,0x0000,0x001f,0x001f,0x001f,0x001f
};
static unsigned short JillG_sprite[] = {
0x2a01,0x0011,0x000C,0x0000,0x001f,0x001f,0x001f,0x001f,0xffff,0xffff,
0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xb5b6,0x001f,0x001f,0x001f,
0x001f,0x001f,0x001f,0x001f,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
0xffff,0xffff,0xffff,0xffff,0xb5b6,0x001f,0xffff,0xb5b6,0x001f,0x001f,
0xffff,0xffff,0xdc2b,0xdc2b,0xdc2b,0xdc2b,0xdc2b,0xdc2b,0xdc2b,0xffff,
0xffff,0xffff,0xffff,0xffff,0xb5b6,0x001f,0x001f,0xffff,0xdc2b,0xfced,
0xfced,0xfced,0xfced,0xfced,0xfced,0xfced,0xdc2b,0xffff,0xffff,0xffff,
0xffff,0xb5b6,0x001f,0x001f,0xffff,0xfced,0x0000,0xfced,0xfced,0xfced,
0xfced,0x0000,0xfced,0xfced,0xffff,0xffff,0xffff,0xffff,0xb5b6,0x001f,
0xffff,0xffff,0xfced,0x0000,0xfced,0xfbad,0xfbad,0xfced,0x0000,0xfced,
0xfced,0xffff,0xffff,0xffff,0xffff,0xb5b6,0xffff,0x001f,0xffff,0xfced,
0xfced,0xfced,0xfced,0xfced,0xfced,0xfced,0xfced,0xfced,0xffff,0xffff,
0xffff,0xffff,0xb5b6,0x001f,0x001f,0xffff,0xffff,0xffff,0xffff,0xffff,
0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xb5b6,
0x001f,0x001f,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xb5b6,0x001f,0x001f,0x001f,
0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,
0xb5b6,0x001f,0xffff,0xb5b6,0x001f,0x001f,0x001f,0x001f,0xb5b6,0x001f,
0x001f,0x001f,0x001f,0x001f,0xb5b6,0x001f,0x001f,0x001f,0x001f,0x001f,
0x001f,0x001f,0x001f,0x001f,0x001f,0xb5b6,0x001f,0x001f,0x001f,0x001f,
0x001f,0xb5b6,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f
};
static unsigned short JillG_shadow_sprite[] = {
0x2a01,0x0011,0x000C,0x0000,0x001f,0x001f,0x001f,0x001f,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x001f,0x001f,0x001f,
0x001f,0x001f,0x001f,0x001f,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x001f,0x0000,0x0000,0x001f,0x001f,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x001f,0x001f,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x001f,0x001f,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x001f,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x001f,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x001f,0x001f,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x001f,0x001f,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x001f,0x001f,0x001f,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x001f,0x0000,0x0000,0x001f,0x001f,0x001f,0x001f,0x0000,0x001f,
0x001f,0x001f,0x001f,0x001f,0x0000,0x001f,0x001f,0x001f,0x001f,0x001f,
0x001f,0x001f,0x001f,0x001f,0x001f,0x0000,0x001f,0x001f,0x001f,0x001f,
0x001f,0x0000,0x001f,0x001f,0x001f,0x001f,0x001f,0x001f
};
static unsigned short Fire_sprite[] = {
0x2a01,0x0007,0x0007,0x0000,0x001f,0x001f,0xfb40,0xfb40,0xfb40,0x001f,
0x001f,0x001f,0xfb40,0xfb40,0xfb40,0xfec0,0xfb40,0x001f,0xfb40,0xfb40,
0xfb40,0xfb40,0xfb40,0xfec0,0xfb40,0xfb40,0xfb40,0xfb40,0xfb40,0xfec0,
0xfb40,0xfb40,0xfb40,0xfec0,0xfb40,0xfec0,0xfb40,0xfec0,0xfb40,0x001f,
0xfb40,0xfec0,0xfb40,0xfec0,0xfb40,0x001f,0x001f,0x001f,0xfb40,0xfb40,
0xfb40,0x001f,0x001f
};
static unsigned short Fire_shadow_sprite[] = {
0x2a01,0x0007,0x0007,0x0000,0x001f,0x001f,0x0000,0x0000,0x0000,0x001f,
0x001f,0x001f,0x0000,0x0000,0x0000,0x0000,0x0000,0x001f,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x001f,
0x0000,0x0000,0x0000,0x0000,0x0000,0x001f,0x001f,0x001f,0x0000,0x0000,
0x0000,0x001f,0x001f
};
static unsigned short Green_sprite[] = {
0x2a01,0x0007,0x0007,0x0000,0x001f,0x001f,0x4fe0,0x4fe0,0x4fe0,0x001f,
0x001f,0x001f,0x4fe0,0x4fe0,0x4fe0,0xb7e0,0x4fe0,0x001f,0x4fe0,0x4fe0,
0x4fe0,0x4fe0,0x4fe0,0xb7e0,0x4fe0,0x4fe0,0x4fe0,0x4fe0,0x4fe0,0xb7e0,
0x4fe0,0x4fe0,0x4fe0,0xb7e0,0x4fe0,0xb7e0,0x4fe0,0xb7e0,0x4fe0,0x001f,
0x4fe0,0xb7e0,0x4fe0,0xb7e0,0x4fe0,0x001f,0x001f,0x001f,0x4fe0,0x4fe0,
0x4fe0,0x001f,0x001f
};
struct bullet {
int x;
int y;
int vx;
int vy;
};
struct green {
int x;
int y;
};
void initialiserFichier(void) {
FILE* fp = NULL;
fp = fopen("JetpackImpossible","bw+");
if (fp != NULL) {
fputc('0', fp);
fclose(fp);
}else{
show_msgbox("Erreur","Erreur de fichier");
}
}
void setHighscore(const unsigned int score) {
FILE* fp = NULL;
fp = fopen("JetpackImpossible.dat","bw+");
if (fp != NULL) {
fprintf(fp, "%d", score);
fclose(fp);
}else{
show_msgbox("Erreur","Erreur de fichier");
}
}
unsigned int getHighscore(void) {
char txt[5];
unsigned int score;
FILE* fp = NULL;
fp = fopen("JetpackImpossible.dat","br");
if (fp != NULL) {
fgets(txt, 5, fp);
sscanf(txt, "%u", &score);
fclose(fp);
return score;
}else{
show_msgbox("Erreur","Erreur de fichier");
return 1;
}
}
void DrawImage(int x,int y,SDL_Surface* img,SDL_Surface* scr) {
SDL_Rect position;
position.x=x;
position.y=y;
SDL_BlitSurface(img,NULL,scr,&position);
}
int main(int argc,char *argv[]) {
FILE* fp = NULL;
fp = fopen("JetpackImpossible.dat","r");
if (fp == NULL) {
initialiserFichier();
}else{
fclose(fp);
}
//int main(void){
nSDL_EnableRelativePaths(argv); //on a besoin de ça si on met des bmps à charger dans le dossier
/* --- Initialisation de la SDL --- */
SDL_Surface* screen;
SDL_Init(SDL_INIT_VIDEO);
screen=SDL_SetVideoMode(320,240,has_colors?16:8,SDL_SWSURFACE);
SDL_FillRect(screen,NULL,0);
SDL_Flip(screen);
SDL_Surface* Jill;
SDL_Surface* Jill_shadow;
SDL_Surface* JillD=SDL_DisplayFormat(nSDL_LoadImage(JillD_sprite));
SDL_Surface* JillG=SDL_DisplayFormat(nSDL_LoadImage(JillG_sprite));
SDL_Surface* JillD_shadow=SDL_DisplayFormat(nSDL_LoadImage(JillD_shadow_sprite));
SDL_Surface* JillG_shadow=SDL_DisplayFormat(nSDL_LoadImage(JillG_shadow_sprite));
SDL_Surface* Fire=SDL_DisplayFormat(nSDL_LoadImage(Fire_sprite));
SDL_Surface* Fire_shadow=SDL_DisplayFormat(nSDL_LoadImage(Fire_shadow_sprite));
SDL_Surface* Green=SDL_DisplayFormat(nSDL_LoadImage(Green_sprite));
SDL_Surface* Green_shadow=SDL_DisplayFormat(nSDL_LoadImage(Fire_shadow_sprite)); //a la même ombre qu'un Fire
//Jill=SDL_LoadBMP("Jill.bmp.tns");
SDL_SetColorKey(JillD,SDL_SRCCOLORKEY,SDL_MapRGB(JillD->format,0,0,255));
SDL_SetColorKey(JillG,SDL_SRCCOLORKEY,SDL_MapRGB(JillG->format,0,0,255));
SDL_SetColorKey(JillD_shadow,SDL_SRCCOLORKEY,SDL_MapRGB(JillD_shadow->format,0,0,255));
SDL_SetColorKey(JillG_shadow,SDL_SRCCOLORKEY,SDL_MapRGB(JillG_shadow->format,0,0,255));
SDL_SetColorKey(Fire_shadow,SDL_SRCCOLORKEY,SDL_MapRGB(Fire_shadow->format,0,0,255));
SDL_SetColorKey(Fire,SDL_SRCCOLORKEY,SDL_MapRGB(Fire->format,0,0,255));
SDL_SetColorKey(Green_shadow,SDL_SRCCOLORKEY,SDL_MapRGB(Green_shadow->format,0,0,255));
SDL_SetColorKey(Green,SDL_SRCCOLORKEY,SDL_MapRGB(Green->format,0,0,255));
nSDL_Font* scoreFont_mini = nSDL_LoadCustomFont(fontChars_mini,128,128,128);
nSDL_Font* scoreFont_mini_shadow = nSDL_LoadCustomFont(fontChars_mini,0,0,0);
char score_txt[5]={"0"};
Jill=JillD;
Jill_shadow=JillD_shadow;
struct bullet* bullets=malloc(13*sizeof(struct bullet));
struct green* greens=malloc(3*sizeof(struct green));
int i; //utilisé dans les boucles for
int keep_playing=1;
while (keep_playing) {
SDL_FillRect(screen,NULL,0);
for (i=0;i<13;i++) {
bullets[i].x=(rand()%320)*512;
bullets[i].y=(rand()%240)*512;
int r=rand();
bullets[i].vx=cos(r)*256.0;
bullets[i].vy=sin(r)*256.0;
}
for (i=0;i<3;i++) {
greens[i].x=rand()%320;
greens[i].y=rand()%240;
}
int alive=1;
int pause=1;
int score=0;
int x=SCREEN_WIDTH/2<<shift_x;
int y=SCREEN_HEIGHT/2<<shift_y;
int vx=0;
int vy=0;
while (K_7||K_9);
//on attend que l'utilisateur lâche les touches avant de commencer
//sinon il risque de décoller sans le vouloir dans la nouvelle partie
//(surtout qi ce n'est pa la première partie)
while (keep_playing&&alive) {
sprintf(score_txt,"%d",score);
for (i=0;i<13;i++) {
DrawImage(bullets[i].x/512,bullets[i].y/512,Fire_shadow,screen);
int xt=bullets[i].x+bullets[i].vx;
int yt=bullets[i].y+bullets[i].vy;
if (xt<0) {xt=320*512;}
if (xt>320*512) {xt=0;}
if (yt<0) {yt=240*512;}
if (yt>240*512) {yt=0;}
bullets[i].x=xt;
bullets[i].y=yt;
DrawImage(bullets[i].x/512,bullets[i].y/512,Fire,screen);
if ((abs((x>>shift_x)+8-xt/512-3)<11) && (abs((y>>shift_y)+6-yt/512-3)<9) && (score>0)) {
alive=0;
}
}
for (i=0;i<3;i++) {
if ((abs((x>>shift_x)+8-greens[i].x-3)<11) && (abs((y>>shift_y)+6-greens[i].y-3)<9)) {
DrawImage(greens[i].x,greens[i].y,Green_shadow,screen);
score++;
greens[i].x=rand()%320;
greens[i].y=rand()%240;
}
DrawImage(greens[i].x,greens[i].y,Green,screen);
}
if (K_ENTER) {score++;}
if (K_7 || K_9) {
//accélération vers le haut
vy-=4;
if (vy<-vy_limit) {vy=-vy_limit;}
if (K_7) {
//accélération vers la gauche
Jill=JillG;
Jill_shadow=JillG_shadow;
vx=vx-4;
if (vx<-vx_limit) {vx=-vx_limit;}
}
if (K_9) {
//accélération vers la droite
Jill=JillD;
Jill_shadow=JillD_shadow;
vx=vx+4;
if (vx>vx_limit) {vx=vx_limit;}
}
}else{
//gravité et frottements
if (vy<vy_limit) {vy+=3;};
vx=(vx<0)-(vx>0)+vx;
}
y+=vy;
x+=vx;
if (x>>shift_x<(-8)) {x=(320-8)<<shift_x;}
if (x>>shift_x>320-8) {x=-8<<shift_x;}
if (y>>shift_y<(-8)) {y=(240-8)<<shift_y;}
if (y>>shift_y>240-8) {y=-8<<shift_y;}
DrawImage(x>>shift_x,y>>shift_y,Jill,screen);
nSDL_DrawStringCF(screen,scoreFont_mini,SCREEN_WIDTH/2-nSDL_GetStringWidth(scoreFont_mini,score_txt)/2,50,score_txt);
SDL_Flip(screen);
if (K_TAB) {pause=1;}
if (pause) {
while (!(K_7||K_9||K_ESC));
pause=0;
}
if (K_ESC) {
keep_playing=0;
}
nSDL_DrawStringCF(screen,scoreFont_mini_shadow,SCREEN_WIDTH/2-nSDL_GetStringWidth(scoreFont_mini_shadow,score_txt)/2,50,score_txt);
DrawImage(x>>shift_x,y>>shift_y,Jill_shadow,screen);
SDL_Delay(5);
//Ne sert qu'à ralentir l'émulateur
//A enlever avant de compiler pour calculette
}
if (getHighscore()<score) {
//afficher "nouveau highscore"
setHighscore(score);
}
}
free(greens);
free(bullets);
SDL_FreeSurface(JillD);
SDL_FreeSurface(JillG);
SDL_FreeSurface(JillD_shadow);
SDL_FreeSurface(JillG_shadow);
SDL_FreeSurface(Fire);
SDL_FreeSurface(Fire_shadow);
SDL_FreeSurface(Green);
SDL_FreeSurface(Green_shadow);
nSDL_FreeFont(scoreFont_mini);
nSDL_FreeFont(scoreFont_mini_shadow);
SDL_Quit();
return 0;
}
Je mets déjà des SDL_DisplayFormat (pas dans l'archive sur TI Planet mais dans le code posté ci-dessus), et je n'ai pas vu de différences avec le lag.
Pour le sin et le cos, pas besoin de LUT, ils sont juste dans l'initialisation (qui n'est pas time critical).
matref wrote:Va ... quoi ?
C'est à toi de savoir ce que tu dois libérer ou pas. Règle universelle : tous les nSDL_LoadImage() doivent être libérés avec SDL_FreeSurface, tous les malloc() avec free().
Ce que je fais en général, c'est mettre un gros fatty commentaire avec // TO FREE ou // TO SDL_FREESURFACE à côté du truc en question.
C'est ce que je fais pour l'instant mais justement, je n'ai pas un moyen de vérifier que je n'en ai pas oublié ?
![]() Pokemon Topaze (Axe) discussion and download links here | (19:29:36) noelnadal: plus sérieusement, j'ai très peu de problèmes (22:45:44) Clifward: J'aime rire du malheur des autres ![]() (2017.11.18 - 17:07:12) Fireworks: Hayleia !!!!! (2017.11.18 - 17:07:19) TI-Bot: Fireworks has been logged out (Kicked). (2017.11.18 - 17:07:22) TI-Bot: Ban of user Fireworks revoked. (2017.11.18 - 17:07:25) TI-Bot: Fireworks logs into the Chat. (2017.11.18 - 17:07:28) Fireworks: <3 (2017.11.18 - 17:07:31) Fireworks: 208 |
-
HayleiaGénéreux
Niveau 17: GM (Grand Maître des calculatrices)- Posts: 2509
- Images: 2
- Joined: 30 Aug 2011, 08:22
- Gender:
- Calculator(s):→ MyCalcs profile
- Class: Templar
Re: Jetpack Impossible
Autant pour moi, j'avais pas vu les deux boucles. Par contre SDL_DisplayFormat ne libère pas l'ancienne surface (regarde en bas dans la doc), tu va avoir des fuites comme ça.
-
hoffa
Niveau 3: MH (Membre Habitué)- Posts: 4
- Joined: 29 May 2011, 00:00
- Gender:
- Calculator(s):→ MyCalcs profile
Re: Jetpack Impossible
Ok, j'ai réglé ça avec une variable temporaire, merci 
Sinon, j'ai mis à jour l'archive (avec le nouveau code source donc (plus récent que celui posté plus haut)) avec un écran titre et la sauvegarde du highscore. J'ai aussi changé quelques constantes du "moteur physique".


Sinon, j'ai mis à jour l'archive (avec le nouveau code source donc (plus récent que celui posté plus haut)) avec un écran titre et la sauvegarde du highscore. J'ai aussi changé quelques constantes du "moteur physique".
![]() Pokemon Topaze (Axe) discussion and download links here | (19:29:36) noelnadal: plus sérieusement, j'ai très peu de problèmes (22:45:44) Clifward: J'aime rire du malheur des autres ![]() (2017.11.18 - 17:07:12) Fireworks: Hayleia !!!!! (2017.11.18 - 17:07:19) TI-Bot: Fireworks has been logged out (Kicked). (2017.11.18 - 17:07:22) TI-Bot: Ban of user Fireworks revoked. (2017.11.18 - 17:07:25) TI-Bot: Fireworks logs into the Chat. (2017.11.18 - 17:07:28) Fireworks: <3 (2017.11.18 - 17:07:31) Fireworks: 208 |
-
HayleiaGénéreux
Niveau 17: GM (Grand Maître des calculatrices)- Posts: 2509
- Images: 2
- Joined: 30 Aug 2011, 08:22
- Gender:
- Calculator(s):→ MyCalcs profile
- Class: Templar
Re: Jetpack Impossible
Oui voilà, au pire regarde mon code car j'ai fait moi aussi des DisplayFormat sur toutes mes surfaces... (n'oublies pas de faire DisplayFormatAlpha sur les surfaces qui ont une couche alpha).
Aussi, je n'ai pas été revoir ton code, mais n'oublies pas de libérer les SDL_Font avec un SDL_FreeFont !
En plus, ce sont vraiment des tableaux énormes...
Sinon, de rien pour système de Highscore
Fais gaffe par contre, tu as oublié le .dat pour le initialiserFichier
Aussi, je n'ai pas été revoir ton code, mais n'oublies pas de libérer les SDL_Font avec un SDL_FreeFont !

En plus, ce sont vraiment des tableaux énormes...

Sinon, de rien pour système de Highscore

Fais gaffe par contre, tu as oublié le .dat pour le initialiserFichier

Bonjour
-
pierrotdu18Premium
Niveau 15: CC (Chevalier des Calculatrices)- Posts: 975
- Joined: 07 Nov 2013, 20:18
- Location: Paris V
- Gender:
- Calculator(s):→ MyCalcs profile
- Class: MP* Lycée Henri IV
Return to Native: Ndless, Linux, ...
Who is online
Users browsing this forum: ClaudeBot [spider] and 5 guests