Rogue-like ascii based on Arduboy


#21

@Pharap and all of person who posted, very thank you!

I got to learn a lot of precious opinions and information, and I really learned.

I see you have an array of items ( ii , i1 , i2 …).
I don’t know what the different arrays mean, but I understand what you are doing.
An Item struct would be useful for this.

I want to rewrite this program with struct — hero, item, monster, dungeon and so on.
And I will challenge GitHub!


#22

When I was examining about arduino, I came across a @Mr.Blinky 's article by Arduboy made with breadboard.I assembled it and tried playing some games.And, as I opened the sample “Hello world.ino” and moved the characters “Hello world”, I wanted to make something game.The game I came up with was then “Rogue”.

Although “Rogue” is a small program, I thought it was impossible to fit all the programs to 32 kbytes.The binary of “Rogue” for windowsOS in my hand is also 152 kbytes! At first I thought about omitting rings and wands, but I felt like trying to do as much as I could.

My “Hello world” program grew bigger and bigger.Both the variables and the code became more and more messed up.Sorry to everyone who downloaded the source program.

I did not feel like completing it and I did not intend to complete it, so the file name was still “HelloWorldx.ino”.However, I think that it was good.I was able to meet the new world (everyone in this community).

There are many different points from the original “Rogue”.
-Poor message
-Items with different effects
-Invocation condition of special attack
-etc…etc…etc…
I want to play a complete original “Rogue clone” on Arduboy. Furthermore, I want to bring it closer to the original “Rogue”.I would be happy if you play and give me opinions.


#23

It’s fine. Least you fit them in.

According to GunMan Tacco Truck (a popular iOS game), nothing is inedible.

You do? :crazy_face:
Would you mind sharing that bit?


Good luck on your next program!


#24

No, no!
I can not write windows app. It is “Rogue Clone II for Win32 Version 1.3.4” by HEPOPO.

I will make NetHack! :joy:


#25

Great!
Then I’ll just wait to test your great work then.


(Pharap) #26

If you explain what ii, i1, i2 … are,
I can show you how to use a struct instead.

At the moment I cannot use a struct,
because I don’t understand how ii, i1 etc are functioning.

There are special techniques and strategies for reducing the code size.

The first thing I did was to change how the strings are stored:

To understand strings.h, you need to understand arrays and pointers.

Before, you used 2D arrays.
Now I am using char arrays and arrays of const char * (pointers).
This uses less memory.

Hopefully these images will be understandable.
(The '0’s are actually '\0', the ASCII ‘null character’.)

2D array:


(Too many '0’s - wasted space.)

Array of pointers:


(No wasted space.)


The second thing I did ‘the FlashStringHelper trick’.
To understand that, you need to know about “function overloading”.


#27

This is a new release.
Now available on original Arduboy.

HelloWorld9red2.ino.hex.pdf (78.7 KB)

This version is:
[FIX] An unidentified scroll appears in the game.
[FIX] Wnen you read ? of anger, there are many kestrels.
[FIX] When you blind, you cannot read scroll.

@Pharap many thanks.
I take time to read English sentences.I also write English sentencestake time. I’m really sorry that the reply was delayed.


#28

To @Pharap , many many thanks.

I’m sorry to have trouble. It is absolutely necessary for the game loading and saving function.

They are:

ii ID item
7~4 bit kind of the item(1=gold, 2=food, … 9=amulet)
3~0 bit variation(0=food, 1=mold…)

i1 amount of the item
In most case 1, stackable items are amount.
Stackables are 2=food, 3=weapon(variation>=4), 5=potion, 6=scroll

i2 bonus 1
3=weapon: extra dex.
4=armor : extra AC
7=ring : extra bonus(= of dex and damage)
8=wand : number of charge

i3 bonus 2(only weapon)
3=weapon: extra damage

i4 bit flag
7 bit: stackable
6 bit: cursed
5 bit: known(for weapon, armor, ring and wand)
4 bit: wielded(for weapon, armor and ring)
3 bit: coated(for armor)
2 bit: opened(for ? of scare)
1 bit: known2(not available now)
0 bit: not use

Wow! It is a wizard magic for me! But I want to do my best and understand.


(Stephane C) #29

Thank you so much for this game. It really is really awesome. Finally someone released a rogue game like I like them.

Is it normal that even if I die when I start over I am still at the level I died at? And keep all the loot I have? Also is there an ending or it’s just random infinitely?


(Pharap) #30

怒りの”?”ですか?

Kestrel? “長元坊”?

私も。私は遅い、日本語が上手じゃないですから。

To explain in Japanese would take a long time.

大丈夫さ。

ビット七は左とビットゼロは右ですか?
ビット七は右とビットゼロは左ですか?

(I don’t know how to say “or” in Japanese… 又は? “左又は右”?)

The code could look like this:

enum class ItemType : uint8_t
{
	None = 0x00,
	Gold = 0x01,
	Food = 0x02,
	Weapon = 0x03,
	\\ ...
	Amulet = 0x09,
};

enum class ItemId : uint8_t
{
	Gold = 0x10,
	Food = 0x20,
	Mold = 0x21,
	Mace = 0x30,
	Axe = 0x31,
	Sword = 0x32,
	Bow = 0x33,
	Dart = 0x34,
	\\ ...
};

ItemType getType(ItemId itemId)
{
	return static_cast<ItemType>((static_cast<uint8_t>(itemId) >> 4) 0x0F);
}

enum class ItemAttributes : uint8_t
{
	None,
	Stackable = (1 << 0),
	Cursed = (1 << 1),
	Known =  (1 << 2),
	Wielded = (1 << 3),
	Coated = (1 << 4),
	Opened = (1 << 5),
	Known2 = (1 << 6),
	Reserved = (1 << 7),
};

struct Item
{
	ItemId item;
	uint8_t amount;
	uint8_t stat;
	uint8_t damage;
	ItemAttributes attributes;
};

Item inventory[10];

enum class: https://ja.cppreference.com/w/cpp/language/enum
static_cast: https://ja.cppreference.com/w/cpp/language/static_cast
0x00/0x31 etc: https://www.mathsisfun.com/binary-decimal-hexadecimal.html

はい!私は魔道士だ!ゼハハハハ!

(それは冗談です。 私は髑髏! 私は人間。)

I want to explain, but explaining in Japanese is difficult.
I do not know the correct words.
(E.g. ‘function’, ‘call a function’, ‘object’, ‘class’)

Maybe you will understand this code?:

const char text1[] PROGMEM = "hello world";

// In RAM
const char text2[] = "goodbye world";

void thing1()
{
	// 嘘. (Incorrect)
	// Calls Print::print(const char str[])
	// Tries to read RAM, not PROGMEM.
	aruboy.print(text1);
	
	// 正解. (Correct)
	// Calls Print::print(const char str[])
	// Reads RAM.
	aruboy.print(text2);
}

void thing2()
{
	// 正解. (Correct)
	// Calls Print::print(const __FlashStringHelper *)
	// Reads PROGMEM.
	aruboy.print(reinterpret_cast<const __FlashStringHelper *>(text1));
	
	// 嘘. (Incorrect)
	// Calls Print::print(const __FlashStringHelper *)
	// Tries to read PROGMEM, not RAM.
	aruboy.print(reinterpret_cast<const __FlashStringHelper *>(text2));
}

size_t Print::print(const __FlashStringHelper *ifsh):


(while(1) should be while(true).)

See pgm_read_byte? It reads from ‘progmem’.


#31

Many Thank you, @Vampirics !

I thought that no one has played this game. Looking at your message, I am very pleased to know that at least one person is playing this game. I’m really thankful to you.

I’d like to add save and load functions to this game. But I have not done it yet. I programmed to be able to continue the game until that function is attached. It is normal behavior.
Amulet is falling deeper than the 26th floor of this dungeon. When you pick up that amulet, the descending staircase changes to an upstairs stairway. If you return to the ground with that amulet you will be Winner.


#32

My teacher, @Pharap. I am sorry I made you my teacher without permission.
And, I am sorry for the incomprehensible explanation.

“? of anger” means “a scroll of anger”. This makes all monsters awake. But I
programmed this makes monsters that does not exist awake, too. So, many kestrels (ID=0 monster in this program) appears.

if(bitRead{i4[i],7)==1){ // stackable item
if(bitRead{i4[i],6)==1){ // item is cursed …and so on.

By the way, “or” is “Aruiwa” in Japanese. 「A あるいは(or) B」

I must understand how to manipulate arrays using pointers and how to use structures. And this program has to be rewritten in a way appropriate to the method. I learn the code that my teacher wrote carefully.

p.s.) I created a new account for GitHub yesterday.


#33

I was planning on downloading it, but my dad then drag me to Starbucks, so I ended up with other things to do.

I might as well try tomorrow, and see how’s my 18650 goes at powering my modified arduboy.


@Pharap

Matter of the fact, being the only person in the entire school to know these words was sure a sad thing.
A dozen others learn programming, but half of them only study algorithms while the other half don’t learn them in English.
So I ended up with no one to talk to.
Well my only friends do, because I helped them with their programming class.


(Pharap) #34

いいですよ。私は皆の”先生”。

いいですよ。

I am sorry for mixing formal and informal Japanese.
Formality is difficult. (格式は難いです。)

あ、なるほど。

あ、ケストラルはモンスター… なるほど。
(モンスターあるいは怪獣ですか?)

Ah. ビット七は左とビットゼロは右です。

7 6 5 4 3 2 1 0
Stackable Cursed Known Wielded Coated Opened Known2 (Reserved)
enum class ItemAttributes : uint8_t
{
	None,
	Reserved = (1 << 0),
	Known2 = (1 << 1),
	Opened = (1 << 2),
	Coated = (1 << 3),
	Wielded = (1 << 4),
	Known =  (1 << 5),
	Cursed = (1 << 6),
	Stackable = (1 << 7),
};

Although, I think the other way (ビット七は右とビットゼロは左) would be more efficient.

The ATmega32u4 (アーヂュボイのシーピーユー) does not have a “barrel shifter” (日本語).
This means bits are shifted one at a time.
I.e. x >> 7 in assembly (アセンブリ言語) is:

LSR r0
LSR r0
LSR r0
LSR r0
LSR r0
LSR r0
LSR r0

But x >> 1 in assembly (アセンブリ言語) is:

LSR r0

(r0 means 'register 0`, it could be a different number.)

So to be efficient, more common bitfields should have lower numbers.
(I.e. the most common field should be in bit 0.)

それは"理にかなう"ですか?
(ごめんなさい、verb conjugation is hard.)

ありがとうございます。

それは難い。

Some advice: think of RAM as a big array of bytes.
A pointer is an index into that array (RAM).
So, a pointer is like an index into RAM.

A pointer is actually an integer. (ポインターは整数です。)
Try this:

#include <Arduboy2.h>

Arduboy2 arduboy;

void setup()
{
	arduboy.begin();
}

void loop()
{
	if(!arduboy.nextFrame())
		return;
		
	arduboy.pollButtons();
		
	arduboy.clear();
	
	int8_t a = 5;
	int8_t * pointer = &a;
	
	// 整数を見せる
	arduboy.println(static_cast<uintptr>(pointer));
		
	arduboy.display();
}

Think of them as a group of variables.

それはいいです。アカはどれですか?

(”アカ”は”アカウント”ですね?)

If you need help using GitHub, I can explain that too.

This explains how to create a “repo”:
https://help.github.com/articles/create-a-repo/
(“repo” (リポ) = “repository” (リポジトリ ).)


The more I try to use Japanese, the more I realise there are certain common words I don’t know.

E.g.

  • “to help”/“to assist” - as in “to help with programming”, not “助けて, save me, I’m dying”
  • “difficult” - I found “難い” and “難しい”, but I don’t know which is correct
  • “to explain” - It seems there are lots of words for ‘explain’.
    • “説き明かす”?
    • “説き聞かせる”?
    • “説き示す”?
    • “言い含める”?

(Even if I understand those, I’m still bad at ‘conjugating verbs’. Tenses are difficult.)


That’s not necessarily bad, it depends what their goal is.

If they only care about getting employed by a local tech company then not understanding the English probably isn’t important.
If they want to contribute to computer science academically (i.e. through research and PHDs and things) then they’ll probably need to understand enough English to write a research paper in English.

Equally, if they only want to be employed as a programmer they don’t need to understand all algorithms in detail, they only need a basic understanding.
But if they want to do academic stuff, understanding algorithms is usually quite important.

Strictly speaking for making small video games neither are important, but they’d be useful for making larger video games.

Keep helping them. Helping people is a good thing to do.


#35

My teacher, @Pharap.

It seems like a small hawk, but I do not understand well either. in Rogue game, this monster is the weakest, but they can act twice as quickly.

I see. Great.

Thank you.

“難い” is “Katai”, it means almost “difficult”, but old-fashioned.
“難しい” is “Muzukashii”, we use it normally.
“Explain” is “説明する”, “Setsumeisuru” in Japanese. “解き明かす” etc… is not wrong, but it is not much used. I seem to be your Japanese teacher, are not you? I am sorry for making you great.

My GitHub account is “BlueMaxDX”.
I forgot the important report. My .hex size is:

Sketch uses 27982 bytes (97%) of program storage space. Maximum is 28672 bytes.

I felt that the game seems to be able to add load and save functions.


(Pharap) #36

A small falcon.
It seems that the kanji for ‘hawk’ is the same as for ‘falcon’ - 鷹.
(Hawks and falcons are unrelated species apparently.)

儂は昔風ですか? (冗談です。)

いいえ、私はおっさんじゃない。

ありがとうございます。
Dictionaries explain meaning, but not usage.

はい。
私はプログラミング先生。
あなたは日本語先生。
がんばりましょう。

I’m not “great” yet, but I’m improving.

Found it.

それは印象的。

How did the code become so small?

It’s possible.

You can save a struct with EEPROM.put and load with EEPROM.get.
E.g.

struct Player
{
	int16_t x;
	int16_t y;
	uint8_t healthPoints;
	uint8_t level;
};

// Any number bigger than 16
constexpr uint16_t SaveAddress = 256;
constexpr uint16_t PlayerSaveAddress = SaveAddress;

void savePlayer(const Player & player)
{
	EEPROM.put(PlayerSaveAddress, player);
}

void loadPlayer(Player & player)
{
	EEPROM.get(PlayerSaveAddress, player);
}

If this is too big, I know some other ways too.


Hrm, maybe I should use 僕 or 自分 instead of 私?
(I’m used to 俺, but I think that’s too impolite?)


#37

My teacher, @Pharap.

I figured out how unnecessarily written code I was writing. When putting together the codes that are similar in function, the size of the file got smaller and smaller. I do not reduce any effect that comes out during the game at all.

Thank you. I’ll try to do my best.

”私"-“watashi” is used by women. Then, men also use it in certain places.
“僕”-“boku” is used by men. I usually use “僕”.
“自分”-“jibun” gives a fair impression a little. It gives an impression like a police officer or a soldier.
”俺"-“ore” is a slightly rough impression. It is used among minded men.


(Pharap) #38

いいです。
Using functions for common code is important.
Lots of small functions is better than fewer large functions.
(◯ 大勢小さいファンクション。 ╳ 少し大型ファンクション。)

Could you upload the latest code to GitHub please?


私 is what my “15 minute Japanese” book uses.
(It doesn’t mention any other words for “I”.)

I use this because I’ve heard it’s more ‘formal’,
and because it was the word I learned first.

I’ve heard ‘boku’ is only used by younger boys?
(Or maybe that’s a stereotype?)

Hrm, I think I’ll use that for doing moderator things.

Yeah, in anime it’s used mainly by “tough guys”.
I like the way it sounds, but I don’t use it because I’ve heard it’s considered rude in most situations.

(I don’t know what “minded men” means. I’m guessing it’s a bad translation? Or an idiom? Or maybe “close friends” (仲間/友達)?)


If you’re wondering what I’ve read: this and this.


I have to get used to not using “I” anyway.
(It’s hard, because English uses ‘pronouns’ (“I”, “me”, “you” etc.) all the time.)


#39

To @Vampirics
Since it is a topic about my game, can I talk over here?
In the original “Rogue”, the status is always displayed on the screen. However, in my “rogue” the screen is too small to display all the time. If I add a status display function to the menu, two steps are needed to see it. But I want to know what it will be, so I will try to make that version.

To my teacher, @Pharap.

Of course!
However, my program is undergoing renovation and is becoming messed up. Please wait a little more.

Sorry. it is bad translation, maybe. I mean it is “close friends”.
The protagonist “Son Goku” of Japanese animation “Dragon Ball” is calling to himself as “おら”-“ora”. ”おら"-“ora” is a different way of saying “俺”-“ore”.

After now, I will fight against a messy program!


(Stephane C) #40

Maybe pressing a combination could work instead? Also I am not sure your game actually displays the floor we are on. Would be nice to know how far down we are.

I am sure you will find ways and do your best. Great job so far.