Programming on the Nintendo DS - issue with collisions - nintendo-ds

Sorry if this question has already been asked, but I have not managed to find any advice on the internet for my issue. I am currently trying to program a little game on the Nintendo DS, in which the player has to move a sprite (currently a square) until it reaches the exit. For this, I use a sprite I have included using a grit file, and also a background enabled in tiled mode. However, I am having a problem when it comes to checking if the sprite is going to collide with a wall. Here is the code I have both for the background configuration (where I declare the tiles and the map) and also for the sprite movements (I didn't add the condition for all cases yet, as it didn't work well) :
void configureMaze_Sub() {
int row, col;
for (row = 0; row < 24; row ++) {
for (col = 0; col < 32; col ++) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 1;
if (col == 15 && (row != 12 && row !=4 && row != 19)) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
}
if ((row == 1 || row == 22) && (col > 2 && col < 29)) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
}
if ((col == 3 || col == 28) && (row > 1 && row < 22 && row != 12)) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
}
if ((row == 3 || row == 20) && (col > 4 && col < 27)) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
}
if ((col == 5 || col == 26) && (row != 9 && row != 15 && row > 3 && row < 20)) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
}
if (row == 8 && (col > 5 && col < 15)) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
}
if (row == 16 && (col > 15 && col < 26)) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
}
if ((row == 12) && (col > 5 && col < 26)) {
BG_MAP_RAM_SUB(3)[row * 32 + col] = 0;
}
}
}
}
void gameplayMaze() {
int x = 103, y = 41, keys;
int maze_success = 0;
while (maze_success == 0) {
scanKeys();
keys = keysHeld();
int xmod = x / 8;
int ymod = x / 8;
if ((keys & KEY_RIGHT) && BG_MAP_RAM_SUB(3)[xmod + 32 * ymod] == 1) {
x++;
printf("%d \n", x);
}
if ((keys & KEY_LEFT) && BG_MAP_RAM_SUB(3)[xmod + 32 * ymod] == 1) {
x--;
}
if (keys & KEY_UP) {
y--;
}
if (keys & KEY_DOWN) {
y++;
}
oamSet(&oamSub,
0,
x, y,
0,
0,
SpriteSize_8x8,
SpriteColorFormat_256Color,
gfxSub,
-1,
false,
false,
false, false,
false
);
swiWaitForVBlank();
oamUpdate(&oamSub);
}
The main problem I have is to try to change from the coordinates of the tiles (which are 8x8) to the ones of the map, as for the coordinates of the sprite (256x192). If any of you have any hint to help me, I would be very grateful! I am still new to programming on the NDS, so I am still struggling to get the hang of it.

Related

How to format a number into thousands, millions and billions with dart/flutter?

How to get a number converted into something like this: 12K, 1.5M, 4.2B from a normal number like: 134900.
This is a minimalist function, of course you'll have to add validation code to verify if the number is valid before executing the function. Otherwise Enjoy ...
void main() {
double num = 1250;
var myNumber = k_m_b_generator(num);
print(myNumber);
}
String k_m_b_generator(num) {
if (num > 999 && num < 99999) {
return "${(num / 1000).toStringAsFixed(1)} K";
} else if (num > 99999 && num < 999999) {
return "${(num / 1000).toStringAsFixed(0)} K";
} else if (num > 999999 && num < 999999999) {
return "${(num / 1000000).toStringAsFixed(1)} M";
} else if (num > 999999999) {
return "${(num / 1000000000).toStringAsFixed(1)} B";
} else {
return num.toString();
}
}
You can use flutter's NumberFormat class with the compact function.
formatNumber(dynamic myNumber) {
// Convert number into a string if it was not a string previously
String stringNumber = myNumber.toString();
// Convert number into double to be formatted.
// Default to zero if unable to do so
double doubleNumber = double.tryParse(stringNumber) ?? 0;
// Set number format to use
NumberFormat numberFormat = new NumberFormat.compact();
return numberFormat.format(doubleNumber);
}
The answer is not entirely correct. If you test it, you will see what i meant. Base on the answer above, I created this solution:
String numberFormat(int n) {
String num = n.toString();
int len = num.length;
if (n >= 1000 && n < 1000000) {
return num.substring(0, len - 3) + '.' + num.substring(len - 3, 1 + (len - 3)) + 'k';
} else if (n >= 1000000 && n < 1000000000) {
return num.substring(0, len - 6) + '.' + num.substring(len - 6, 1 + (len - 6)) + 'm';
} else if (n > 1000000000) {
return num.substring(0, len - 9) + '.' + num.substring(len - 9, 1 + (len - 9)) + 'b';
} else {
return num.toString();
}
}

How to print in the console that figure?

I want to print that in the console:
*
**
***
**
*
so, my code is:
Scanner input = new Scanner(System.in);
int n = input.nextInt();
char c = '*';
if (1 < n && n < 20) {
for (int row = 1; row <= n; row++) {
for (int col = 1; col <= row; col++) {
System.out.print(c);
}
System.out.println();
}
any proposals how to finish?
You want to print "* **". Write this:
System.out.print("* **");
If my answer is not that what you excpected, than give us more information. What is your actual problem. See StackOverflowFAQ
If n is your "*" length,below code:
if (1 < n && n < 20) {
for (int row = 1; row <= n; row++) {
for (int col = 1; col <= row; col++) {
System.out.print(c);
}
System.out.println();
}
for (int row =1; row <= n; row++) {
for (int col = n-row; col >0 ; col--) {
System.out.print(c);
}
System.out.println();
}
}

Apparent Multiple Failures Using Google Chrome Versions 30 to 33

I've been developing the Image Slider Theme(dated 02/20/2015 - Jssor Slider 18.0 Development Kit)(Jssor.Slider.FullPack\demos-no-jquery\image-slider-2.source.html with jssor.slider.min.js). I have not modified the javascript code. I'm finding failures of various script implementations in Chrome versions 30 through 33 with this Image Slider and several other in the Development Kit. Previous January Development Kit also shows errors. No problems with any other browsers or versions of those browsers that are not already indicated and/or addressed.
I have found that tweaking the function SetPosition "elseif" from:
" else if ($Jssor$.$IsBrowserChrome() && $Jssor$.$BrowserVersion() >= 30 && $Jssor$.$BrowserVersion() < 34)"
to:
" else if ($Jssor$.$IsBrowserChrome() && $Jssor$.$BrowserVersion() >= 32 && $Jssor$.$BrowserVersion() < 34)"
function SetPosition(elmt, position) {
var orientation = _DragOrientation > 0 ? _DragOrientation : _PlayOrientation;
var x = _StepLengthX * position * (orientation & 1);
var y = _StepLengthY * position * ((orientation >> 1) & 1);
if ($Jssor$.$IsBrowserChrome() && $Jssor$.$BrowserVersion() < 38) {
x = x.toFixed(3);
y = y.toFixed(3);
}
else {
x = Math.round(x);
y = Math.round(y);
}
if ($Jssor$.$IsBrowserIE() && $Jssor$.$BrowserVersion() >= 10 && $Jssor$.$BrowserVersion() < 11) {
elmt.style.msTransform = "translate(" + x + "px, " + y + "px)";
}
else if ($Jssor$.$IsBrowserChrome() && $Jssor$.$BrowserVersion() >= 30 && $Jssor$.$BrowserVersion() < 34) {
elmt.style.WebkitTransition = "transform 0s";
elmt.style.WebkitTransform = "translate3d(" + x + "px, " + y + "px, 0px) perspective(2000px)";
}
else {
$Jssor$.$CssLeft(elmt, x);
$Jssor$.$CssTop(elmt, y);
}
}
I'm using this as a quick-fix until I can delve into it further. Has anyone noticed anything along this line?
The following code is to improve performance of sliding left<->right for chrome (version 30 to 33).
else if ($Jssor$.$IsBrowserChrome() && $Jssor$.$BrowserVersion() >= 30 && $Jssor$.$BrowserVersion() < 34) {
elmt.style.WebkitTransition = "transform 0s";
elmt.style.WebkitTransform = "translate3d(" + x + "px, " + y + "px, 0px) perspective(2000px)";
}
After about a year, chrome went to version 40. Now it's time to remove it.
Thanks.

Why .hash section in my ELF file is not valid?

In a .hash section, for some x, if chain[x] != SHN_UNDEF,
it should hold hash(name(bucket[x])) === hash(name(bucket[chain[x]])) % nbucket
But why it's not the case for my shared object file?
For example, name(bucket[224]) == "_ZN9VADEnergyD0Ev" whose (ELF hash % nbucket) is 224,
name(bucket[8]) == "speex_bits_write_whole_bytes" whose (ELF hash % nbucket) is 8,
but chain[224] == 8.
(the file is avalible here)
Or my code for reading elf is wrong?
nbucket = ((int *)hash)[0];
nchain = ((int *)hash)[1];
memcpy(bucket, hash + 8, nbucket * 4);
memcpy(succ, hash + nbucket * 4 + 8, nchain * 4);
for (i = 0; i < nbucket; i++) {
printf("%d %d\n", bucket[i], succ[i]);
if (bucket[i] && succ[i])
pred[succ[i]] = i;
}
printf("%d %d\n", nbucket, nchain);
#define sym_name(x, symtbl, strtbl) (strtbl + symtbl[x].st_name)
for (i = 0; i < nbucket; i++) {
if (pred[i] == 0) {
printf("=======\n");
for (j = i; j; j = succ[j]) {
char *sname = sym_name(bucket[j], dynsym, dynstr);
printf("%d,succ=%d ", j, succ[j]);
printf("%d:%s\n", _dl_elf_hash(sname) % nbucket, sname);
}
}
}
It's my fault. It should be
hash(name(bucket[x])) === hash(name(chain[bucket[x]])) % nbucket
and
nbucket = ((int *)hash)[0];
nchain = ((int *)hash)[1];
memcpy(bucket, hash + 8, nbucket * 4);
memcpy(succ, hash + nbucket * 4 + 8, nchain * 4);
for (i = 0; i < nbucket; i++) {
printf("%d %d\n", bucket[i], succ[i]);
if (bucket[i] && succ[i])
pred[succ[i]] = i;
}
printf("%d %d\n", nbucket, nchain);
#define sym_name(x, symtbl, strtbl) (strtbl + symtbl[x].st_name)
for (i = 0; i < nbucket; i++) {
printf("=======\n");
for (j = bucket[i]; j; j = succ[j]) {
char *sname = sym_name(j, dynsym, dynstr);
printf("%d,succ=%d ", j, succ[j]);
printf("%d:%s\n", _dl_elf_hash(sname) % nbucket, sname);
}
}

Simple cryptographic puzzle [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm looking for a way to solve this crypt arithmetic problem of:
ROBERT + GERALD = DONALD
and potentially others as well, where each letter represents a digit.
How would you go about solving this by hand and how does that relate to solving it programmatically?
Thank you in advance
You can actually work this out as a sum:
robert
+ gerald
------
= donald
and use basic mathematical knowledge.
For example, there's no carry possible in the right column (6) and we have T + D = D. That means T must be zero.
Similarly, for column 5, there's no carry from column 6 and R + L = L means R is zero as well, and no carry to column 4.
Same with column 4, E + A = A so E is zero.
So we now have:
0ob000
+ g00ald
------
= donald
From there, we can infer from columns 3 and 1 that b==n and g==d and they (along with o/a/l/d) can be any value since every digit is being added to zero so there is no chance of carry anywhere. So let's just make them all one:
011000
+ 100111
------
= 111111
In fact, you could make them all zero and end up with 000000 + 000000 = 000000.
But that's hardly programming related, so let's make it so:
#include <stdio.h>
int main (void) {
int robert, gerald, donald;
for (int r = 0; r < 10; r++) {
for (int o = 0; o < 10; o++) {
for (int b = 0; b < 10; b++) {
for (int e = 0; e < 10; e++) {
for (int t = 0; t < 10; t++) {
for (int g = 0; g < 10; g++) {
for (int a = 0; a < 10; a++) {
for (int l = 0; l < 10; l++) {
for (int d = 0; d < 10; d++) {
for (int n = 0; n < 10; n++) {
robert = r * 100000 + o * 10000 + b * 1000 + e * 100 + r * 10 + t;
gerald = g * 100000 + e * 10000 + r * 1000 + a * 100 + l * 10 + d;
donald = d * 100000 + o * 10000 + n * 1000 + a * 100 + l * 10 + d;
if (robert + gerald == donald) {
printf (" %06d\n", robert);
printf ("+ %06d\n", gerald);
printf (" ------\n");
printf ("= %06d\n", donald);
printf ("........\n");
}
}
}
}
}
}
}
}
}
}
}
return 0;
}
That will give you a whole host of solutions.
And, before you complain that you cannot have repeated digits, there is no solution if that's the case, since mathematically both T and R must be zero, as shown in the original reasoning above. And you can prove this empirically with:
#include <stdio.h>
int main (void) {
int robert, gerald, donald;
for (int r = 0; r < 10; r++) {
for (int o = 0; o < 10; o++) {
if (o==r) continue;
for (int b = 0; b < 10; b++) {
if ((b==r) || (b==o)) continue;
for (int e = 0; e < 10; e++) {
if ((e==r) || (e==o) || (e==b)) continue;
for (int t = 0; t < 10; t++) {
if ((t==r) || (t==o) || (t==b) || (t==e)) continue;
for (int g = 0; g < 10; g++) {
if ((g==r) || (g==o) || (g==b) || (g==e) || (g==t)) continue;
for (int a = 0; a < 10; a++) {
if ((a==r) || (a==o) || (a==b) || (a==e) || (a==t) || (a==g)) continue;
for (int l = 0; l < 10; l++) {
if ((l==r) || (l==o) || (l==b) || (l==e) || (l==t) || (l==g) || (l==a)) continue;
for (int d = 0; d < 10; d++) {
if ((d==r) || (d==o) || (d==b) || (d==e) || (d==t) || (d==g) || (d==a) || (d==l)) continue;
for (int n = 0; n < 10; n++) {
if ((n==r) || (n==o) || (n==b) || (n==e) || (n==t) || (n==g) || (n==a) || (n==l) || (n==d)) continue;
robert = r * 100000 + o * 10000 + b * 1000 + e * 100 + r * 10 + t;
gerald = g * 100000 + e * 10000 + r * 1000 + a * 100 + l * 10 + d;
donald = d * 100000 + o * 10000 + n * 1000 + a * 100 + l * 10 + d;
if (robert + gerald == donald) {
printf (" %06d\n", robert);
printf ("+ %06d\n", gerald);
printf (" ------\n");
printf ("= %06d\n", donald);
printf ("........\n");
}
}
}
}
}
}
}
}
}
}
}
return 0;
}
which outputs no solutions.
Now DONALD + GERALD = ROBERT, that's a different matter but you can solve that simply by modifying the code above slightly, making the if statement into:
if (donald + gerald == robert) {
printf (" %06d\n", donald);
printf ("+ %06d\n", gerald);
printf (" ------\n");
printf ("= %06d\n", robert);
printf ("........\n");
}
and you get the single solution:
526485
+ 197485
------
= 723970