#sysinit
Explore tagged Tumblr posts
sololinuxes · 5 years ago
Text
Diferencias entre Systemd y SysVinit (SysV)
Tumblr media
Diferencias entre Systemd y SysVinit (SysV). Systemd es el sistema de inicio y administración del sistema, que han adoptado la mayoría de distribuciones Linux. Más moderno, más complejo, y quizás con un excesivo control sobre el sistema generó una gran polémica en su implantación. Excelentes distribuciones se negaron en rotundo a usarlo, como por ejemplo ALT Linux, Gentoo, Knoopix, PCLinux OS. En otras como Debian, los usuarios disconformes crearon un derivado, Devuan. Lo que está claro, es que le pese a quien le pese Systemd ganó la batalla sobre el administrador tradicional de init, SysVinit. Systemd es compatible con los scripts de inicio SysV y LSB, además funciona como reemplazo directo de sysvinit.  
Diferencias entre Systemd y SysVinit
Systemd es el primer proceso iniciado por el kernel y siempre tendrá el pid 1. Fedora 15 fue la primera distribución linux que adoptó systemd, poco a poco todas fueron en cascada (creo que la última grande fue CentOS 7). Esta herramienta en línea de comandos administra todos los demonios, también los servicios systemd que nos permiten iniciar, reiniciar, detener, habilitar, deshabilitar, recargar y muchos más. Además, es importante saber que Systemd no usa scripts bash para manejar el sistema como SysVinit, utiliza unos archivos llamados ".service" que se suponen más rápidos. También destacamos que systemd clasifica todos los demonios en cgroups.   Qué es SysVinit SysVinit, más conocido como SysV, es uno de los primeros sistemas de inicio para sistemas UNIX/Linux. El primer proceso que inicia el kernel es init, y se mantiene activo mientras la máquina siga en funcionamiento, es el proceso principal. La gran mayoría de distros Linux utilizaban SysV, y aunque se crearon otras alternativas como Service Managament, Upstart, etc, ninguna llegó a implantarse en masa. Hasta que llegó Systemd y fue adoptada por la gran mayoría de distros, debemos reconocer que el SysVinit actual es una herramienta en desuso.   Qué es Systemd Systemd es la herramienta init y administradora del sistema, que usan como estándar las distribuciones linux. Permite manejar todo el sistema systemd. Principales características de Systemd Systemd ofrece una paralelización muy potente. Hace uso de la activación de socket y D-Bus para iniciar los servicios. Soporta el inicio de los demonios bajo demanda. Controla los procesos que utilizan el cgroups de Linux. Permite crear instantáneas y posterior restauración del estado del sistema. Maneja los puntos de montaje y desmontaje automáticamente. Implanta una lógica de control del servicio basada en dependencias transaccionales.   Comandos de Systemd y SysVinit Vemos las diferencias de los comandos más utilizados por los dos sistemas, al servicio lo denominamos ejemplo.   Diferencia entre Targets y Runlevels Systemd usa el concepto Targets (objetivos), que tiene un propósito muy parecido al de los Runlevels (niveles de ejecución) de SysV, pero con una forma de operar diferente. En SysVinit se interpretan con números enteros, y en Systemd se especifica el propósito.   Otros comandos de Systemd Como ultimo apunte del articulo es evidente que systemd es el sistema más extendido, por lo tanto siempre es conveniente conocer algunos comandos extra, seguro que te serán útiles.   Canales de Telegram: Canal SoloLinux – Canal SoloWordpress Espero que este articulo te sea de utilidad, puedes ayudarnos a mantener el servidor con una donación (paypal), o también colaborar con el simple gesto de compartir nuestros artículos en tu sitio web, blog, foro o redes sociales.   Read the full article
0 notes
hackernewsrobot · 2 years ago
Text
FreeBSD spends 7% of its boot time running a bubblesort on its SYSINITs
https://twitter.com/cperciva/status/1659558311920914432 Comments
0 notes
pseudonourishment · 5 years ago
Text
#LinuxSucks
Yea. There. I said it. Yes. I did.
I meant it. Why? A few important things have happened in the years since 1991 when Linus Torvalds introduced the world to Linux. Yes, the world has changed and technology has evolved since but that's not what I'm talking about: The community has changed. Not for the better. Yea, we all know about Linus's rants on the mailing list as well as in public. They're no different than Steve Jobs or Elon Musk. Some say thats greatness in action but I doubt that. Others say that its the narcissism being reflected from the leadership. How about its something else?
Let's break this down even further:
First of all, systemd. EVERYTHING about systemd is wrong. Can anyone tell me what about systemd follows the #UnixPhilosophy? Anyone? The #UnixPhilosophy (in its most basic statement) is defined as:
This is the Unix philosophy: Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.(that last part still holds true, even today)
Systemd, as it stands, goes completely against that philosophy. I blame Linus because he knew systemd was shit but let it into the kernel anyway. As a result most major distros now use systemd. Systemd is still far from being the solid rock that sysinit still is. Sure, I could list other issues I see with Linux, such as audio (which I also blame on the hardware manufacturers but this particular issue lies with the same creator who created systemd) or the politics in Linux Kernel Development.
Addtional problems with the kernel lie with Digital-Rights-Management which I also blame on Linus. DRM is the bane of the FLOSS movement and community. Why even support Open Source if what is driving Open Source is being subverted with DRM? DRM is so embedded in the Linux kernel that removing it at this point would be a complete clusterfuck.
I could go on and on and on about the Linux kernel.
Linus is to blame for a lot of this but I blame the community for most of this. Without any real leadership (except for the big money corporate donors pouring money into the Linux Foundation), the kernel is a reflection of the community: fragmented and discombobulated. FLOSS was supposed to represent both equality and freedom. Free as in free beer, free coffee. Libre as in liberated, liberal. FLOSS was supposed to level the playing field between the haves and the have nots. The movement, the philosophy have not lived up to their promises or expectations. By becoming a corporate whore, the Linux Foundation lost site of its vision a long time ago. These same corporations that donate to the Linux Foundation have abused Open Source developers. They have taken what is known as the Open Source Initiative and turned it into something it was not meant for: free labor, among other things.
Many of the distros and many of the sites that I used to traverse I no longer do because these communties have become infected with far-right conspiracy theorists (a.k.a. Truth-Seekers or QAnon). It doesn't matter where you go on the web, these idiots are there. Again, I blame Linus. Why? He could've shown leadership. He could've said "Hey this does not reflect me, our community, or our values." But he did not. Granted, noobs used to be "challenged" by the community to "search and figure it out" or "RTFM" but those days of being henpecked by those who considered themselves to be "*nix gurus" have long since vanished. These "gurus" have been replaced by those with a covert political agenda. I've seen idiotic, bullshit comments such as "If you didn't vote for Trump you must be a Windows user." or "The government uses Windows to spy on you." Don't get me started on Bill Gates and anti-vaxers.
What about Richard Stallman, though? I'm glad he's gone. He was part of the problem.
0 notes
awsexchage · 7 years ago
Photo
Tumblr media
Docker + Alpine Linux + nginx導入手順 https://ift.tt/2NHBIZ5
DockerでAlpine Linuxイメージ上にnginxを導入する手順を示す。
Alpine Linuxイメージ入手
% docker pull alpine Using default tag: latest latest: Pulling from library/alpine 8e3ba11ec2a2: Pull complete Digest: sha256:7043076348bf5040220df6ad703798fd8593a0918d06d3ce30c6c93be117e430 Status: Downloaded newer image for alpine:latest % docker images REPOSITORY TAG IMAGE ID CREATED SIZE alpine latest 11cd0b38bc3c 3 days ago 4.41MB
デーモンとして起動
ここではローカルの8080ポートをDockerコンテナの80ポートに接続する。
% docker run -itd -p 8080:80 11cd0b38bc3c 692b51724e157c4bc85fa87dd8df9393fbecc8c22e192b63e8b52fa7ef8b87cb
事前準備(update & rc-status導入)
% docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 58ff8b32b34a 11cd0b38bc3c "/bin/sh" 56 seconds ago Up 54 seconds 0.0.0.0:8080->80/tcp youthful_joliot % docker exec -it 58ff8b32b34a sh # apk update fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz v3.8.0-7-gae564a61dc [http://dl-cdn.alpinelinux.org/alpine/v3.8/main] v3.8.0-4-gc5ede23c7e [http://dl-cdn.alpinelinux.org/alpine/v3.8/community] OK: 9532 distinct packages available # apk add openrc (1/1) Installing openrc (0.35.5-r4) Executing openrc-0.35.5-r4.post-install Executing busybox-1.28.4-r0.trigger OK: 8 MiB in 16 packages
nginx導入
# apk add nginx (1/2) Installing pcre (8.42-r0) (2/2) Installing nginx (1.14.0-r0) Executing nginx-1.14.0-r0.pre-install Executing busybox-1.28.4-r0.trigger OK: 6 MiB in 15 packages
パッケージをインストールしただけではnginxは動作しないので、以下いくつかのファイルを変更する。
/etc/rc.conf
# sed -i'.bak' 's/^#rc_sys=""/rc_sys="lxc"/' /etc/rc.conf # sed -i 's/^#rc_provide="!net"/rc_provide="loopback net"/' /etc/rc.conf
/etc/inittab
# sed -i'.bak' '/getty/d' /etc/inittab
/lib/rc/sh/init.sh
# sed -i'.bak' 's/mount -t tmpfs/# mount -t tmpfs/' /lib/rc/sh/init.sh
/etc/init.d/hostname
# sed -i'.bak' 's/hostname $opts/# hostname $opts/' /etc/init.d/hostname
/lib/rc/sh/openrc-run.sh
# sed -i'.bak' 's/cgroup_add_service$/# cgroup_add_service/' /lib/rc/sh/openrc-run.sh
openrc用のファイルを用意
# mkdir /run/openrc # touch /run/openrc/softlevel
最後にnginxの設定ファイルを変更し、/にアクセスした際にindex.htmlを返すようにする。
# sed -i'.bak' 's/return 404;/root html;\n\t\tindex index.html;/' /etc/nginx/conf.d/default.conf
設定変更が終わったらnginxを起動する。
# rc-status * Caching service dependencies ... [ ok ] Runlevel: sysinit Dynamic Runlevel: hotplugged Dynamic Runlevel: needed/wanted Dynamic Runlevel: manual # rc-service nginx checkconfig * Checking nginx configuration ... * /run/nginx: creating directory * /run/nginx: correcting owner [ ok ] # rc-service nginx start * Starting nginx ... [ ok ] # ps -ef | grep nginx 207 root 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf 208 nginx 0:00 nginx: worker process 209 nginx 0:00 nginx: worker process 210 nginx 0:00 nginx: worker process 211 nginx 0:00 nginx: worker process
nginxが起動したらブラウザでlocalhost:8080にアクセスして以下のページが表示されればよい。
Welcome to nginx! If you see this page, the nginx web server is successfully installed and working. Further configuration is required. For online documentation and support please refer to nginx.org. Commercial support is available at nginx.com. Thank you for using nginx.
元記事はこちら
「Docker + Alpine Linux + nginx導入手順」
July 24, 2018 at 02:00PM
0 notes
yingchuanjienai · 8 years ago
Text
shooting.h
////////////////////////////////////////////////////////// // プリプロセッサ ////////////////////////////////////////////////////////// #define PI 3.141592653589793 // 円周率 #define SLEEP_TIME  40  // スリープタイムms #define SCREENSIZEX  70  // スクリーンサイズx #define SCREENSIZEY  23  // スクリーンサイズy #define SPEED_MYPLANE 1.0  // 自機のスピード #define MSLNUM   32  // 攻撃の最大数 #define SPEED_MSL  1.0  // 攻撃のスピード #define ENENUM   64  // 敵の最大数 #define ENE_INCIDENCE 10  // 敵の発生率 #define MYHITPOINT  50  // 自機のヒットポイント
////////////////////////////////////////////////////////// // プロトタイプ ////////////////////////////////////////////////////////// void SysInit(void); void GameInit(void); void KeyScan(void); void MoveMyPlane(void); void AttackMyPlane(void); void DrawMyPlane(void); void DrawMissile(void); void RegistEnemy(void); void DrawEnemy(void); void Judge(void); void EnemyAttack(void);  // 敵の攻撃 void DrawEnemyAttack(void); // 敵の攻撃描画
////////////////////////////////////////////////////////// // グローバル ////////////////////////////////////////////////////////// CConsole g_cnsl;   // コンソール・クラスのオブジェクト int score;
// 自機 typedef struct {  double x;  double y;  int hp; }MYPLANE; MYPLANE mp;
// 攻撃テーブル typedef struct {  bool flg;   // フラグ  double x;   // x  double y;   // y  double v;   // 角度 }MISSILE; MISSILE msl[MSLNUM]; // プレイヤーのミサイルテーブル MISSILE emsl[MSLNUM]; // 敵のミサイルテーブル
// 敵のテーブル typedef struct {  bool flg;   // フラグ  unsigned type;  // 種別  double x;   // 座標x  double y;   // 座標y  double v;   // 角度  double spd;   // スピード  double hp;   // ヒットポイント }ENEMY; ENEMY enemy[ENENUM];
// KEYS構造体(キー入力で使用) typedef struct {  bool mKeyLEFT;     // 「←」キー  bool mKeyRIGHT;     // 「→」キー  bool mKeyUP;     // 「↑」キー  bool mKeyDOWN;     // 「↓」キー  bool mKeyENTER;     // 「Enter」  bool mKeySHIFT;     // 「SHIFT」  bool mKeySPACE;     // 「Space」  bool mKeyZ;  bool mKeyALLFALSE;    // どのキーも押されていない }KEYS; static KEYS mKeys;
0 notes
daengkhao · 8 years ago
Text
Sysadmin Diaries - Day 18
Today’s quick tip,checking for critical security patches. Today I was checking some RHEL servers for security fixes that could be applied. Here’s how I did it.
For RHEL 6 , need to check yum-security-plugin is installed (for RHEL 7 it has been incorporated into yum)
#rpm -qa | grep yum-plugin-security yum-plugin-security-1.1.30-14.el6.noarch
Check for critical security updates
# yum --security --sec-severity=Critical check-update Loaded plugins: package_upload, product-id, security, subscription-manager This system is receiving updates from Red Hat Subscription Management. rhel-6-server-rpms | 2.0 kB 00:00 rhel-6-server-rpms/primary | 29 MB 00:00 rhel-6-server-rpms 18431/18431 Limiting package lists to security relevant ones rhel-6-server-rpms/updateinfo | 3.3 MB 00:00 23 package(s) needed for security, out of 585 available glibc.i686 2.12-1.192.el6 rhel-6-server-rpms glibc.x86_64 2.12-1.192.el6 rhel-6-server-rpms glibc-common.x86_64 2.12-1.192.el6 rhel-6-server-rpms glibc-devel.x86_64 2.12-1.192.el6 rhel-6-server-rpms glibc-headers.x86_64 2.12-1.192.el6 rhel-6-server-rpms java-1.6.0-openjdk.x86_64 1:1.6.0.41-1.13.13.1.el6_8 rhel-6-server-rpms java-1.7.0-openjdk.x86_64 1:1.7.0.121-2.6.8.1.el6_8 rhel-6-server-rpms libsmbclient.x86_64 3.6.23-36.el6_8 rhel-6-server-rpms nscd.x86_64 2.12-1.192.el6 rhel-6-server-rpms nspr.x86_64 4.11.0-1.el6 rhel-6-server-rpms nss.x86_64 3.21.3-2.el6_8 rhel-6-server-rpms nss-sysinit.x86_64 3.21.3-2.el6_8 rhel-6-server-rpms nss-tools.x86_64 3.21.3-2.el6_8 rhel-6-server-rpms nss-util.x86_64 3.21.3-1.el6_8 rhel-6-server-rpms ruby.x86_64 1.8.7.374-4.el6_6 rhel-6-server-rpms ruby-libs.x86_64 1.8.7.374-4.el6_6 rhel-6-server-rpms samba.x86_64 3.6.23-36.el6_8 rhel-6-server-rpms samba-client.x86_64 3.6.23-36.el6_8 rhel-6-server-rpms samba-common.x86_64 3.6.23-36.el6_8 rhel-6-server-rpms samba-winbind.x86_64 3.6.23-36.el6_8 rhel-6-server-rpms samba-winbind-clients.x86_64 3.6.23-36.el6_8 rhel-6-server-rpms samba4-libs.x86_64 4.2.10-7.el6_8 rhel-6-server-rpms xulrunner.x86_64 17.0.10-1.el6_4 rhel-6-server-rpms
To find the advisory references
# yum --sec-severity=Critical updateinfo list Loaded plugins: package_upload, product-id, security, subscription-manager This system is receiving updates from Red Hat Subscription Management. rhel-6-server-rpms | 2.0 kB 0:00 RHSA-2016:0175 Critical/Sec. glibc-2.12-1.166.el6_7.7.i686 RHSA-2016:0175 Critical/Sec. glibc-common-2.12-1.166.el6_7.7.x86_64 RHSA-2016:0175 Critical/Sec. glibc-devel-2.12-1.166.el6_7.7.x86_64 RHSA-2016:0175 Critical/Sec. glibc-headers-2.12-1.166.el6_7.7.x86_64 RHSA-2013:0605 Critical/Sec. java-1.6.0-openjdk-1:1.6.0.0-1.57.1.11.9.el6_4.x86_64 RHSA-2013:0602 Critical/Sec. java-1.7.0-openjdk-1:1.7.0.9-2.3.8.0.el6_4.x86_64 RHSA-2013:0751 Critical/Sec. java-1.7.0-openjdk-1:1.7.0.19-2.3.9.1.el6_4.x86_64 RHSA-2013:0957 Critical/Sec. java-1.7.0-openjdk-1:1.7.0.25-2.3.10.3.el6_4.x86_64 RHSA-2013:1451 Critical/Sec. java-1.7.0-openjdk-1:1.7.0.45-2.4.3.2.el6_4.x86_64 RHSA-2014:0026 Critical/Sec. java-1.7.0-openjdk-1:1.7.0.51-2.4.4.1.el6_5.x86_64 RHSA-2014:0406 Critical/Sec. java-1.7.0-openjdk-1:1.7.0.55-2.4.7.1.el6_5.x86_64 RHSA-2016:0053 Critical/Sec. java-1.7.0-openjdk-1:1.7.0.95-2.6.4.0.el6_7.x86_64 RHSA-2016:0511 Critical/Sec. java-1.7.0-openjdk-1:1.7.0.99-2.6.5.0.el6_7.x86_64 RHSA-2016:0675 Critical/Sec. java-1.7.0-openjdk-1:1.7.0.101-2.6.6.1.el6_7.x86_64 RHSA-2015:0251 Critical/Sec. libsmbclient-3.6.23-14.el6_6.x86_64 RHSA-2016:0611 Critical/Sec. libsmbclient-3.6.23-30.el6_7.x86_64 RHSA-2016:0175 Critical/Sec. nscd-2.12-1.166.el6_7.7.x86_64 RHSA-2014:0917 Critical/Sec. nspr-4.10.6-1.el6_5.x86_64 RHSA-2014:0917 Critical/Sec. nss-3.16.1-4.el6_5.x86_64 RHSA-2014:0917 Critical/Sec. nss-sysinit-3.16.1-4.el6_5.x86_64 RHSA-2014:0917 Critical/Sec. nss-tools-3.16.1-4.el6_5.x86_64 RHSA-2014:0917 Critical/Sec. nss-util-3.16.1-1.el6_5.x86_64 RHSA-2013:1764 Critical/Sec. ruby-1.8.7.352-13.el6.x86_64 RHSA-2013:1764 Critical/Sec. ruby-libs-1.8.7.352-13.el6.x86_64 RHSA-2015:0251 Critical/Sec. samba-3.6.23-14.el6_6.x86_64 RHSA-2016:0611 Critical/Sec. samba-3.6.23-30.el6_7.x86_64 RHSA-2015:0251 Critical/Sec. samba-client-3.6.23-14.el6_6.x86_64 RHSA-2016:0611 Critical/Sec. samba-client-3.6.23-30.el6_7.x86_64 RHSA-2015:0251 Critical/Sec. samba-common-3.6.23-14.el6_6.x86_64 RHSA-2016:0611 Critical/Sec. samba-common-3.6.23-30.el6_7.x86_64 RHSA-2015:0251 Critical/Sec. samba-winbind-3.6.23-14.el6_6.x86_64 RHSA-2016:0611 Critical/Sec. samba-winbind-3.6.23-30.el6_7.x86_64 RHSA-2015:0251 Critical/Sec. samba-winbind-clients-3.6.23-14.el6_6.x86_64 RHSA-2016:0611 Critical/Sec. samba-winbind-clients-3.6.23-30.el6_7.x86_64 RHSA-2015:0250 Critical/Sec. samba4-libs-4.0.0-66.el6_6.rc4.x86_64 RHSA-2013:0614 Critical/Sec. xulrunner-17.0.3-2.el6_4.x86_64 RHSA-2013:0696 Critical/Sec. xulrunner-17.0.5-1.el6_4.x86_64 RHSA-2013:0820 Critical/Sec. xulrunner-17.0.6-2.el6_4.x86_64 RHSA-2013:0981 Critical/Sec. xulrunner-17.0.7-1.el6_4.x86_64 RHSA-2013:1140 Critical/Sec. xulrunner-17.0.8-3.el6_4.x86_64 RHSA-2013:1268 Critical/Sec. xulrunner-17.0.9-1.el6_4.x86_64 RHSA-2013:1476 Critical/Sec. xulrunner-17.0.10-1.el6_4.x86_64 updateinfo list done
To find out detailed information about an update
#yum updateinfo RHSA-2016:0175 Loaded plugins: package_upload, product-id, security, subscription-manager This system is receiving updates from Red Hat Subscription Management. rhel-6-server-rpms | 2.0 kB 00:00 =============================================================================== Critical: glibc security and bug fix update =============================================================================== Update ID : RHSA-2016:0175 Release : Type : security Status : final Issued : 2016-02-16 00:00:00 Bugs : 1293532 - CVE-2015-7547 glibc: getaddrinfo stack-based buffer overflow CVEs : CVE-2015-7547 Description : The glibc packages provide the standard C libraries (libc), etc :
Bye!
0 notes
yingchuanjienai · 8 years ago
Text
main .cpp
#include <stdio.h> #include <conio.h> #include <math.h> #include "Console.h" #include "shooting.h"
////////////////////////////////////////////////////////// // メインエントリ ////////////////////////////////////////////////////////// void main(void) {  SysInit();  // 初期化する  GameInit();
 // メインループ  for(;mp.hp>0;Sleep(SLEEP_TIME)) // SLEEP調整  {   g_cnsl.Clear();  // 画面クリア   KeyScan();   // キー入力
  // 内部処理   MoveMyPlane();  // 自機の移動   AttackMyPlane(); // 自機の攻撃   RegistEnemy();  // 敵の発生   EnemyAttack();  // 敵の攻撃
  // 判定   Judge();
  // 描画   DrawEnemyAttack(); // 敵の攻撃描画   DrawEnemy();  // 敵の描画   DrawMissile();  // 攻撃の描画   DrawMyPlane();  // 自機の描画
  // スコアとか   g_cnsl.SetCursorPosition(10, 0);   g_cnsl.SetColor(H_WHITE, L_BLACK);   printf("HP : %d/%d \t SCORE : %d", mp.hp, MYHITPOINT, score);
   // 操作説明   g_cnsl.SetCursorPosition(10, 24);   g_cnsl.SetColor(H_WHITE, L_BLACK);   printf("Move=Arrow / Shoot=Z");  }
 g_cnsl.SetCursorPosition(SCREENSIZEX/2, SCREENSIZEY/2);  g_cnsl.SetColor(H_WHITE, L_BLACK);  printf("GAME OVER");
 fflush(stdin); }
////////////////////////////////////////////////////////// // 敵の攻撃 ////////////////////////////////////////////////////////// void EnemyAttack(void) {  int i, j;
 // 敵のミサイルの登録  for(i=0 ; i<ENENUM ; i++){ // それぞれの   if(enemy[i].flg){   // 画面上の敵に対して    if(rand()%100 < 1){   // 攻撃率     for(j=0 ; j<MSLNUM ; j++) if(!emsl[j].flg){ // あいてるところを探して      emsl[j].flg = true;   // ひとつ登録      emsl[j].x = enemy[i].x;  // x座標      emsl[j].y = enemy[i].y;  // y座標      emsl[j].v = atan2(mp.y-enemy[i].y, mp.x-enemy[i].x); // ラジアンで狙いうち      break; // ひとつ登録したらOK     }    }   }  } }
////////////////////////////////////////////////////////// // 敵の攻撃描画 ////////////////////////////////////////////////////////// void DrawEnemyAttack(void) {  int i;
 for(i=0 ; i<MSLNUM ; i++){   if(emsl[i].flg){    // 描画    g_cnsl.SetCursorPosition((int)emsl[i].x, (int)emsl[i].y);    g_cnsl.SetColor(L_WHITE, L_BLACK);    printf("o");
   // 移動    emsl[i].x += cos(emsl[i].v) * 1.0;    emsl[i].y += sin(emsl[i].v) * 1.0;    if(emsl[i].x < 0 || emsl[i].x > SCREENSIZEX || emsl[i].y < 0 || emsl[i].y > SCREENSIZEY) emsl[i].flg = false;   }
 } }
////////////////////////////////////////////////////////// // あたり判定 ////////////////////////////////////////////////////////// void Judge(void) {  int i,j;  // 敵と自機  for(i=0 ; i<ENENUM ; i++){   if(enemy[i].flg){    if(fabs(mp.x-enemy[i].x) < 1.0 && fabs(mp.y-enemy[i].y) < 1.0){     mp.hp -= (enemy[i].type+1)*10;     enemy[i].flg = false;    }   }  }
 // 敵の攻撃と自機  for(i=0 ; i<MSLNUM ; i++){   if(emsl[i].flg){    if(fabs(mp.x-emsl[i].x) < 1.0 && fabs(mp.y-emsl[i].y) < 1.0){     mp.hp--;     emsl[i].flg = false;    }   }  }
 // 攻撃と敵  for(i=0 ; i<ENENUM ; i++){   if(enemy[i].flg){    for(j=0 ; j<MSLNUM ; j++){     if(msl[j].flg){      if(fabs(msl[j].x-enemy[i].x) < 1.0 && fabs(msl[j].y-enemy[i].y) < 1.0){       enemy[i].hp--;       msl[j].flg = false;      }     }    }    if(enemy[i].hp <= 0){     score += (enemy[i].type+1)*100;     enemy[i].flg = false;    }   }  }
 // 判定の結果、もし自機のHPが負の数になった場合は0にしとく  if(mp.hp < 0) mp.hp = 0; }
////////////////////////////////////////////////////////// // 敵の移動と描画 ////////////////////////////////////////////////////////// void DrawEnemy(void) {  int i;  char e = 'V';  for(i=0 ; i<ENENUM ; i++){   if(enemy[i].flg){    // 描画    g_cnsl.SetCursorPosition((int)enemy[i].x, (int)enemy[i].y);    g_cnsl.SetColor(enemy[i].type+10, L_BLACK);    printf("%c", e+enemy[i].type);
   // 移動    enemy[i].x += cos(enemy[i].v) * enemy[i].spd;    enemy[i].y += sin(enemy[i].v) * enemy[i].spd;    if(enemy[i].x < 0 || enemy[i].x > SCREENSIZEX || enemy[i].y < 0 || enemy[i].y > SCREENSIZEY) enemy[i].flg = false;   }  } }
////////////////////////////////////////////////////////// // 敵の発生 ////////////////////////////////////////////////////////// void RegistEnemy(void) {  int i;  if(rand()%100 < ENE_INCIDENCE){   for(i=0 ; i<ENENUM ; i++){    if(!enemy[i].flg){     enemy[i].flg = true;     enemy[i].x = rand()%SCREENSIZEX;     enemy[i].y = 0;     enemy[i].type = rand()%3;     enemy[i].hp = 1 + enemy[i].type;     enemy[i].spd = (double)(50+rand()%150)/1000;     enemy[i].v = (45+rand()%90) * PI /180.0; // ラジアンで     break;    }   }  } }
////////////////////////////////////////////////////////// // 攻撃の移動と描画 ////////////////////////////////////////////////////////// void DrawMissile(void) {  int i;  for(i=0 ; i<MSLNUM ; i++){   if(msl[i].flg){
   // 描画    g_cnsl.SetCursorPosition((int)msl[i].x, (int)msl[i].y);    g_cnsl.SetColor(H_YELLOW, L_BLACK);    printf(":");
   // 移動    if(msl[i].y > 0) msl[i].y -= SPEED_MSL;    else msl[i].flg = false;   }  }
}
////////////////////////////////////////////////////////// // 自機の攻撃 ////////////////////////////////////////////////////////// void AttackMyPlane(void) {  int i;  if(mKeys.mKeyZ){   for(i=0 ; i<MSLNUM ; i++){    if(!msl[i].flg){     msl[i].flg = true;     msl[i].x = mp.x;     msl[i].y = mp.y - 1;     break;    }   }  } }
////////////////////////////////////////////////////////// // 自機の描画 ////////////////////////////////////////////////////////// void DrawMyPlane(void) {  g_cnsl.SetCursorPosition((int)mp.x, (int)mp.y);  g_cnsl.SetColor(H_GREEN, L_BLACK);  printf("A"); }
////////////////////////////////////////////////////////// // 自機の移動 ////////////////////////////////////////////////////////// void MoveMyPlane(void) {  if(mKeys.mKeyRIGHT && mp.x<SCREENSIZEX) mp.x+=SPEED_MYPLANE;  if(mKeys.mKeyLEFT && mp.x>0)   mp.x-=SPEED_MYPLANE;  if(mKeys.mKeyDOWN && mp.y<SCREENSIZEY) mp.y+=SPEED_MYPLANE;  if(mKeys.mKeyUP && mp.y>1)    mp.y-=SPEED_MYPLANE; }
////////////////////////////////////////////////////////// // ゲームの初期化 ////////////////////////////////////////////////////////// void GameInit(void) {  int i;
 // 自機の初期化  mp.x = SCREENSIZEX/2;  mp.y = SCREENSIZEY-2;  mp.hp = MYHITPOINT;
 // ミサイルテーブルの初期化  for(i=0 ; i<MSLNUM ; i++) msl[i].flg = false; // プレイヤ  for(i=0 ; i<MSLNUM ; i++) emsl[i].flg = false; // 敵
 // 敵テーブルの初期化  for(i=0 ; i<ENENUM ; i++) enemy[i].flg = false;
 // スコアの初期化  score = 0;
}
////////////////////////////////////////////////////////// // システムの初期化 ////////////////////////////////////////////////////////// void SysInit(void) {  // カーソルを消す  g_cnsl.SetCursorInfo(25, FALSE); }
////////////////////////////////////////////////////////// // キー入力 ////////////////////////////////////////////////////////// void KeyScan(void) {  if(GetAsyncKeyState(VK_LEFT) < 0) mKeys.mKeyLEFT = TRUE; else mKeys.mKeyLEFT = FALSE;  if(GetAsyncKeyState(VK_RIGHT) < 0) mKeys.mKeyRIGHT = TRUE; else mKeys.mKeyRIGHT = FALSE;  if(GetAsyncKeyState(VK_UP) < 0) mKeys.mKeyUP = TRUE;  else mKeys.mKeyUP=FALSE;  if(GetAsyncKeyState(VK_DOWN) < 0) mKeys.mKeyDOWN = TRUE; else mKeys.mKeyDOWN=FALSE;  if(GetAsyncKeyState(VK_SHIFT) < 0) mKeys.mKeySHIFT =TRUE; else mKeys.mKeySHIFT=FALSE;  if(GetAsyncKeyState(VK_SPACE) < 0) mKeys.mKeySPACE =TRUE; else mKeys.mKeySPACE=FALSE;  if(GetAsyncKeyState('Z') < 0) mKeys.mKeyZ =TRUE;   else mKeys.mKeyZ=FALSE; }
0 notes