赞 | 12 |
VIP | 107 |
好人卡 | 6 |
积分 | 4 |
经验 | 31122 |
最后登录 | 2024-6-29 |
在线时间 | 1606 小时 |
Lv2.观梦者 傻♂逼
- 梦石
- 0
- 星屑
- 374
- 在线时间
- 1606 小时
- 注册时间
- 2007-3-13
- 帖子
- 6562
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 yangff 于 2011-5-9 22:02 编辑
直接上代码
在RM里面用《快速存储Bitmap的Marshal》By 61
C++
int * hBitmap;
void xxx(int bitmap,int width,int height){
hBitmap=(int*)bitmap;
}
要用的时候就
hBitmap[y*width+x]=color
欢迎蛋疼
PS:hBitmap是上下颠倒的= =
PPS:府上一段生命游戏求检测……不知道为什么,几个常数怎么调都不对……#¥T#T¥·T- $LifeBitmapLonely=true
- #APIs
- class LifeAPI<Win32API
- def initialize(func,inp="",out="")
- super("LifeGame",func,inp,out)
- end
- end
- module LifeGame
- StartGame=LifeAPI.new("startGame","lll","l")
- NextGame=LifeAPI.new("nextGame")
- SetXY=LifeAPI.new("setXY","ll")
- ExitGame=LifeAPI.new("exitGame")
- end
- class LifeBitmap < Bitmap
- include LifeGame
- def initialize(width,height)
- if $LifeBitmapLonely
- $LifeBitmapLonely=false
- end
- super(width,height)
- StartGame.call(width,height,address)
- end
- def dispose
- $LifeBitmapLonely=true
- ExitGame.call
- super
- end
- def update
- NextGame.call
- end
- def setXY(x,y)
- SetXY.call(x,y)
- end
- end
- $s=Sprite.new
- $s.z=999
- $s.bitmap=LifeBitmap.new(32,32)
- $s.zoom_x=10
- $s.zoom_y=10
- while true
- $s.bitmap.update
- Graphics.wait(1)
- Mouse.update
- pos=Mouse.pos
- if not pos.nil?
- if (pos[0]<320) and (pos[1]<320)
- pos[0]/=10
- pos[1]/=10
- $s.bitmap.setXY(*pos)
- # for i in 0...60
- # Mouse.update
- # Graphics.update
- # end
- end
- end
- end
复制代码- // LifeGame.cpp : 定义 DLL 应用程序的导出函数。
- //
- #include "stdafx.h"
- #define Live 0xFF00FFFF
- #define Death 0xFFFF0000
- int dir[8][2]={{-1, -1}, {-1, 0}, {-1,1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}};
- int mWidth=0;
- int mHeight=0;
- int* bitHandle=0;
- int* map;
- bool playing=false;
- /* 0 1 2 3 4 mw-1
- x 0
- y 1
- 2
- 3
- 4
- mh-1
- */
- int xyth(int x,int y)
- {
- return (mHeight-1-y)*mWidth+x;
- }
- int startGame(int width,int height,int hbitmap)
- {
- playing=true;
- srand((unsigned)time(NULL));
- //int a[width*height]={};
- map=new int[width*height+1];
- mWidth=width;
- mHeight=height;
- bitHandle=(int*)hbitmap;
- //Init map
- for (int i=0;i<width*height;i++)
- {
- if ((rand()%1)==0)
- {
- bitHandle[i]=Live;
- map[i]=Live;
- }
- else
- {
- bitHandle[i]=Death;
- map[i]=Death;
- }
- }
- return true;
- }
- void nextGame()
- {
- if (!playing) return;
- int count=0;
-
- for (int y=1;y<mHeight-1;y++)
- for (int x=1;x<mWidth-1;x++)
- {
- count=0;
- /* for (int c=0;c<8;c++)
- {
- int x1=x+dir[c][0];
- int y1=y+dir[c][1];
- //if ((((y+dir[c][1])<0)||((y+dir[c][1])>mHeight)) || (((x+dir[c][0])<0)||((x+dir[c][0])>mWidth)))
- if (((x1<0)||(x1>mWidth))||((y1<0)||(y1>mHeight)))
- {count+=1;
- continue ;}
- //if (xyth(x1,y1)<mWidth*mHeight){
- if (bitHandle[xyth(x1,y1)]==Live){ count+=1;}//}
- }*/
- if (bitHandle[xyth(x-1,y)]==Live)count++;
- if (bitHandle[xyth(x-1,y-1)]==Live)count++;
- if (bitHandle[xyth(x-1,y+1)]==Live)count++;
- if (bitHandle[xyth(x,y-1)]==Live)count++;
- if (bitHandle[xyth(x,y+1)]==Live)count++;
- if (bitHandle[xyth(x+1,y)]==Live)count++;
- if (bitHandle[xyth(x+1,y-1)]==Live)count++;
- if (bitHandle[xyth(x+1,y+1)]==Live)count++;
- if (count>5) map[xyth(x,y)]=Live;
- if (count<5) map[xyth(x,y)]=Death;
- }
- for (int i=0;i<mWidth*mHeight;i++)
- bitHandle[i]=map[i];
- }
- void setXY(int x,int y)
- {
- int c=xyth(x,y);
- if (map[c]==Live) {map[c]= Death;}
- else{
- map[c]=Live;}
- bitHandle[c]=map[c];
- }
- void exitGame()
- {
- playing=false;
- }
复制代码 |
|